diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-09 11:10:00 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-09 11:10:00 -0500 |
commit | f164d9124708b50789dbb6959e1de96cc5697c48 (patch) | |
tree | 6dffd12e08c5383130df0252fb69cd6d6330794f /toolkit/components/webextensions/test/mochitest/test_ext_background_teardown.html | |
parent | 30de4018913f0cdaea19d1dd12ecd8209e2ed08e (diff) | |
download | UXP-f164d9124708b50789dbb6959e1de96cc5697c48.tar UXP-f164d9124708b50789dbb6959e1de96cc5697c48.tar.gz UXP-f164d9124708b50789dbb6959e1de96cc5697c48.tar.lz UXP-f164d9124708b50789dbb6959e1de96cc5697c48.tar.xz UXP-f164d9124708b50789dbb6959e1de96cc5697c48.zip |
Rename Toolkit's webextensions component directory to better reflect what it is.
Diffstat (limited to 'toolkit/components/webextensions/test/mochitest/test_ext_background_teardown.html')
-rw-r--r-- | toolkit/components/webextensions/test/mochitest/test_ext_background_teardown.html | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/toolkit/components/webextensions/test/mochitest/test_ext_background_teardown.html b/toolkit/components/webextensions/test/mochitest/test_ext_background_teardown.html new file mode 100644 index 000000000..bb6b2e970 --- /dev/null +++ b/toolkit/components/webextensions/test/mochitest/test_ext_background_teardown.html @@ -0,0 +1,76 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test for background script teardown</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> +"use strict"; + +add_task(function* test_background_reload_and_unload() { + function background() { + browser.test.onMessage.addListener(msg => { + browser.test.assertEq("reload-background", msg); + location.reload(); + }); + browser.test.sendMessage("background-url", location.href); + } + + let chromeScript = SpecialPowers.loadChromeScript( + SimpleTest.getTestFileURL("file_teardown_test.js")); + yield chromeScript.promiseOneMessage("chromescript-startup"); + + let extensionData = { + background, + }; + + let extension = ExtensionTestUtils.loadExtension(extensionData); + function* getContextEvents() { + chromeScript.sendAsyncMessage("get-context-events"); + let contextEvents = yield chromeScript.promiseOneMessage("context-events"); + return contextEvents.filter(event => event.extensionId == extension.id); + } + yield extension.startup(); + let backgroundUrl = yield extension.awaitMessage("background-url"); + + let contextEvents = yield* getContextEvents(); + is(contextEvents.length, 1, + "ExtensionContext state change after loading an extension"); + is(contextEvents[0].eventType, "load"); + is(contextEvents[0].url, backgroundUrl, + "The ExtensionContext should be the background page"); + + extension.sendMessage("reload-background"); + yield extension.awaitMessage("background-url"); + + contextEvents = yield* getContextEvents(); + is(contextEvents.length, 2, + "ExtensionContext state changes after reloading the background page"); + is(contextEvents[0].eventType, "unload", + "Unload ExtensionContext of background page"); + is(contextEvents[0].url, backgroundUrl, "ExtensionContext URL = background"); + is(contextEvents[1].eventType, "load", + "Create new ExtensionContext for background page"); + is(contextEvents[1].url, backgroundUrl, "ExtensionContext URL = background"); + yield extension.unload(); + + contextEvents = yield* getContextEvents(); + is(contextEvents.length, 1, + "ExtensionContext state change after unloading the extension"); + is(contextEvents[0].eventType, "unload", + "Unload ExtensionContext for background page after extension unloads"); + is(contextEvents[0].url, backgroundUrl, "ExtensionContext URL = background"); + + chromeScript.sendAsyncMessage("cleanup"); + chromeScript.destroy(); +}); +</script> + +</body> +</html> |