Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

followup. Fix the timeout on the html/browsers/browsing-the-web/navigating-across-documents/014.html web platform test. #4148

Merged
merged 5 commits into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<iframe id="test" name="test"></iframe>
<form action="javascript:parent.events.push('submit')"></form>
<form target="test" action="javascript:parent.events.push('submit');"></form>
<a target="test" onclick="document.forms[0].submit()">Test</a>
<script>
var t = async_test(undefined, {timeout:4000});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
onload = t.step_func_done(function() {
assert_equals(frames[0].document.documentElement.textContent,
"1", "string return should cause navigation");
// The rest of the test is disabled for now, until
// https://github.com/whatwg/html/issues/1895 gets sorted out
/*
assert_equals(frames[1].document.documentElement.textContent,
"", "number return should not cause navigation");
assert_equals(frames[2].document.documentElement.textContent,
Expand All @@ -28,5 +31,6 @@
"", "null return should not cause navigation");
assert_equals(frames[6].document.documentElement.textContent,
"", "String object return should not cause navigation");
*/
});
</script>
8 changes: 8 additions & 0 deletions html/browsers/the-window-object/support/noopener-target.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<script>
var channelName = location.search.substr(1);
var channel = new BroadcastChannel(channelName);
channel.postMessage({ name: window.name,
haveOpener: window.opener !== null });
window.close();
</script>
105 changes: 105 additions & 0 deletions html/browsers/the-window-object/window-open-noopener.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!doctype html>
<meta charset=utf-8>
<title>window.open() with "noopener" tests</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
var testData = [
{ testDescription: "window.open() with 'noopener' should not reuse existing target",
secondWindowFeatureString: "noopener",
shouldReuse: false },
{ testDescription: "noopener needs to be present as a token on its own",
secondWindowFeatureString: "noopener=1",
shouldReuse: true },
{ testDescription: "noopener needs to be present as a token on its own again",
secondWindowFeatureString: "noopener=0",
shouldReuse: true },
{ testDescription: "noopener needs to be present as a token on its own yet again",
secondWindowFeatureString: "make me noopener",
shouldReuse: true },
{ testDescription: "Trailing noopener should work",
secondWindowFeatureString: "abc def, \n\r noopener",
shouldReuse: false },
{ testDescription: "Leading noopener should work",
secondWindowFeatureString: "noopener \f\t , hey, there",
shouldReuse: false },
{ testDescription: "Interior noopener should work",
secondWindowFeatureString: "and now, noopener , hey, there",
shouldReuse: false },
];

var tests = [];
/**
* Loop over our testData array and kick off an async test for each entry. Each
* async test opens a window using window.open() with some per-test unique name,
* then tries to do a second window.open() call with the same name and the
* test-specific feature string. It then checks whether that second
* window.open() call reuses the existing window, whether the return value of
* the second window.open() call is correct (it should be null in the noopener
* cases and non-null in the cases when the existing window gets reused) and so
* forth.
*/
for (var i = 0; i < testData.length; ++i) {
var test = testData[i];
var t = async_test(test.testDescription);
tests.push(t);
t.secondWindowFeatureString = test.secondWindowFeatureString;
t.windowName = "someuniquename" + i;

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

var w1 = window.open("", windowName);
this.add_cleanup(function() { w1.close(); });

assert_equals(w1.opener, window);

var w2 = window.open("", windowName, this.secondWindowFeatureString);
assert_equals(w2, w1);
assert_equals(w2.opener, w1.opener);
assert_equals(w2.opener, window);
this.done();
});
} else {
t.step(function() {
var w1;
this.add_cleanup(function() { w1.close(); });

var windowName = this.windowName;
var channel = new BroadcastChannel(windowName);

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(w1.opener, window);
assert_equals(w1.location.href, "about:blank");
});

w1 = window.open("", windowName);
assert_equals(w1.opener, window);

var w2 = window.open("support/noopener-target.html?" + windowName,
windowName, this.secondWindowFeatureString);
assert_equals(w2, null);

assert_equals(w1.opener, window);
});
}
}

