diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/components/urlbar/tests/browser-updateResults | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/urlbar/tests/browser-updateResults')
11 files changed, 8811 insertions, 0 deletions
diff --git a/browser/components/urlbar/tests/browser-updateResults/browser.ini b/browser/components/urlbar/tests/browser-updateResults/browser.ini new file mode 100644 index 0000000000..f20fed7e13 --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser.ini @@ -0,0 +1,17 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +[DEFAULT] +support-files = + head.js + +[browser_appendSpanCount.js] +[browser_suggestedIndex_10_search_10_url.js] +[browser_suggestedIndex_10_search_5_url.js] +[browser_suggestedIndex_10_url_10_search.js] +[browser_suggestedIndex_10_url_5_search.js] +[browser_suggestedIndex_5_search_10_url.js] +[browser_suggestedIndex_5_search_5_url.js] +[browser_suggestedIndex_5_url_10_search.js] +[browser_suggestedIndex_5_url_5_search.js] diff --git a/browser/components/urlbar/tests/browser-updateResults/browser_appendSpanCount.js b/browser/components/urlbar/tests/browser-updateResults/browser_appendSpanCount.js new file mode 100644 index 0000000000..bcf9609597 --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser_appendSpanCount.js @@ -0,0 +1,183 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test makes sure that when the view updates itself and appends new rows, +// the new rows start out hidden when they exceed the current visible result +// span count. It includes a tip result so that it tests a row with > 1 result +// span. + +"use strict"; + +add_task(async function viewUpdateAppendHidden() { + // We'll use this test provider to test specific results. We assume that + // history and bookmarks have been cleared (by init() above). + let provider = new DelayingTestProvider(); + UrlbarProvidersManager.registerProvider(provider); + registerCleanupFunction(() => { + UrlbarProvidersManager.unregisterProvider(provider); + }); + + // We do two searches below without closing the panel. Use "firefox cach" as + // the first query and "firefox cache" as the second so that (1) an + // intervention tip is triggered both times but also so that (2) the queries + // are different each time. + let baseQuery = "firefox cache"; + let queries = [baseQuery.substring(0, baseQuery.length - 1), baseQuery]; + let maxResults = UrlbarPrefs.get("maxRichResults"); + + let queryStrings = []; + for (let i = 0; i < maxResults; i++) { + queryStrings.push(`${baseQuery} ${i}`); + } + + // First search: Trigger the intervention tip and a view full of search + // suggestions. + provider._results = queryStrings.map( + suggestion => + new UrlbarResult( + UrlbarUtils.RESULT_TYPE.SEARCH, + UrlbarUtils.RESULT_SOURCE.SEARCH, + { + query: queries[0], + suggestion, + lowerCaseSuggestion: suggestion.toLocaleLowerCase(), + engine: Services.search.defaultEngine.name, + } + ) + ); + provider.finishQueryPromise = Promise.resolve(); + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: queries[0], + }); + + // Sanity check the tip result and row count. + let tipResult = await UrlbarTestUtils.getDetailsOfResultAt(window, 1); + Assert.equal( + tipResult.type, + UrlbarUtils.RESULT_TYPE.TIP, + "Result at index 1 is a tip" + ); + let tipResultSpan = UrlbarUtils.getSpanForResult( + tipResult.element.row.result + ); + Assert.greater(tipResultSpan, 1, "Sanity check: Tip has large result span"); + let expectedRowCount = maxResults - tipResultSpan + 1; + Assert.equal( + UrlbarTestUtils.getResultCount(window), + expectedRowCount, + "Sanity check: Initial row count takes tip result span into account" + ); + + // Second search: Change the provider's results so that it has enough history + // to fill up the view. Search suggestion rows cannot be updated to history + // results, so the view will append the history results as new rows. + provider._results = queryStrings.map(title => { + let url = "http://example.com/" + title; + return new UrlbarResult( + UrlbarUtils.RESULT_TYPE.URL, + UrlbarUtils.RESULT_SOURCE.HISTORY, + { + title, + url, + displayUrl: "http://example.com/" + title, + } + ); + }); + + // Don't allow the search to finish until we check the updated rows. We'll + // accomplish that by adding a mutation observer on the rows and delaying + // resolving the provider's finishQueryPromise. When all new rows have been + // added, we expect the new row count to be: + // + // expectedRowCount // the original row count + // + (expectedRowCount - 2) // the newly added history row count (hidden) + // -------------------------- + // (2 * expectedRowCount) - 2 + // + // The `- 2` subtracts the heuristic and tip result. + let newExpectedRowCount = 2 * expectedRowCount - 2; + let mutationPromise = new Promise(resolve => { + let observer = new MutationObserver(mutations => { + let childCount = UrlbarTestUtils.getResultCount(window); + info(`Rows mutation observer called, childCount now ${childCount}`); + if (newExpectedRowCount <= childCount) { + observer.disconnect(); + resolve(); + } + }); + observer.observe(UrlbarTestUtils.getResultsContainer(window), { + childList: true, + }); + }); + + // Now do the second search but don't wait for it to finish. + let resolveQuery; + provider.finishQueryPromise = new Promise( + resolve => (resolveQuery = resolve) + ); + let queryPromise = UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: queries[1], + }); + + // Wait for the history rows to be added. + await mutationPromise; + + // Check the rows. We can't use UrlbarTestUtils.getDetailsOfResultAt() here + // because it waits for the query to finish. + Assert.equal( + UrlbarTestUtils.getResultCount(window), + newExpectedRowCount, + "New expected row count" + ); + // stale search rows + let rows = UrlbarTestUtils.getResultsContainer(window).children; + for (let i = 2; i < expectedRowCount; i++) { + let row = rows[i]; + Assert.equal( + row.result.type, + UrlbarUtils.RESULT_TYPE.SEARCH, + `Result at index ${i} is a search result` + ); + Assert.ok( + BrowserTestUtils.is_visible(row), + `Search result at index ${i} is visible` + ); + Assert.equal( + row.getAttribute("stale"), + "true", + `Search result at index ${i} is stale` + ); + } + // new hidden history rows + for (let i = expectedRowCount; i < newExpectedRowCount; i++) { + let row = rows[i]; + Assert.equal( + row.result.type, + UrlbarUtils.RESULT_TYPE.URL, + `Result at index ${i} is a URL result` + ); + Assert.ok( + !BrowserTestUtils.is_visible(row), + `URL result at index ${i} is hidden` + ); + Assert.ok( + !row.hasAttribute("stale"), + `URL result at index ${i} is not stale` + ); + } + + // Finish the query, and we're done. + resolveQuery(); + await queryPromise; + + await UrlbarTestUtils.promisePopupClose(window); + gURLBar.handleRevert(); + + // We unregister the provider above in a cleanup function so we don't + // accidentally interfere with later tests, but do it here too in case we add + // more tasks to this test. It's harmless to call more than once. + UrlbarProvidersManager.unregisterProvider(provider); +}); diff --git a/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_search_10_url.js b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_search_10_url.js new file mode 100644 index 0000000000..755c453850 --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_search_10_url.js @@ -0,0 +1,1102 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test checks row visibility during view updates when rows with suggested +// indexes are added and removed. Each task performs two searches: Search 1 +// returns 10 results with search suggestions, and search 2 returns 10 results +// with URL results. + +"use strict"; + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes (because the original search results can't +// be replaced with URL results) +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -9 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -9 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -9 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -9 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 9 results including suggestedIndex = 1 with resultSpan = 2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 9 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [[1, 2], -1], + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + hidden: true, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 9 results including suggestedIndex = 1 with resultSpan = 2 +// Search 2: +// 9 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// 9 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [[1, 2]], + viewCount: 9, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [[1, 2], -1], + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); diff --git a/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_search_5_url.js b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_search_5_url.js new file mode 100644 index 0000000000..bd707dd422 --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_search_5_url.js @@ -0,0 +1,661 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test checks row visibility during view updates when rows with suggested +// indexes are added and removed. Each task performs two searches: Search 1 +// returns 10 results with search suggestions, and search 2 returns 5 results +// with URL results. + +"use strict"; + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -3 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -3, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -3, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 10, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 9 results including suggestedIndex = 1 with resultSpan = 2 +// Search 2: +// 5 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// 9 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [[1, 2]], + viewCount: 9, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [[1, 2], -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); diff --git a/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_url_10_search.js b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_url_10_search.js new file mode 100644 index 0000000000..57f172adba --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_url_10_search.js @@ -0,0 +1,1185 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test checks row visibility during view updates when rows with suggested +// indexes are added and removed. Each task performs two searches: Search 1 +// returns 10 results where the first result is a search suggestion and the +// remainder are URL results, and search 2 returns 10 results with search +// suggestions. This tests the view-update logic that allows search suggestions +// to replace other results once an existing suggestion row is encountered. + +"use strict"; + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// Indexes 2-8 replaced with search suggestions +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// Indexes 2-8 replaced with search suggestions +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -2 +// Expected visible rows during update: +// Indexes 2-7 replaced with search suggestions +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 7, + type: UrlbarPrefs.get("resultMenu") + ? UrlbarUtils.RESULT_TYPE.URL + : UrlbarUtils.RESULT_TYPE.SEARCH, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 7, + type: UrlbarPrefs.get("resultMenu") + ? UrlbarUtils.RESULT_TYPE.URL + : UrlbarUtils.RESULT_TYPE.SEARCH, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// Indexes 2-8 replaced with search suggestions +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// Indexes 2-8 replaced with search suggestions +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 7, + type: UrlbarPrefs.get("resultMenu") + ? UrlbarUtils.RESULT_TYPE.URL + : UrlbarUtils.RESULT_TYPE.SEARCH, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -9 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -9 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -9 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -9 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -9, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 7, + type: UrlbarPrefs.get("resultMenu") + ? UrlbarUtils.RESULT_TYPE.URL + : UrlbarUtils.RESULT_TYPE.SEARCH, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// Indexes 2-8 replaced with search suggestions +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 9 results including suggestedIndex = 1 with resultSpan = 2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + resultSpan: 2, + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 9 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [[1, 2], -1], + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + hidden: true, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 9 results including suggestedIndex = 1 with resultSpan = 2 +// Search 2: +// 9 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// Indexes 2-8 replaced with search suggestions +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndexes: [[1, 2]], + viewCount: 9, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [[1, 2], -1], + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); diff --git a/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_url_5_search.js b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_url_5_search.js new file mode 100644 index 0000000000..03d6f158f4 --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_10_url_5_search.js @@ -0,0 +1,707 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test checks row visibility during view updates when rows with suggested +// indexes are added and removed. Each task performs two searches: Search 1 +// returns 10 results where the first result is a search suggestion and the +// remainder are URL results, and search 2 returns 5 results with search +// suggestions. This tests the view-update logic that allows search suggestions +// to replace other results once an existing suggestion row is encountered. + +"use strict"; + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// Indexes 1 and 2 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// Indexes 3 and 4 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -3 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -3, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -3, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 10, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// Index 3 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 10, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 10 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 10 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 10, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 9 results including suggestedIndex = 1 with resultSpan = 2 +// Search 2: +// 5 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// Index 3 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 9, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndexes: [[1, 2]], + viewCount: 9, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [[1, 2], -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); diff --git a/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_search_10_url.js b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_search_10_url.js new file mode 100644 index 0000000000..dfd626d701 --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_search_10_url.js @@ -0,0 +1,1015 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test checks row visibility during view updates when rows with suggested +// indexes are added and removed. Each task performs two searches: Search 1 +// returns 5 results with search suggestions, and search 2 returns 10 results +// with URL results. + +"use strict"; + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 search-1 rows + 1 search-2 row (the one before the suggestedIndex row) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 4 +// Expected visible rows during update: +// 5 search-1 rows + 3 search-2 rows (the ones before the suggestedIndex row) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 4, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 4, + hidden: true, + }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 6 +// Expected visible rows during update: +// 5 search-1 rows + 5 search-2 rows (the ones before the suggestedIndex row) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 6, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 6, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 8 +// Expected visible rows during update: +// 5 search-1 rows + 5 search-2 rows (some of the ones before the +// suggestedIndex) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 8, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 8, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 search-1 rows + 5 search-2 rows (some of the ones before the +// suggestedIndex) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 search-1 rows + 5 search-2 rows +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -2 +// Expected visible rows during update: +// 5 search-1 rows + 5 search-2 rows +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -4 +// Expected visible rows during update: +// 5 search-1 rows + 5 search-2 rows +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -4, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -4, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -6 +// Expected visible rows during update: +// 5 search-1 rows + 3 search-2 rows (the ones before the suggestedIndex row) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -6, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -6, + hidden: true, + }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -8 +// Expected visible rows during update: +// 5 search-1 rows + 1 search-2 row (the one before the suggestedIndex row) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -8, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -8, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 search-1 rows + 5 search-2 rows +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 3 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 3, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 3, + hidden: true, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = -7 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -7, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -7, + hidden: true, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 search-1 rows + 5 search-2 rows (some of the ones before the +// suggestedIndex) +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.URL }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 9 results including suggestedIndex = 1 with resultSpan = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 9 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [[1, 2], -1], + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + hidden: true, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 with resultSpan = 2 +// Search 2: +// 9 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// 5 search-1 rows + 4 search-2 rows +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [[1, 2]], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [[1, 2], -1], + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.URL }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); diff --git a/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_search_5_url.js b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_search_5_url.js new file mode 100644 index 0000000000..49d6ac0663 --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_search_5_url.js @@ -0,0 +1,1131 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test checks row visibility during view updates when rows with suggested +// indexes are added and removed. Each task performs two searches: Search 1 +// returns 5 results with search suggestions, and search 2 returns 5 results +// with URL results. + +"use strict"; + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 search-1 rows + 1 search-2 row (the one before the suggestedIndex row) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 search-1 rows + 3 search-2 rows (the ones before the suggestedIndex) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 search-1 rows + 3 search-2 rows (the ones before the suggestedIndex row) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// 5 search-1 rows + 2 search-2 rows (the one before the suggestedIndex row) +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 search-1 rows + 3 search-2 rows (i.e., all rows from both searches) +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -3 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -3, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -3, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 original rows with no changes (because the original search results can't +// be replaced with URL results) +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = -3 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -3, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -3, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// 5 original rows with no changes (because the original search results can't +// be replaced with URL results) +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 4, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + viewCount: 5, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 4, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 search-1 rows + 2 search-2 rows (the ones before the suggestedIndex row) +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); diff --git a/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_url_10_search.js b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_url_10_search.js new file mode 100644 index 0000000000..4306efbeff --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_url_10_search.js @@ -0,0 +1,1057 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test checks row visibility during view updates when rows with suggested +// indexes are added and removed. Each task performs two searches: Search 1 +// returns 5 results where the first result is a search suggestion and the +// remainder are URL results, and search 2 returns 10 results with search +// suggestions. This tests the view-update logic that allows search suggestions +// to replace other results once an existing suggestion row is encountered. + +"use strict"; + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 4 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 4, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 4, + hidden: true, + }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 6 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 6, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 6, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 8 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 8, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 8, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -2 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -4 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -4, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -4, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -6 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -6, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -6, + hidden: true, + }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = -8 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -8, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -8, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = -9 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -9, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 8, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 3 +// Expected visible rows during update: +// Index 2 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 3, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 3, + hidden: true, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = 9 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = -1 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { count: 5, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 10 results including suggestedIndex = -7 +// Expected visible rows during update: +// Index 2 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -7, + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -7, + hidden: true, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 10 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 10, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 9 results including suggestedIndex = 1 with resultSpan = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + resultSpan: 2, + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + hidden: true, + }, + { count: 7, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 9 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [[1, 2], -1], + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + hidden: true, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 with resultSpan = 2 +// Search 2: +// 9 results including: +// suggestedIndex = 1 with resultSpan = 2 +// suggestedIndex = -1 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndexes: [[1, 2]], + viewCount: 5, + }, + search2: { + otherCount: 10, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [[1, 2], -1], + viewCount: 9, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + resultSpan: 2, + }, + { count: 6, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + }, + ], +}); diff --git a/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_url_5_search.js b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_url_5_search.js new file mode 100644 index 0000000000..44078c2251 --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/browser_suggestedIndex_5_url_5_search.js @@ -0,0 +1,1203 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test checks row visibility during view updates when rows with suggested +// indexes are added and removed. Each task performs two searches: Search 1 +// returns 5 results where the first result is a search suggestion and the +// remainder are URL results, and search 2 returns 5 results with search +// suggestions. This tests the view-update logic that allows search suggestions +// to replace other results once an existing suggestion row is encountered. + +"use strict"; + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// Index 2 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 2, + type: UrlbarPrefs.get("resultMenu") + ? UrlbarUtils.RESULT_TYPE.URL + : UrlbarUtils.RESULT_TYPE.SEARCH, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = -3 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -3, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -3, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 2, + type: UrlbarPrefs.get("resultMenu") + ? UrlbarUtils.RESULT_TYPE.URL + : UrlbarUtils.RESULT_TYPE.SEARCH, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// Index 2 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 9 +// Search 2: +// 5 results including suggestedIndex = -3 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 9, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -3, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -3, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// Indexes 2 and 3 replaced with search suggestions, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 2, + type: UrlbarPrefs.get("resultMenu") + ? UrlbarUtils.RESULT_TYPE.URL + : UrlbarUtils.RESULT_TYPE.SEARCH, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// Index 2 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + hidden: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = 1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = 2 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 2, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = 9 +// Expected visible rows during update: +// Index 2 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: 9, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 9, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = -1 +// Expected visible rows during update: +// Index 2 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -1, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + stale: true, + }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -2 +// Search 2: +// 5 results including suggestedIndex = -2 +// Expected visible rows during update: +// All search-2 rows +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -2, + viewCount: 5, + }, + search2: { + otherCount: 3, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndex: -2, + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { + count: 1, + type: UrlbarPrefs.get("resultMenu") + ? UrlbarUtils.RESULT_TYPE.URL + : UrlbarUtils.RESULT_TYPE.SEARCH, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -2, + }, + { + count: 1, + type: UrlbarPrefs.get("resultMenu") + ? UrlbarUtils.RESULT_TYPE.URL + : UrlbarUtils.RESULT_TYPE.SEARCH, + }, + ], +}); + +// Search 1: +// 5 results, no suggestedIndex +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + viewCount: 5, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 3, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = 1 +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// Index 3 replaced with search suggestion, no other changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: 1, + viewCount: 5, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); + +// Search 1: +// 5 results including suggestedIndex = -1 +// Search 2: +// 5 results including suggestedIndex = 1 and suggestedIndex = -1 +// Expected visible rows during update: +// 5 original rows with no changes +add_suggestedIndex_task({ + search1: { + other: [ + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL }, + ], + suggestedIndex: -1, + viewCount: 5, + }, + search2: { + otherCount: 2, + otherType: UrlbarUtils.RESULT_TYPE.SEARCH, + suggestedIndexes: [1, -1], + viewCount: 5, + }, + duringUpdate: [ + { count: 1 }, + { count: 1, type: UrlbarUtils.RESULT_TYPE.SEARCH, stale: true }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.URL, stale: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + stale: true, + }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: 1, + hidden: true, + }, + { count: 2, type: UrlbarUtils.RESULT_TYPE.SEARCH, hidden: true }, + { + count: 1, + type: UrlbarUtils.RESULT_TYPE.URL, + suggestedIndex: -1, + hidden: true, + }, + ], +}); diff --git a/browser/components/urlbar/tests/browser-updateResults/head.js b/browser/components/urlbar/tests/browser-updateResults/head.js new file mode 100644 index 0000000000..7bdb1bcb1f --- /dev/null +++ b/browser/components/urlbar/tests/browser-updateResults/head.js @@ -0,0 +1,550 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// The files in this directory test UrlbarView.#updateResults(). + +"use strict"; + +ChromeUtils.defineESModuleGetters(this, { + PlacesTestUtils: "resource://testing-common/PlacesTestUtils.sys.mjs", + UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.sys.mjs", + UrlbarResult: "resource:///modules/UrlbarResult.sys.mjs", + UrlbarUtils: "resource:///modules/UrlbarUtils.sys.mjs", + UrlbarView: "resource:///modules/UrlbarView.sys.mjs", +}); + +XPCOMUtils.defineLazyGetter(this, "UrlbarTestUtils", () => { + const { UrlbarTestUtils: module } = ChromeUtils.importESModule( + "resource://testing-common/UrlbarTestUtils.sys.mjs" + ); + module.init(this); + return module; +}); + +add_setup(async function headInit() { + await PlacesUtils.history.clear(); + await PlacesUtils.bookmarks.eraseEverything(); + + await SpecialPowers.pushPrefEnv({ + set: [ + // Make absolutely sure the panel stays open during the test. There are + // spurious blurs on WebRender TV tests as the test starts that cause the + // panel to close and the query to be canceled, resulting in intermittent + // failures without this. + ["ui.popup.disable_autohide", true], + + // Make sure maxRichResults is 10 for sanity. + ["browser.urlbar.maxRichResults", 10], + ], + }); + + // Increase the timeout of the remove-stale-rows timer so that it doesn't + // interfere with the tests. + let originalRemoveStaleRowsTimeout = UrlbarView.removeStaleRowsTimeout; + UrlbarView.removeStaleRowsTimeout = 30000; + registerCleanupFunction(() => { + UrlbarView.removeStaleRowsTimeout = originalRemoveStaleRowsTimeout; + }); +}); + +/** + * A test provider that doesn't finish startQuery() until `finishQueryPromise` + * is resolved. + */ +class DelayingTestProvider extends UrlbarTestUtils.TestProvider { + finishQueryPromise = null; + async startQuery(context, addCallback) { + for (let result of this._results) { + addCallback(this, result); + } + await this.finishQueryPromise; + } +} + +/** + * Makes a result with a suggested index. + * + * @param {number} suggestedIndex + * The preferred index of the result. + * @param {number} resultSpan + * The result will have this span. + * @returns {UrlbarResult} + */ +function makeSuggestedIndexResult(suggestedIndex, resultSpan = 1) { + return Object.assign( + new UrlbarResult( + UrlbarUtils.RESULT_TYPE.URL, + UrlbarUtils.RESULT_SOURCE.HISTORY, + { + url: "http://example.com/si", + displayUrl: "http://example.com/si", + title: "suggested index", + } + ), + { suggestedIndex, resultSpan } + ); +} + +/** + * Makes an array of results for the suggestedIndex tests. The array will + * include a heuristic followed by the specified results. + * + * @param {object} options + * The options object + * @param {number} [options.count] + * The number of results to return other than the heuristic. This and + * `type` must be given together. + * @param {UrlbarUtils.RESULT_TYPE} [options.type] + * The type of results to return other than the heuristic. This and `count` + * must be given together. + * @param {Array} [options.specs] + * If you want a mix of result types instead of only one type, then use this + * param instead of `count` and `type`. Each item in this array must be an + * object with the following properties: + * {number} count + * The number of results to return for the given `type`. + * {UrlbarUtils.RESULT_TYPE} type + * The type of results. + * @returns {Array} + * An array of results. + */ +function makeProviderResults({ count = 0, type = undefined, specs = [] }) { + if (count) { + specs.push({ count, type }); + } + + let query = "test"; + let results = [ + Object.assign( + new UrlbarResult( + UrlbarUtils.RESULT_TYPE.SEARCH, + UrlbarUtils.RESULT_SOURCE.SEARCH, + { + query, + engine: Services.search.defaultEngine.name, + } + ), + { heuristic: true } + ), + ]; + + for (let { count: specCount, type: specType } of specs) { + for (let i = 0; i < specCount; i++) { + let str = `${query} ${results.length}`; + switch (specType) { + case UrlbarUtils.RESULT_TYPE.SEARCH: + results.push( + new UrlbarResult( + UrlbarUtils.RESULT_TYPE.SEARCH, + UrlbarUtils.RESULT_SOURCE.SEARCH, + { + query, + suggestion: str, + lowerCaseSuggestion: str.toLowerCase(), + engine: Services.search.defaultEngine.name, + } + ) + ); + break; + case UrlbarUtils.RESULT_TYPE.URL: + results.push( + new UrlbarResult( + UrlbarUtils.RESULT_TYPE.URL, + UrlbarUtils.RESULT_SOURCE.HISTORY, + { + url: "http://example.com/" + i, + displayUrl: "http://example.com/" + i, + title: str, + } + ) + ); + break; + default: + throw new Error(`Unsupported makeProviderResults type: ${specType}`); + } + } + } + + return results; +} + +let gSuggestedIndexTaskIndex = 0; + +/** + * Adds a suggestedIndex test task. See doSuggestedIndexTest() for params. + * + * @param {object} options + * See doSuggestedIndexTest(). + */ +function add_suggestedIndex_task(options) { + if (!gSuggestedIndexTaskIndex) { + initSuggestedIndexTest(); + } + let testIndex = gSuggestedIndexTaskIndex++; + let testName = "test_" + testIndex; + let testDesc = JSON.stringify(options); + let func = async () => { + info(`Running task at index ${testIndex}: ${testDesc}`); + await doSuggestedIndexTest(options); + }; + Object.defineProperty(func, "name", { value: testName }); + add_task(func); +} + +/** + * Initializes suggestedIndex tests. You don't normally need to call this from + * your test because add_suggestedIndex_task() calls it automatically. + */ +function initSuggestedIndexTest() { + // These tests can time out on Mac TV WebRender just because they do so much, + // so request a longer timeout. + if (AppConstants.platform == "macosx") { + requestLongerTimeout(3); + } + registerCleanupFunction(() => { + gSuggestedIndexTaskIndex = 0; + }); +} + +/** + * @typedef {object} SuggestedIndexTestOptions + * @property {number} [otherCount] + * The number of results other than the heuristic and suggestedIndex results + * that the provider should return for search 1. This and `otherType` must be + * given together. + * @property {UrlbarUtils.RESULT_TYPE} [otherType] + * The type of results other than the heuristic and suggestedIndex results + * that the provider should return for search 1. This and `otherCount` must be + * given together. + * @property {Array} [other] + * If you want the provider to return a mix of result types instead of only + * one type, then use this param instead of `otherCount` and `otherType`. Each + * item in this array must be an object with the following properties: + * {number} count + * The number of results to return for the given `type`. + * {UrlbarUtils.RESULT_TYPE} type + * The type of results. + * @property {number} viewCount + * The total number of results expected in the view after search 1 finishes, + * including the heuristic and suggestedIndex results. + * @param {number} [suggestedIndex] + * If given, the provider will return a result with this suggested index for + * search 1. + * @property {number} [resultSpan] + * If this and `search1.suggestedIndex` are given, then the suggestedIndex + * result for search 1 will have this resultSpan. + * @property {Array} [suggestedIndexes] + * If you want the provider to return more than one suggestedIndex result for + * search 1, then use this instead of `search1.suggestedIndex`. Each item in + * this array must be one of the following: + * suggestedIndex value + * [suggestedIndex, resultSpan] tuple + */ + +/** + * Runs a suggestedIndex test. Performs two searches and checks the results just + * after the view update and after the second search finishes. The caller is + * responsible for passing in a description of what the rows should look like + * just after the view update finishes but before the second search finishes, + * i.e., before stale rows are removed and hidden rows are shown -- this is the + * `duringUpdate` param. The important thing this checks is that the rows with + * suggested indexes don't move around or appear in the wrong places. + * + * @param {object} options + * The options object + * @param {SuggestedIndexTestOptions} options.search1 + * The first search options object + * @param {SuggestedIndexTestOptions} options.search2 + * This object has the same properties as the `search1` object but it applies + * to the second search. + * @param {Array<{ count: number, type: UrlbarUtils.RESULT_TYPE, suggestedIndex: ?number, stale: ?boolean, hidden: ?boolean }>} options.duringUpdate + * An array of expected row states during the view update. Each item in the + * array must be an object with the following properties: + * {number} count + * The number of rows in the view to which this row state object applies. + * {UrlbarUtils.RESULT_TYPE} type + * The expected type of the rows. + * {number} [suggestedIndex] + * The expected suggestedIndex of the row. + * {boolean} [stale] + * Whether the rows are expected to be stale. Defaults to false. + * {boolean} [hidden] + * Whether the rows are expected to be hidden. Defaults to false. + */ +async function doSuggestedIndexTest({ search1, search2, duringUpdate }) { + // We use this test provider to test specific results. It has an Infinity + // priority so that it provides all results in our test searches, including + // the heuristic. That lets us avoid any potential races with the built-in + // providers; testing them is not important here. + let provider = new DelayingTestProvider({ priority: Infinity }); + UrlbarProvidersManager.registerProvider(provider); + registerCleanupFunction(() => { + UrlbarProvidersManager.unregisterProvider(provider); + }); + + // Set up the first search. First, add the non-suggestedIndex results to the + // provider. + provider._results = makeProviderResults({ + specs: search1.other, + count: search1.otherCount, + type: search1.otherType, + }); + + // Set up `suggestedIndexes`. It's an array with [suggestedIndex, resultSpan] + // tuples. + if (!search1.suggestedIndexes) { + search1.suggestedIndexes = []; + } + search1.suggestedIndexes = search1.suggestedIndexes.map(value => + typeof value == "number" ? [value, 1] : value + ); + if (typeof search1.suggestedIndex == "number") { + search1.suggestedIndexes.push([ + search1.suggestedIndex, + search1.resultSpan || 1, + ]); + } + + // Add the suggestedIndex results to the provider. + for (let [suggestedIndex, resultSpan] of search1.suggestedIndexes) { + provider._results.push( + makeSuggestedIndexResult(suggestedIndex, resultSpan) + ); + } + + // Do the first search. + provider.finishQueryPromise = Promise.resolve(); + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "test", + }); + + // Sanity check the results. + Assert.equal( + UrlbarTestUtils.getResultCount(window), + search1.viewCount, + "Row count after first search" + ); + for (let [suggestedIndex, resultSpan] of search1.suggestedIndexes) { + let index = + suggestedIndex >= 0 + ? Math.min(search1.viewCount - 1, suggestedIndex) + : Math.max(0, search1.viewCount + suggestedIndex); + let result = await UrlbarTestUtils.getDetailsOfResultAt(window, index); + Assert.equal( + result.element.row.result.suggestedIndex, + suggestedIndex, + "suggestedIndex after first search" + ); + Assert.equal( + UrlbarUtils.getSpanForResult(result.element.row.result), + resultSpan, + "resultSpan after first search" + ); + } + + // Set up the second search. First, add the non-suggestedIndex results to the + // provider. + provider._results = makeProviderResults({ + specs: search2.other, + count: search2.otherCount, + type: search2.otherType, + }); + + // Set up `suggestedIndexes`. It's an array with [suggestedIndex, resultSpan] + // tuples. + if (!search2.suggestedIndexes) { + search2.suggestedIndexes = []; + } + search2.suggestedIndexes = search2.suggestedIndexes.map(value => + typeof value == "number" ? [value, 1] : value + ); + if (typeof search2.suggestedIndex == "number") { + search2.suggestedIndexes.push([ + search2.suggestedIndex, + search2.resultSpan || 1, + ]); + } + + // Add the suggestedIndex results to the provider. + for (let [suggestedIndex, resultSpan] of search2.suggestedIndexes) { + provider._results.push( + makeSuggestedIndexResult(suggestedIndex, resultSpan) + ); + } + + let rowCountDuringUpdate = duringUpdate.reduce( + (count, rowState) => count + rowState.count, + 0 + ); + + // Don't allow the search to finish until we check the updated rows. We'll + // accomplish that by adding a mutation observer to observe completion of the + // update and delaying resolving the provider's finishQueryPromise. + let mutationPromise = new Promise(resolve => { + let lastRowState = duringUpdate[duringUpdate.length - 1]; + let observer = new MutationObserver(mutations => { + observer.disconnect(); + resolve(); + }); + if (lastRowState.stale) { + // The last row during the update is expected to become stale. Wait for + // the stale attribute to be set on it. We'll actually just wait for any + // attribute. + let { children } = UrlbarTestUtils.getResultsContainer(window); + observer.observe(children[children.length - 1], { attributes: true }); + } else if (search1.viewCount == rowCountDuringUpdate) { + // No rows are expected to be added during the view update, so it must be + // the case that some rows will be updated for results in the the second + // search. Wait for any change to an existing row. + observer.observe(UrlbarTestUtils.getResultsContainer(window), { + subtree: true, + attributes: true, + characterData: true, + }); + } else { + // Rows are expected to be added during the update. Wait for them. + observer.observe(UrlbarTestUtils.getResultsContainer(window), { + childList: true, + }); + } + }); + + // Now do the second search but don't wait for it to finish. + let resolveQuery; + provider.finishQueryPromise = new Promise( + resolve => (resolveQuery = resolve) + ); + let queryPromise = UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "test", + }); + + // Wait for the update to finish. + await mutationPromise; + + // Check the rows. We can't use UrlbarTestUtils.getDetailsOfResultAt() here + // because it waits for the search to finish. + Assert.equal( + UrlbarTestUtils.getResultCount(window), + rowCountDuringUpdate, + "Row count during update" + ); + let rows = UrlbarTestUtils.getResultsContainer(window).children; + let rowIndex = 0; + for (let rowState of duringUpdate) { + for (let i = 0; i < rowState.count; i++) { + let row = rows[rowIndex]; + + // type + if ("type" in rowState) { + Assert.equal( + row.result.type, + rowState.type, + `Type at index ${rowIndex} during update` + ); + } + + // suggestedIndex + if ("suggestedIndex" in rowState) { + Assert.ok( + row.result.hasSuggestedIndex, + `Row at index ${rowIndex} has suggestedIndex during update` + ); + Assert.equal( + row.result.suggestedIndex, + rowState.suggestedIndex, + `suggestedIndex at index ${rowIndex} during update` + ); + } else { + Assert.ok( + !row.result.hasSuggestedIndex, + `Row at index ${rowIndex} does not have suggestedIndex during update` + ); + } + + // resultSpan + Assert.equal( + UrlbarUtils.getSpanForResult(row.result), + rowState.resultSpan || 1, + `resultSpan at index ${rowIndex} during update` + ); + + // stale + if (rowState.stale) { + Assert.equal( + row.getAttribute("stale"), + "true", + `Row at index ${rowIndex} is stale during update` + ); + } else { + Assert.ok( + !row.hasAttribute("stale"), + `Row at index ${rowIndex} is not stale during update` + ); + } + + // visible + Assert.equal( + BrowserTestUtils.is_visible(row), + !rowState.hidden, + `Visible at index ${rowIndex} during update` + ); + + rowIndex++; + } + } + + // Finish the search. + resolveQuery(); + await queryPromise; + + // Check the rows now that the second search is done. First, build a map from + // real indexes to suggested index. e.g., if a suggestedIndex = -1, then the + // real index = the result count - 1. + let suggestedIndexesByRealIndex = new Map(); + for (let [suggestedIndex, resultSpan] of search2.suggestedIndexes) { + let realIndex = + suggestedIndex >= 0 + ? Math.min(suggestedIndex, search2.viewCount - 1) + : Math.max(0, search2.viewCount + suggestedIndex); + suggestedIndexesByRealIndex.set(realIndex, [suggestedIndex, resultSpan]); + } + + Assert.equal( + UrlbarTestUtils.getResultCount(window), + search2.viewCount, + "Row count after update" + ); + for (let i = 0; i < search2.viewCount; i++) { + let result = rows[i].result; + let tuple = suggestedIndexesByRealIndex.get(i); + if (tuple) { + let [suggestedIndex, resultSpan] = tuple; + Assert.ok( + result.hasSuggestedIndex, + `Row at index ${i} has suggestedIndex after update` + ); + Assert.equal( + result.suggestedIndex, + suggestedIndex, + `suggestedIndex at index ${i} after update` + ); + Assert.equal( + UrlbarUtils.getSpanForResult(result), + resultSpan, + `resultSpan at index ${i} after update` + ); + } else { + Assert.ok( + !result.hasSuggestedIndex, + `Row at index ${i} does not have suggestedIndex after update` + ); + } + } + + await UrlbarTestUtils.promisePopupClose(window); + gURLBar.handleRevert(); + UrlbarProvidersManager.unregisterProvider(provider); +} |