зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1659128 - Exit search mode as appropriate when input.setURI is called. r=harry
We need to exit search mode when a page loads in the current tab. We may need to exit search mode for page loads in other tabs too: If you're in search mode, click a slow link, switch tabs, and the page loads in the meantime, then search mode should be not be entered when you switch back. I don't think we handle that case correctly right now, and this patch doesn't address that at all. That's worth doing in another bug because I think the fix will be different. At first I added an `onLocationChange` method to UrlbarInput that was called by `XULBrowserWindow.onLocationChange` in browser.js [1], just like we have an `onLocationChange` in UrlbarProviderSearchTips called by `XULBrowserWindow.onLocationChange`. But we need to potentially exit search mode any time `input.setURI` is called. `setURI` happens to be called by `XULBrowserWindow.onLocationChange`, one of the several places that calls it [2]. `setURI` is also called when switching tabs. Bug 1647899 already took care of handling search mode for tab switches, but it would be nice to handle all this in one place. `setURI` is also how `userTypedValue` is restored in the input, and of course `userTypedValue` is something we need to restore when switching tabs, just like search mode. For these reasons I moved per-tab search mode restoration to `setURI` as part of this. I'm also changing the name of the second parameter in `setURI`. I wasn't sure whether it's true iff we're switching tabs, so I tracked down why that param was added. It was added in bug 1478348, and comment 21 confirms it was added to tell `setURI` and `XULBrowserWindow.onLocationChange` when they're being called due to a tab switch. To make this clearer, I renamed the param and added some javadoc for `XULBrowserWindow.onLocationChange`. [1] https://searchfox.org/mozilla-central/rev/50cb0892948fb4291b9a6b1b30122100ec7d4ef2/browser/base/content/browser.js#5205 [2] https://searchfox.org/mozilla-central/search?q=symbol:%23setURI&redirect=false Differential Revision: https://phabricator.services.mozilla.com/D87172
This commit is contained in:
Родитель
0c976d908a
Коммит
4a6570ffd6
|
@ -5203,6 +5203,25 @@ var XULBrowserWindow = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* An nsIWebProgressListener method called by tabbrowser. The `aIsSimulated`
|
||||
* parameter is extra and not declared in nsIWebProgressListener, however; see
|
||||
* below.
|
||||
*
|
||||
* @param {nsIWebProgress} aWebProgress
|
||||
* The nsIWebProgress instance that fired the notification.
|
||||
* @param {nsIRequest} aRequest
|
||||
* The associated nsIRequest. This may be null in some cases.
|
||||
* @param {nsIURI} aLocationURI
|
||||
* The URI of the location that is being loaded.
|
||||
* @param {integer} aFlags
|
||||
* Flags that indicate the reason the location changed. See the
|
||||
* nsIWebProgressListener.LOCATION_CHANGE_* values.
|
||||
* @param {boolean} aIsSimulated
|
||||
* True when this is called by tabbrowser due to switching tabs and
|
||||
* undefined otherwise. This parameter is not declared in
|
||||
* nsIWebProgressListener.onLocationChange; see bug 1478348.
|
||||
*/
|
||||
onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags, aIsSimulated) {
|
||||
var location = aLocationURI ? aLocationURI.spec : "";
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
AppConstants: "resource://gre/modules/AppConstants.jsm",
|
||||
BrowserUtils: "resource://gre/modules/BrowserUtils.jsm",
|
||||
ExtensionSearchHandler: "resource://gre/modules/ExtensionSearchHandler.jsm",
|
||||
ObjectUtils: "resource://gre/modules/ObjectUtils.jsm",
|
||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
||||
ReaderMode: "resource://gre/modules/ReaderMode.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
|
@ -95,6 +96,7 @@ class UrlbarInput {
|
|||
this.valueIsTyped = false;
|
||||
this.formHistoryName = DEFAULT_FORM_HISTORY_NAME;
|
||||
this.lastQueryContextPromise = Promise.resolve();
|
||||
this.searchMode = null;
|
||||
this._actionOverrideKeyCount = 0;
|
||||
this._autofillPlaceholder = "";
|
||||
this._lastSearchString = "";
|
||||
|
@ -283,10 +285,11 @@ class UrlbarInput {
|
|||
*
|
||||
* @param {nsIURI} [uri]
|
||||
* If this is unspecified, the current URI will be used.
|
||||
* @param {boolean} [updatePopupNotifications]
|
||||
* Passed though to `setPageProxyState`.
|
||||
* @param {boolean} [dueToTabSwitch]
|
||||
* True if this is being called due to switching tabs and false
|
||||
* otherwise.
|
||||
*/
|
||||
setURI(uri, updatePopupNotifications) {
|
||||
setURI(uri = null, dueToTabSwitch = false) {
|
||||
let value = this.window.gBrowser.userTypedValue;
|
||||
let valid = false;
|
||||
|
||||
|
@ -339,10 +342,21 @@ class UrlbarInput {
|
|||
this.selectionStart = this.selectionEnd = 0;
|
||||
}
|
||||
|
||||
this.setPageProxyState(
|
||||
valid ? "valid" : "invalid",
|
||||
updatePopupNotifications
|
||||
);
|
||||
// The proxystate must be set before setting search mode below because
|
||||
// search mode depends on it.
|
||||
this.setPageProxyState(valid ? "valid" : "invalid", dueToTabSwitch);
|
||||
|
||||
// If we're switching tabs, restore the tab's search mode. Otherwise, if
|
||||
// the URI is valid, exit search mode. This must happen after setting
|
||||
// proxystate above because search mode depends on it.
|
||||
if (dueToTabSwitch) {
|
||||
let searchMode = this._searchModesByBrowser.get(
|
||||
this.window.gBrowser.selectedBrowser
|
||||
);
|
||||
this.setSearchMode(searchMode || {});
|
||||
} else if (valid) {
|
||||
this.setSearchMode({});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1189,6 +1203,18 @@ class UrlbarInput {
|
|||
source = null;
|
||||
}
|
||||
|
||||
// As an optimization, bail if the given search mode is already active.
|
||||
// Otherwise browser_preferences_usage.js fails due to accessing the
|
||||
// browser.urlbar.placeholderName pref (via BrowserSearch.initPlaceHolder
|
||||
// below) too many times. That test does not enter search mode, but it
|
||||
// triggers many calls to this method with an empty object via setURI.
|
||||
if (
|
||||
(!this.searchMode && !engineName && !source) ||
|
||||
ObjectUtils.deepEqual(this.searchMode, { engineName, source })
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._searchModeIndicatorTitle.textContent = "";
|
||||
this._searchModeLabel.textContent = "";
|
||||
this._searchModeIndicatorTitle.removeAttribute("data-l10n-id");
|
||||
|
@ -1459,12 +1485,6 @@ class UrlbarInput {
|
|||
|
||||
this._resetSearchState();
|
||||
|
||||
// Restore the tab's search mode, if any.
|
||||
let searchMode = this._searchModesByBrowser.get(
|
||||
this.window.gBrowser.selectedBrowser
|
||||
);
|
||||
this.setSearchMode(searchMode || {});
|
||||
|
||||
// Switching tabs doesn't always change urlbar focus, so we must try to
|
||||
// reopen here too, not just on focus.
|
||||
// We don't use the original TabSelect event because caching it causes
|
||||
|
@ -1996,8 +2016,6 @@ class UrlbarInput {
|
|||
// area when the current tab is re-selected.
|
||||
browser.focus();
|
||||
|
||||
this.setSearchMode({});
|
||||
|
||||
if (openUILinkWhere != "current") {
|
||||
this.handleRevert();
|
||||
}
|
||||
|
|
|
@ -137,6 +137,9 @@ run-if = e10s
|
|||
[browser_revert.js]
|
||||
[browser_searchFunction.js]
|
||||
[browser_searchMode_no_results.js]
|
||||
[browser_searchMode_setURI.js]
|
||||
support-files =
|
||||
dummy_page.html
|
||||
[browser_searchMode_suggestions.js]
|
||||
support-files =
|
||||
searchSuggestionEngine.xml
|
||||
|
|
|
@ -332,141 +332,3 @@ add_task(async function pref_flip_while_enabled() {
|
|||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
|
||||
// Tests that search mode is stored per tab and restored when switching tabs.
|
||||
add_task(async function tab_switch() {
|
||||
// Open three tabs. We'll enter search mode in tabs 0 and 2.
|
||||
let tabs = [];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
gBrowser,
|
||||
url: "http://example.com/" + i,
|
||||
});
|
||||
tabs.push(tab);
|
||||
}
|
||||
|
||||
// Switch to tab 0.
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
|
||||
// Do a search and enter search mode. Pass fireInputEvent so that
|
||||
// userTypedValue is set and restored when we switch back to this tab. This
|
||||
// isn't really necessary but it simulates the user's typing, and it also
|
||||
// means that we'll start a search when we switch back to this tab.
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: TEST_QUERY,
|
||||
fireInputEvent: true,
|
||||
});
|
||||
await UrlbarTestUtils.enterSearchMode(window);
|
||||
|
||||
// Switch to tab 1. Search mode should be exited.
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[1]);
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Switch back to tab 0. We should do a search (for TEST_QUERY) and re-enter
|
||||
// search mode.
|
||||
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(
|
||||
window
|
||||
).getSelectableButtons(true);
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
engineName: oneOffs[0].engine.name,
|
||||
});
|
||||
|
||||
// Switch to tab 2. Search mode should be exited.
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Do another search (in tab 2) and enter search mode. This time, click a
|
||||
// local one-off just to test a different source.
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: TEST_QUERY + " tab 2",
|
||||
fireInputEvent: true,
|
||||
});
|
||||
let localOneOff = UrlbarTestUtils.getOneOffSearchButtons(window)
|
||||
.localButtons[0];
|
||||
Assert.ok(
|
||||
localOneOff,
|
||||
"Sanity check: There should be at least one local one-off"
|
||||
);
|
||||
Assert.ok(
|
||||
localOneOff.source,
|
||||
"Sanity check: Local one-off should have a truthy source"
|
||||
);
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
EventUtils.synthesizeMouseAtCenter(localOneOff, {});
|
||||
await searchPromise;
|
||||
Assert.ok(UrlbarTestUtils.isPopupOpen(window), "Urlbar view is still open.");
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
source: localOneOff.source,
|
||||
});
|
||||
|
||||
// Switch back to tab 0. We should do a search and still be in search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
engineName: oneOffs[0].engine.name,
|
||||
});
|
||||
|
||||
// Switch to tab 1. Search mode should be exited.
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[1]);
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Switch back to tab 2. We should do a search and re-enter search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
source: localOneOff.source,
|
||||
});
|
||||
|
||||
// Exit search mode.
|
||||
await UrlbarTestUtils.exitSearchMode(window, { clickClose: true });
|
||||
|
||||
// Switch to tab 0. We should do a search and re-enter search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
engineName: oneOffs[0].engine.name,
|
||||
});
|
||||
|
||||
// Switch back to tab 2. We should do a search but search mode should be
|
||||
// exited.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Switch back to tab 0. We should do a search and re-enter search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
engineName: oneOffs[0].engine.name,
|
||||
});
|
||||
|
||||
// Exit search mode.
|
||||
await UrlbarTestUtils.exitSearchMode(window, { clickClose: true });
|
||||
|
||||
// Switch back to tab 2. We should do a search but no search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Switch back to tab 0. We should do a search but no search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
await UrlbarTestUtils.promisePopupClose(window);
|
||||
for (let tab of tabs) {
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,420 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Tests that search mode remains active or is exited when setURI is called,
|
||||
* depending on the situation. For example, loading a page in the current tab
|
||||
* should exit search mode, due to calling setURI.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const BOOKMARK_URL = "http://www.example.com/browser_searchMode_setURI.js";
|
||||
const LINK_PAGE_URL =
|
||||
"http://mochi.test:8888/browser/browser/components/urlbar/tests/browser/dummy_page.html";
|
||||
|
||||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.urlbar.update2", true],
|
||||
["browser.urlbar.update2.localOneOffs", true],
|
||||
["browser.urlbar.update2.oneOffsRefresh", true],
|
||||
],
|
||||
});
|
||||
|
||||
// Add a bookmark so we can enter bookmarks search mode and pick it.
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url: BOOKMARK_URL,
|
||||
});
|
||||
registerCleanupFunction(async () => {
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
|
||||
if (gURLBar.getAttribute("pageproxystate") == "invalid") {
|
||||
gURLBar.handleRevert();
|
||||
}
|
||||
});
|
||||
|
||||
// Opens a new tab, enters search mode, does a search for our test bookmark, and
|
||||
// picks it. Uses a variety of initial URLs and search strings in order to hit
|
||||
// different branches in setURI. Search mode should be exited in all cases.
|
||||
add_task(async function pickResult() {
|
||||
for (let test of [
|
||||
// initialURL, searchString
|
||||
["about:blank", BOOKMARK_URL],
|
||||
["about:blank", new URL(BOOKMARK_URL).origin],
|
||||
["about:blank", new URL(BOOKMARK_URL).pathname],
|
||||
[BOOKMARK_URL, BOOKMARK_URL],
|
||||
[BOOKMARK_URL, new URL(BOOKMARK_URL).origin],
|
||||
[BOOKMARK_URL, new URL(BOOKMARK_URL).pathname],
|
||||
]) {
|
||||
await doPickResultTest(...test);
|
||||
}
|
||||
});
|
||||
|
||||
async function doPickResultTest(initialURL, searchString) {
|
||||
info(
|
||||
"doPickResultTest with args: " +
|
||||
JSON.stringify({
|
||||
initialURL,
|
||||
searchString,
|
||||
})
|
||||
);
|
||||
|
||||
await BrowserTestUtils.withNewTab(initialURL, async () => {
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: searchString,
|
||||
fireInputEvent: true,
|
||||
});
|
||||
|
||||
await UrlbarTestUtils.enterSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
});
|
||||
|
||||
// Arrow down to the bookmark result.
|
||||
let foundResult = false;
|
||||
for (let i = 0; i < UrlbarTestUtils.getResultCount(window); i++) {
|
||||
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
|
||||
if (
|
||||
result.source == UrlbarUtils.RESULT_SOURCE.BOOKMARKS &&
|
||||
result.url == BOOKMARK_URL
|
||||
) {
|
||||
foundResult = true;
|
||||
break;
|
||||
}
|
||||
EventUtils.synthesizeKey("KEY_ArrowDown");
|
||||
}
|
||||
Assert.ok(foundResult, "The bookmark result should have been found");
|
||||
|
||||
// Press enter.
|
||||
let loadPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
EventUtils.synthesizeKey("KEY_Enter");
|
||||
await loadPromise;
|
||||
Assert.equal(
|
||||
gBrowser.currentURI.spec,
|
||||
BOOKMARK_URL,
|
||||
"Should have loaded the bookmarked URL"
|
||||
);
|
||||
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
});
|
||||
}
|
||||
|
||||
// Opens a new tab containing a link, enters search mode, and clicks the link.
|
||||
// Uses a variety of search strings and link hrefs in order to hit different
|
||||
// branches in setURI. Search mode should be exited in all cases, and the href
|
||||
// in the link should be opened.
|
||||
add_task(async function clickLink() {
|
||||
for (let test of [
|
||||
// searchString, href to use in the link
|
||||
[LINK_PAGE_URL, LINK_PAGE_URL],
|
||||
[LINK_PAGE_URL, "http://www.example.com/"],
|
||||
["test", LINK_PAGE_URL],
|
||||
["test", "http://www.example.com/"],
|
||||
[null, LINK_PAGE_URL],
|
||||
[null, "http://www.example.com/"],
|
||||
]) {
|
||||
await doClickLinkTest(...test);
|
||||
}
|
||||
});
|
||||
|
||||
async function doClickLinkTest(searchString, href) {
|
||||
info(
|
||||
"doClickLinkTest with args: " +
|
||||
JSON.stringify({
|
||||
searchString,
|
||||
href,
|
||||
})
|
||||
);
|
||||
|
||||
await BrowserTestUtils.withNewTab(LINK_PAGE_URL, async () => {
|
||||
if (searchString) {
|
||||
// Do a search with the search string.
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: searchString,
|
||||
fireInputEvent: true,
|
||||
});
|
||||
Assert.ok(
|
||||
gBrowser.selectedBrowser.userTypedValue,
|
||||
"userTypedValue should be defined"
|
||||
);
|
||||
} else {
|
||||
// Open top sites.
|
||||
await UrlbarTestUtils.promisePopupOpen(window, () => {
|
||||
document.getElementById("Browser:OpenLocation").doCommand();
|
||||
});
|
||||
Assert.strictEqual(
|
||||
gBrowser.selectedBrowser.userTypedValue,
|
||||
null,
|
||||
"userTypedValue should be null"
|
||||
);
|
||||
}
|
||||
|
||||
// Enter search mode and then close the popup so we can click the link in
|
||||
// the page.
|
||||
await UrlbarTestUtils.enterSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
});
|
||||
await UrlbarTestUtils.promisePopupClose(window);
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
});
|
||||
|
||||
// Add a link to the page and click it.
|
||||
let loadPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
await ContentTask.spawn(gBrowser.selectedBrowser, href, async cHref => {
|
||||
let link = this.content.document.createElement("a");
|
||||
link.textContent = "Click me";
|
||||
link.href = cHref;
|
||||
this.content.document.body.append(link);
|
||||
link.click();
|
||||
});
|
||||
await loadPromise;
|
||||
Assert.equal(
|
||||
gBrowser.currentURI.spec,
|
||||
href,
|
||||
"Should have loaded the href URL"
|
||||
);
|
||||
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
});
|
||||
}
|
||||
|
||||
// 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, null, true],
|
||||
["about:blank", null, "about:blank", true],
|
||||
["about:blank", null, "http://www.example.com/", false],
|
||||
|
||||
["about:blank", "about:blank", null, false],
|
||||
["about:blank", "about:blank", "about:blank", false],
|
||||
["about:blank", "about:blank", "http://www.example.com/", false],
|
||||
|
||||
["about:blank", "http://www.example.com/", null, true],
|
||||
["about:blank", "http://www.example.com/", "about:blank", true],
|
||||
["about:blank", "http://www.example.com/", "http://www.example.com/", true],
|
||||
|
||||
["about:blank", "not a URL", null, true],
|
||||
["about:blank", "not a URL", "about:blank", true],
|
||||
["about:blank", "not a URL", "http://www.example.com/", true],
|
||||
|
||||
["http://www.example.com/", null, null, false],
|
||||
["http://www.example.com/", null, "about:blank", true],
|
||||
["http://www.example.com/", null, "http://www.example.com/", false],
|
||||
|
||||
["http://www.example.com/", "about:blank", null, false],
|
||||
["http://www.example.com/", "about:blank", "about:blank", false],
|
||||
[
|
||||
"http://www.example.com/",
|
||||
"about:blank",
|
||||
"http://www.example.com/",
|
||||
false,
|
||||
],
|
||||
|
||||
["http://www.example.com/", "http://www.example.com/", null, true],
|
||||
["http://www.example.com/", "http://www.example.com/", "about:blank", true],
|
||||
[
|
||||
"http://www.example.com/",
|
||||
"http://www.example.com/",
|
||||
"http://www.example.com/",
|
||||
true,
|
||||
],
|
||||
|
||||
["http://www.example.com/", "not a URL", null, true],
|
||||
["http://www.example.com/", "not a URL", "about:blank", true],
|
||||
["http://www.example.com/", "not a URL", "http://www.example.com/", 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 || null,
|
||||
`userTypedValue should be ${searchString || null}`
|
||||
);
|
||||
|
||||
// Call setURI.
|
||||
let uri = url ? Services.io.newURI(url) : null;
|
||||
gURLBar.setURI(uri);
|
||||
|
||||
UrlbarTestUtils.assertSearchMode(
|
||||
window,
|
||||
!expectSearchMode
|
||||
? null
|
||||
: {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
}
|
||||
);
|
||||
|
||||
gURLBar.handleRevert();
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
});
|
||||
}
|
||||
|
||||
// Tests that search mode is stored per tab and restored when switching tabs.
|
||||
// Restoration is handled in setURI, which is why this task is in this file.
|
||||
add_task(async function tabSwitch() {
|
||||
// Open three tabs. We'll enter search mode in tabs 0 and 2.
|
||||
let tabs = [];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
gBrowser,
|
||||
url: "http://example.com/" + i,
|
||||
});
|
||||
tabs.push(tab);
|
||||
}
|
||||
|
||||
// Switch to tab 0.
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
|
||||
// Do a search and enter search mode. Pass fireInputEvent so that
|
||||
// userTypedValue is set and restored when we switch back to this tab. This
|
||||
// isn't really necessary but it simulates the user's typing, and it also
|
||||
// means that we'll start a search when we switch back to this tab.
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: "test",
|
||||
fireInputEvent: true,
|
||||
});
|
||||
await UrlbarTestUtils.enterSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
});
|
||||
|
||||
// Switch to tab 1. Search mode should be exited.
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[1]);
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Switch back to tab 0. We should do a search (for "test") and re-enter
|
||||
// search mode.
|
||||
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
});
|
||||
|
||||
// Switch to tab 2. Search mode should be exited.
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Do another search (in tab 2) and enter search mode. Use a different source
|
||||
// from tab 0 just to use something different.
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: "test tab 2",
|
||||
fireInputEvent: true,
|
||||
});
|
||||
await UrlbarTestUtils.enterSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.TABS,
|
||||
});
|
||||
|
||||
// Switch back to tab 0. We should do a search and still be in search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
});
|
||||
|
||||
// Switch to tab 1. Search mode should be exited.
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[1]);
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Switch back to tab 2. We should do a search and re-enter search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.TABS,
|
||||
});
|
||||
|
||||
// Exit search mode.
|
||||
await UrlbarTestUtils.exitSearchMode(window, { clickClose: true });
|
||||
|
||||
// Switch to tab 0. We should do a search and re-enter search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
});
|
||||
|
||||
// Switch back to tab 2. We should do a search but search mode should be
|
||||
// inactive.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Switch back to tab 0. We should do a search and re-enter search mode.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
});
|
||||
|
||||
// Exit search mode.
|
||||
await UrlbarTestUtils.exitSearchMode(window, { clickClose: true });
|
||||
|
||||
// Switch back to tab 2. We should do a search but search mode should be
|
||||
// inactive.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
// Switch back to tab 0. We should do a search but search mode should be
|
||||
// inactive.
|
||||
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
await searchPromise;
|
||||
UrlbarTestUtils.assertSearchMode(window, null);
|
||||
|
||||
await UrlbarTestUtils.promisePopupClose(window);
|
||||
for (let tab of tabs) {
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
});
|
|
@ -29,6 +29,9 @@ add_task(async function setup() {
|
|||
await Services.search.setDefault(defaultEngine);
|
||||
await Services.search.moveEngine(suggestionsEngine, 0);
|
||||
|
||||
await PlacesUtils.history.clear();
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
// Add some form history.
|
||||
await UrlbarTestUtils.formHistory.add([
|
||||
{ value: "hello formHistory 1", source: suggestionsEngine.name },
|
||||
|
|
Загрузка…
Ссылка в новой задаче