From 8bac8a33cec6d61e37f77361443694cdf0c610e9 Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Thu, 25 Nov 2021 01:14:51 +0000 Subject: [PATCH] Bug 1738815: Move quicksuggest tests into own dir. r=adw Differential Revision: https://phabricator.services.mozilla.com/D131324 --- .eslintrc.js | 6 +- browser/components/urlbar/moz.build | 8 ++- .../urlbar/tests/browser/browser.ini | 15 ----- .../urlbar/tests/browser/head-common.js | 9 --- .../urlbar/tests/browser/quicksuggest.sjs | 9 --- .../QuickSuggestTestUtils.jsm | 0 .../tests/quicksuggest/browser/browser.ini | 20 +++++++ .../browser/browser_quicksuggest.js | 3 +- .../browser_quicksuggest_configuration.js | 0 .../browser/browser_quicksuggest_indexes.js | 3 +- .../browser_quicksuggest_onboardingDialog.js | 0 .../browser_quicksuggest_telemetry.js} | 4 +- .../urlbar/tests/quicksuggest/browser/head.js | 31 ++++++++++ .../browser/searchSuggestionEngine.sjs | 57 +++++++++++++++++++ .../browser/searchSuggestionEngine.xml | 11 ++++ .../browser/subdialog.xhtml | 0 .../urlbar/tests/quicksuggest/unit/head.js | 4 ++ .../unit/test_quicksuggest.js | 0 .../unit/test_quicksuggest_keywordtree.js | 0 .../unit/test_quicksuggest_merino.js | 0 .../unit/test_quicksuggest_migrate_v1.js | 0 .../unit/test_quicksuggest_offlineDefault.js | 0 .../tests/quicksuggest/unit/xpcshell.ini | 10 ++++ .../components/urlbar/tests/unit/xpcshell.ini | 5 -- 24 files changed, 147 insertions(+), 48 deletions(-) delete mode 100644 browser/components/urlbar/tests/browser/quicksuggest.sjs rename browser/components/urlbar/tests/{ => quicksuggest}/QuickSuggestTestUtils.jsm (100%) create mode 100644 browser/components/urlbar/tests/quicksuggest/browser/browser.ini rename browser/components/urlbar/tests/{ => quicksuggest}/browser/browser_quicksuggest.js (97%) rename browser/components/urlbar/tests/{ => quicksuggest}/browser/browser_quicksuggest_configuration.js (100%) rename browser/components/urlbar/tests/{ => quicksuggest}/browser/browser_quicksuggest_indexes.js (99%) rename browser/components/urlbar/tests/{ => quicksuggest}/browser/browser_quicksuggest_onboardingDialog.js (100%) rename browser/components/urlbar/tests/{browser/browser_urlbar_telemetry_quicksuggest.js => quicksuggest/browser/browser_quicksuggest_telemetry.js} (99%) create mode 100644 browser/components/urlbar/tests/quicksuggest/browser/head.js create mode 100644 browser/components/urlbar/tests/quicksuggest/browser/searchSuggestionEngine.sjs create mode 100644 browser/components/urlbar/tests/quicksuggest/browser/searchSuggestionEngine.xml rename browser/components/urlbar/tests/{ => quicksuggest}/browser/subdialog.xhtml (100%) create mode 100644 browser/components/urlbar/tests/quicksuggest/unit/head.js rename browser/components/urlbar/tests/{ => quicksuggest}/unit/test_quicksuggest.js (100%) rename browser/components/urlbar/tests/{ => quicksuggest}/unit/test_quicksuggest_keywordtree.js (100%) rename browser/components/urlbar/tests/{ => quicksuggest}/unit/test_quicksuggest_merino.js (100%) rename browser/components/urlbar/tests/{ => quicksuggest}/unit/test_quicksuggest_migrate_v1.js (100%) rename browser/components/urlbar/tests/{ => quicksuggest}/unit/test_quicksuggest_offlineDefault.js (100%) create mode 100644 browser/components/urlbar/tests/quicksuggest/unit/xpcshell.ini diff --git a/.eslintrc.js b/.eslintrc.js index 7cbe74de4397..d03179b215d4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -21,7 +21,11 @@ function removeOverrides(config) { return config; } -const xpcshellTestPaths = ["**/test*/unit*/**/", "**/test*/xpcshell/**/"]; +const xpcshellTestPaths = [ + "**/test*/unit*/**/", + "**/test*/*/unit*/", + "**/test*/xpcshell/**/", +]; const browserTestPaths = ["**/test*/**/browser*/"]; diff --git a/browser/components/urlbar/moz.build b/browser/components/urlbar/moz.build index b8186e333d5f..24d8d54c5be9 100644 --- a/browser/components/urlbar/moz.build +++ b/browser/components/urlbar/moz.build @@ -51,7 +51,7 @@ EXTRA_JS_MODULES += [ ] TESTING_JS_MODULES += [ - "tests/QuickSuggestTestUtils.jsm", + "tests/quicksuggest/QuickSuggestTestUtils.jsm", "tests/UrlbarTestUtils.jsm", ] BROWSER_CHROME_MANIFESTS += [ @@ -59,7 +59,11 @@ BROWSER_CHROME_MANIFESTS += [ "tests/browser-updateResults/browser.ini", "tests/browser/browser.ini", "tests/ext/browser/browser.ini", + "tests/quicksuggest/browser/browser.ini", +] +XPCSHELL_TESTS_MANIFESTS += [ + "tests/quicksuggest/unit/xpcshell.ini", + "tests/unit/xpcshell.ini", ] -XPCSHELL_TESTS_MANIFESTS += ["tests/unit/xpcshell.ini"] SPHINX_TREES["/browser/urlbar"] = "docs" diff --git a/browser/components/urlbar/tests/browser/browser.ini b/browser/components/urlbar/tests/browser/browser.ini index 64c8c31d8c78..af7175e6b585 100644 --- a/browser/components/urlbar/tests/browser/browser.ini +++ b/browser/components/urlbar/tests/browser/browser.ini @@ -171,19 +171,6 @@ support-files = [browser_populateAfterPushState.js] [browser_primary_selection_safe_on_new_tab.js] [browser_privateBrowsingWindowChange.js] -[browser_quicksuggest.js] -support-files = - quicksuggest.sjs -skip-if = asan # Bug 1701321 -[browser_quicksuggest_configuration.js] -skip-if = asan # Bug 1701321 -[browser_quicksuggest_indexes.js] -support-files = - quicksuggest.sjs -skip-if = asan # Bug 1701321 -[browser_quicksuggest_onboardingDialog.js] -support-files = - subdialog.xhtml [browser_raceWithTabs.js] [browser_redirect_error.js] support-files = redirect_error.sjs @@ -333,8 +320,6 @@ tags = search-telemetry [browser_urlbar_telemetry_places.js] https_first_disabled = true tags = search-telemetry -[browser_urlbar_telemetry_quicksuggest.js] -tags = search-telemetry [browser_urlbar_telemetry_remotetab.js] tags = search-telemetry [browser_urlbar_telemetry_searchmode.js] diff --git a/browser/components/urlbar/tests/browser/head-common.js b/browser/components/urlbar/tests/browser/head-common.js index 24553c1759e8..2790178a769c 100644 --- a/browser/components/urlbar/tests/browser/head-common.js +++ b/browser/components/urlbar/tests/browser/head-common.js @@ -30,15 +30,6 @@ XPCOMUtils.defineLazyServiceGetter( "nsIClipboardHelper" ); -XPCOMUtils.defineLazyGetter(this, "QuickSuggestTestUtils", () => { - const { QuickSuggestTestUtils: module } = ChromeUtils.import( - "resource://testing-common/QuickSuggestTestUtils.jsm" - ); - module.init(this); - registerCleanupFunction(() => module.uninit()); - return module; -}); - XPCOMUtils.defineLazyGetter(this, "UrlbarTestUtils", () => { const { UrlbarTestUtils: module } = ChromeUtils.import( "resource://testing-common/UrlbarTestUtils.jsm" diff --git a/browser/components/urlbar/tests/browser/quicksuggest.sjs b/browser/components/urlbar/tests/browser/quicksuggest.sjs deleted file mode 100644 index 3c00c24619ae..000000000000 --- a/browser/components/urlbar/tests/browser/quicksuggest.sjs +++ /dev/null @@ -1,9 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -function handleRequest(request, response) { - Components.utils.importGlobalProperties(["URLSearchParams"]); - let query = new URLSearchParams(request.queryString); - response.setHeader("Content-Type", "text/html", false); - response.write(query.get("q")); -} diff --git a/browser/components/urlbar/tests/QuickSuggestTestUtils.jsm b/browser/components/urlbar/tests/quicksuggest/QuickSuggestTestUtils.jsm similarity index 100% rename from browser/components/urlbar/tests/QuickSuggestTestUtils.jsm rename to browser/components/urlbar/tests/quicksuggest/QuickSuggestTestUtils.jsm diff --git a/browser/components/urlbar/tests/quicksuggest/browser/browser.ini b/browser/components/urlbar/tests/quicksuggest/browser/browser.ini new file mode 100644 index 000000000000..f4ab4ebf5f2a --- /dev/null +++ b/browser/components/urlbar/tests/quicksuggest/browser/browser.ini @@ -0,0 +1,20 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# 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/. + +[DEFAULT] +support-files = + head.js + searchSuggestionEngine.xml + searchSuggestionEngine.sjs + subdialog.xhtml + +[browser_quicksuggest.js] +skip-if = asan # Bug 1701321 +[browser_quicksuggest_configuration.js] +skip-if = asan # Bug 1701321 +[browser_quicksuggest_indexes.js] +skip-if = asan # Bug 1701321 +[browser_quicksuggest_onboardingDialog.js] +[browser_quicksuggest_telemetry.js] +tags = search-telemetry diff --git a/browser/components/urlbar/tests/browser/browser_quicksuggest.js b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest.js similarity index 97% rename from browser/components/urlbar/tests/browser/browser_quicksuggest.js rename to browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest.js index c4e8e1e5f329..f95820d191bf 100644 --- a/browser/components/urlbar/tests/browser/browser_quicksuggest.js +++ b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest.js @@ -11,8 +11,7 @@ XPCOMUtils.defineLazyModuleGetters(this, { UrlbarQuickSuggest: "resource:///modules/UrlbarQuickSuggest.jsm", }); -const TEST_URL = - "http://mochi.test:8888/browser/browser/components/urlbar/tests/browser/quicksuggest.sjs"; +const TEST_URL = "http://example.com/quicksuggest"; const TEST_DATA = [ { diff --git a/browser/components/urlbar/tests/browser/browser_quicksuggest_configuration.js b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_configuration.js similarity index 100% rename from browser/components/urlbar/tests/browser/browser_quicksuggest_configuration.js rename to browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_configuration.js diff --git a/browser/components/urlbar/tests/browser/browser_quicksuggest_indexes.js b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_indexes.js similarity index 99% rename from browser/components/urlbar/tests/browser/browser_quicksuggest_indexes.js rename to browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_indexes.js index a1a6b076afe5..6023512ed6b7 100644 --- a/browser/components/urlbar/tests/browser/browser_quicksuggest_indexes.js +++ b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_indexes.js @@ -25,8 +25,7 @@ const NON_SPONSORED_INDEX_PREF = const SPONSORED_SEARCH_STRING = "frabbits"; const NON_SPONSORED_SEARCH_STRING = "nonspon"; -const TEST_URL = - "http://mochi.test:8888/browser/browser/components/urlbar/tests/browser/quicksuggest.sjs"; +const TEST_URL = "http://example.com/quicksuggest"; const TEST_DATA = [ { diff --git a/browser/components/urlbar/tests/browser/browser_quicksuggest_onboardingDialog.js b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_onboardingDialog.js similarity index 100% rename from browser/components/urlbar/tests/browser/browser_quicksuggest_onboardingDialog.js rename to browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_onboardingDialog.js diff --git a/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_quicksuggest.js b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_telemetry.js similarity index 99% rename from browser/components/urlbar/tests/browser/browser_urlbar_telemetry_quicksuggest.js rename to browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_telemetry.js index 64535aded310..4cf2d1db4a7f 100644 --- a/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_quicksuggest.js +++ b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_telemetry.js @@ -15,9 +15,7 @@ XPCOMUtils.defineLazyModuleGetters(this, { NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm", }); -const TEST_SJS = - "http://mochi.test:8888/browser/browser/components/urlbar/tests/browser/quicksuggest.sjs"; -const TEST_URL = TEST_SJS + "?q=frabbits"; +const TEST_URL = "http://example.com/quicksuggest?q=frabbits"; const TEST_SEARCH_STRING = "frab"; const TEST_DATA = [ { diff --git a/browser/components/urlbar/tests/quicksuggest/browser/head.js b/browser/components/urlbar/tests/quicksuggest/browser/head.js new file mode 100644 index 000000000000..324c161047eb --- /dev/null +++ b/browser/components/urlbar/tests/quicksuggest/browser/head.js @@ -0,0 +1,31 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let sandbox; + +/* import-globals-from ../../browser/head-common.js */ +Services.scriptloader.loadSubScript( + "chrome://mochitests/content/browser/browser/components/urlbar/tests/browser/head-common.js", + this +); + +XPCOMUtils.defineLazyModuleGetters(this, { + TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.jsm", +}); + +XPCOMUtils.defineLazyGetter(this, "QuickSuggestTestUtils", () => { + const { QuickSuggestTestUtils: module } = ChromeUtils.import( + "resource://testing-common/QuickSuggestTestUtils.jsm" + ); + module.init(this); + registerCleanupFunction(() => module.uninit()); + return module; +}); + +registerCleanupFunction(async () => { + // Ensure the Urlbar popup is always closed at the end of a test, to save having + // to do it within each test. + await UrlbarTestUtils.promisePopupClose(window); +}); diff --git a/browser/components/urlbar/tests/quicksuggest/browser/searchSuggestionEngine.sjs b/browser/components/urlbar/tests/quicksuggest/browser/searchSuggestionEngine.sjs new file mode 100644 index 000000000000..145392fcf2ee --- /dev/null +++ b/browser/components/urlbar/tests/quicksuggest/browser/searchSuggestionEngine.sjs @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +let gTimer; + +function handleRequest(req, resp) { + // Parse the query params. If the params aren't in the form "foo=bar", then + // treat the entire query string as a search string. + let params = req.queryString.split("&").reduce((memo, pair) => { + let [key, val] = pair.split("="); + if (!val) { + // This part isn't in the form "foo=bar". Treat it as the search string + // (the "query"). + val = key; + key = "query"; + } + memo[decode(key)] = decode(val); + return memo; + }, {}); + + let timeout = parseInt(params.timeout); + if (timeout) { + // Write the response after a timeout. + resp.processAsync(); + gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); + gTimer.init( + () => { + writeResponse(params, resp); + resp.finish(); + }, + timeout, + Ci.nsITimer.TYPE_ONE_SHOT + ); + return; + } + + writeResponse(params, resp); +} + +function writeResponse(params, resp) { + // Echo back the search string with "foo" and "bar" appended. + let suffixes = ["foo", "bar"]; + if (params.count) { + // Add more suffixes. + let serial = 0; + while (suffixes.length < params.count) { + suffixes.push(++serial); + } + } + let data = [params.query, suffixes.map(s => params.query + s)]; + resp.setHeader("Content-Type", "application/json", false); + resp.write(JSON.stringify(data)); +} + +function decode(str) { + return decodeURIComponent(str.replace(/\+/g, encodeURIComponent(" "))); +} diff --git a/browser/components/urlbar/tests/quicksuggest/browser/searchSuggestionEngine.xml b/browser/components/urlbar/tests/quicksuggest/browser/searchSuggestionEngine.xml new file mode 100644 index 000000000000..142c91849c05 --- /dev/null +++ b/browser/components/urlbar/tests/quicksuggest/browser/searchSuggestionEngine.xml @@ -0,0 +1,11 @@ + + + + +browser_searchSuggestionEngine searchSuggestionEngine.xml + + + + + diff --git a/browser/components/urlbar/tests/browser/subdialog.xhtml b/browser/components/urlbar/tests/quicksuggest/browser/subdialog.xhtml similarity index 100% rename from browser/components/urlbar/tests/browser/subdialog.xhtml rename to browser/components/urlbar/tests/quicksuggest/browser/subdialog.xhtml diff --git a/browser/components/urlbar/tests/quicksuggest/unit/head.js b/browser/components/urlbar/tests/quicksuggest/unit/head.js new file mode 100644 index 000000000000..e7cf4426eb7f --- /dev/null +++ b/browser/components/urlbar/tests/quicksuggest/unit/head.js @@ -0,0 +1,4 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* import-globals-from ../../unit/head.js */ diff --git a/browser/components/urlbar/tests/unit/test_quicksuggest.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest.js similarity index 100% rename from browser/components/urlbar/tests/unit/test_quicksuggest.js rename to browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest.js diff --git a/browser/components/urlbar/tests/unit/test_quicksuggest_keywordtree.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_keywordtree.js similarity index 100% rename from browser/components/urlbar/tests/unit/test_quicksuggest_keywordtree.js rename to browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_keywordtree.js diff --git a/browser/components/urlbar/tests/unit/test_quicksuggest_merino.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_merino.js similarity index 100% rename from browser/components/urlbar/tests/unit/test_quicksuggest_merino.js rename to browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_merino.js diff --git a/browser/components/urlbar/tests/unit/test_quicksuggest_migrate_v1.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v1.js similarity index 100% rename from browser/components/urlbar/tests/unit/test_quicksuggest_migrate_v1.js rename to browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_migrate_v1.js diff --git a/browser/components/urlbar/tests/unit/test_quicksuggest_offlineDefault.js b/browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_offlineDefault.js similarity index 100% rename from browser/components/urlbar/tests/unit/test_quicksuggest_offlineDefault.js rename to browser/components/urlbar/tests/quicksuggest/unit/test_quicksuggest_offlineDefault.js diff --git a/browser/components/urlbar/tests/quicksuggest/unit/xpcshell.ini b/browser/components/urlbar/tests/quicksuggest/unit/xpcshell.ini new file mode 100644 index 000000000000..a94a5c253a7c --- /dev/null +++ b/browser/components/urlbar/tests/quicksuggest/unit/xpcshell.ini @@ -0,0 +1,10 @@ +[DEFAULT] +skip-if = toolkit == 'android' # bug 1730213 +head = head.js ../../unit/head.js +firefox-appdir = browser + +[test_quicksuggest.js] +[test_quicksuggest_keywordtree.js] +[test_quicksuggest_merino.js] +[test_quicksuggest_migrate_v1.js] +[test_quicksuggest_offlineDefault.js] diff --git a/browser/components/urlbar/tests/unit/xpcshell.ini b/browser/components/urlbar/tests/unit/xpcshell.ini index dc1506b0f3ae..e0debb33cdf1 100644 --- a/browser/components/urlbar/tests/unit/xpcshell.ini +++ b/browser/components/urlbar/tests/unit/xpcshell.ini @@ -70,11 +70,6 @@ skip-if = !sync [test_tags_general.js] [test_tags_matchBookmarkTitles.js] [test_tags_returnedInSearches.js] -[test_quicksuggest.js] -[test_quicksuggest_keywordtree.js] -[test_quicksuggest_merino.js] -[test_quicksuggest_migrate_v1.js] -[test_quicksuggest_offlineDefault.js] [test_tokenizer.js] [test_trimming.js] [test_unitConversion.js]