diff --git a/testing/mochitest/api.js b/testing/mochitest/bootstrap.js similarity index 65% rename from testing/mochitest/api.js rename to testing/mochitest/bootstrap.js index 4dafd518d0f3..b076c57040ec 100644 --- a/testing/mochitest/api.js +++ b/testing/mochitest/bootstrap.js @@ -2,8 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* globals ExtensionAPI */ - ChromeUtils.import("resource://gre/modules/AppConstants.jsm"); ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); ChromeUtils.import("resource://gre/modules/Services.jsm"); @@ -40,20 +38,10 @@ const windowTracker = { }, }; -function androidStartup() { +function androidStartup(data, reason) { // Only browser chrome tests need help starting. let testRoot = Services.prefs.getStringPref("mochitest.testRoot", ""); if (testRoot.endsWith("/chrome")) { - // The initial window is created from browser startup, which races - // against extension initialization. If it has already been created, - // inject the test scripts now, otherwise wait for the browser window - // to show up. - let win = Services.wm.getMostRecentWindow("navigator:browser"); - if (win) { - loadChromeScripts(win); - return; - } - windowTracker.init(); } } @@ -106,38 +94,29 @@ function loadMochitest(e) { loadChromeScripts(win); } -this.mochikit = class extends ExtensionAPI { - onStartup() { - let aomStartup = Cc["@mozilla.org/addons/addon-manager-startup;1"] - .getService(Ci.amIAddonManagerStartup); - const manifestURI = Services.io.newURI("manifest.json", null, this.extension.rootURI); - const targetURL = this.extension.rootURI.resolve("content/"); - this.chromeHandle = aomStartup.registerChrome(manifestURI, [ - ["content", "mochikit", targetURL], - ]); - - if (AppConstants.platform == "android") { - androidStartup(); - } else { - let win = Services.wm.getMostRecentWindow("navigator:browser"); - // wait for event fired from start_desktop.js containing the - // suite and url to load - win.addEventListener("mochitest-load", loadMochitest); - } +function startup(data, reason) { + if (AppConstants.platform == "android") { + androidStartup(data, reason); + } else { + let win = Services.wm.getMostRecentWindow("navigator:browser"); + // wait for event fired from start_desktop.js containing the + // suite and url to load + win.addEventListener("mochitest-load", loadMochitest); } +} - onShutdown() { - if (AppConstants.platform != "android") { - let windows = Services.wm.getEnumerator("navigator:browser"); - while (windows.hasMoreElements()) { - let win = windows.getNext().QueryInterface(Ci.nsIDOMWindow); - WindowListener.tearDownWindow(win); - } - - Services.wm.removeListener(WindowListener); +function shutdown(data, reason) { + if (AppConstants.platform != "android") { + let windows = Services.wm.getEnumerator("navigator:browser"); + while (windows.hasMoreElements()) { + let win = windows.getNext().QueryInterface(Ci.nsIDOMWindow); + WindowListener.tearDownWindow(win); } - this.chromeHandle.destruct(); - this.chromeHandle = null; + Services.wm.removeListener(WindowListener); } -}; +} + +function install(data, reason) {} +function uninstall(data, reason) {} + diff --git a/testing/mochitest/jar.mn b/testing/mochitest/jar.mn new file mode 100644 index 000000000000..f6df24454f0d --- /dev/null +++ b/testing/mochitest/jar.mn @@ -0,0 +1,42 @@ +mochikit.jar: +% content mochikit %content/ + content/browser-harness.xul (browser-harness.xul) + content/browser-test.js (browser-test.js) + content/chrome-harness.js (chrome-harness.js) + content/mochitest-e10s-utils.js (mochitest-e10s-utils.js) + content/shutdown-leaks-collector.js (shutdown-leaks-collector.js) + content/ShutdownLeaksCollector.jsm (ShutdownLeaksCollector.jsm) + content/harness.xul (harness.xul) + content/redirect.html (redirect.html) + content/server.js (server.js) + content/chunkifyTests.js (chunkifyTests.js) + content/manifestLibrary.js (manifestLibrary.js) + content/nested_setup.js (nested_setup.js) + content/dynamic/getMyDirectory.sjs (dynamic/getMyDirectory.sjs) + content/static/harness.css (static/harness.css) + content/tests/SimpleTest/ChromePowers.js (tests/SimpleTest/ChromePowers.js) + content/tests/SimpleTest/EventUtils.js (tests/SimpleTest/EventUtils.js) + content/tests/SimpleTest/ExtensionTestUtils.js (tests/SimpleTest/ExtensionTestUtils.js) + content/tests/SimpleTest/AddTask.js (tests/SimpleTest/AddTask.js) + content/tests/SimpleTest/AsyncUtilsContent.js (tests/SimpleTest/AsyncUtilsContent.js) + content/tests/SimpleTest/LogController.js (tests/SimpleTest/LogController.js) + content/tests/SimpleTest/MemoryStats.js (tests/SimpleTest/MemoryStats.js) + content/tests/SimpleTest/MozillaLogger.js (../specialpowers/content/MozillaLogger.js) + content/tests/SimpleTest/specialpowers.js (../specialpowers/content/specialpowers.js) + content/tests/SimpleTest/SpecialPowersObserverAPI.js (../specialpowers/content/SpecialPowersObserverAPI.js) + content/tests/SimpleTest/specialpowersAPI.js (../specialpowers/content/specialpowersAPI.js) + content/tests/SimpleTest/setup.js (tests/SimpleTest/setup.js) + content/tests/SimpleTest/SimpleTest.js (tests/SimpleTest/SimpleTest.js) + content/tests/SimpleTest/StructuredLog.jsm (../modules/StructuredLog.jsm) + content/tests/SimpleTest/test.css (tests/SimpleTest/test.css) + content/tests/SimpleTest/TestRunner.js (tests/SimpleTest/TestRunner.js) + content/tests/SimpleTest/iframe-between-tests.html (tests/SimpleTest/iframe-between-tests.html) + content/tests/SimpleTest/WindowSnapshot.js (tests/SimpleTest/WindowSnapshot.js) + content/tests/SimpleTest/MockObjects.js (tests/SimpleTest/MockObjects.js) + content/tests/SimpleTest/NativeKeyCodes.js (tests/SimpleTest/NativeKeyCodes.js) + content/tests/SimpleTest/paint_listener.js (tests/SimpleTest/paint_listener.js) + content/tests/SimpleTest/docshell_helpers.js (../../docshell/test/chrome/docshell_helpers.js) + content/tests/BrowserTestUtils/content-task.js (BrowserTestUtils/content/content-task.js) + content/tests/BrowserTestUtils/content-about-page-utils.js (BrowserTestUtils/content/content-about-page-utils.js) + content/tests/BrowserTestUtils/content-utils.js (BrowserTestUtils/content/content-utils.js) + diff --git a/testing/mochitest/manifest.json b/testing/mochitest/manifest.json deleted file mode 100644 index c90f5c6cd9dc..000000000000 --- a/testing/mochitest/manifest.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "manifest_version": 2, - "name": "Mochitest", - "version": "2.0", - - "applications": { - "gecko": { - "id": "mochikit@mozilla.org" - } - }, - - "experiment_apis": { - "mochikit": { - "schema": "schema.json", - "parent": { - "scopes": ["addon_parent"], - "script": "api.js", - "events": ["startup"] - } - } - } -} diff --git a/testing/mochitest/moz.build b/testing/mochitest/moz.build index 4c91e6523232..a28dcc1f0397 100644 --- a/testing/mochitest/moz.build +++ b/testing/mochitest/moz.build @@ -13,67 +13,13 @@ DIRS += [ XPI_NAME = 'mochijar' +JAR_MANIFESTS += ['jar.mn'] + USE_EXTENSION_MANIFEST = True -FINAL_TARGET_FILES += [ - 'api.js', - 'manifest.json', - 'schema.json', -] +FINAL_TARGET_PP_FILES += ['install.rdf'] -FINAL_TARGET_FILES.content += [ - 'browser-harness.xul', - 'browser-test.js', - 'chrome-harness.js', - 'chunkifyTests.js', - 'harness.xul', - 'manifestLibrary.js', - 'mochitest-e10s-utils.js', - 'nested_setup.js', - 'redirect.html', - 'server.js', - 'shutdown-leaks-collector.js', - 'ShutdownLeaksCollector.jsm', -] - -FINAL_TARGET_FILES.content.dynamic += [ - 'dynamic/getMyDirectory.sjs', -] - -FINAL_TARGET_FILES.content.static += [ - 'static/harness.css', -] - -FINAL_TARGET_FILES.content.tests.SimpleTest += [ - '../../docshell/test/chrome/docshell_helpers.js', - '../modules/StructuredLog.jsm', - '../specialpowers/content/MozillaLogger.js', - '../specialpowers/content/specialpowers.js', - '../specialpowers/content/specialpowersAPI.js', - '../specialpowers/content/SpecialPowersObserverAPI.js', - 'tests/SimpleTest/AddTask.js', - 'tests/SimpleTest/AsyncUtilsContent.js', - 'tests/SimpleTest/ChromePowers.js', - 'tests/SimpleTest/EventUtils.js', - 'tests/SimpleTest/ExtensionTestUtils.js', - 'tests/SimpleTest/iframe-between-tests.html', - 'tests/SimpleTest/LogController.js', - 'tests/SimpleTest/MemoryStats.js', - 'tests/SimpleTest/MockObjects.js', - 'tests/SimpleTest/NativeKeyCodes.js', - 'tests/SimpleTest/paint_listener.js', - 'tests/SimpleTest/setup.js', - 'tests/SimpleTest/SimpleTest.js', - 'tests/SimpleTest/test.css', - 'tests/SimpleTest/TestRunner.js', - 'tests/SimpleTest/WindowSnapshot.js', -] - -FINAL_TARGET_FILES.content.tests.BrowserTestUtils += [ - 'BrowserTestUtils/content/content-about-page-utils.js', - 'BrowserTestUtils/content/content-task.js', - 'BrowserTestUtils/content/content-utils.js', -] +FINAL_TARGET_FILES += ['bootstrap.js'] MOCHITEST_MANIFESTS += [ 'baselinecoverage/plain/mochitest.ini', diff --git a/testing/mochitest/redirect.html b/testing/mochitest/redirect.html index 660f9b6c25c0..eba346952a8e 100644 --- a/testing/mochitest/redirect.html +++ b/testing/mochitest/redirect.html @@ -25,9 +25,8 @@ // added until then. window.addEventListener("MozAfterPaint", function() { setTimeout(redirectToHarness, 0); - - // In case the listener is not ready, re-try periodically - setInterval(redirectToHarness, 5000); + // In case the listener was not ready, try again after a few seconds. + setTimeout(redirectToHarness, 5000); }, {once: true}); } diff --git a/testing/mochitest/schema.json b/testing/mochitest/schema.json deleted file mode 100644 index fe51488c7066..000000000000 --- a/testing/mochitest/schema.json +++ /dev/null @@ -1 +0,0 @@ -[] diff --git a/toolkit/mozapps/extensions/AddonManagerStartup.cpp b/toolkit/mozapps/extensions/AddonManagerStartup.cpp index c1c071c1fdc7..6a5aeb81b351 100644 --- a/toolkit/mozapps/extensions/AddonManagerStartup.cpp +++ b/toolkit/mozapps/extensions/AddonManagerStartup.cpp @@ -670,13 +670,11 @@ public: NS_DECL_NSIJSRAIIHELPER using Override = AutoTArray; - using Content = AutoTArray; using Locale = AutoTArray; - RegistryEntries(FileLocation& location, nsTArray&& overrides, nsTArray&& content, nsTArray&& locales) + RegistryEntries(FileLocation& location, nsTArray&& overrides, nsTArray&& locales) : mLocation(location) , mOverrides(std::move(overrides)) - , mContent(std::move(content)) , mLocales(std::move(locales)) {} @@ -691,7 +689,6 @@ protected: private: FileLocation mLocation; const nsTArray mOverrides; - const nsTArray mContent; const nsTArray mLocales; }; @@ -709,11 +706,6 @@ RegistryEntries::Register() cr->ManifestOverride(context, 0, const_cast(args), 0); } - for (auto& content: mContent) { - const char* args[] = {content[0].get(), content[1].get()}; - cr->ManifestContent(context, 0, const_cast(args), 0); - } - for (auto& locale : mLocales) { const char* args[] = {locale[0].get(), locale[1].get(), locale[2].get()}; cr->ManifestLocale(context, 0, const_cast(args), 0); @@ -759,7 +751,6 @@ AddonManagerStartup::RegisterChrome(nsIURI* manifestURI, JS::HandleValue locatio nsTArray locales; - nsTArray content; nsTArray overrides; JS::RootedObject locs(cx, &locations.toObject()); @@ -787,9 +778,6 @@ AddonManagerStartup::RegisterChrome(nsIURI* manifestURI, JS::HandleValue locatio if (type.EqualsLiteral("override")) { NS_ENSURE_TRUE(vals.Length() == 2, NS_ERROR_INVALID_ARG); overrides.AppendElement(vals); - } else if (type.EqualsLiteral("content")) { - NS_ENSURE_TRUE(vals.Length() == 2, NS_ERROR_INVALID_ARG); - content.AppendElement(vals); } else if (type.EqualsLiteral("locale")) { NS_ENSURE_TRUE(vals.Length() == 3, NS_ERROR_INVALID_ARG); locales.AppendElement(vals); @@ -808,7 +796,6 @@ AddonManagerStartup::RegisterChrome(nsIURI* manifestURI, JS::HandleValue locatio auto entry = MakeRefPtr(location, std::move(overrides), - std::move(content), std::move(locales)); entry->Register(); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_registerchrome.js b/toolkit/mozapps/extensions/test/xpcshell/test_registerchrome.js index 137f0db70303..d66598fc2c9d 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_registerchrome.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_registerchrome.js @@ -16,7 +16,6 @@ add_task(async function() { let uri2 = getFileURI("manifest.json"); let overrideURL = Services.io.newURI("chrome://global/content/foo"); - let contentURL = Services.io.newURI("chrome://test/content/foo"); let localeURL = Services.io.newURI("chrome://global/locale/foo"); let origOverrideURL = registry.convertChromeURL(overrideURL); @@ -25,29 +24,23 @@ add_task(async function() { // eslint-disable-next-line no-unused-vars let entry1 = aomStartup.registerChrome(uri1, [ ["override", "chrome://global/content/foo", file1.spec], - ["content", "test", file2.spec + "/"], ["locale", "global", "en-US", file2.spec + "/"], ]); let entry2 = aomStartup.registerChrome(uri2, [ ["override", "chrome://global/content/foo", file2.spec], - ["content", "test", file1.spec + "/"], ["locale", "global", "en-US", file1.spec + "/"], ]); // Initially, the second entry should override the first. equal(registry.convertChromeURL(overrideURL).spec, file2.spec); - let file = file1.spec + "/foo"; - equal(registry.convertChromeURL(contentURL).spec, file); - equal(registry.convertChromeURL(localeURL).spec, file); + equal(registry.convertChromeURL(localeURL).spec, file1.spec + "/foo"); - // After destroying the second entry, the first entry should now take + // After destroying the second entry, the first entry should not take // precedence. entry2.destruct(); equal(registry.convertChromeURL(overrideURL).spec, file1.spec); - file = file2.spec + "/foo"; - equal(registry.convertChromeURL(contentURL).spec, file); - equal(registry.convertChromeURL(localeURL).spec, file); + equal(registry.convertChromeURL(localeURL).spec, file2.spec + "/foo"); // After dropping the reference to the first entry and allowing it to // be GCed, we should be back to the original entries. @@ -56,9 +49,6 @@ add_task(async function() { Cu.forceCC(); equal(registry.convertChromeURL(overrideURL).spec, origOverrideURL.spec); equal(registry.convertChromeURL(localeURL).spec, origLocaleURL.spec); - Assert.throws(() => registry.convertChromeURL(contentURL), - e => e.result == Cr.NS_ERROR_FILE_NOT_FOUND, - "chrome://test/ should no longer be registered"); }); add_task(async function() { @@ -68,6 +58,7 @@ add_task(async function() { ["foo"], [{}], [[]], + [["content", "foo", "bar"]], [["locale", "global"]], [["locale", "global", "en", "foo", "foo"]], [["override", "en"]],