diff options
Diffstat (limited to 'browser/components/urlbar/tests/quicksuggest/browser')
4 files changed, 179 insertions, 15 deletions
diff --git a/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_onboardingDialog.js b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_onboardingDialog.js index 6256a5aec2..dbd8f59ade 100644 --- a/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_onboardingDialog.js +++ b/browser/components/urlbar/tests/quicksuggest/browser/browser_quicksuggest_onboardingDialog.js @@ -373,7 +373,6 @@ const VARIATION_TEST_DATA = [ "onboardingNext", "onboardingAccept", "onboardingLearnMore", - "onboardingReject", "onboardingSkipLink", "onboardingDialog", "onboardingAccept", @@ -706,7 +705,6 @@ const VARIATION_TEST_DATA = [ "onboardingNext", "onboardingLearnMore", "onboardingAccept", - "onboardingReject", "onboardingSkipLink", "onboardingDialog", "onboardingLearnMore", @@ -762,7 +760,6 @@ const VARIATION_TEST_DATA = [ defaultFocusOrder: [ "onboardingLearnMore", "onboardingAccept", - "onboardingReject", "onboardingSkipLink", "onboardingDialog", "onboardingLearnMore", diff --git a/browser/components/urlbar/tests/quicksuggest/browser/browser_telemetry_impressionEdgeCases.js b/browser/components/urlbar/tests/quicksuggest/browser/browser_telemetry_impressionEdgeCases.js index 8682f1f53a..821c5cf470 100644 --- a/browser/components/urlbar/tests/quicksuggest/browser/browser_telemetry_impressionEdgeCases.js +++ b/browser/components/urlbar/tests/quicksuggest/browser/browser_telemetry_impressionEdgeCases.js @@ -172,7 +172,7 @@ add_task(async function hiddenRow() { // mutation listener to the view so we can tell when the quick suggest row is // added. let mutationPromise = new Promise(resolve => { - let observer = new MutationObserver(mutations => { + let observer = new MutationObserver(() => { let rows = UrlbarTestUtils.getResultsContainer(window).children; for (let row of rows) { if (row.result.providerName == "UrlbarProviderQuickSuggest") { diff --git a/browser/components/urlbar/tests/quicksuggest/browser/browser_weather.js b/browser/components/urlbar/tests/quicksuggest/browser/browser_weather.js index 1c3f0e62e7..e10e87b516 100644 --- a/browser/components/urlbar/tests/quicksuggest/browser/browser_weather.js +++ b/browser/components/urlbar/tests/quicksuggest/browser/browser_weather.js @@ -11,6 +11,11 @@ ChromeUtils.defineESModuleGetters(this, { UrlbarProviderWeather: "resource:///modules/UrlbarProviderWeather.sys.mjs", }); +// This test takes a while and can time out in verify mode. Each task is run +// twice, once with Rust enabled and once with it disabled. Once we remove the +// JS backend this should improve a lot, but for now request a longer timeout. +requestLongerTimeout(5); + add_setup(async function () { await QuickSuggestTestUtils.ensureQuickSuggestInit({ remoteSettingsRecords: [ @@ -21,6 +26,15 @@ add_setup(async function () { ], }); await MerinoTestUtils.initWeather(); + + // When `add_tasks_with_rust()` disables the Rust backend and forces sync, the + // JS backend will sync `Weather` with remote settings. Since keywords are + // present in remote settings at that point (we added them above), `Weather` + // will then start fetching. The fetch may or may not be done before our test + // task starts. To make sure it's done, queue another fetch and await it. + registerAddTasksWithRustSetup(async () => { + await QuickSuggest.weather._test_fetch(); + }); }); // Basic checks of the row DOM. @@ -341,11 +355,8 @@ async function doDismissTest(command) { await UrlbarTestUtils.promisePopupClose(window); // Enable the weather suggestion again and wait for it to be fetched. - let fetchPromise = QuickSuggest.weather.waitForFetches(); UrlbarPrefs.clear("suggest.weather"); - info("Waiting for weather fetch after re-enabling the suggestion"); - await fetchPromise; - info("Got weather fetch"); + await QuickSuggest.weather._test_fetch(); // Wait for keywords to be re-synced from remote settings. await QuickSuggestTestUtils.forceSync(); @@ -396,6 +407,94 @@ async function doSessionOngoingCommandTest(command) { await doDismissTest("not_interested"); } +// Test for menu item to mange the suggest. +add_tasks_with_rust(async function manage() { + await BrowserTestUtils.withNewTab({ gBrowser }, async browser => { + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: MerinoTestUtils.WEATHER_KEYWORD, + }); + + let resultIndex = 1; + let details = await UrlbarTestUtils.getDetailsOfResultAt( + window, + resultIndex + ); + assertIsWeatherResult(details.result, true); + + const managePage = "about:preferences#search"; + let onManagePageLoaded = BrowserTestUtils.browserLoaded( + browser, + false, + managePage + ); + // Click the command. + await UrlbarTestUtils.openResultMenuAndClickItem(window, "manage", { + resultIndex, + }); + await onManagePageLoaded; + Assert.equal( + browser.currentURI.spec, + managePage, + "The manage page is loaded" + ); + + await UrlbarTestUtils.promisePopupClose(window); + }); +}); + +// Test for simple UI. +add_tasks_with_rust(async function simpleUI() { + const testData = [ + { + weatherSimpleUI: true, + expectedSummary: + MerinoTestUtils.WEATHER_SUGGESTION.current_conditions.summary, + }, + { + weatherSimpleUI: false, + expectedSummary: `${MerinoTestUtils.WEATHER_SUGGESTION.current_conditions.summary}; ${MerinoTestUtils.WEATHER_SUGGESTION.forecast.summary}`, + }, + ]; + + for (let { weatherSimpleUI, expectedSummary } of testData) { + let nimbusCleanup = await UrlbarTestUtils.initNimbusFeature({ + weatherSimpleUI, + }); + + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: MerinoTestUtils.WEATHER_KEYWORD, + }); + + let resultIndex = 1; + let details = await UrlbarTestUtils.getDetailsOfResultAt( + window, + resultIndex + ); + assertIsWeatherResult(details.result, true); + + let { row } = details.element; + let summary = row.querySelector(".urlbarView-dynamic-weather-summaryText"); + + // `getViewUpdate()` is allowed to be async and `UrlbarView` awaits it even + // though the `Weather` implementation is not async. That means the summary + // text content will be updated asyncly, so we need to wait for it. + await TestUtils.waitForCondition( + () => summary.textContent == expectedSummary, + "Waiting for the row's summary text to be updated" + ); + Assert.equal( + summary.textContent, + expectedSummary, + "The summary text should be correct" + ); + + await UrlbarTestUtils.promisePopupClose(window); + await nimbusCleanup(); + } +}); + function assertIsWeatherResult(result, isWeatherResult) { let provider = UrlbarPrefs.get("quickSuggestRustEnabled") ? UrlbarProviderQuickSuggest diff --git a/browser/components/urlbar/tests/quicksuggest/browser/head.js b/browser/components/urlbar/tests/quicksuggest/browser/head.js index 7d62a44d45..cc5f449e94 100644 --- a/browser/components/urlbar/tests/quicksuggest/browser/head.js +++ b/browser/components/urlbar/tests/quicksuggest/browser/head.js @@ -636,20 +636,49 @@ function _assertGleanPing(ping) { } } +let gAddTasksWithRustSetup; + /** * Adds two tasks: One with the Rust backend disabled and one with it enabled. * The names of the task functions will be the name of the passed-in task - * function appended with "_rustDisabled" and "_rustEnabled" respectively. Call - * with the usual `add_task()` arguments. + * function appended with "_rustDisabled" and "_rustEnabled". If the passed-in + * task doesn't have a name, "anonymousTask" will be used. + * + * Call this with the usual `add_task()` arguments. Additionally, an object with + * the following properties can be specified as any argument: + * + * {boolean} skip_if_rust_enabled + * If true, a "_rustEnabled" task won't be added. Useful when Rust is enabled + * by default but the task doesn't make sense with Rust and you still want to + * test some behavior when Rust is disabled. * * @param {...any} args * The usual `add_task()` arguments. */ function add_tasks_with_rust(...args) { + let skipIfRustEnabled = false; + let i = args.findIndex(a => a.skip_if_rust_enabled); + if (i >= 0) { + skipIfRustEnabled = true; + args.splice(i, 1); + } + let taskFnIndex = args.findIndex(a => typeof a == "function"); let taskFn = args[taskFnIndex]; for (let rustEnabled of [false, true]) { + let newTaskName = + (taskFn.name || "anonymousTask") + + (rustEnabled ? "_rustEnabled" : "_rustDisabled"); + + if (rustEnabled && skipIfRustEnabled) { + info( + "add_tasks_with_rust: Skipping due to skip_if_rust_enabled: " + + newTaskName + ); + continue; + } + let newTaskFn = async (...taskFnArgs) => { info("add_tasks_with_rust: Setting rustEnabled: " + rustEnabled); UrlbarPrefs.set("quicksuggest.rustEnabled", rustEnabled); @@ -660,12 +689,30 @@ function add_tasks_with_rust(...args) { await QuickSuggestTestUtils.forceSync(); info("add_tasks_with_rust: Done forcing sync"); + if (gAddTasksWithRustSetup) { + info("add_tasks_with_rust: Calling setup function"); + await gAddTasksWithRustSetup(); + info("add_tasks_with_rust: Done calling setup function"); + } + let rv; try { info( "add_tasks_with_rust: Calling original task function: " + taskFn.name ); rv = await taskFn(...taskFnArgs); + } catch (e) { + // Clearly report any unusual errors to make them easier to spot and to + // make the flow of the test clearer. The harness throws NS_ERROR_ABORT + // when a normal assertion fails, so don't report that. + if (e.result != Cr.NS_ERROR_ABORT) { + Assert.ok( + false, + "add_tasks_with_rust: The original task function threw an error: " + + e + ); + } + throw e; } finally { info( "add_tasks_with_rust: Done calling original task function: " + @@ -683,11 +730,32 @@ function add_tasks_with_rust(...args) { return rv; }; - Object.defineProperty(newTaskFn, "name", { - value: taskFn.name + (rustEnabled ? "_rustEnabled" : "_rustDisabled"), - }); - let addTaskArgs = [...args]; - addTaskArgs[taskFnIndex] = newTaskFn; + Object.defineProperty(newTaskFn, "name", { value: newTaskName }); + + let addTaskArgs = []; + for (let j = 0; j < args.length; j++) { + addTaskArgs[j] = + j == taskFnIndex + ? newTaskFn + : Cu.cloneInto(args[j], this, { cloneFunctions: true }); + } add_task(...addTaskArgs); } } + +/** + * Registers a setup function that `add_tasks_with_rust()` will await before + * calling each of your original tasks. Call this at most once in your test file + * (i.e., in `add_setup()`). This is useful when enabling/disabling Rust has + * side effects related to your particular test that need to be handled or + * awaited for each of your tasks. On the other hand, if only one or two of your + * tasks need special setup, do it directly in those tasks instead of using + * this. The passed-in `setupFn` is automatically unregistered on cleanup. + * + * @param {Function} setupFn + * A function that will be awaited before your original tasks are called. + */ +function registerAddTasksWithRustSetup(setupFn) { + gAddTasksWithRustSetup = setupFn; + registerCleanupFunction(() => (gAddTasksWithRustSetup = null)); +} |