Bug 1276738 - Add a test to ensure that we clone sessionStorage when opening new windows. r=gabor
authorMike Conley <mconley@mozilla.com>
Mon, 02 May 2016 17:36:41 -0400
changeset 341222 0997a7d078e2ee01436c24a22cc894589a57f3f8
parent 341221 e5abd4c6319dc6296fa322cac1c4e0f853ae6757
child 341223 695bae385079c1dc5f7e3e805a12815e7ea1da74
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs1276738
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1276738 - Add a test to ensure that we clone sessionStorage when opening new windows. r=gabor MozReview-Commit-ID: B2rLxdpWKOu
embedding/components/windowwatcher/test/file_storage_copied.html
embedding/components/windowwatcher/test/mochitest.ini
embedding/components/windowwatcher/test/test_storage_copied.html
new file mode 100644
--- /dev/null
+++ b/embedding/components/windowwatcher/test/file_storage_copied.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+This page is opened in a new window by test_storage_copied.html.
+We need to return the sessionStorage value for the item "test-item",
+by way of postMessage.
+-->
+<head>
+<body>Opened!</body>
+<script>
+  window.postMessage(window.sessionStorage.getItem("test-item"), "*");
+</script>
+</html>
\ No newline at end of file
--- a/embedding/components/windowwatcher/test/mochitest.ini
+++ b/embedding/components/windowwatcher/test/mochitest.ini
@@ -1,5 +1,8 @@
 [DEFAULT]
 tags = openwindow
 
 [test_blank_named_window.html]
 [test_named_window.html]
+[test_storage_copied.html]
+support-files =
+  file_storage_copied.html
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/embedding/components/windowwatcher/test/test_storage_copied.html
@@ -0,0 +1,45 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test sessionStorage is copied over when a new window opens to the
+same domain as the opener.
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test storage copied</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+  <script src="head.js" type="application/javascript;version=1.8"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+  <script type="application/javascript">
+    "use strict";
+
+    function waitForMessage(win) {
+      return new Promise(resolve => {
+        win.addEventListener("message", function onMessage(event) {
+          win.removeEventListener("message", onMessage);
+          resolve(event.data);
+        });
+      });
+    }
+
+    add_task(function*() {
+      const TEST_VALUE = "test-value";
+      // This magic value of 2 means that by default, when content tries
+      // to open a new window, it'll actually open in a new window instead
+      // of a new tab.
+      yield SpecialPowers.pushPrefEnv({"set": [
+        ["browser.link.open_newwindow", 2],
+      ]});
+
+      window.sessionStorage.setItem("test-item", TEST_VALUE);
+      let win = window.open("file_storage_copied.html", "my_window");
+      let data = yield waitForMessage(win);
+      is(data, TEST_VALUE, "Should have cloned the test value");
+      win.close();
+    });
+  </script>
+</body>
+</html>
\ No newline at end of file