summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts')
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-closed.html31
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-multiple.html35
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-noopener.html25
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-noreferrer.html29
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-setter.html33
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-setter.window.js38
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener.html55
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/close-opener.html30
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/message-window-opener.html14
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/multiple-opener.html32
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/no-opener.html16
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/open-closer.html17
-rw-r--r--testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/opener-setter.html23
13 files changed, 378 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-closed.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-closed.html
new file mode 100644
index 0000000000..106c3f97cb
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-closed.html
@@ -0,0 +1,31 @@
+<!doctype html>
+<meta charset="utf-8">
+<html>
+ <head>
+ <title>Auxiliary Browsing Contexts: window.opener when Opener Removed/Closed</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/common/PrefixedLocalStorage.js"></script>
+ </head>
+ <body>
+ <div id="log"></div>
+ <script>
+ var prefixedLocalStorage;
+ setup (() => prefixedLocalStorage = new PrefixedLocalStorageTest());
+ async_test(t => {
+ t.add_cleanup (() => prefixedLocalStorage.cleanup());
+ var a = document.createElement('a');
+ a.href = prefixedLocalStorage.url('resources/open-closer.html');
+ a.target = '_blank';
+ prefixedLocalStorage.onSet('openerIsNull', t.step_func_done(e => {
+ // The window for this auxiliary browsing context's opener
+ // has been closed and discarded, so the aux browsing context
+ // should now report `null` for `window.opener`
+ assert_equals(e.newValue, 'true');
+ }));
+ document.body.append(a);
+ a.click();
+ }, 'An auxiliary browsing context should report `null` for `window.opener` when that browsing context is discarded');
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-multiple.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-multiple.html
new file mode 100644
index 0000000000..e71d4dc868
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-multiple.html
@@ -0,0 +1,35 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Auxiliary Browsing Contexts: window.opener, multiple</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/common/PrefixedLocalStorage.js"></script>
+ </head>
+ <body>
+ <div id="log"></div>
+ <script>
+ var prefixedLocalStorage;
+ setup (() => prefixedLocalStorage = new PrefixedLocalStorageTest());
+ async_test(t => {
+ t.add_cleanup (() => prefixedLocalStorage.cleanup());
+ var a = document.createElement('a');
+ a.href = prefixedLocalStorage.url('resources/multiple-opener.html');
+ a.target = 'multipleOpener';
+ window.name = 'topOpener';
+ document.body.appendChild(a);
+ window.addEventListener('message', t.step_func_done(e => {
+ var aux1 = e.data.aux1; // First opened context
+ var aux2 = e.data.aux2; // Context opened by first-opened context
+ assert_equals(aux1.name, 'multipleOpener');
+ assert_equals(aux1.openerName, window.name);
+ assert_equals(aux1.isTop, true);
+ assert_equals(aux2.name, 'multipleOpenee');
+ assert_equals(aux2.openerName, aux1.name);
+ assert_equals(aux2.isTop, true);
+ }));
+ a.click();
+ }, 'An auxiliary browsing context should be able to open another auxiliary browsing context');
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-noopener.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-noopener.html
new file mode 100644
index 0000000000..086a96442d
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-noopener.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Auxiliary Browsing Contexts: window.opener noopener</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/common/PrefixedLocalStorage.js"></script>
+ </head>
+ <body>
+ <div id="log"></div>
+ <script>
+ var prefixedLocalStorage;
+ setup(() => prefixedLocalStorage = new PrefixedLocalStorageTest());
+ async_test(t => {
+ t.add_cleanup(() => prefixedLocalStorage.cleanup());
+ prefixedLocalStorage.onSet('openerIsNull', t.step_func_done(e => {
+ assert_equals(e.newValue, 'true');
+ }));
+ window.open(prefixedLocalStorage.url('resources/no-opener.html'),
+ 'iShouldNotHaveAnOpener',
+ 'noopener');
+ }, 'Auxiliary browsing context created via `window.open` setting `noopener` should report `window.opener` `null`');
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-noreferrer.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-noreferrer.html
new file mode 100644
index 0000000000..b8226bd2b9
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-noreferrer.html
@@ -0,0 +1,29 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Auxiliary Browsing Contexts: window.opener noreferrer</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/common/PrefixedLocalStorage.js"></script>
+ </head>
+ <body>
+ <div id="log"></div>
+ <script>
+ var prefixedLocalStorage;
+ setup(() => prefixedLocalStorage = new PrefixedLocalStorageTest());
+ async_test(t => {
+ t.add_cleanup(() => prefixedLocalStorage.cleanup());
+ var a = document.createElement('a');
+ a.href = prefixedLocalStorage.url('resources/no-opener.html');
+ a.target = '_blank';
+ a.rel = 'noreferrer';
+ window.name = 'topWindow';
+ document.body.appendChild(a);
+ prefixedLocalStorage.onSet('openerIsNull', t.step_func_done(e => {
+ assert_equals(e.newValue, 'true');
+ }));
+ a.click();
+ }, 'Auxiliary browsing context created with `rel="noreferrer"` should report `window.opener` `null`');
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-setter.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-setter.html
new file mode 100644
index 0000000000..ac6e47b846
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-setter.html
@@ -0,0 +1,33 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Auxiliary Browsing Contexts: window.opener setter</title>
+ <meta name=timeout content=long>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/common/PrefixedLocalStorage.js"></script>
+ </head>
+ <body>
+ <div id="log"></div>
+ <script>
+ var prefixedLocalStorage;
+ setup(() => prefixedLocalStorage = new PrefixedLocalStorageTest());
+ async_test(t => {
+ t.add_cleanup(() => prefixedLocalStorage.cleanup());
+ prefixedLocalStorage.onSet('openerIsNull', t.step_func_done(e => {
+ assert_equals(e.newValue, 'true');
+ }));
+ window.open(prefixedLocalStorage.url('resources/opener-setter.html'),
+ 'iShouldSetOpenerToNull');
+ }, 'Auxiliary browsing context created via `window.open` and setting `window.opener` to `null` should report `window.opener` `null`');
+ async_test(t => {
+ t.add_cleanup(() => prefixedLocalStorage.cleanup());
+ prefixedLocalStorage.onSet('openerIsTest', t.step_func_done(e => {
+ assert_equals(e.newValue, 'true');
+ }));
+ window.open(prefixedLocalStorage.url('resources/opener-setter.html'),
+ 'iShouldSetOpenerToTest');
+ }, 'Auxiliary browsing context created via `window.open` and setting `window.opener` to `test` should report `test`');
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-setter.window.js b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-setter.window.js
new file mode 100644
index 0000000000..6d540ce97c
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener-setter.window.js
@@ -0,0 +1,38 @@
+[
+ undefined,
+ 42,
+ function() { return "hi" },
+ "hi",
+ {},
+ [],
+ Symbol()
+].forEach(val => {
+ test(t => {
+ const frame = document.body.appendChild(document.createElement("iframe")),
+ win = frame.contentWindow;
+ t.add_cleanup(() => frame.remove());
+
+ assert_own_property(win, "opener");
+ assert_equals(win.opener, null);
+ const beforeDesc = Object.getOwnPropertyDescriptor(win, "opener"),
+ openerGet = beforeDesc.get,
+ openerSet = beforeDesc.set;
+ assert_own_property(beforeDesc, "get");
+ assert_own_property(beforeDesc, "set");
+ assert_true(beforeDesc.enumerable);
+ assert_true(beforeDesc.configurable);
+
+ win.opener = val;
+ assert_equals(win.opener, val);
+ assert_equals(openerGet(), null);
+
+ const desc = Object.getOwnPropertyDescriptor(win, "opener");
+ assert_equals(desc.value, val);
+ assert_true(desc.writable);
+ assert_true(desc.enumerable);
+ assert_true(desc.configurable);
+
+ openerSet("x");
+ assert_equals(win.opener, "x");
+ }, "Setting window.opener to " + String(val)); // String() needed for symbols
+});
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener.html
new file mode 100644
index 0000000000..c43d3bd3bf
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/opener.html
@@ -0,0 +1,55 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Auxiliary Browsing Contexts: window.opener</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/common/PrefixedLocalStorage.js"></script>
+ </head>
+ <body>
+ <div id="log"></div>
+ <script>
+ var prefixedLocalStorage;
+ setup (() => {
+ window.name = 'topWindow';
+ prefixedLocalStorage = new PrefixedLocalStorageTest();
+ });
+
+ function cleanup () {
+ prefixedLocalStorage.setItem('closeAll', 'true');
+ prefixedLocalStorage.clear();
+ }
+
+ function testOpener (t, target) {
+ t.add_cleanup(cleanup);
+ window.addEventListener('message', t.step_func(e => {
+ if (e.data.name === target) {
+ // The opener IDL attribute...must return the WindowProxy object of the
+ // browsing context from which the current browsing context was created
+ assert_equals(e.data.openerName, 'topWindow');
+ // Auxiliary browsing contexts are always top-level browsing contexts
+ assert_equals(e.data.isTop, true);
+ t.done();
+ }
+ }));
+ }
+
+ async_test(t => {
+ var target = 'windowOpenerA';
+ var a = document.createElement('a');
+ a.href = prefixedLocalStorage.url('resources/message-window-opener.html');
+ a.target = target;
+ document.body.appendChild(a);
+ testOpener(t, target);
+ a.click();
+ }, 'Newly-created auxiliary browsing context should report `window.opener`');
+
+ async_test(t => {
+ var target = 'windowOpenerB';
+ testOpener(t, target);
+ window.open(prefixedLocalStorage.url('resources/message-window-opener.html'),
+ target);
+ }, 'Browsing context created with `window.open` should report `window.opener`');
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/close-opener.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/close-opener.html
new file mode 100644
index 0000000000..f41773ed2c
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/close-opener.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<meta charset="utf-8">
+<html>
+<body onload="closeOpener()">
+<p>This window should close its opener.</p>
+<script src="/common/PrefixedLocalStorage.js"></script>
+<script>
+var prefixedLocalStorage = new PrefixedLocalStorageResource({
+ close_on_cleanup: true
+});
+var prefixedLocalStorage = new PrefixedLocalStorageResource({
+ close_on_cleanup: true
+});
+function closeOpener () {
+ if (window.opener) {
+ window.opener.close();
+
+ // Give the browsing context a chance to dispose of itself
+ function waitForContextDiscard () {
+ if (window.opener === null) {
+ return prefixedLocalStorage.setItem('openerIsNull', 'true');
+ }
+ return setTimeout(waitForContextDiscard, 0);
+ }
+ waitForContextDiscard();
+ }
+}
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/message-window-opener.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/message-window-opener.html
new file mode 100644
index 0000000000..8105650b61
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/message-window-opener.html
@@ -0,0 +1,14 @@
+<script src="/common/PrefixedLocalStorage.js"></script>
+<script>
+var prefixedLocalStorage = new PrefixedLocalStorageResource({
+ close_on_cleanup: true
+});
+
+if (window.opener) {
+ window.opener.postMessage ({
+ name : window.name,
+ openerName: window.opener.name,
+ isTop : window.top === window
+ }, '*');
+}
+</script>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/multiple-opener.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/multiple-opener.html
new file mode 100644
index 0000000000..2e63b9f4c6
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/multiple-opener.html
@@ -0,0 +1,32 @@
+<!doctype html>
+<html>
+<script src="/common/PrefixedLocalStorage.js"></script>
+<body onload="openNested()">
+<script>
+var prefixedLocalStorage = new PrefixedLocalStorageResource({
+ close_on_cleanup: true
+});
+function openNested () {
+ // Listen for message from opened context and pass through to this
+ // context's opener
+ window.addEventListener('message', (e) => {
+ if (window.opener) {
+ window.opener.postMessage({
+ aux2: e.data, // From multipleOpenee
+ aux1: { // This context
+ name : window.name,
+ openerName : window.opener.name,
+ isTop : window.top === window
+ }
+ }, '*');
+ }
+ });
+ var a = document.createElement('a');
+ a.target = 'multipleOpenee';
+ a.href = prefixedLocalStorage.url('message-window-opener.html');
+ document.body.appendChild(a);
+ a.click();
+}
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/no-opener.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/no-opener.html
new file mode 100644
index 0000000000..afd72f948d
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/no-opener.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<meta charset="utf-8">
+<html>
+<p>This window should have no opener.</p>
+<script src="/common/PrefixedLocalStorage.js"></script>
+<script>
+var prefixedLocalStorage = new PrefixedLocalStorageResource({
+ close_on_cleanup: true
+});
+function checkOpener () {
+ return prefixedLocalStorage.setItem('openerIsNull', window.opener === null);
+}
+</script>
+<body onload="checkOpener()">
+</body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/open-closer.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/open-closer.html
new file mode 100644
index 0000000000..7575c7c95f
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/open-closer.html
@@ -0,0 +1,17 @@
+<!doctype html>
+<meta charset="utf-8">
+<html>
+<body onload="openAuxiliary()">
+<a rel="opener" target="_blank">Open auxiliary context that will close this window (its opener)</a>
+<script src="/common/PrefixedLocalStorage.js"></script>
+<script>
+function openAuxiliary () {
+ var prefixedLocalStorage = new PrefixedLocalStorageResource();
+ var a = document.body.querySelector('a');
+ a.href = prefixedLocalStorage.url('close-opener.html');
+ document.body.append(a);
+ a.click();
+}
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/opener-setter.html b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/opener-setter.html
new file mode 100644
index 0000000000..4112dae0ce
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/windows/auxiliary-browsing-contexts/resources/opener-setter.html
@@ -0,0 +1,23 @@
+<!doctype html>
+<meta charset="utf-8">
+<html>
+<p>This window should set the window.opener attribute</p>
+<script src="/common/PrefixedLocalStorage.js"></script>
+<script>
+var prefixedLocalStorage = new PrefixedLocalStorageResource({
+ close_on_cleanup: true
+});
+function checkOpener () {
+ if (window.name == 'iShouldSetOpenerToNull') {
+ window.opener = null;
+ return prefixedLocalStorage.setItem('openerIsNull', window.opener === null);
+ }
+ if (window.name == 'iShouldSetOpenerToTest') {
+ window.opener = 'test';
+ return prefixedLocalStorage.setItem('openerIsTest', window.opener === "test");
+ }
+}
+</script>
+<body onload="checkOpener()">
+</body>
+</html>