mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 1201377 - [webext] Nuke content script sandbox when page closes (r=gabor)
This commit is contained in:
parent
33f30d2bec
commit
2a80660ea9
@ -243,7 +243,6 @@ ExtensionContext.prototype = {
|
||||
|
||||
callOnClose(obj) {
|
||||
this.onClose.add(obj);
|
||||
Cu.nukeSandbox(this.sandbox);
|
||||
},
|
||||
|
||||
forgetOnClose(obj) {
|
||||
@ -254,6 +253,7 @@ ExtensionContext.prototype = {
|
||||
for (let obj of this.onClose) {
|
||||
obj.close();
|
||||
}
|
||||
Cu.nukeSandbox(this.sandbox);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -19,3 +19,4 @@ support-files =
|
||||
[test_extension_contentscript.html]
|
||||
[test_extension_webrequest.html]
|
||||
[test_generate_extension.html]
|
||||
[test_sandbox_var.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>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="application/javascript;version=1.8">
|
||||
"use strict";
|
||||
|
||||
function backgroundScript() {
|
||||
browser.runtime.onMessage.addListener(result => {
|
||||
browser.test.assertEq(result, 12, "x is 12");
|
||||
browser.test.notifyPass("background test passed");
|
||||
});
|
||||
}
|
||||
|
||||
function contentScript() {
|
||||
window.x = 12;
|
||||
browser.runtime.onMessage.addListener(function() {});
|
||||
browser.runtime.sendMessage(window.x);
|
||||
}
|
||||
|
||||
let extensionData = {
|
||||
background: "(" + backgroundScript.toString() + ")()",
|
||||
manifest: {
|
||||
"content_scripts": [{
|
||||
"matches": ["http://mochi.test/tests/toolkit/components/extensions/test/mochitest/file_contentscript_*.html"],
|
||||
"js": ["content_script.js"],
|
||||
"run_at": "document_start"
|
||||
}]
|
||||
},
|
||||
|
||||
files: {
|
||||
"content_script.js": "(" + contentScript.toString() + ")()",
|
||||
},
|
||||
};
|
||||
|
||||
add_task(function* test_contentscript() {
|
||||
let extension = ExtensionTestUtils.loadExtension(extensionData);
|
||||
yield extension.startup();
|
||||
info("extension loaded");
|
||||
|
||||
yield new Promise(resolve => { setTimeout(resolve, 0); });
|
||||
|
||||
let win = window.open();
|
||||
|
||||
win.location = "file_contentscript_page1.html";
|
||||
|
||||
yield Promise.all([waitForLoad(win), extension.awaitFinish()]);
|
||||
|
||||
win.close();
|
||||
|
||||
yield extension.unload();
|
||||
info("extension unloaded");
|
||||
});
|
||||
|
||||
function waitForLoad(win) {
|
||||
return new Promise(resolve => {
|
||||
win.addEventListener("load", function listener() {
|
||||
win.removeEventListener("load", listener, true);
|
||||
resolve();
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user