Bug 1452299: Make browser_ext_settings_overrides_search a less-dodgy xpcshell test. r=mkaply
authorKris Maglione <maglione.k@gmail.com>
Fri, 06 Apr 2018 17:34:23 -0700
changeset 467739 97dd772529d888777e85b202a32aa7414df24491
parent 467738 8e754a50cee54e4d516657e52c6fe9779df82762
child 467740 e138e43fb405ee86f92682d3a142f79ea80ed906
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkaply
bugs1452299
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1452299: Make browser_ext_settings_overrides_search a less-dodgy xpcshell test. r=mkaply MozReview-Commit-ID: CffGpvV9vck
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_settings_overrides_search.js
browser/components/extensions/test/xpcshell/test_ext_settings_overrides_search.js
browser/components/extensions/test/xpcshell/xpcshell-common.ini
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -130,17 +130,16 @@ disabled = bug 1438663
 [browser_ext_sessions_forgetClosedTab.js]
 [browser_ext_sessions_forgetClosedWindow.js]
 [browser_ext_sessions_getRecentlyClosed.js]
 [browser_ext_sessions_getRecentlyClosed_private.js]
 [browser_ext_sessions_getRecentlyClosed_tabs.js]
 [browser_ext_sessions_restore.js]
 [browser_ext_sessions_window_tab_value.js]
 [browser_ext_settings_overrides_default_search.js]
-[browser_ext_settings_overrides_search.js]
 [browser_ext_sidebarAction.js]
 [browser_ext_sidebarAction_browser_style.js]
 [browser_ext_sidebarAction_context.js]
 [browser_ext_sidebarAction_contextMenu.js]
 [browser_ext_sidebarAction_runtime.js]
 [browser_ext_sidebarAction_tabs.js]
 [browser_ext_sidebarAction_windows.js]
 [browser_ext_simple.js]
rename from browser/components/extensions/test/browser/browser_ext_settings_overrides_search.js
rename to browser/components/extensions/test/xpcshell/test_ext_settings_overrides_search.js
--- a/browser/components/extensions/test/browser/browser_ext_settings_overrides_search.js
+++ b/browser/components/extensions/test/xpcshell/test_ext_settings_overrides_search.js
@@ -1,20 +1,32 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 
 "use strict";
 
+ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
+ChromeUtils.import("resource://gre/modules/Timer.jsm");
+
+let delay = () => new Promise(resolve => setTimeout(resolve, 0));
 
 const kSearchEngineURL = "https://example.com/?search={searchTerms}";
 const kSearchSuggestURL = "http://example.com/?suggest={searchTerms}";
 const kSearchTerm = "foo";
 const kSearchTermIntl = "日";
 const URLTYPE_SUGGEST_JSON = "application/x-suggestions+json";
 
+AddonTestUtils.init(this);
+AddonTestUtils.createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "42", "42");
+
+add_task(async function setup() {
+  await AddonTestUtils.promiseStartupManager();
+  Services.search.init();
+});
+
 add_task(async function test_extension_adding_engine() {
   let ext1 = ExtensionTestUtils.loadExtension({
     manifest: {
       "chrome_settings_overrides": {
         "search_provider": {
           "name": "MozSearch",
           "keyword": "MozSearch",
           "search_url": kSearchEngineURL,
@@ -29,21 +41,22 @@ add_task(async function test_extension_a
 
   let engine = Services.search.getEngineByName("MozSearch");
   ok(engine, "Engine should exist.");
 
   let expectedSuggestURL = kSearchSuggestURL.replace("{searchTerms}", kSearchTerm);
   let submissionSuggest = engine.getSubmission(kSearchTerm, URLTYPE_SUGGEST_JSON);
   let encodedSubmissionURL = engine.getSubmission(kSearchTermIntl).uri.spec;
   let testSubmissionURL = kSearchEngineURL.replace("{searchTerms}", encodeURIComponent(kSearchTermIntl));
-  is(encodedSubmissionURL, testSubmissionURL, "Encoded UTF-8 URLs should match");
+  equal(encodedSubmissionURL, testSubmissionURL, "Encoded UTF-8 URLs should match");
 
-  is(submissionSuggest.uri.spec, expectedSuggestURL, "Suggest URLs should match");
+  equal(submissionSuggest.uri.spec, expectedSuggestURL, "Suggest URLs should match");
 
   await ext1.unload();
+  await delay();
 
   engine = Services.search.getEngineByName("MozSearch");
   ok(!engine, "Engine should not exist");
 });
 
 add_task(async function test_extension_adding_engine_with_spaces() {
   let ext1 = ExtensionTestUtils.loadExtension({
     manifest: {
@@ -59,16 +72,17 @@ add_task(async function test_extension_a
   });
 
   await ext1.startup();
 
   let engine = Services.search.getEngineByName("MozSearch");
   ok(engine, "Engine should exist.");
 
   await ext1.unload();
+  await delay();
 
   engine = Services.search.getEngineByName("MozSearch");
   ok(!engine, "Engine should not exist");
 });
 
 
 add_task(async function test_upgrade_default_position_engine() {
   let ext1 = ExtensionTestUtils.loadExtension({
@@ -85,17 +99,23 @@ add_task(async function test_upgrade_def
           "id": "testengine@mozilla.com",
         },
       },
       "version": "0.1",
     },
     useAddonManager: "temporary",
   });
 
-  let ext2 = ExtensionTestUtils.loadExtension({
+  await ext1.startup();
+
+  let engine = Services.search.getEngineByName("MozSearch");
+  Services.search.currentEngine = engine;
+  Services.search.moveEngine(engine, 1);
+
+  await ext1.upgrade({
     manifest: {
       "chrome_settings_overrides": {
         "search_provider": {
           "name": "MozSearch",
           "keyword": "MozSearch",
           "search_url": "https://example.com/?q={searchTerms}",
         },
       },
@@ -104,26 +124,18 @@ add_task(async function test_upgrade_def
           "id": "testengine@mozilla.com",
         },
       },
       "version": "0.2",
     },
     useAddonManager: "temporary",
   });
 
-  await ext1.startup();
-
-  let engine = Services.search.getEngineByName("MozSearch");
-  Services.search.currentEngine = engine;
-  Services.search.moveEngine(engine, 1);
+  engine = Services.search.getEngineByName("MozSearch");
+  equal(Services.search.currentEngine, engine, "Default engine should still be MozSearch");
+  equal(Services.search.getEngines().indexOf(engine), 1, "Engine is in position 1");
 
-  await ext2.startup();
-
-  engine = Services.search.getEngineByName("MozSearch");
-  is(Services.search.currentEngine, engine, "Default engine should still be MozSearch");
-  is(Services.search.getEngines().indexOf(engine), 1, "Engine is in position 1");
-
-  await ext2.unload();
   await ext1.unload();
+  await delay();
 
   engine = Services.search.getEngineByName("MozSearch");
   ok(!engine, "Engine should not exist");
 });
--- a/browser/components/extensions/test/xpcshell/xpcshell-common.ini
+++ b/browser/components/extensions/test/xpcshell/xpcshell-common.ini
@@ -2,11 +2,12 @@
 [test_ext_browsingData.js]
 [test_ext_browsingData_cookies_cache.js]
 [test_ext_browsingData_downloads.js]
 [test_ext_browsingData_passwords.js]
 [test_ext_browsingData_settings.js]
 [test_ext_chrome_settings_overrides_update.js]
 [test_ext_geckoProfiler_control.js]
 [test_ext_history.js]
+[test_ext_settings_overrides_search.js]
 [test_ext_url_overrides_newtab.js]
 [test_ext_url_overrides_newtab_update.js]