Bug 1318154 test remote iframe in background page, r=aswan draft
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 17 Nov 2016 12:06:22 -0800
changeset 440557 71002713a01942510e8d402136b599fd1634d41b
parent 439734 51750761f2c61c64cf0553f6cb5fefd4999d3bc0
child 537407 faf14cc8544f4e99f408eefed96e1908ec3f12f7
push id36262
push usermixedpuppy@gmail.com
push dateThu, 17 Nov 2016 20:07:20 +0000
reviewersaswan
bugs1318154
milestone53.0a1
Bug 1318154 test remote iframe in background page, r=aswan MozReview-Commit-ID: FuWxJXMyAtZ
toolkit/components/extensions/test/mochitest/file_remote_frame.html
toolkit/components/extensions/test/mochitest/mochitest.ini
toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/file_remote_frame.html
@@ -0,0 +1,20 @@
+<!DOCTYPE>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <script>
+      "use strict";
+      var response = {
+        tabs: false,
+        cookie: document.cookie,
+      };
+      try {
+        browser.tabs.create({url: "file_sample.html"});
+        response.tabs = true;
+      } catch (e) {
+        // ok
+      }
+      window.parent.postMessage(response, "*");
+    </script>
+  </head>
+</html>
\ No newline at end of file
--- a/toolkit/components/extensions/test/mochitest/mochitest.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest.ini
@@ -23,16 +23,17 @@ support-files =
   file_image_redirect.png
   file_style_good.css
   file_style_bad.css
   file_style_redirect.css
   file_script_good.js
   file_script_bad.js
   file_script_redirect.js
   file_script_xhr.js
+  file_remote_frame.html
   file_sample.html
   redirection.sjs
   file_privilege_escalation.html
   file_ext_test_api_injection.js
   file_permission_xhr.html
   file_teardown_test.js
   return_headers.sjs
   webrequest_worker.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html
@@ -7,16 +7,17 @@
   <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
   <script type="text/javascript" src="head.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 
 <script type="text/javascript">
 "use strict";
+/* eslint-disable mozilla/balanced-listeners */
 
 add_task(function* test_webext_tab_subframe_privileges() {
   function background() {
     browser.runtime.onMessage.addListener(async ({msg, success, tabId, error}) => {
       if (msg == "webext-tab-subframe-privileges") {
         if (success) {
           await browser.tabs.remove(tabId);
 
@@ -191,12 +192,50 @@ add_task(function* test_webext_contentsc
 
   yield extension.awaitFinish("webext-contentscript-subframe-privileges");
 
   win.close();
 
   yield extension.unload();
 });
 
+add_task(function* test_webext_background_remote_subframe_privileges() {
+  function backgroundSubframeScript() {
+    window.addEventListener("message", evt => {
+      browser.test.assertEq("http://mochi.test:8888", evt.origin, "postmessage origin ok");
+      browser.test.assertFalse(evt.data.tabs, "remote frame cannot access webextension APIs");
+      browser.test.assertEq("cookie=monster", evt.data.cookie, "cookies yum yum");
+      browser.test.notifyPass("webext-background-subframe-privileges");
+    }, {once: true});
+    browser.cookies.set({url: "http://mochi.test:8888", name: "cookie", "value": "monster"});
+  }
+
+  let extensionData = {
+    manifest: {
+      permissions: ["cookies", "*://mochi.test/*", "tabs"],
+      background: {
+        page: "background.html",
+      },
+    },
+    files: {
+      "background.html": `<!DOCTYPE>
+         <head>
+           <meta charset="utf-8">
+           <script src="background-subframe.js"><\/script>
+         </head>
+         <body>
+           <iframe src='${SimpleTest.getTestFileURL("file_remote_frame.html")}'></iframe>
+         </body>
+       </html>`,
+      "background-subframe.js": backgroundSubframeScript,
+    },
+  };
+  let extension = ExtensionTestUtils.loadExtension(extensionData);
+
+  yield extension.startup();
+
+  yield extension.awaitFinish("webext-background-subframe-privileges");
+  yield extension.unload();
+});
 </script>
 
 </body>
 </html>