Skip to content

Commit

Permalink
Bug 1551447 [wpt PR 16451] - Update noopener tests to match spec rule…
Browse files Browse the repository at this point in the history
…s for choosing a browsing con…, a=testonly

Automatic update from web-platform-tests
HTML: correct noopener tests

In particular, if a name is given use that first and potentially reuse a window.

Closes whatwg/html#1826.
--

wpt-commits: 0c79d0d99c720f679fa089374971778e461e6662
wpt-pr: 16451

UltraBlame original commit: f2b4dc0d863dcdd1768145f1fa83462cf9a9271c
  • Loading branch information
marco-c committed Oct 4, 2019
1 parent c8277cb commit 0d045e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@
<script src=/resources/testharnessreport.js></script>
<script>
var testData = [
{ testDescription: "window.open() with 'noopener' should not reuse existing target",
{ testDescription: "window.open() with 'noopener' should reuse existing target",
secondWindowFeatureString: "noopener",
shouldReuse: false },
shouldReturnWindow: false },
{ testDescription: "noopener=1 means the same as noopener",
secondWindowFeatureString: "noopener=1",
shouldReuse: false },
shouldReturnWindow: false },
{ testDescription: "noopener=0 means lack of noopener",
secondWindowFeatureString: "noopener=0",
shouldReuse: true },
{ testDescription: "noopener needs to be present as a token on its own",
shouldReturnWindow: true },
{ testDescription: "noopener separated only by spaces should work",
secondWindowFeatureString: "make me noopener",
shouldReuse: true },
shouldReturnWindow: false },
{ testDescription: "Trailing noopener should work",
secondWindowFeatureString: "abc def, \n\r noopener",
shouldReuse: false },
shouldReturnWindow: false },
{ testDescription: "Leading noopener should work",
secondWindowFeatureString: "noopener \f\t , hey, there",
shouldReuse: false },
shouldReturnWindow: false },
{ testDescription: "Interior noopener should work",
secondWindowFeatureString: "and now, noopener , hey, there",
shouldReuse: false },
shouldReturnWindow: false },
{ testDescription: "noreferrer should also suppress opener when reusing existing target",
secondWindowFeatureString: "noreferrer",
shouldReturnWindow: false },
];

/**
Expand All @@ -54,7 +57,7 @@
t.secondWindowFeatureString = test.secondWindowFeatureString;
t.windowName = "someuniquename" + i;

if (test.shouldReuse) {
if (test.shouldReturnWindow) {
t.step(function() {
var windowName = this.windowName;

Expand Down Expand Up @@ -83,9 +86,9 @@
channel.onmessage = this.step_func_done(function(e) {
var data = e.data;
assert_equals(data.name, windowName, "Should have the right name");
assert_equals(data.haveOpener, false, "Should not have opener");
assert_equals(data.haveOpener, true, "Should still have opener");
assert_equals(w1.opener, window);
assert_equals(w1.location.href, "about:blank");
assert_not_equals(w1.location.href, "about:blank", "Should have navigated");
});

w1 = window.open("", windowName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,41 @@

/**
* And now check that a noopener load targeted at something other than one of
* the three special targets above in fact ignores existing things with the
* the three special targets above is still able to reuse existing things with the
* given name. We do this in two ways. First, by opening a window named
* "ourpopup" and then doing a load via <a rel="noopener" target="ourpopup"> and
* verifying that the load happens in a window with a null opener, etc, while
* the opener of the thing we opened is not modified. And second, by targeting
* <a rel="noopener"> at a name that an existing subframe has, and ensuring that
* this subframe is not navigated.
*/
var t1 = async_test("Check that targeting of rel=noopener with a given name ignores an existing window with that name");
var t1 = async_test("Check that targeting of rel=noopener with a given name reuses an existing window with that name");
var w;
t1.add_cleanup(function() { w.close(); });
var channel = new BroadcastChannel("ourpopup");
channel.onmessage = t1.step_func_done(function(e) {
var data = e.data;
assert_false(data.hasOpener);
assert_true(data.hasOpener);
assert_false(data.hasParent);
assert_equals(data.name, "ourpopup");
assert_equals(w.opener, window);
assert_equals(w.location.href, "about:blank");
assert_not_equals(w.location.href, "about:blank");
});
t1.step(function() {
w = window.open("", "ourpopup");
assert_equals(w.opener, window);
document.querySelectorAll("a")[0].click();
});

var t2 = async_test("Check that targeting of rel=noopener with a given name ignores an existing subframe with that name");
var t2 = async_test("Check that targeting of rel=noopener with a given name reuses an existing subframe with that name");
var channel = new BroadcastChannel("oursubframe");
channel.onmessage = t2.step_func_done(function(e) {
var data = e.data;
assert_false(data.hasOpener);
assert_false(data.hasParent);
assert_true(data.hasParent);
assert_equals(data.name, "oursubframe");
assert_equals(document.querySelector("iframe").contentWindow.location.href,
"about:blank");
assert_not_equals(document.querySelector("iframe").contentWindow.location.href,
"about:blank");
});
t2.step(function() {
document.querySelectorAll("a")[1].click();
Expand Down

0 comments on commit 0d045e7

Please sign in to comment.