Bug 1308688 tests r=kmag
authorAndrew Swan <aswan@mozilla.com>
Wed, 26 Oct 2016 16:22:56 -0700
changeset 342348 d070f532ca2d35470e6996b0fd3e58cd351f9c06
parent 342347 910ceca7e8637c4c3ea963fd054e6c449eeff6a7
child 342349 dd79181d183f821a7303b5665d75ebc9ecc60d8f
push id86845
push useraswan@mozilla.com
push dateSat, 11 Feb 2017 22:27:05 +0000
treeherdermozilla-inbound@d070f532ca2d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1308688
milestone54.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 1308688 tests r=kmag MozReview-Commit-ID: 8DOZbPY7FZ9
toolkit/components/extensions/test/mochitest/file_WebRequest_permission_original.html
toolkit/components/extensions/test/mochitest/file_WebRequest_permission_original.js
toolkit/components/extensions/test/mochitest/file_WebRequest_permission_redirected.html
toolkit/components/extensions/test/mochitest/file_WebRequest_permission_redirected.js
toolkit/components/extensions/test/mochitest/mochitest-common.ini
toolkit/components/extensions/test/mochitest/test_ext_webrequest_permission.html
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/file_WebRequest_permission_original.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+
+<html>
+<head>
+<meta charset="utf-8">
+</head>
+<body>
+
+<script src="http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest/file_WebRequest_permission_original.js"></script>
+<script>
+"use strict";
+
+window.parent.postMessage({
+  page: "original",
+  script: window.testScript,
+}, "*");
+</script>
+</body>
+</html>
+
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/file_WebRequest_permission_original.js
@@ -0,0 +1,2 @@
+"use strict";
+window.testScript = "original";
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/file_WebRequest_permission_redirected.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+
+<html>
+<head>
+<meta charset="utf-8">
+</head>
+<body>
+
+<script src="http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest/file_WebRequest_permission_original.js"></script>
+<script>
+"use strict";
+
+window.parent.postMessage({
+  page: "redirected",
+  script: window.testScript,
+}, "*");
+</script>
+</body>
+</html>
+
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/file_WebRequest_permission_redirected.js
@@ -0,0 +1,2 @@
+"use strict";
+window.testScript = "redirected";
--- a/toolkit/components/extensions/test/mochitest/mochitest-common.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest-common.ini
@@ -3,16 +3,20 @@ support-files =
   chrome_cleanup_script.js
   head.js
   file_mixed.html
   head_webrequest.js
   file_csp.html
   file_csp.html^headers^
   file_to_drawWindow.html
   file_WebRequest_page3.html
+  file_WebRequest_permission_original.html
+  file_WebRequest_permission_redirected.html
+  file_WebRequest_permission_original.js
+  file_WebRequest_permission_redirected.js
   file_webNavigation_clientRedirect.html
   file_webNavigation_clientRedirect_httpHeaders.html
   file_webNavigation_clientRedirect_httpHeaders.html^headers^
   file_webNavigation_frameClientRedirect.html
   file_webNavigation_frameRedirect.html
   file_webNavigation_manualSubframe.html
   file_webNavigation_manualSubframe_page1.html
   file_webNavigation_manualSubframe_page2.html
@@ -101,15 +105,16 @@ subsuite = webrequest
 subsuite = webrequest
 [test_ext_webrequest_filter.html]
 subsuite = webrequest
 [test_ext_webrequest_suspend.html]
 subsuite = webrequest
 [test_ext_webrequest_upload.html]
 skip-if = os == 'android' # Currently fails in emulator tests
 subsuite = webrequest
+[test_ext_webrequest_permission.html]
 [test_ext_webnavigation.html]
 subsuite = webnavigation
 [test_ext_webnavigation_filters.html]
 subsuite = webnavigation
 [test_ext_window_postMessage.html]
 [test_ext_subframes_privileges.html]
 [test_ext_xhr_capabilities.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_permission.html
@@ -0,0 +1,73 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for content script</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+  <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";
+
+add_task(function* test_permissions() {
+  function background() {
+    browser.webRequest.onBeforeRequest.addListener(details => {
+      if (details.url.includes("_original")) {
+        let redirectUrl = details.url
+                                 .replace("mochi.test:8888", "example.com")
+                                 .replace("_original", "_redirected");
+        return {redirectUrl};
+      }
+      return {};
+    }, {urls: ["<all_urls>"]}, ["blocking"]);
+  }
+
+  let extensionData = {
+    manifest: {
+      permissions: ["webRequest", "webRequestBlocking", "<all_urls>"],
+    },
+    background,
+  };
+
+  let extension = ExtensionTestUtils.loadExtension(extensionData);
+  yield extension.startup();
+
+  function* check() {
+    let iframe = document.createElement("iframe");
+    document.body.appendChild(iframe);
+
+    let promise = new Promise(resolve => {
+      let listener = event => {
+        window.removeEventListener("message", listener);
+        resolve(event.data);
+      };
+      window.addEventListener("message", listener);
+    });
+
+    iframe.setAttribute("src", "http://example.com/tests/toolkit/components/extensions/test/mochitest/file_WebRequest_permission_original.html");
+    let result = yield promise;
+    document.body.removeChild(iframe);
+    return result;
+  }
+
+  let results = yield check();
+  is(results.page, "redirected", "Regular webRequest redirect works on an unprivileged page");
+  is(results.script, "redirected", "Regular webRequest redirect works from an unprivileged page");
+
+  yield SpecialPowers.pushPrefEnv({
+    set: [["extensions.webapi.testing", true]],
+  });
+
+  results = yield check();
+  is(results.page, "original", "webRequest redirect fails on a privileged page");
+  is(results.script, "original", "webRequest redirect fails from a privileged page");
+
+  yield extension.unload();
+});
+</script>
+
+</body>
+</html>