Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

/* Any copyright is dedicated to the Public Domain.
"use strict";
const { ActionsProviderContextualSearch } = ChromeUtils.importESModule(
);
const { AddonTestUtils } = ChromeUtils.importESModule(
);
add_setup(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.contextualSearch.enabled", true],
["browser.urlbar.secondaryActions.featureGate", true],
],
});
let ext = await SearchTestUtils.installSearchExtension({
name: "Contextual",
});
await AddonTestUtils.waitForSearchProviderStartup(ext);
});
add_task(async function test_selectContextualSearchResult_already_installed() {
const ENGINE_TEST_URL = "https://example.com/";
let onLoaded = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
false,
ENGINE_TEST_URL
);
BrowserTestUtils.startLoadingURIString(
gBrowser.selectedBrowser,
ENGINE_TEST_URL
);
await onLoaded;
const query = "search";
let engine = Services.search.getEngineByName("Contextual");
const [expectedUrl] = UrlbarUtils.getSearchQueryUrl(engine, query);
Assert.ok(
expectedUrl.includes(`?q=${query}`),
"Expected URL should be a search URL"
);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: query,
});
info("Focus and select the contextual search result");
let onLoad = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
false,
expectedUrl
);
EventUtils.synthesizeKey("KEY_Tab");
EventUtils.synthesizeKey("KEY_Enter");
await onLoad;
Assert.equal(
gBrowser.selectedBrowser.currentURI.spec,
expectedUrl,
"Selecting the contextual search result opens the search URL"
);
});
add_task(async function test_selectContextualSearchResult_not_installed() {
const ENGINE_TEST_URL =
const EXPECTED_URL =
let onLoaded = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
false,
ENGINE_TEST_URL
);
BrowserTestUtils.startLoadingURIString(
gBrowser.selectedBrowser,
ENGINE_TEST_URL
);
await onLoaded;
const query = "search";
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: query,
});
info("Focus and select the contextual search result");
let onLoad = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
false,
EXPECTED_URL
);
EventUtils.synthesizeKey("KEY_Tab");
EventUtils.synthesizeKey("KEY_Enter");
await onLoad;
Assert.equal(
gBrowser.selectedBrowser.currentURI.spec,
EXPECTED_URL,
"Selecting the contextual search result opens the search URL"
);
ActionsProviderContextualSearch.resetForTesting();
});