Bug 1390346 test jar caching in combination with redirects, r=rpl
MozReview-Commit-ID: 6sFdcruieh6
--- a/toolkit/components/extensions/test/mochitest/mochitest-common.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest-common.ini
@@ -80,16 +80,17 @@ skip-if = os == 'android' # bug 1369440
[test_ext_generate.html]
[test_ext_geolocation.html]
skip-if = os == 'android' # Android support Bug 1336194
[test_ext_new_tab_processType.html]
[test_ext_notifications.html]
[test_ext_permission_xhr.html]
[test_ext_proxy.html]
skip-if = os == 'android' && debug # Bug 1357635
+[test_ext_redirect_jar.html]
[test_ext_runtime_connect.html]
[test_ext_runtime_connect_twoway.html]
[test_ext_runtime_connect2.html]
[test_ext_runtime_disconnect.html]
[test_ext_runtime_id.html]
[test_ext_sandbox_var.html]
[test_ext_sendmessage_doublereply.html]
[test_ext_sendmessage_frameId.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_ext_redirect_jar.html
@@ -0,0 +1,91 @@
+<!DOCTYPE HTML>
+
+<html>
+<head>
+<meta charset="utf-8">
+ <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";
+
+function getExtension() {
+ return ExtensionTestUtils.loadExtension({
+ manifest: {
+ "applications": {
+ "gecko": {
+ "id": "redirect-to-jar@mochi.test",
+ },
+ },
+ "permissions": [
+ "webRequest",
+ "webRequestBlocking",
+ "<all_urls>",
+ ],
+ "web_accessible_resources": [
+ "finished.html",
+ ],
+ },
+ useAddonManager: "temporary",
+ files: {
+ "finished.html": `
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <meta charset="utf-8">
+ </head>
+ <body>
+ <h1>redirected!</h1>
+ </body>
+ </html>
+ `,
+ },
+ background: async () => {
+ let redirectUrl = browser.extension.getURL("finished.html");
+ browser.webRequest.onBeforeRequest.addListener(details => {
+ return {redirectUrl};
+ }, {urls: ["*://*/intercept*"]}, ["blocking"]);
+
+ async function testSubFrameResource(tabId, code) {
+ let [result] = await browser.tabs.executeScript(tabId, {code: `
+ new Promise(resolve => {
+ var s = document.createElement('iframe');
+ s.src = "/intercept?r=" + Math.random();
+ s.onload = () => resolve(['loaded', s.contentWindow.location.href]);
+ s.onerror = () => resolve(['error']);
+ document.documentElement.appendChild(s);
+ setTimeout(() => resolve(['timed_out']), 2000);
+ });`,
+ });
+ return result;
+ }
+
+ let tab = await browser.tabs.create({url: "http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest/file_sample.html"});
+ let result = await testSubFrameResource(tab.id);
+ browser.test.assertEq("loaded", result[0], "frame 1 loaded");
+ browser.test.assertEq(redirectUrl, result[1], "frame 1 redirected");
+ // Bug 1390346 If jar caching breaks redirects, this next test will fail.
+ result = await testSubFrameResource(tab.id);
+ browser.test.assertEq("loaded", result[0], "frame 2 loaded");
+ browser.test.assertEq(redirectUrl, result[1], "frame 2 redirected");
+ await browser.tabs.remove(tab.id);
+ browser.test.sendMessage("requestsCompleted");
+ },
+ });
+}
+
+add_task(async function test_redirect_to_jar() {
+ let extension = getExtension();
+ await extension.startup();
+ await extension.awaitMessage("requestsCompleted");
+ await extension.unload();
+});
+
+</script>
+</body>
+</html>
--- a/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
@@ -5,67 +5,86 @@ Cu.import("resource://gre/modules/Prefer
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(async 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;
- xhr.send();
- });
- }
+const {
+ createAppInfo,
+ promiseShutdownManager,
+ promiseStartupManager,
+} = AddonTestUtils;
+
+AddonTestUtils.init(this);
+
+createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
- Promise.all([backgroundFetch("foo.css"), backgroundFetch("bar.CsS?x#y"), backgroundFetch("foo.txt")]).then(results => {
- browser.test.assertEq("body { max-width: 42px; }", results[0], "CSS file localized");
- browser.test.assertEq("body { max-width: 42px; }", results[1], "CSS file localized");
+let extensionData = {
+ 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;
+ xhr.send();
+ });
+ }
- browser.test.assertEq("body { __MSG_foo__; }", results[2], "Text file not localized");
+ Promise.all([backgroundFetch("foo.css"), backgroundFetch("bar.CsS?x#y"), backgroundFetch("foo.txt")]).then(results => {
+ browser.test.assertEq("body { max-width: 42px; }", results[0], "CSS file localized");
+ browser.test.assertEq("body { max-width: 42px; }", results[1], "CSS file localized");
+
+ browser.test.assertEq("body { __MSG_foo__; }", results[2], "Text file not localized");
+
+ browser.test.notifyPass("i18n-css");
+ });
- browser.test.notifyPass("i18n-css");
- });
+ browser.test.sendMessage("ready", browser.runtime.getURL("foo.css"));
+ },
- browser.test.sendMessage("ready", browser.runtime.getURL("foo.css"));
+ manifest: {
+ "applications": {
+ "gecko": {
+ "id": "i18n_css@mochi.test",
+ },
},
- manifest: {
- "web_accessible_resources": ["foo.css", "foo.txt", "locale.css"],
+ "web_accessible_resources": ["foo.css", "foo.txt", "locale.css"],
- "content_scripts": [{
- "matches": ["http://*/*/file_sample.html"],
- "css": ["foo.css"],
- }],
+ "content_scripts": [{
+ "matches": ["http://*/*/file_sample.html"],
+ "css": ["foo.css"],
+ }],
- "default_locale": "en",
- },
+ "default_locale": "en",
+ },
- files: {
- "_locales/en/messages.json": JSON.stringify({
- "foo": {
- "message": "max-width: 42px",
- "description": "foo",
- },
- }),
+ files: {
+ "_locales/en/messages.json": JSON.stringify({
+ "foo": {
+ "message": "max-width: 42px",
+ "description": "foo",
+ },
+ }),
- "foo.css": "body { __MSG_foo__; }",
- "bar.CsS": "body { __MSG_foo__; }",
- "foo.txt": "body { __MSG_foo__; }",
- "locale.css": '* { content: "__MSG_@@ui_locale__ __MSG_@@bidi_dir__ __MSG_@@bidi_reversed_dir__ __MSG_@@bidi_start_edge__ __MSG_@@bidi_end_edge__" }',
- },
- });
+ "foo.css": "body { __MSG_foo__; }",
+ "bar.CsS": "body { __MSG_foo__; }",
+ "foo.txt": "body { __MSG_foo__; }",
+ "locale.css": '* { content: "__MSG_@@ui_locale__ __MSG_@@bidi_dir__ __MSG_@@bidi_reversed_dir__ __MSG_@@bidi_start_edge__ __MSG_@@bidi_end_edge__" }',
+ },
+};
+
+async function test_i18n_css(options = {}) {
+ extensionData.useAddonManager = options.useAddonManager;
+ let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup();
let cssURL = await extension.awaitMessage("ready");
function fetch(url) {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.overrideMimeType("text/plain");
@@ -116,9 +135,20 @@ add_task(async function test_i18n_css()
Preferences.reset(LOCALE);
Preferences.reset(DIR);
Preferences.reset(DIR_LEGACY);
}
await extension.awaitFinish("i18n-css");
await extension.unload();
+}
+
+add_task(async function startup() {
+ await promiseStartupManager();
});
+add_task(test_i18n_css);
+add_task(async function test_i18n_css_xpi() {
+ await test_i18n_css({useAddonManager: "temporary"});
+});
+add_task(async function startup() {
+ await promiseShutdownManager();
+});