MozReview-Commit-ID: 8DOZbPY7FZ9

--HG--
extra : rebase_source : c8495c96e9af4c76053a74f00b5a87467f2ec94f
extra : intermediate-source : af75c6520fbaf604eb0ece140e2601e6c51c5b4b
extra : source : 1150dfe4aa4b7aca0a47f253b409f881524e2a3e
This commit is contained in:
Andrew Swan 2016-10-26 16:22:56 -07:00
Родитель 4bdc66dec5
Коммит 0cb08702ba
6 изменённых файлов: 120 добавлений и 0 удалений

Просмотреть файл

@ -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>

Просмотреть файл

@ -0,0 +1 @@
window.testScript = "original";

Просмотреть файл

@ -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>

Просмотреть файл

@ -0,0 +1 @@
window.testScript = "redirected";

Просмотреть файл

@ -8,6 +8,10 @@ support-files =
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^
@ -106,6 +110,7 @@ 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]

Просмотреть файл

@ -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>