Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'linux' && os_version == '18.04' && asan OR os == 'linux' && os_version == '18.04' && tsan OR win11_2009 && asan
- Manifest: browser/components/urlbar/tests/browser/browser.toml
/* Any copyright is dedicated to the Public Domain.
/**
* Tests that search mode remains active or is exited when setURI is called,
* depending on the situation.
*/
"use strict";
// Opens a new tab, does a search, enters search mode, and then manually calls
// setURI. Uses a variety of initial URLs, search strings, and setURI arguments
// in order to hit different branches in setURI. Search mode should remain
// active or be exited as appropriate.
add_task(async function setURI() {
for (let test of [
// initialURL, searchString, url, expectSearchMode
["about:blank", "", null, true],
["about:blank", "", "about:blank", true],
["about:blank", "about:blank", null, false],
["about:blank", "about:blank", "about:blank", false],
["about:blank", "not a URL", null, true],
["about:blank", "not a URL", "about:blank", true],
[
"about:blank",
false,
],
[
true,
],
]) {
await doSetURITest(...test);
}
});
async function doSetURITest(initialURL, searchString, url, expectSearchMode) {
info(
"doSetURITest with args: " +
JSON.stringify({
initialURL,
searchString,
url,
expectSearchMode,
})
);
await BrowserTestUtils.withNewTab(initialURL, async () => {
if (searchString) {
// Do a search with the search string.
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: searchString,
fireInputEvent: true,
});
} else {
// Open top sites.
await UrlbarTestUtils.promisePopupOpen(window, () => {
document.getElementById("Browser:OpenLocation").doCommand();
});
}
// Enter search mode and close the view.
await UrlbarTestUtils.enterSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
});
await UrlbarTestUtils.promisePopupClose(window);
Assert.strictEqual(
gBrowser.selectedBrowser.userTypedValue,
searchString,
`userTypedValue should be ${searchString}`
);
// Call setURI.
let uri = url ? Services.io.newURI(url) : null;
gURLBar.setURI(uri);
await UrlbarTestUtils.assertSearchMode(
window,
!expectSearchMode
? null
: {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
entry: "oneoff",
}
);
gURLBar.handleRevert();
await UrlbarTestUtils.assertSearchMode(window, null);
});
}