mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 729241 - Switch-to-tab selections update adaptive records. r=harry,mak
Differential Revision: https://phabricator.services.mozilla.com/D132743
This commit is contained in:
parent
3f4f5734f2
commit
1476d08fab
@ -833,8 +833,10 @@ class UrlbarInput {
|
||||
),
|
||||
};
|
||||
|
||||
// We cache the search string because switching tab may clear it.
|
||||
let searchString = this._lastSearchString;
|
||||
this.controller.engagementEvent.record(event, {
|
||||
searchString: this._lastSearchString,
|
||||
searchString,
|
||||
selIndex,
|
||||
selType: "tabswitch",
|
||||
provider: result.providerName,
|
||||
@ -848,6 +850,15 @@ class UrlbarInput {
|
||||
if (switched && prevTab.isEmpty) {
|
||||
this.window.gBrowser.removeTab(prevTab);
|
||||
}
|
||||
|
||||
if (switched && !this.isPrivate && !result.heuristic) {
|
||||
// We don't await for this, because a rejection should not interrupt
|
||||
// the load. Just reportError it.
|
||||
UrlbarUtils.addToInputHistory(url, searchString).catch(
|
||||
Cu.reportError
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
case UrlbarUtils.RESULT_TYPE.SEARCH: {
|
||||
@ -1001,7 +1012,8 @@ class UrlbarInput {
|
||||
}
|
||||
|
||||
if (!this.isPrivate && !result.heuristic) {
|
||||
// This should not interrupt the load anyway.
|
||||
// We don't await for this, because a rejection should not interrupt
|
||||
// the load. Just reportError it.
|
||||
UrlbarUtils.addToInputHistory(url, this._lastSearchString).catch(
|
||||
Cu.reportError
|
||||
);
|
||||
|
@ -274,6 +274,7 @@ support-files =
|
||||
[browser_suppressFocusBorder.js]
|
||||
[browser_switchTab_closesUrlbarPopup.js]
|
||||
[browser_switchTab_decodeuri.js]
|
||||
[browser_switchTab_inputHistory.js]
|
||||
[browser_switchTab_override.js]
|
||||
[browser_switchToTab_chiclet.js]
|
||||
[browser_switchToTab_closes_newtab.js]
|
||||
|
@ -0,0 +1,91 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* This tests ensures that the urlbar adaptive behavior updates
|
||||
* when using switch to tab in the address bar dropdown.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
add_task(async function setup() {
|
||||
registerCleanupFunction(async () => {
|
||||
await PlacesUtils.history.clear();
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function test_adaptive_with_search_term_and_switch_tab() {
|
||||
await PlacesUtils.history.clear();
|
||||
let urls = [
|
||||
"https://example.com/",
|
||||
"https://example.com/#cat",
|
||||
"https://example.com/#cake",
|
||||
"https://example.com/#car",
|
||||
];
|
||||
|
||||
info(`Load tabs in same order as urls`);
|
||||
let tabs = [];
|
||||
for (let url of urls) {
|
||||
let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, url, false, true);
|
||||
gBrowser.loadTabs([url], {
|
||||
inBackground: true,
|
||||
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
});
|
||||
|
||||
let tab = await tabPromise;
|
||||
tabs.push(tab);
|
||||
}
|
||||
|
||||
info(`Switch to tab 0`);
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
|
||||
info("Wait for autocomplete");
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: "ca",
|
||||
});
|
||||
|
||||
let result1 = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.notEqual(result1.url, urls[1], `${urls[1]} url should not be first`);
|
||||
|
||||
info(`Scroll down to select the ${urls[1]} entry using keyboard`);
|
||||
let result2 = await UrlbarTestUtils.getDetailsOfResultAt(
|
||||
window,
|
||||
UrlbarTestUtils.getSelectedRowIndex(window)
|
||||
);
|
||||
|
||||
while (result2.url != urls[1]) {
|
||||
EventUtils.synthesizeKey("KEY_ArrowDown");
|
||||
result2 = await UrlbarTestUtils.getDetailsOfResultAt(
|
||||
window,
|
||||
UrlbarTestUtils.getSelectedRowIndex(window)
|
||||
);
|
||||
}
|
||||
|
||||
Assert.equal(
|
||||
result2.type,
|
||||
UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
|
||||
"Selected entry should be tab switch"
|
||||
);
|
||||
Assert.equal(result2.url, urls[1]);
|
||||
|
||||
info("Visiting tab 1");
|
||||
EventUtils.synthesizeKey("KEY_Enter");
|
||||
Assert.equal(gBrowser.selectedTab, tabs[1], "Should have switched to tab 1");
|
||||
|
||||
info("Switch back to tab 0");
|
||||
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
|
||||
|
||||
info("Wait for autocomplete");
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: "ca",
|
||||
});
|
||||
|
||||
let result3 = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
Assert.equal(result3.url, urls[1], `${urls[1]} url should be first`);
|
||||
|
||||
for (let tab of tabs) {
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user