Bug 1308688 tests r=kmag
☠☠ backed out by e2c43c2604ab ☠ ☠
authorAndrew Swan <aswan@mozilla.com>
Wed, 26 Oct 2016 16:22:56 -0700
changeset 342322 3ac2e09d98cb55fb9440b0cb9267ed365293aa9a
parent 342321 c043f1737e222180549cb754ddd2e83f0d2223bd
child 342323 fcb87a45ab4a2f66f1b68e5ad80720fc7ce9cdae
push id86829
push useraswan@mozilla.com
push dateSat, 11 Feb 2017 03:36:50 +0000
treeherdermozilla-inbound@3ac2e09d98cb [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,1 @@
+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,1 @@
+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>