Bug 1288276 - Add tests for background page context. r=billm
☠☠ backed out by 697966241877 ☠ ☠
authorRob Wu <rob@robwu.nl>
Fri, 22 Jul 2016 18:25:02 -0700
changeset 308401 a32b3e3c6b34d28e5e1d4f484f0fa6ef74a458cd
parent 308400 d1cd8175cc471e05b2e097e4b165a6cf74690c7e
child 308402 2c234f5a191673f6a4b0490435851e61852a54e8
push id80334
push userkwierso@gmail.com
push dateFri, 05 Aug 2016 21:06:09 +0000
treeherdermozilla-inbound@12b31a12d10a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1288276
milestone51.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 1288276 - Add tests for background page context. r=billm MozReview-Commit-ID: 8FsN8NoCreW
toolkit/components/extensions/test/mochitest/mochitest.ini
toolkit/components/extensions/test/mochitest/test_ext_background_teardown.html
--- a/toolkit/components/extensions/test/mochitest/mochitest.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest.ini
@@ -71,16 +71,17 @@ skip-if = (os == 'android' || buildapp =
 [test_ext_sendmessage_doublereply.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # sender.tab is undefined on b2g. Bug 1258975 on android.
 [test_ext_storage_content.html]
 [test_ext_storage_tab.html]
 skip-if = os == 'android' # Android does not currently support tabs.
 [test_ext_cookies.html]
 [test_ext_background_api_injection.html]
 [test_ext_background_generated_url.html]
+[test_ext_background_teardown.html]
 [test_ext_i18n.html]
 skip-if = (os == 'android') # Bug 1258975 on android.
 [test_ext_web_accessible_resources.html]
 skip-if = (os == 'android') # Bug 1258975 on android.
 [test_ext_webrequest.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # webrequest api uninplemented (bug 1199504). Bug 1258975 on android.
 [test_ext_webnavigation.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # needs TabManager which is not yet implemented. Bug 1258975 on android.
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/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 backgroundScript() {
+    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: `(${backgroundScript})();`,
+  };
+
+  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>