diff options
Diffstat (limited to 'browser/components/firefoxview/tests/browser/browser_history_firefoxview.js')
-rw-r--r-- | browser/components/firefoxview/tests/browser/browser_history_firefoxview.js | 75 |
1 files changed, 47 insertions, 28 deletions
diff --git a/browser/components/firefoxview/tests/browser/browser_history_firefoxview.js b/browser/components/firefoxview/tests/browser/browser_history_firefoxview.js index a6c697e398..c4c096acff 100644 --- a/browser/components/firefoxview/tests/browser/browser_history_firefoxview.js +++ b/browser/components/firefoxview/tests/browser/browser_history_firefoxview.js @@ -15,8 +15,8 @@ const HISTORY_EVENT = [["firefoxview_next", "history", "visits", undefined]]; const SHOW_ALL_HISTORY_EVENT = [ ["firefoxview_next", "show_all_history", "tabs", undefined], ]; - const NEVER_REMEMBER_HISTORY_PREF = "browser.privatebrowsing.autostart"; + const DAY_MS = 24 * 60 * 60 * 1000; const today = new Date(); const yesterday = new Date(Date.now() - DAY_MS); @@ -24,6 +24,14 @@ const twoDaysAgo = new Date(Date.now() - DAY_MS * 2); const threeDaysAgo = new Date(Date.now() - DAY_MS * 3); const fourDaysAgo = new Date(Date.now() - DAY_MS * 4); const oneMonthAgo = new Date(today); +const dates = [ + today, + yesterday, + twoDaysAgo, + threeDaysAgo, + fourDaysAgo, + oneMonthAgo, +]; // Set the date for the first day of the last month oneMonthAgo.setDate(1); @@ -47,13 +55,14 @@ function isElInViewport(element) { ); } -async function historyComponentReady(historyComponent) { +async function historyComponentReady(historyComponent, expectedHistoryItems) { await TestUtils.waitForCondition( () => [...historyComponent.allHistoryItems.values()].reduce( (acc, { length }) => acc + length, 0 - ) === 24 + ) === expectedHistoryItems, + "History component ready" ); let expected = historyComponent.historyMapByDate.length; @@ -148,6 +157,18 @@ async function addHistoryItems(dateAdded) { }); } +function createHistoryEntries() { + let historyEntries = []; + for (let i = 0; i < 4; i++) { + historyEntries.push({ + url: URLs[i], + title: `Example Domain ${i}`, + visits: dates.map(date => [{ date }]), + }); + } + return historyEntries; +} + add_setup(async () => { await SpecialPowers.pushPrefEnv({ set: [["browser.firefox-view.search.enabled", true]], @@ -160,21 +181,20 @@ add_setup(async () => { add_task(async function test_list_ordering() { await PlacesUtils.history.clear(); - await addHistoryItems(today); - await addHistoryItems(yesterday); - await addHistoryItems(twoDaysAgo); - await addHistoryItems(threeDaysAgo); - await addHistoryItems(fourDaysAgo); - await addHistoryItems(oneMonthAgo); + const historyEntries = createHistoryEntries(); + await PlacesUtils.history.insertMany(historyEntries); await withFirefoxView({}, async browser => { const { document } = browser.contentWindow; - await navigateToCategoryAndWait(document, "history"); + await navigateToViewAndWait(document, "history"); - let historyComponent = document.querySelector("view-history"); + let historyComponent = await TestUtils.waitForCondition( + () => document.querySelector("view-history"), + "History component rendered" + ); historyComponent.profileAge = 8; - await historyComponentReady(historyComponent); + await historyComponentReady(historyComponent, historyEntries.length); let firstCard = historyComponent.cards[0]; @@ -262,7 +282,7 @@ add_task(async function test_empty_states() { await withFirefoxView({}, async browser => { const { document } = browser.contentWindow; - await navigateToCategoryAndWait(document, "history"); + await navigateToViewAndWait(document, "history"); let historyComponent = document.querySelector("view-history"); historyComponent.profileAge = 8; @@ -350,7 +370,7 @@ add_task(async function test_observers_removed_when_view_is_hidden() { ); await withFirefoxView({}, async browser => { const { document } = browser.contentWindow; - await navigateToCategoryAndWait(document, "history"); + await navigateToViewAndWait(document, "history"); const historyComponent = document.querySelector("view-history"); historyComponent.profileAge = 8; let visitList = await TestUtils.waitForCondition(() => @@ -390,20 +410,16 @@ add_task(async function test_observers_removed_when_view_is_hidden() { add_task(async function test_show_all_history_telemetry() { await PlacesUtils.history.clear(); - await addHistoryItems(today); - await addHistoryItems(yesterday); - await addHistoryItems(twoDaysAgo); - await addHistoryItems(threeDaysAgo); - await addHistoryItems(fourDaysAgo); - await addHistoryItems(oneMonthAgo); + const historyEntries = createHistoryEntries(); + await PlacesUtils.history.insertMany(historyEntries); await withFirefoxView({}, async browser => { const { document } = browser.contentWindow; - await navigateToCategoryAndWait(document, "history"); + await navigateToViewAndWait(document, "history"); let historyComponent = document.querySelector("view-history"); historyComponent.profileAge = 8; - await historyComponentReady(historyComponent); + await historyComponentReady(historyComponent, historyEntries.length); await clearAllParentTelemetryEvents(); let showAllHistoryBtn = historyComponent.showAllHistoryBtn; @@ -422,12 +438,15 @@ add_task(async function test_show_all_history_telemetry() { }); add_task(async function test_search_history() { + await PlacesUtils.history.clear(); + const historyEntries = createHistoryEntries(); + await PlacesUtils.history.insertMany(historyEntries); await withFirefoxView({}, async browser => { const { document } = browser.contentWindow; - await navigateToCategoryAndWait(document, "history"); + await navigateToViewAndWait(document, "history"); const historyComponent = document.querySelector("view-history"); historyComponent.profileAge = 8; - await historyComponentReady(historyComponent); + await historyComponentReady(historyComponent, historyEntries.length); const searchTextbox = await TestUtils.waitForCondition( () => historyComponent.searchTextbox, "The search textbox is displayed." @@ -447,7 +466,7 @@ add_task(async function test_search_history() { ); await TestUtils.waitForCondition(() => { const { rowEls } = historyComponent.lists[0]; - return rowEls.length === 1 && rowEls[0].mainEl.href === URLs[0]; + return rowEls.length === 1 && rowEls[0].mainEl.href === URLs[1]; }, "There is one matching search result."); info("Input a bogus search query."); @@ -504,7 +523,7 @@ add_task(async function test_persist_collapse_card_after_view_change() { await addHistoryItems(today); await withFirefoxView({}, async browser => { const { document } = browser.contentWindow; - await navigateToCategoryAndWait(document, "history"); + await navigateToViewAndWait(document, "history"); const historyComponent = document.querySelector("view-history"); historyComponent.profileAge = 8; await TestUtils.waitForCondition( @@ -529,8 +548,8 @@ add_task(async function test_persist_collapse_card_after_view_change() { ); // Switch to a new view and then back to History - await navigateToCategoryAndWait(document, "syncedtabs"); - await navigateToCategoryAndWait(document, "history"); + await navigateToViewAndWait(document, "syncedtabs"); + await navigateToViewAndWait(document, "history"); // Check that first history card is still collapsed after changing view ok( |