/**
* Loop over the special targets that ignore noopener and check that doing a
* window.open() with those targets correctly reuses the existing window.
*/
for (var target of ["_self", "_parent", "_top"]) {
var t = async_test("noopener window.open targeting " + target);
tests.push(t);
t.openedWindow = window.open(`javascript:var w2 = window.open("", "${target}", "noopener"); this.checkValues(w2); this.close(); void(0);`);
assert_equals(t.openedWindow.opener, window);
t.openedWindow.checkValues = t.step_func_done(function(win) {
assert_equals(win, this.openedWindow);
});
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!doctype html>
<meta charset=utf-8>
<title>Test behavior of rel="noopener" links</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<iframe name="oursubframe"></iframe>
<a href="support/noopener-target-2.html" rel="noopener" target="ourpopup"></a>
<a href="support/noopener-target-2.html" rel="noopener" target="oursubframe"></a>
<script>
var tests = [];
// First test the special targets
function target1Loaded(win) {
// Find the relevant test
var test = tests.find((t) => t.openedWindow == win);
test.step(function() {
assert_equals(win.opener, window);
win.close();
test.done();
});
}
/**
* Test that <a rel="noopener"> targeted at one of _self, _parent, _top does the
* load in the appropriate existing browsing context instead of opening a new
* one. The test is run in a separate popup window we open and which we can
* navigate without causing the test harness going into conniptions.
*/
for (var target of ["self", "parent", "top"]) {
var t = async_test("Check that rel=noopener with target=_" + target + " does a normal load");
tests.push(t);
t.openedWindow = window.open("support/noopener-popup.html");
t.targetName = target;
t.openedWindow.onload = t.step_func(function() {
this.openedWindow.findLink(this.targetName).click();
});
}

/**
* 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
* 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 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_false(data.hasParent);
assert_equals(data.name, "ourpopup");
assert_equals(w.opener, window);
assert_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 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_equals(data.name, "oursubframe");
assert_equals(document.querySelector("iframe").contentWindow.location.href,
"about:blank");
});
t2.step(function() {
document.querySelectorAll("a")[1].click();
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<script>
function findLink(arg) {
var doc;
if (arg == "self") {
doc = document;
} else {
doc = frames[0].document;
}
return doc.getElementById(arg + "target");
}
</script>
<a rel="noopener" target="_self" id="selftarget"
href="noopener-target-1.html"></a>
<iframe srcdoc='
<a rel="noopener" target="_parent" id="parenttarget"
href="noopener-target-1.html"></a>
<a rel="noopener" target="_top" id="toptarget"
href="noopener-target-1.html"></a>'></iframe>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<script>
opener.target1Loaded(this);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<script>
var channel = new BroadcastChannel(this.name);
channel.postMessage({ hasOpener: opener !== null ,
hasParent: parent != this,
name: window.name });
window.close();
</script>
83 changes: 83 additions & 0 deletions secure-contexts/basic-dedicated-worker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Test WorkerGlobalScope.isSecureContext for HTTP creator</title>
<meta name="help" href="https://w3c.github.io/webappsec-secure-contexts/#monkey-patching-global-object">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="server-locations.sub.js"></script>
</head>
<body>
<script>
var t1 = async_test("HTTP worker");
var t2 = async_test("HTTPS worker");
var t3 = async_test("HTTP nested worker");
var t4 = async_test("HTTPS nested worker");
var t5 = async_test("HTTP worker from HTTPS subframe");
var t6 = async_test("HTTPS worker from HTTPS subframe");

var w1 = new Worker(http_dir + "support/dedicated-worker-script.js");
w1.onmessage = t1.step_func_done(function(e) {
assert_false(e.data);
});
w1.onerror = t1.step_func_done(function(e) {
assert_unreached("isSecureContext should be supported");
});

var w2 = new Worker(https_dir + "support/dedicated-worker-script.js");
w2.onmessage = t2.step_func_done(function(e) {
assert_unreached("cross-origin workers should not be loaded");
});
w2.onerror = t2.step_func_done(function(e) {
e.preventDefault();
});

var w3 = new Worker(http_dir + "support/parent-dedicated-worker-script.js");
w3.onmessage = t3.step_func_done(function(e) {
assert_false(e.data);
});
w3.onerror = t3.step_func_done(function(e) {
assert_unreached("isSecureContext should be supported");
});

var w4 = new Worker(https_dir + "support/parent-dedicated-worker-script.js");
w4.onmessage = t4.step_func_done(function(e) {
assert_unreached("cross-origin workers should not be loaded");
});
w4.onerror = t4.step_func_done(function(e) {
e.preventDefault();
});

onmessage = function(e) {
var data = e.data;
if (data.type == "http") {
t5.step(function() {
assert_true(data.error);
});
t5.done();
} else if (data.type == "https") {
t6.step(function() {
assert_false(data.error);
assert_false(data.isSecureContext);
});
t6.done();
} else {
t5.step(function() {
assert_unreached("Unknown message");
});
t5.done();
t6.step(function() {
assert_unreached("Unknown message");
});
t6.done();
}
}

var ifr = document.createElement("iframe");
ifr.src = https_dir + "support/https-subframe-dedicated.html";
document.body.appendChild(ifr);
</script>
</body>
</html>