Bug 1288885: Migrate localStorage mochitests to xpcshell. r?aswan
MozReview-Commit-ID: 1sjpnsKYEv5
--- a/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
+++ b/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
@@ -205,20 +205,23 @@ var ExtensionTestUtils = {
let normalized = Schemas.normalize(manifest, "manifest.WebExtensionManifest", context);
normalized.errors = errors;
return normalized;
}),
currentScope: null,
+ profileDir: null,
init(scope) {
this.currentScope = scope;
+ this.profileDir = scope.do_get_profile();
+
// We need to load at least one frame script into every message
// manager to ensure that the scriptable wrapper for its global gets
// created before we try to access it externally. If we don't, we
// fail sanity checks on debug builds the first time we try to
// create a wrapper, because we should never have a global without a
// cached wrapper.
Services.mm.loadFrameScript("data:text/javascript,null", true);
--- a/toolkit/components/extensions/test/mochitest/mochitest.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest.ini
@@ -46,17 +46,16 @@ skip-if = buildapp == 'b2g' # runat != d
[test_ext_contentscript_api_injection.html]
[test_ext_contentscript_create_iframe.html]
[test_ext_contentscript_devtools_metadata.html]
[test_ext_contentscript_css.html]
[test_ext_downloads.html]
[test_ext_exclude_include_globs.html]
[test_ext_i18n_css.html]
[test_ext_generate.html]
-[test_ext_localStorage.html]
[test_ext_notifications.html]
[test_ext_permission_xhr.html]
skip-if = buildapp == 'b2g' # JavaScript error: jar:remoteopenfile:///data/local/tmp/generated-extension.xpi!/content.js, line 46: NS_ERROR_ILLEGAL_VALUE:
[test_ext_runtime_connect.html]
skip-if = (os == 'android' || buildapp == 'b2g') # port.sender.tab is undefined on b2g. Bug 1258975 on android.
[test_ext_runtime_connect_twoway.html]
skip-if = (os == 'android' || buildapp == 'b2g') # port.sender.tab is undefined on b2g. Bug 1258975 on android.
[test_ext_runtime_connect2.html]
rename from toolkit/components/extensions/test/mochitest/test_ext_localStorage.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_localStorage.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_localStorage.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_localStorage.js
@@ -1,21 +1,10 @@
-<!DOCTYPE HTML>
-<html>
-<head>
- <title>WebExtension test</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">
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
function backgroundScript() {
let hasRun = localStorage.getItem("has-run");
let result;
if (!hasRun) {
localStorage.setItem("has-run", "yup");
localStorage.setItem("test-item", "item1");
@@ -33,28 +22,28 @@ function backgroundScript() {
result = "cleared";
}
}
browser.test.sendMessage("result", result);
browser.test.notifyPass("localStorage");
}
let extensionData = {
- background: "(" + backgroundScript.toString() + ")()",
+ background: backgroundScript,
};
-add_task(function* test_contentscript() {
+add_task(function* test_localStorage() {
let id = "test-webextension@mozilla.com";
const RESULTS = ["item1", "item2", "deleted", "cleared", "item1"];
for (let expected of RESULTS) {
let extension = ExtensionTestUtils.loadExtension(extensionData, id);
- let [, actual] = yield Promise.all([extension.startup(), extension.awaitMessage("result")]);
+
+ yield extension.startup();
+
+ let actual = yield extension.awaitMessage("result");
+
yield extension.awaitFinish("localStorage");
yield extension.unload();
- is(actual, expected, "got expected localStorage data");
+ equal(actual, expected, "got expected localStorage data");
}
});
-</script>
-
-</body>
-</html>
--- a/toolkit/components/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell.ini
@@ -7,16 +7,17 @@ skip-if = toolkit == 'gonk' || appname =
[test_csp_custom_policies.js]
[test_csp_validator.js]
[test_ext_alarms.js]
[test_ext_background_runtime_connect_params.js]
[test_ext_contexts.js]
[test_ext_extension.js]
[test_ext_idle.js]
[test_ext_json_parser.js]
+[test_ext_localStorage.js]
[test_ext_manifest_content_security_policy.js]
[test_ext_manifest_incognito.js]
[test_ext_onmessage_removelistener.js]
[test_ext_runtime_getPlatformInfo.js]
[test_ext_runtime_sendMessage.js]
[test_ext_schemas.js]
[test_ext_simple.js]
[test_getAPILevelForWindow.js]