Bug 1518863: Part 4 - Add tests. r=aswan

Differential Revision: https://phabricator.services.mozilla.com/D21449

--HG--
extra : rebase_source : 4bb7654ce9a5538cad170633dcf5ddffeed7ce45
This commit is contained in:
Kris Maglione 2019-02-27 13:57:08 -08:00
Родитель 4dfb42d89b
Коммит 73a527c54f
2 изменённых файлов: 63 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,62 @@
"use strict";
function delay(time) {
return new Promise(resolve => {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(resolve, time);
});
}
const {Extension} = ChromeUtils.import("resource://gre/modules/Extension.jsm");
add_task(async function test_startup_request_handler() {
const ID = "request-startup@xpcshell.mozilla.org";
let extension = ExtensionTestUtils.loadExtension({
manifest: {
applications: {gecko: {id: ID}},
},
files: {
"meh.txt": "Meh.",
},
});
let ready = false;
let resolvePromise;
let promise = new Promise(resolve => {
resolvePromise = resolve;
});
promise.then(() => {
ready = true;
});
let origInitLocale = Extension.prototype.initLocale;
Extension.prototype.initLocale = async function initLocale() {
await promise;
return origInitLocale.call(this);
};
let startupPromise = extension.startup();
await delay(0);
let policy = WebExtensionPolicy.getByID(ID);
let url = policy.getURL("meh.txt");
let resp = ExtensionTestUtils.fetch(url, url);
resp.then(() => {
ok(ready, "Shouldn't get response before extension is ready");
});
await delay(2000);
resolvePromise();
await startupPromise;
let body = await resp;
equal(body, "Meh.", "Got the correct response");
await extension.unload();
Extension.prototype.initLocale = origInitLocale;
});

Просмотреть файл

@ -107,6 +107,7 @@ skip-if = os == "android" && debug
[test_ext_startup_cache.js]
skip-if = os == "android"
[test_ext_startup_perf.js]
[test_ext_startup_request_handler.js]
[test_ext_storage.js]
skip-if = os == "android" && debug
[test_ext_storage_idb_data_migration.js]