зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1344616: Migrate content script mochitests to xpcshell. r=mixedpuppy
MozReview-Commit-ID: 2ljMgRTIi5r --HG-- rename : toolkit/components/extensions/test/mochitest/test_ext_contentscript.html => toolkit/components/extensions/test/xpcshell/test_ext_contentscript.js rename : toolkit/components/extensions/test/mochitest/test_ext_i18n.html => toolkit/components/extensions/test/xpcshell/test_ext_i18n.js rename : toolkit/components/extensions/test/mochitest/test_ext_i18n_css.html => toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js extra : rebase_source : adfe7c0d88a674076f37a8faf6dedf7400f316f0
This commit is contained in:
Родитель
88c2557115
Коммит
2ad60b1f3d
|
@ -913,13 +913,13 @@ this.Extension = class extends ExtensionData {
|
|||
|
||||
Services.obs.removeObserver(this, "xpcom-shutdown");
|
||||
|
||||
this.broadcast("Extension:FlushJarCache", {path: file.path}).then(() => {
|
||||
return this.broadcast("Extension:FlushJarCache", {path: file.path}).then(() => {
|
||||
// We can't delete this file until everyone using it has
|
||||
// closed it (because Windows is dumb). So we wait for all the
|
||||
// child processes (including the parent) to flush their JAR
|
||||
// caches. These caches may keep the file open.
|
||||
file.remove(false);
|
||||
});
|
||||
}).catch(Cu.reportError);
|
||||
}
|
||||
|
||||
shutdown(reason) {
|
||||
|
@ -955,7 +955,7 @@ this.Extension = class extends ExtensionData {
|
|||
|
||||
ExtensionManagement.shutdownExtension(this.uuid);
|
||||
|
||||
this.cleanupGeneratedFile();
|
||||
return this.cleanupGeneratedFile();
|
||||
}
|
||||
|
||||
observe(subject, topic, data) {
|
||||
|
|
|
@ -238,17 +238,15 @@ class ExtensionWrapper {
|
|||
});
|
||||
}
|
||||
|
||||
unload() {
|
||||
async unload() {
|
||||
if (this.state != "running") {
|
||||
throw new Error("Extension not running");
|
||||
}
|
||||
this.state = "unloading";
|
||||
|
||||
this.extension.shutdown();
|
||||
await this.extension.shutdown();
|
||||
|
||||
this.state = "unloaded";
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -48,5 +48,6 @@ MOCHITEST_MANIFESTS += [
|
|||
MOCHITEST_CHROME_MANIFESTS += ['test/mochitest/chrome.ini']
|
||||
XPCSHELL_TESTS_MANIFESTS += [
|
||||
'test/xpcshell/native_messaging.ini',
|
||||
'test/xpcshell/xpcshell-remote.ini',
|
||||
'test/xpcshell/xpcshell.ini',
|
||||
]
|
||||
|
|
|
@ -53,7 +53,6 @@ skip-if = os == 'android' # Android does not support multiple windows.
|
|||
[test_ext_geturl.html]
|
||||
[test_ext_background_canvas.html]
|
||||
[test_ext_content_security_policy.html]
|
||||
[test_ext_contentscript.html]
|
||||
[test_ext_contentscript_api_injection.html]
|
||||
[test_ext_contentscript_context.html]
|
||||
[test_ext_contentscript_create_iframe.html]
|
||||
|
@ -68,7 +67,6 @@ skip-if = os == 'android' # Android does not support multiple windows.
|
|||
[test_ext_contentscript_teardown.html]
|
||||
[test_ext_exclude_include_globs.html]
|
||||
[test_ext_external_messaging.html]
|
||||
[test_ext_i18n_css.html]
|
||||
[test_ext_generate.html]
|
||||
[test_ext_geolocation.html]
|
||||
skip-if = os == 'android' # Android support Bug 1336194
|
||||
|
@ -94,7 +92,6 @@ skip-if = os == 'android' # Android support Bug 1336194
|
|||
[test_ext_tab_teardown.html]
|
||||
skip-if = os == 'android' # Bug 1258975 on android.
|
||||
[test_ext_unload_frame.html]
|
||||
[test_ext_i18n.html]
|
||||
[test_ext_listener_proxies.html]
|
||||
[test_ext_web_accessible_resources.html]
|
||||
[test_ext_webrequest_auth.html]
|
||||
|
|
|
@ -4,13 +4,14 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|||
|
||||
/* exported createHttpServer, promiseConsoleOutput, cleanupDir */
|
||||
|
||||
Components.utils.import("resource://gre/modules/AppConstants.jsm");
|
||||
Components.utils.import("resource://gre/modules/Task.jsm");
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/Timer.jsm");
|
||||
Components.utils.import("resource://testing-common/AddonTestUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
|
||||
"resource://gre/modules/AppConstants.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ContentTask",
|
||||
"resource://testing-common/ContentTask.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Extension",
|
||||
"resource://gre/modules/Extension.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ExtensionData",
|
||||
|
@ -56,6 +57,10 @@ function createHttpServer(port = -1) {
|
|||
return server;
|
||||
}
|
||||
|
||||
if (AppConstants.platform === "android") {
|
||||
Services.io.offline = true;
|
||||
}
|
||||
|
||||
var promiseConsoleOutput = Task.async(function* (task) {
|
||||
const DONE = `=== console listener ${Math.random()} done ===`;
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
/* globals ExtensionTestUtils */
|
||||
|
||||
ExtensionTestUtils.remoteContentScripts = true;
|
|
@ -1,18 +1,10 @@
|
|||
<!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";
|
||||
|
||||
const server = createHttpServer();
|
||||
server.registerDirectory("/data/", do_get_file("data"));
|
||||
|
||||
const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;
|
||||
|
||||
add_task(function* test_contentscript() {
|
||||
function background() {
|
||||
browser.runtime.onMessage.addListener(([msg, expectedStates, readyState], sender) => {
|
||||
|
@ -41,7 +33,7 @@ add_task(function* test_contentscript() {
|
|||
function contentScript() {
|
||||
let manifest = browser.runtime.getManifest();
|
||||
void manifest.applications.gecko.id;
|
||||
chrome.runtime.sendMessage(["chrome-namespace-ok"]);
|
||||
browser.runtime.sendMessage(["chrome-namespace-ok"]);
|
||||
}
|
||||
|
||||
let extensionData = {
|
||||
|
@ -49,22 +41,22 @@ add_task(function* test_contentscript() {
|
|||
applications: {gecko: {id: "contentscript@tests.mozilla.org"}},
|
||||
content_scripts: [
|
||||
{
|
||||
"matches": ["http://mochi.test/*/file_sample.html"],
|
||||
"matches": ["http://*/*/file_sample.html"],
|
||||
"js": ["content_script_start.js"],
|
||||
"run_at": "document_start",
|
||||
},
|
||||
{
|
||||
"matches": ["http://mochi.test/*/file_sample.html"],
|
||||
"matches": ["http://*/*/file_sample.html"],
|
||||
"js": ["content_script_end.js"],
|
||||
"run_at": "document_end",
|
||||
},
|
||||
{
|
||||
"matches": ["http://mochi.test/*/file_sample.html"],
|
||||
"matches": ["http://*/*/file_sample.html"],
|
||||
"js": ["content_script_idle.js"],
|
||||
"run_at": "document_idle",
|
||||
},
|
||||
{
|
||||
"matches": ["http://mochi.test/*/file_sample.html"],
|
||||
"matches": ["http://*/*/file_sample.html"],
|
||||
"js": ["content_script.js"],
|
||||
"run_at": "document_idle",
|
||||
},
|
||||
|
@ -96,21 +88,15 @@ add_task(function* test_contentscript() {
|
|||
|
||||
yield extension.startup();
|
||||
|
||||
let win = window.open("file_sample.html");
|
||||
let contentPage = yield ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
|
||||
|
||||
yield Promise.all([waitForLoad(win), completePromise, chromeNamespacePromise]);
|
||||
info("test page loaded");
|
||||
yield Promise.all([completePromise, chromeNamespacePromise]);
|
||||
|
||||
win.close();
|
||||
yield contentPage.close();
|
||||
|
||||
is(loadingCount, 1, "document_start script ran exactly once");
|
||||
is(interactiveCount, 1, "document_end script ran exactly once");
|
||||
is(completeCount, 1, "document_idle script ran exactly once");
|
||||
equal(loadingCount, 1, "document_start script ran exactly once");
|
||||
equal(interactiveCount, 1, "document_end script ran exactly once");
|
||||
equal(completeCount, 1, "document_idle script ran exactly once");
|
||||
|
||||
yield extension.unload();
|
||||
info("extension unloaded");
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,21 +1,18 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for WebExtension localization APIs</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";
|
||||
|
||||
SimpleTest.registerCleanupFunction(() => { SpecialPowers.clearUserPref("intl.accept_languages"); });
|
||||
SimpleTest.registerCleanupFunction(() => { SpecialPowers.clearUserPref("general.useragent.locale"); });
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
|
||||
|
||||
const server = createHttpServer();
|
||||
server.registerDirectory("/data/", do_get_file("data"));
|
||||
|
||||
const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;
|
||||
|
||||
do_register_cleanup(() => {
|
||||
Preferences.reset("intl.accept_languages");
|
||||
Preferences.reset("general.useragent.locale");
|
||||
});
|
||||
|
||||
|
||||
add_task(function* test_i18n() {
|
||||
function runTests(assertEq) {
|
||||
|
@ -65,7 +62,7 @@ add_task(function* test_i18n() {
|
|||
"default_locale": "jp",
|
||||
|
||||
content_scripts: [
|
||||
{"matches": ["http://mochi.test/*/file_sample.html"],
|
||||
{"matches": ["http://*/*/file_sample.html"],
|
||||
"js": ["content.js"]},
|
||||
],
|
||||
},
|
||||
|
@ -154,21 +151,15 @@ add_task(function* test_i18n() {
|
|||
|
||||
yield extension.startup();
|
||||
|
||||
let win = window.open("file_sample.html");
|
||||
let contentPage = yield ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
|
||||
yield extension.awaitMessage("content-script-finished");
|
||||
win.close();
|
||||
yield contentPage.close();
|
||||
|
||||
yield extension.unload();
|
||||
});
|
||||
|
||||
add_task(function* test_get_accept_languages() {
|
||||
function background() {
|
||||
function checkResults(source, results, expected) {
|
||||
if (results[0] === "en-us" && expected[0] === "en-US") {
|
||||
// This sometimes winds up with unexpected capitalization in Android tests.
|
||||
expected[0] = expected[0].toLowerCase();
|
||||
}
|
||||
|
||||
browser.test.assertEq(
|
||||
expected.length,
|
||||
results.length,
|
||||
|
@ -181,63 +172,59 @@ add_task(function* test_get_accept_languages() {
|
|||
});
|
||||
}
|
||||
|
||||
let tabId;
|
||||
function background(checkResultsFn) {
|
||||
browser.test.onMessage.addListener(([msg, expected]) => {
|
||||
browser.i18n.getAcceptLanguages().then(results => {
|
||||
checkResultsFn("background", results, expected);
|
||||
|
||||
browser.tabs.query({currentWindow: true, active: true}).then(tabs => {
|
||||
tabId = tabs[0].id;
|
||||
browser.test.sendMessage("ready");
|
||||
browser.test.sendMessage("background-done");
|
||||
});
|
||||
|
||||
browser.test.onMessage.addListener(async ([msg, expected]) => {
|
||||
let contentResults = await browser.tabs.sendMessage(tabId, "get-results");
|
||||
let backgroundResults = await browser.i18n.getAcceptLanguages();
|
||||
|
||||
checkResults("contentScript", contentResults, expected);
|
||||
checkResults("background", backgroundResults, expected);
|
||||
|
||||
browser.test.sendMessage("done");
|
||||
});
|
||||
}
|
||||
|
||||
function content() {
|
||||
browser.runtime.onMessage.addListener((msg, sender, respond) => {
|
||||
browser.i18n.getAcceptLanguages(respond);
|
||||
return true;
|
||||
function content(checkResultsFn) {
|
||||
browser.test.onMessage.addListener(([msg, expected]) => {
|
||||
browser.i18n.getAcceptLanguages().then(results => {
|
||||
checkResultsFn("contentScript", results, expected);
|
||||
|
||||
browser.test.sendMessage("content-done");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
"content_scripts": [{
|
||||
"matches": ["http://mochi.test/*/file_sample.html"],
|
||||
"matches": ["http://*/*/file_sample.html"],
|
||||
"run_at": "document_start",
|
||||
"js": ["content_script.js"],
|
||||
}],
|
||||
},
|
||||
|
||||
background,
|
||||
background: `(${background})(${checkResults})`,
|
||||
|
||||
files: {
|
||||
"content_script.js": content,
|
||||
"content_script.js": `(${content})(${checkResults})`,
|
||||
},
|
||||
});
|
||||
|
||||
let win = window.open("file_sample.html");
|
||||
let contentPage = yield ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
|
||||
|
||||
yield extension.startup();
|
||||
yield extension.awaitMessage("ready");
|
||||
|
||||
let expectedLangs = ["en-US", "en"];
|
||||
extension.sendMessage(["expect-results", expectedLangs]);
|
||||
yield extension.awaitMessage("done");
|
||||
yield extension.awaitMessage("background-done");
|
||||
yield extension.awaitMessage("content-done");
|
||||
|
||||
expectedLangs = ["en-US", "en", "fr-CA", "fr"];
|
||||
SpecialPowers.setCharPref("intl.accept_languages", expectedLangs.toString());
|
||||
Preferences.set("intl.accept_languages", expectedLangs.toString());
|
||||
extension.sendMessage(["expect-results", expectedLangs]);
|
||||
yield extension.awaitMessage("done");
|
||||
SpecialPowers.clearUserPref("intl.accept_languages");
|
||||
yield extension.awaitMessage("background-done");
|
||||
yield extension.awaitMessage("content-done");
|
||||
Preferences.reset("intl.accept_languages");
|
||||
|
||||
win.close();
|
||||
yield contentPage.close();
|
||||
|
||||
yield extension.unload();
|
||||
});
|
||||
|
@ -250,7 +237,6 @@ add_task(function* test_get_ui_language() {
|
|||
};
|
||||
}
|
||||
|
||||
function background(getResultsFn) {
|
||||
function checkResults(source, results, expected) {
|
||||
browser.test.assertEq(
|
||||
expected,
|
||||
|
@ -264,59 +250,55 @@ add_task(function* test_get_ui_language() {
|
|||
);
|
||||
}
|
||||
|
||||
let tabId;
|
||||
|
||||
function background(getResultsFn, checkResultsFn) {
|
||||
browser.test.onMessage.addListener(([msg, expected]) => {
|
||||
browser.tabs.sendMessage(tabId, "get-results", result => {
|
||||
checkResults("contentScript", result, expected);
|
||||
checkResults("background", getResultsFn(), expected);
|
||||
checkResultsFn("background", getResultsFn(), expected);
|
||||
|
||||
browser.test.sendMessage("done");
|
||||
});
|
||||
});
|
||||
|
||||
browser.tabs.query({currentWindow: true, active: true}, tabs => {
|
||||
tabId = tabs[0].id;
|
||||
browser.test.sendMessage("ready");
|
||||
browser.test.sendMessage("background-done");
|
||||
});
|
||||
}
|
||||
|
||||
function content(getResultsFn) {
|
||||
browser.runtime.onMessage.addListener((msg, sender, respond) => {
|
||||
respond(getResultsFn());
|
||||
function content(getResultsFn, checkResultsFn) {
|
||||
browser.test.onMessage.addListener(([msg, expected]) => {
|
||||
checkResultsFn("contentScript", getResultsFn(), expected);
|
||||
|
||||
browser.test.sendMessage("content-done");
|
||||
});
|
||||
}
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
"content_scripts": [{
|
||||
"matches": ["http://mochi.test/*/file_sample.html"],
|
||||
"matches": ["http://*/*/file_sample.html"],
|
||||
"run_at": "document_start",
|
||||
"js": ["content_script.js"],
|
||||
}],
|
||||
},
|
||||
|
||||
background: `(${background})(${getResults})`,
|
||||
background: `(${background})(${getResults}, ${checkResults})`,
|
||||
|
||||
files: {
|
||||
"content_script.js": `(${content})(${getResults})`,
|
||||
"content_script.js": `(${content})(${getResults}, ${checkResults})`,
|
||||
},
|
||||
});
|
||||
|
||||
let win = window.open("file_sample.html");
|
||||
let contentPage = yield ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
|
||||
|
||||
yield extension.startup();
|
||||
yield extension.awaitMessage("ready");
|
||||
|
||||
extension.sendMessage(["expect-results", "en_US"]);
|
||||
yield extension.awaitMessage("done");
|
||||
|
||||
SpecialPowers.setCharPref("general.useragent.locale", "he");
|
||||
yield extension.awaitMessage("background-done");
|
||||
yield extension.awaitMessage("content-done");
|
||||
|
||||
Preferences.set("general.useragent.locale", "he");
|
||||
|
||||
extension.sendMessage(["expect-results", "he"]);
|
||||
yield extension.awaitMessage("done");
|
||||
|
||||
win.close();
|
||||
yield extension.awaitMessage("background-done");
|
||||
yield extension.awaitMessage("content-done");
|
||||
|
||||
yield contentPage.close();
|
||||
|
||||
yield extension.unload();
|
||||
});
|
||||
|
@ -338,7 +320,6 @@ add_task(function* test_detect_language() {
|
|||
"Pour une aide rapide et effective, veuiller trouver votre aide dans le menu ci-dessus." +
|
||||
"Motoring events began soon after the construction of the first successful gasoline-fueled automobiles. The quick brown fox jumped over the lazy dog";
|
||||
|
||||
function background() {
|
||||
function checkResult(source, result, expected) {
|
||||
browser.test.assertEq(expected.isReliable, result.isReliable, "result.confident is true");
|
||||
browser.test.assertEq(
|
||||
|
@ -357,51 +338,43 @@ add_task(function* test_detect_language() {
|
|||
});
|
||||
}
|
||||
|
||||
let tabId;
|
||||
|
||||
browser.tabs.query({currentWindow: true, active: true}, tabs => {
|
||||
tabId = tabs[0].id;
|
||||
browser.test.sendMessage("ready");
|
||||
function backgroundScript(checkResultFn) {
|
||||
browser.test.onMessage.addListener(([msg, expected]) => {
|
||||
browser.i18n.detectLanguage(msg).then(result => {
|
||||
checkResultFn("background", result, expected);
|
||||
browser.test.sendMessage("background-done");
|
||||
});
|
||||
|
||||
browser.test.onMessage.addListener(async ([msg, expected]) => {
|
||||
let backgroundResults = await browser.i18n.detectLanguage(msg);
|
||||
let contentResults = await browser.tabs.sendMessage(tabId, msg);
|
||||
|
||||
checkResult("background", backgroundResults, expected);
|
||||
checkResult("contentScript", contentResults, expected);
|
||||
|
||||
browser.test.sendMessage("done");
|
||||
});
|
||||
}
|
||||
|
||||
function content() {
|
||||
browser.runtime.onMessage.addListener((msg, sender, respond) => {
|
||||
browser.i18n.detectLanguage(msg, respond);
|
||||
return true;
|
||||
function content(checkResultFn) {
|
||||
browser.test.onMessage.addListener(([msg, expected]) => {
|
||||
browser.i18n.detectLanguage(msg).then(result => {
|
||||
checkResultFn("contentScript", result, expected);
|
||||
browser.test.sendMessage("content-done");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
"content_scripts": [{
|
||||
"matches": ["http://mochi.test/*/file_sample.html"],
|
||||
"matches": ["http://*/*/file_sample.html"],
|
||||
"run_at": "document_start",
|
||||
"js": ["content_script.js"],
|
||||
}],
|
||||
},
|
||||
|
||||
background,
|
||||
background: `(${backgroundScript})(${checkResult})`,
|
||||
|
||||
files: {
|
||||
"content_script.js": content,
|
||||
"content_script.js": `(${content})(${checkResult})`,
|
||||
},
|
||||
});
|
||||
|
||||
let win = window.open("file_sample.html");
|
||||
let contentPage = yield ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
|
||||
|
||||
yield extension.startup();
|
||||
yield extension.awaitMessage("ready");
|
||||
|
||||
let expected = {
|
||||
isReliable: true,
|
||||
|
@ -417,7 +390,8 @@ add_task(function* test_detect_language() {
|
|||
],
|
||||
};
|
||||
extension.sendMessage([fr_en_string, expected]);
|
||||
yield extension.awaitMessage("done");
|
||||
yield extension.awaitMessage("background-done");
|
||||
yield extension.awaitMessage("content-done");
|
||||
|
||||
expected = {
|
||||
isReliable: true,
|
||||
|
@ -429,14 +403,10 @@ add_task(function* test_detect_language() {
|
|||
],
|
||||
};
|
||||
extension.sendMessage([af_string, expected]);
|
||||
yield extension.awaitMessage("done");
|
||||
yield extension.awaitMessage("background-done");
|
||||
yield extension.awaitMessage("content-done");
|
||||
|
||||
win.close();
|
||||
yield contentPage.close();
|
||||
|
||||
yield extension.unload();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,24 +1,22 @@
|
|||
<!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";
|
||||
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
|
||||
|
||||
const server = createHttpServer();
|
||||
server.registerDirectory("/data/", do_get_file("data"));
|
||||
|
||||
const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;
|
||||
|
||||
const XMLHttpRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest");
|
||||
|
||||
add_task(function* test_i18n_css() {
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
background: function() {
|
||||
function backgroundFetch(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.overrideMimeType("text/plain");
|
||||
xhr.open("GET", url);
|
||||
xhr.onload = () => { resolve(xhr.responseText); };
|
||||
xhr.onerror = reject;
|
||||
|
@ -42,7 +40,7 @@ add_task(function* test_i18n_css() {
|
|||
"web_accessible_resources": ["foo.css", "foo.txt", "locale.css"],
|
||||
|
||||
"content_scripts": [{
|
||||
"matches": ["http://mochi.test/*/file_sample.html"],
|
||||
"matches": ["http://*/*/file_sample.html"],
|
||||
"css": ["foo.css"],
|
||||
}],
|
||||
|
||||
|
@ -70,6 +68,7 @@ add_task(function* test_i18n_css() {
|
|||
function fetch(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.overrideMimeType("text/plain");
|
||||
xhr.open("GET", url);
|
||||
xhr.onload = () => { resolve(xhr.responseText); };
|
||||
xhr.onerror = reject;
|
||||
|
@ -79,19 +78,25 @@ add_task(function* test_i18n_css() {
|
|||
|
||||
let css = yield fetch(cssURL);
|
||||
|
||||
is(css, "body { max-width: 42px; }", "CSS file localized in mochitest scope");
|
||||
equal(css, "body { max-width: 42px; }", "CSS file localized in mochitest scope");
|
||||
|
||||
let win = window.open("file_sample.html");
|
||||
yield waitForLoad(win);
|
||||
let contentPage = yield ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
|
||||
|
||||
let style = win.getComputedStyle(win.document.body);
|
||||
is(style.maxWidth, "42px", "stylesheet correctly applied");
|
||||
win.close();
|
||||
let maxWidth = yield ContentTask.spawn(contentPage.browser, {}, function* () {
|
||||
/* globals content */
|
||||
let style = content.getComputedStyle(content.document.body);
|
||||
|
||||
return style.maxWidth;
|
||||
});
|
||||
|
||||
equal(maxWidth, "42px", "stylesheet correctly applied");
|
||||
|
||||
yield contentPage.close();
|
||||
|
||||
cssURL = cssURL.replace(/foo.css$/, "locale.css");
|
||||
|
||||
css = yield fetch(cssURL);
|
||||
is(css, '* { content: "en_US ltr rtl left right" }', "CSS file localized in mochitest scope");
|
||||
equal(css, '* { content: "en_US ltr rtl left right" }', "CSS file localized in mochitest scope");
|
||||
|
||||
const LOCALE = "general.useragent.locale";
|
||||
const DIR = "intl.uidirection";
|
||||
|
@ -100,21 +105,17 @@ add_task(function* test_i18n_css() {
|
|||
// We don't wind up actually switching the chrome registry locale, since we
|
||||
// don't have a chrome package for Hebrew. So just override it, and force
|
||||
// RTL directionality.
|
||||
SpecialPowers.setCharPref(LOCALE, "he");
|
||||
SpecialPowers.setIntPref(DIR, 1);
|
||||
SpecialPowers.setCharPref(DIR_LEGACY, "rtl");
|
||||
Preferences.set(LOCALE, "he");
|
||||
Preferences.set(DIR, 1);
|
||||
Preferences.set(DIR_LEGACY, "rtl");
|
||||
|
||||
css = yield fetch(cssURL);
|
||||
is(css, '* { content: "he rtl ltr right left" }', "CSS file localized in mochitest scope");
|
||||
equal(css, '* { content: "he rtl ltr right left" }', "CSS file localized in mochitest scope");
|
||||
|
||||
SpecialPowers.clearUserPref(LOCALE);
|
||||
SpecialPowers.clearUserPref(DIR);
|
||||
SpecialPowers.clearUserPref(DIR_LEGACY);
|
||||
Preferences.reset(LOCALE);
|
||||
Preferences.reset(DIR);
|
||||
Preferences.reset(DIR_LEGACY);
|
||||
|
||||
yield extension.awaitFinish("i18n-css");
|
||||
yield extension.unload();
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -17,7 +17,7 @@ let extensionData = {
|
|||
background: backgroundScript,
|
||||
};
|
||||
|
||||
add_task(function* test_contentscript() {
|
||||
add_task(function* () {
|
||||
let extension = ExtensionTestUtils.loadExtension(extensionData);
|
||||
yield extension.startup();
|
||||
yield extension.awaitFinish("runtime.getPlatformInfo");
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
[test_ext_i18n.js]
|
||||
[test_ext_i18n_css.js]
|
||||
[test_ext_contentscript.js]
|
|
@ -0,0 +1,12 @@
|
|||
[DEFAULT]
|
||||
head = head.js head_remote.js
|
||||
tail =
|
||||
firefox-appdir = browser
|
||||
skip-if = appname == "thunderbird" || os == "android"
|
||||
dupe-manifest =
|
||||
support-files =
|
||||
data/**
|
||||
xpcshell-content.ini
|
||||
tags = webextensions webextensions-e10s
|
||||
|
||||
[include:xpcshell-content.ini]
|
|
@ -2,8 +2,11 @@
|
|||
head = head.js
|
||||
firefox-appdir = browser
|
||||
skip-if = appname == "thunderbird"
|
||||
dupe-manifest =
|
||||
support-files =
|
||||
data/** head_sync.js
|
||||
data/**
|
||||
head_sync.js
|
||||
xpcshell-content.ini
|
||||
tags = webextensions
|
||||
|
||||
[test_csp_custom_policies.js]
|
||||
|
@ -80,3 +83,5 @@ skip-if = os == "android"
|
|||
[test_locale_data.js]
|
||||
[test_native_messaging.js]
|
||||
skip-if = os == "android"
|
||||
|
||||
[include:xpcshell-content.ini]
|
||||
|
|
Загрузка…
Ссылка в новой задаче