From 763d6c428fafc6d703aad73e4efd71a0f5df1990 Mon Sep 17 00:00:00 2001 From: Doug Thayer Date: Wed, 14 Feb 2018 09:17:41 -0800 Subject: [PATCH] Bug 1340498 - Update onVisits tests to use 'page-visited' r=mak MozReview-Commit-ID: FxC3gcUF9hl --HG-- extra : rebase_source : eeb3a99e07e3e5a39d716760cd26795f28f9a74b --- .../tests/unit/test_automigration.js | 3 - docshell/test/browser/browser_bug420605.js | 1 - docshell/test/browser/browser_bug503832.js | 1 - docshell/test/browser/browser_bug655270.js | 1 - services/sync/tests/unit/head_helpers.js | 15 ++- .../sync/tests/unit/test_history_store.js | 25 +--- .../test/unit/common_test_Download.js | 4 +- .../components/downloads/test/unit/head.js | 36 ++--- .../places/tests/PlacesTestUtils.jsm | 12 ++ .../places/tests/browser/browser_bug399606.js | 40 +++--- .../places/tests/browser/browser_bug646422.js | 1 - .../tests/browser/browser_double_redirect.js | 28 ++-- .../browser_multi_redirect_frecency.js | 12 +- .../places/tests/browser/browser_notfound.js | 50 +++---- ...owser_onvisit_title_null_for_navigation.js | 26 ++-- .../places/tests/browser/browser_redirect.js | 36 ++--- .../places/tests/browser/browser_settitle.js | 1 - .../tests/browser/browser_visited_notfound.js | 18 ++- .../components/places/tests/browser/head.js | 1 - .../test_notifications_onDeleteURI.js | 1 - .../test_notifications_onDeleteVisits.js | 1 - .../components/places/tests/head_common.js | 1 - .../tests/history/test_async_history_api.js | 113 ++++++++-------- .../places/tests/history/test_remove.js | 3 - .../tests/history/test_removeByFilter.js | 3 - .../history/test_removeVisitsByFilter.js | 3 - .../places/tests/unit/test_454977.js | 8 +- .../tests/unit/test_download_history.js | 65 +++++---- .../tests/unit/test_history_observer.js | 123 ++++++++++-------- .../places/tests/unit/test_markpageas.js | 48 ++----- 30 files changed, 301 insertions(+), 379 deletions(-) diff --git a/browser/components/migration/tests/unit/test_automigration.js b/browser/components/migration/tests/unit/test_automigration.js index 051bac1a35e0..ca8ab5f9e529 100644 --- a/browser/components/migration/tests/unit/test_automigration.js +++ b/browser/components/migration/tests/unit/test_automigration.js @@ -631,9 +631,6 @@ add_task(async function checkUndoVisitsState() { let observer = { onBeginUpdateBatch() {}, onEndUpdateBatch() {}, - onVisits(visits) { - wrongMethodDeferred.reject(new Error("Unexpected call to onVisits " + visits.length)); - }, onTitleChanged(uri) { wrongMethodDeferred.reject(new Error("Unexpected call to onTitleChanged " + uri.spec)); }, diff --git a/docshell/test/browser/browser_bug420605.js b/docshell/test/browser/browser_bug420605.js index 704437bd06e6..fe40e8f4f1e4 100644 --- a/docshell/test/browser/browser_bug420605.js +++ b/docshell/test/browser/browser_bug420605.js @@ -55,7 +55,6 @@ function test() { var historyObserver = { onBeginUpdateBatch: function() {}, onEndUpdateBatch: function() {}, - onVisits: function() {}, onTitleChanged: function(aURI, aPageTitle) {}, onDeleteURI: function(aURI) {}, onClearHistory: function() {}, diff --git a/docshell/test/browser/browser_bug503832.js b/docshell/test/browser/browser_bug503832.js index 2e5a73a1127f..53357c6ec9d1 100644 --- a/docshell/test/browser/browser_bug503832.js +++ b/docshell/test/browser/browser_bug503832.js @@ -15,7 +15,6 @@ add_task(async function() { var historyObserver = { onBeginUpdateBatch: function() {}, onEndUpdateBatch: function() {}, - onVisits: function() {}, onTitleChanged: function(aURI, aPageTitle) { aURI = aURI.spec; switch (aURI) { diff --git a/docshell/test/browser/browser_bug655270.js b/docshell/test/browser/browser_bug655270.js index 7234aeabf8a7..b256582dc6eb 100644 --- a/docshell/test/browser/browser_bug655270.js +++ b/docshell/test/browser/browser_bug655270.js @@ -48,7 +48,6 @@ function test() { onBeginUpdateBatch: function() { }, onEndUpdateBatch: function() { }, - onVisits: function() { }, onTitleChanged: function() { }, onDeleteURI: function() { }, onClearHistory: function() { }, diff --git a/services/sync/tests/unit/head_helpers.js b/services/sync/tests/unit/head_helpers.js index c862da224cb4..00a154ce38a3 100644 --- a/services/sync/tests/unit/head_helpers.js +++ b/services/sync/tests/unit/head_helpers.js @@ -549,15 +549,18 @@ async function serverForFoo(engine, callback) { async function promiseVisit(expectedType, expectedURI) { return new Promise(resolve => { function done(type, uri) { - if (uri.equals(expectedURI) && type == expectedType) { + if (uri == expectedURI.spec && type == expectedType) { PlacesUtils.history.removeObserver(observer); + PlacesObservers.removeListener(["page-visited"], + observer.handlePlacesEvents); resolve(); } } let observer = { - onVisits(visits) { - Assert.equal(visits.length, 1); - done("added", visits[0].uri); + handlePlacesEvents(events) { + Assert.equal(events.length, 1); + Assert.equal(events[0].type, "page-visited"); + done("added", events[0].url); }, onBeginUpdateBatch() {}, onEndUpdateBatch() {}, @@ -565,13 +568,15 @@ async function promiseVisit(expectedType, expectedURI) { onFrecencyChanged() {}, onManyFrecenciesChanged() {}, onDeleteURI(uri) { - done("removed", uri); + done("removed", uri.spec); }, onClearHistory() {}, onPageChanged() {}, onDeleteVisits() {}, }; PlacesUtils.history.addObserver(observer, false); + PlacesObservers.addListener(["page-visited"], + observer.handlePlacesEvents); }); } diff --git a/services/sync/tests/unit/test_history_store.js b/services/sync/tests/unit/test_history_store.js index fd294bd49997..4e0cd037f080 100644 --- a/services/sync/tests/unit/test_history_store.js +++ b/services/sync/tests/unit/test_history_store.js @@ -13,26 +13,11 @@ const TIMESTAMP3 = (Date.now() - 123894) * 1000; function promiseOnVisitObserved() { return new Promise(res => { - PlacesUtils.history.addObserver({ - onBeginUpdateBatch: function onBeginUpdateBatch() {}, - onEndUpdateBatch: function onEndUpdateBatch() {}, - onPageChanged: function onPageChanged() {}, - onTitleChanged: function onTitleChanged() { - }, - onVisits: function onVisits() { - PlacesUtils.history.removeObserver(this); - res(); - }, - onDeleteVisits: function onDeleteVisits() {}, - onPageExpired: function onPageExpired() {}, - onDeleteURI: function onDeleteURI() {}, - onClearHistory: function onClearHistory() {}, - QueryInterface: ChromeUtils.generateQI([ - Ci.nsINavHistoryObserver, - Ci.nsINavHistoryObserver_MOZILLA_1_9_1_ADDITIONS, - Ci.nsISupportsWeakReference - ]) - }, true); + let listener = new PlacesWeakCallbackWrapper((events) => { + PlacesObservers.removeListener(["page-visited"], listener); + res(); + }); + PlacesObservers.addListener(["page-visited"], listener); }); } diff --git a/toolkit/components/downloads/test/unit/common_test_Download.js b/toolkit/components/downloads/test/unit/common_test_Download.js index 31b960a5d6a5..0fda959abb6b 100644 --- a/toolkit/components/downloads/test/unit/common_test_Download.js +++ b/toolkit/components/downloads/test/unit/common_test_Download.js @@ -2400,7 +2400,7 @@ add_task(async function test_history() { // The history notifications should be received before the download completes. let [time, transitionType] = await promiseVisit; - Assert.equal(time, download.startTime.getTime() * 1000); + Assert.equal(time, download.startTime.getTime()); Assert.equal(transitionType, Ci.nsINavHistoryService.TRANSITION_DOWNLOAD); // Restart and complete the download after clearing history. @@ -2434,7 +2434,7 @@ add_task(async function test_history_tryToKeepPartialData() { // The time set by nsIHelperAppService may be different than the start time in // the download object, thus we only check that it is a meaningful time. Note // that we subtract one second from the earliest time to account for rounding. - Assert.ok(time >= beforeStartTimeMs * 1000 - 1000000); + Assert.ok(time >= beforeStartTimeMs - 1000); // Complete the download before finishing the test. continueResponses(); diff --git a/toolkit/components/downloads/test/unit/head.js b/toolkit/components/downloads/test/unit/head.js index f36f22cd20af..69380c1ba686 100644 --- a/toolkit/components/downloads/test/unit/head.js +++ b/toolkit/components/downloads/test/unit/head.js @@ -146,32 +146,16 @@ function promiseTimeout(aTime) { */ function promiseWaitForVisit(aUrl) { return new Promise(resolve => { - - let uri = NetUtil.newURI(aUrl); - - PlacesUtils.history.addObserver({ - QueryInterface: ChromeUtils.generateQI([Ci.nsINavHistoryObserver]), - onBeginUpdateBatch() {}, - onEndUpdateBatch() {}, - onVisits(aVisits) { - Assert.equal(aVisits.length, 1); - let { - uri: visitUri, - time, - transitionType, - } = aVisits[0]; - if (visitUri.equals(uri)) { - PlacesUtils.history.removeObserver(this); - resolve([time, transitionType]); - } - }, - onTitleChanged() {}, - onDeleteURI() {}, - onClearHistory() {}, - onPageChanged() {}, - onDeleteVisits() {}, - }); - + function listener(aEvents) { + Assert.equal(aEvents.length, 1); + let event = aEvents[0]; + Assert.equal(event.type, "page-visited"); + if (event.url == aUrl) { + PlacesObservers.removeListener(["page-visited"], listener); + resolve([event.visitTime, event.transitionType]); + } + } + PlacesObservers.addListener(["page-visited"], listener); }); } diff --git a/toolkit/components/places/tests/PlacesTestUtils.jsm b/toolkit/components/places/tests/PlacesTestUtils.jsm index fd691934e809..5f858c41db38 100644 --- a/toolkit/components/places/tests/PlacesTestUtils.jsm +++ b/toolkit/components/places/tests/PlacesTestUtils.jsm @@ -318,6 +318,18 @@ var PlacesTestUtils = Object.freeze({ }, waitForNotification(notification, conditionFn = () => true, type = "bookmarks") { + if (type == "places") { + return new Promise(resolve => { + function listener(events) { + if (conditionFn(events)) { + PlacesObservers.removeListener([notification], listener); + resolve(); + } + } + PlacesObservers.addListener([notification], listener); + }); + } + let iface = type == "bookmarks" ? Ci.nsINavBookmarkObserver : Ci.nsINavHistoryObserver; return new Promise(resolve => { diff --git a/toolkit/components/places/tests/browser/browser_bug399606.js b/toolkit/components/places/tests/browser/browser_bug399606.js index a1ea0e951805..aabbd9c0a8b9 100644 --- a/toolkit/components/places/tests/browser/browser_bug399606.js +++ b/toolkit/components/places/tests/browser/browser_bug399606.js @@ -15,43 +15,33 @@ add_task(async function() { ]; // Create and add history observer. - let historyObserver = { - count: 0, - expectedURI: null, - onVisits(aVisits) { - for (let {uri} of aVisits) { - info("Received onVisits: " + uri.spec); - if (uri.equals(this.expectedURI)) { - this.count++; - } + let count = 0; + let expectedURI = null; + function onVisitsListener(aEvents) { + for (let event of aEvents) { + info("Received onVisits: " + event.url); + if (event.url == expectedURI) { + count++; } - }, - onBeginUpdateBatch() {}, - onEndUpdateBatch() {}, - onTitleChanged() {}, - onDeleteURI() {}, - onClearHistory() {}, - onPageChanged() {}, - onDeleteVisits() {}, - QueryInterface: ChromeUtils.generateQI([Ci.nsINavHistoryObserver]) - }; + } + } async function promiseLoadedThreeTimes(uri) { - historyObserver.count = 0; - historyObserver.expectedURI = Services.io.newURI(uri); + count = 0; + expectedURI = uri; let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser); - PlacesUtils.history.addObserver(historyObserver); + PlacesObservers.addListener(["page-visited"], onVisitsListener); gBrowser.loadURI(uri); await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, uri); await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, uri); await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, uri); - PlacesUtils.history.removeObserver(historyObserver); + PlacesObservers.removeListener(["page-visited"], onVisitsListener); BrowserTestUtils.removeTab(tab); } for (let uri of URIS) { await promiseLoadedThreeTimes(uri); - is(historyObserver.count, 1, - "onVisit has been received right number of times for " + uri); + is(count, 1, + "'page-visited' has been received right number of times for " + uri); } }); diff --git a/toolkit/components/places/tests/browser/browser_bug646422.js b/toolkit/components/places/tests/browser/browser_bug646422.js index f3034d053508..481405e18db3 100644 --- a/toolkit/components/places/tests/browser/browser_bug646422.js +++ b/toolkit/components/places/tests/browser/browser_bug646422.js @@ -23,7 +23,6 @@ add_task(async function() { onBeginUpdateBatch() { }, onEndUpdateBatch() { }, - onVisits() { }, onDeleteURI() { }, onClearHistory() { }, onPageChanged() { }, diff --git a/toolkit/components/places/tests/browser/browser_double_redirect.js b/toolkit/components/places/tests/browser/browser_double_redirect.js index 5d447958df3f..a8e799e60b61 100644 --- a/toolkit/components/places/tests/browser/browser_double_redirect.js +++ b/toolkit/components/places/tests/browser/browser_double_redirect.js @@ -11,19 +11,18 @@ add_task(async function() { const FINAL_URI = NetUtil.newURI(BASE_URL + "final.html"); let promiseVisits = new Promise(resolve => { - PlacesUtils.history.addObserver({ - __proto__: NavHistoryObserver.prototype, + let observer = { _notified: [], onVisit(uri, id, time, referrerId, transition) { - info("Received onVisit: " + uri.spec); + info("Received onVisit: " + uri); this._notified.push(uri); - if (!uri.equals(FINAL_URI)) { + if (uri != FINAL_URI.spec) { return; } is(this._notified.length, 4); - PlacesUtils.history.removeObserver(this); + PlacesObservers.removeListener(["page-visited"], this.handleEvents); (async function() { // Get all pages visited from the original typed one @@ -45,18 +44,21 @@ add_task(async function() { resolve(); })(); }, - onVisits(visits) { - is(visits.length, 1, "Right number of visits notified"); + handleEvents(events) { + is(events.length, 1, "Right number of visits notified"); + is(events[0].type, "page-visited"); let { - uri, + url, visitId, - time, - referrerId, + visitTime, + referringVisitId, transitionType, - } = visits[0]; - this.onVisit(uri, visitId, time, referrerId, transitionType); + } = events[0]; + this.onVisit(url, visitId, visitTime, referringVisitId, transitionType); } - }); + }; + observer.handleEvents = observer.handleEvents.bind(observer); + PlacesObservers.addListener(["page-visited"], observer.handleEvents); }); PlacesUtils.history.markPageAsTyped(TEST_URI); diff --git a/toolkit/components/places/tests/browser/browser_multi_redirect_frecency.js b/toolkit/components/places/tests/browser/browser_multi_redirect_frecency.js index ee06c7843899..010c1f0067bb 100644 --- a/toolkit/components/places/tests/browser/browser_multi_redirect_frecency.js +++ b/toolkit/components/places/tests/browser/browser_multi_redirect_frecency.js @@ -32,15 +32,15 @@ async function check_uri(uri, frecency, hidden) { async function waitVisitedNotifications() { let redirectNotified = false; - await PlacesTestUtils.waitForNotification("onVisits", visits => { + await PlacesTestUtils.waitForNotification("page-visited", visits => { is(visits.length, 1, "Was notified for the right number of visits."); - let {uri} = visits[0]; - info("Received onVisits: " + uri.spec); - if (uri.equals(REDIRECT_URI)) { + let {url} = visits[0]; + info("Received 'page-visited': " + url); + if (url == REDIRECT_URI.spec) { redirectNotified = true; } - return uri.equals(TARGET_URI); - }, "history"); + return url == TARGET_URI.spec; + }, "places"); return redirectNotified; } diff --git a/toolkit/components/places/tests/browser/browser_notfound.js b/toolkit/components/places/tests/browser/browser_notfound.js index bbbf042e8ad8..aa17fb64dd1a 100644 --- a/toolkit/components/places/tests/browser/browser_notfound.js +++ b/toolkit/components/places/tests/browser/browser_notfound.js @@ -10,42 +10,24 @@ add_task(async function() { // Create and add history observer. let visitedPromise = new Promise(resolve => { - let historyObserver = { - onVisit(aURI, aVisitID, aTime, aReferringID, aTransitionType) { - PlacesUtils.history.removeObserver(historyObserver); - info("Received onVisit: " + aURI.spec); - fieldForUrl(aURI, "frecency", function(aFrecency) { - is(aFrecency, 0, "Frecency should be 0"); - fieldForUrl(aURI, "hidden", function(aHidden) { - is(aHidden, 0, "Page should not be hidden"); - fieldForUrl(aURI, "typed", function(aTyped) { - is(aTyped, 0, "page should not be marked as typed"); - resolve(); - }); + function listener(aEvents) { + is(aEvents.length, 1, "Right number of visits notified"); + is(aEvents[0].type, "page-visited"); + let uri = NetUtil.newURI(aEvents[0].url); + PlacesObservers.removeListener(["page-visited"], listener); + info("Received 'page-visited': " + uri.spec); + fieldForUrl(uri, "frecency", function(aFrecency) { + is(aFrecency, 0, "Frecency should be 0"); + fieldForUrl(uri, "hidden", function(aHidden) { + is(aHidden, 0, "Page should not be hidden"); + fieldForUrl(uri, "typed", function(aTyped) { + is(aTyped, 0, "page should not be marked as typed"); + resolve(); }); }); - }, - onVisits(aVisits) { - is(aVisits.length, 1, "Right number of visits notified"); - let { - uri, - visitId, - time, - referrerId, - transitionType, - } = aVisits[0]; - this.onVisit(uri, visitId, time, referrerId, transitionType); - }, - onBeginUpdateBatch() {}, - onEndUpdateBatch() {}, - onTitleChanged() {}, - onDeleteURI() {}, - onClearHistory() {}, - onPageChanged() {}, - onDeleteVisits() {}, - QueryInterface: ChromeUtils.generateQI([Ci.nsINavHistoryObserver]) - }; - PlacesUtils.history.addObserver(historyObserver); + }); + } + PlacesObservers.addListener(["page-visited"], listener); }); let newTabPromise = BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL); diff --git a/toolkit/components/places/tests/browser/browser_onvisit_title_null_for_navigation.js b/toolkit/components/places/tests/browser/browser_onvisit_title_null_for_navigation.js index ba03c8630aba..616d11cae4d3 100644 --- a/toolkit/components/places/tests/browser/browser_onvisit_title_null_for_navigation.js +++ b/toolkit/components/places/tests/browser/browser_onvisit_title_null_for_navigation.js @@ -3,19 +3,20 @@ const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/conte add_task(async function checkTitleNotificationForNavigation() { const EXPECTED_URL = Services.io.newURI(TEST_PATH + "empty_page.html"); let promiseTitleChanged = new Promise(resolve => { + function onVisits(aEvents) { + Assert.equal(aEvents.length, 1, "Right number of visits notified"); + Assert.equal(aEvents[0].type, "page-visited"); + let { + url, + lastKnownTitle, + } = aEvents[0]; + info("'page-visited': " + url); + if (url == EXPECTED_URL.spec) { + Assert.equal(lastKnownTitle, null, "Should not have a title"); + } + PlacesObservers.removeListener(["page-visited"], onVisits); + } let obs = { - onVisits(aVisits) { - Assert.equal(aVisits.length, 1, "Right number of visits notified"); - let { - uri, - lastKnownTitle, - } = aVisits[0]; - info("onVisits: " + uri.spec); - if (uri.equals(EXPECTED_URL)) { - Assert.equal(lastKnownTitle, null, "Should not have a title"); - } - }, - onTitleChanged(aURI, aTitle, aGuid) { if (aURI.equals(EXPECTED_URL)) { is(aTitle, "I am an empty page", "Should have correct title in titlechanged notification"); @@ -25,6 +26,7 @@ add_task(async function checkTitleNotificationForNavigation() { }, }; PlacesUtils.history.addObserver(obs); + PlacesObservers.addListener(["page-visited"], onVisits); }); let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, EXPECTED_URL.spec); await promiseTitleChanged; diff --git a/toolkit/components/places/tests/browser/browser_redirect.js b/toolkit/components/places/tests/browser/browser_redirect.js index 0bb8c39f83b2..623f579a2cdf 100644 --- a/toolkit/components/places/tests/browser/browser_redirect.js +++ b/toolkit/components/places/tests/browser/browser_redirect.js @@ -39,15 +39,15 @@ add_task(async function redirect_check_new_typed_visit() { redirectTargetFrecency += TYPED_VISIT_BONUS; let redirectNotified = false; - let visitedPromise = PlacesTestUtils.waitForNotification("onVisits", visits => { + let visitedPromise = PlacesTestUtils.waitForNotification("page-visited", visits => { is(visits.length, 1, "Was notified for the right number of visits."); - let {uri} = visits[0]; - info("Received onVisits for: " + uri.spec); - if (uri.equals(REDIRECT_URI)) { + let {url} = visits[0]; + info("Received 'page-visited': " + url); + if (url == REDIRECT_URI.spec) { redirectNotified = true; } - return uri.equals(TARGET_URI); - }, "history"); + return url == TARGET_URI.spec; + }, "places"); let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, REDIRECT_URI.spec); info("Waiting for onVisits"); @@ -68,15 +68,15 @@ add_task(async function redirect_check_second_typed_visit() { redirectTargetFrecency += TYPED_VISIT_BONUS; let redirectNotified = false; - let visitedPromise = PlacesTestUtils.waitForNotification("onVisits", visits => { + let visitedPromise = PlacesTestUtils.waitForNotification("page-visited", visits => { is(visits.length, 1, "Was notified for the right number of visits."); - let {uri} = visits[0]; - info("Received onVisits: " + uri.spec); - if (uri.equals(REDIRECT_URI)) { + let {url} = visits[0]; + info("Received 'page-visited': " + url); + if (url == REDIRECT_URI.spec) { redirectNotified = true; } - return uri.equals(TARGET_URI); - }, "history"); + return url == TARGET_URI.spec; + }, "places"); let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, REDIRECT_URI.spec); info("Waiting for onVisits"); @@ -95,15 +95,15 @@ add_task(async function redirect_check_subsequent_link_visit() { redirectTargetFrecency += LINK_VISIT_BONUS; let redirectNotified = false; - let visitedPromise = PlacesTestUtils.waitForNotification("onVisits", visits => { + let visitedPromise = PlacesTestUtils.waitForNotification("page-visited", visits => { is(visits.length, 1, "Was notified for the right number of visits."); - let {uri} = visits[0]; - info("Received onVisits: " + uri.spec); - if (uri.equals(REDIRECT_URI)) { + let {url} = visits[0]; + info("Received 'page-visited': " + url); + if (url == REDIRECT_URI.spec) { redirectNotified = true; } - return uri.equals(TARGET_URI); - }, "history"); + return url == TARGET_URI.spec; + }, "places"); let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, REDIRECT_URI.spec); info("Waiting for onVisits"); diff --git a/toolkit/components/places/tests/browser/browser_settitle.js b/toolkit/components/places/tests/browser/browser_settitle.js index e2f9c8efa348..17a1837ac8f7 100644 --- a/toolkit/components/places/tests/browser/browser_settitle.js +++ b/toolkit/components/places/tests/browser/browser_settitle.js @@ -25,7 +25,6 @@ add_task(async function() { data: [], onBeginUpdateBatch() {}, onEndUpdateBatch() {}, - onVisits() {}, onTitleChanged(aURI, aPageTitle, aGUID) { this.data.push({ uri: aURI, title: aPageTitle, guid: aGUID }); diff --git a/toolkit/components/places/tests/browser/browser_visited_notfound.js b/toolkit/components/places/tests/browser/browser_visited_notfound.js index 99e333b23164..59d28255a46e 100644 --- a/toolkit/components/places/tests/browser/browser_visited_notfound.js +++ b/toolkit/components/places/tests/browser/browser_visited_notfound.js @@ -20,16 +20,14 @@ add_task(async function test() { PlacesUtils.history.markPageAsTyped(NetUtil.newURI(TEST_URL)); let promiseVisit = new Promise(resolve => { - let historyObserver = { - __proto__: NavHistoryObserver.prototype, - onVisits(visits) { - PlacesUtils.history.removeObserver(historyObserver); - is(visits.length, 1, "Right number of visits"); - is(visits[0].uri.spec, TEST_URL, "Check visited url"); - resolve(); - } - }; - PlacesUtils.history.addObserver(historyObserver); + function onVisits(events) { + PlacesObservers.removeListener(["page-visited"], onVisits); + is(events.length, 1, "Right number of visits"); + is(events[0].type, "page-visited"); + is(events[0].url, TEST_URL, "Check visited url"); + resolve(); + } + PlacesObservers.addListener(["page-visited"], onVisits); }); gBrowser.selectedBrowser.loadURI(TEST_URL); await promiseVisit; diff --git a/toolkit/components/places/tests/browser/head.js b/toolkit/components/places/tests/browser/head.js index 12eabac2af0c..78e67f35fade 100644 --- a/toolkit/components/places/tests/browser/head.js +++ b/toolkit/components/places/tests/browser/head.js @@ -77,7 +77,6 @@ function NavHistoryObserver() {} NavHistoryObserver.prototype = { onBeginUpdateBatch() {}, onEndUpdateBatch() {}, - onVisits() {}, onTitleChanged() {}, onDeleteURI() {}, onClearHistory() {}, diff --git a/toolkit/components/places/tests/expiration/test_notifications_onDeleteURI.js b/toolkit/components/places/tests/expiration/test_notifications_onDeleteURI.js index a871d29c7344..53e428da4812 100644 --- a/toolkit/components/places/tests/expiration/test_notifications_onDeleteURI.js +++ b/toolkit/components/places/tests/expiration/test_notifications_onDeleteURI.js @@ -77,7 +77,6 @@ add_task(async function test_notifications_onDeleteURI() { onBeginUpdateBatch: function PEX_onBeginUpdateBatch() {}, onEndUpdateBatch: function PEX_onEndUpdateBatch() {}, onClearHistory() {}, - onVisits() {}, onTitleChanged() {}, onDeleteURI(aURI, aGUID, aReason) { currentTest.receivedNotifications++; diff --git a/toolkit/components/places/tests/expiration/test_notifications_onDeleteVisits.js b/toolkit/components/places/tests/expiration/test_notifications_onDeleteVisits.js index 932af76065e3..e77c16a006f8 100644 --- a/toolkit/components/places/tests/expiration/test_notifications_onDeleteVisits.js +++ b/toolkit/components/places/tests/expiration/test_notifications_onDeleteVisits.js @@ -102,7 +102,6 @@ add_task(async function test_notifications_onDeleteVisits() { onBeginUpdateBatch: function PEX_onBeginUpdateBatch() {}, onEndUpdateBatch: function PEX_onEndUpdateBatch() {}, onClearHistory() {}, - onVisits() {}, onTitleChanged() {}, onDeleteURI(aURI, aGUID, aReason) { // Check this uri was not bookmarked. diff --git a/toolkit/components/places/tests/head_common.js b/toolkit/components/places/tests/head_common.js index 811844266c3a..921cfcbd9986 100644 --- a/toolkit/components/places/tests/head_common.js +++ b/toolkit/components/places/tests/head_common.js @@ -734,7 +734,6 @@ function NavHistoryObserver() {} NavHistoryObserver.prototype = { onBeginUpdateBatch() {}, onEndUpdateBatch() {}, - onVisits() {}, onTitleChanged() {}, onDeleteURI() {}, onClearHistory() {}, diff --git a/toolkit/components/places/tests/history/test_async_history_api.js b/toolkit/components/places/tests/history/test_async_history_api.js index 5c2ea61f56df..34afa8c0067d 100644 --- a/toolkit/components/places/tests/history/test_async_history_api.js +++ b/toolkit/components/places/tests/history/test_async_history_api.js @@ -80,48 +80,47 @@ TitleChangedObserver.prototype = { /** * Listens for a visit notification, and calls aCallback when it gets it. - * - * @param aURI - * The URI of the page we expect a notification for. - * @param aCallback - * The method to call when we have gotten the proper notification about - * being visited. */ -function VisitObserver(aURI, - aGUID, - aCallback) { - this.uri = aURI; - this.guid = aGUID; - this.callback = aCallback; -} -VisitObserver.prototype = { - __proto__: NavHistoryObserver.prototype, - onVisits(aVisits) { - info("onVisits()!!!"); - Assert.equal(aVisits.length, 1, "Right number of visits notified"); +class VisitObserver { + constructor(aURI, + aGUID, + aCallback) { + this.uri = aURI; + this.guid = aGUID; + this.callback = aCallback; + this.handlePlacesEvent = this.handlePlacesEvent.bind(this); + PlacesObservers.addListener(["page-visited"], this.handlePlacesEvent); + } + + handlePlacesEvent(aEvents) { + info("'page-visited'!!!"); + Assert.equal(aEvents.length, 1, "Right number of visits notified"); + Assert.equal(aEvents[0].type, "page-visited"); let { - uri, + url, visitId, - time, - referrerId, + visitTime, + referringVisitId, transitionType, - guid, + pageGuid, hidden, visitCount, - typed, + typedCount, lastKnownTitle, - } = aVisits[0]; + } = aEvents[0]; let args = [ - visitId, time, referrerId, transitionType, guid, - hidden, visitCount, typed, lastKnownTitle, + visitId, visitTime, referringVisitId, transitionType, pageGuid, + hidden, visitCount, typedCount, lastKnownTitle, ]; - info("onVisit(" + uri.spec + args.join(", ") + ")"); - if (!this.uri.equals(uri) || this.guid != guid) { + info("'page-visited' (" + url + args.join(", ") + ")"); + if (this.uri.spec != url || this.guid != pageGuid) { return; } - this.callback(time, transitionType, lastKnownTitle); - }, -}; + this.callback(visitTime * 1000, transitionType, lastKnownTitle); + + PlacesObservers.removeListener(["page-visited"], this.handlePlacesEvent); + } +} /** * Tests that a title was set properly in the database. @@ -984,15 +983,15 @@ add_task(async function test_title_change_notifies() { }); let visitPromise = new Promise(resolve => { - PlacesUtils.history.addObserver({ - onVisits(visits) { - Assert.equal(visits.length, 1, "Should only get notified for one visit."); - let {uri} = visits[0]; - Assert.equal(uri.spec, place.uri.spec, "Should get notified for visiting the new URI."); - PlacesUtils.history.removeObserver(this); - resolve(); - } - }); + function onVisits(events) { + Assert.equal(events.length, 1, "Should only get notified for one visit."); + Assert.equal(events[0].type, "page-visited"); + let {url} = events[0]; + Assert.equal(url, place.uri.spec, "Should get notified for visiting the new URI."); + PlacesObservers.removeListener(["page-visited"], onVisits); + resolve(); + } + PlacesObservers.addListener(["page-visited"], onVisits); }); asyncHistory.updatePlaces(place); await visitPromise; @@ -1028,17 +1027,15 @@ add_task(async function test_visit_notifies() { resolve(); } }; - let visitObserver = new VisitObserver(place.uri, place.guid, + new VisitObserver(place.uri, place.guid, function(aVisitDate, aTransitionType) { let visit = place.visits[0]; Assert.equal(visit.visitDate, aVisitDate); Assert.equal(visit.transitionType, aTransitionType); - PlacesUtils.history.removeObserver(visitObserver); finisher(); }); - PlacesUtils.history.addObserver(visitObserver); let observer = function(aSubject, aTopic, aData) { info("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); Assert.ok(aSubject instanceof Ci.nsIURI); @@ -1269,16 +1266,14 @@ add_task(async function test_title_on_initial_visit() { guid: "mnopqrstuvwx", }; let visitPromise = new Promise(resolve => { - let visitObserver = new VisitObserver(place.uri, place.guid, - function(aVisitDate, - aTransitionType, - aLastKnownTitle) { + new VisitObserver(place.uri, place.guid, + function(aVisitDate, + aTransitionType, + aLastKnownTitle) { Assert.equal(place.title, aLastKnownTitle); - PlacesUtils.history.removeObserver(visitObserver); resolve(); }); - PlacesUtils.history.addObserver(visitObserver); }); await promiseUpdatePlaces(place); await visitPromise; @@ -1293,16 +1288,14 @@ add_task(async function test_title_on_initial_visit() { guid: "fghijklmnopq", }; visitPromise = new Promise(resolve => { - let visitObserver = new VisitObserver(place.uri, place.guid, - function(aVisitDate, - aTransitionType, - aLastKnownTitle) { + new VisitObserver(place.uri, place.guid, + function(aVisitDate, + aTransitionType, + aLastKnownTitle) { Assert.equal(place.title, aLastKnownTitle); - PlacesUtils.history.removeObserver(visitObserver); resolve(); }); - PlacesUtils.history.addObserver(visitObserver); }); await promiseUpdatePlaces(place); await visitPromise; @@ -1316,16 +1309,14 @@ add_task(async function test_title_on_initial_visit() { guid: "fghijklmnopq", }; visitPromise = new Promise(resolve => { - let visitObserver = new VisitObserver(place.uri, place.guid, - function(aVisitDate, - aTransitionType, - aLastKnownTitle) { + new VisitObserver(place.uri, place.guid, + function(aVisitDate, + aTransitionType, + aLastKnownTitle) { Assert.equal(null, aLastKnownTitle); - PlacesUtils.history.removeObserver(visitObserver); resolve(); }); - PlacesUtils.history.addObserver(visitObserver); }); await promiseUpdatePlaces(place); await visitPromise; diff --git a/toolkit/components/places/tests/history/test_remove.js b/toolkit/components/places/tests/history/test_remove.js index 7206885587ab..4ce278c03c21 100644 --- a/toolkit/components/places/tests/history/test_remove.js +++ b/toolkit/components/places/tests/history/test_remove.js @@ -44,9 +44,6 @@ add_task(async function test_remove_single() { observer = { onBeginUpdateBatch() {}, onEndUpdateBatch() {}, - onVisits(aVisits) { - reject(new Error("Unexpected call to onVisits " + aVisits.length)); - }, onTitleChanged(aUri) { reject(new Error("Unexpected call to onTitleChanged " + aUri.spec)); }, diff --git a/toolkit/components/places/tests/history/test_removeByFilter.js b/toolkit/components/places/tests/history/test_removeByFilter.js index 12548298151f..16c23e9ed265 100644 --- a/toolkit/components/places/tests/history/test_removeByFilter.js +++ b/toolkit/components/places/tests/history/test_removeByFilter.js @@ -292,9 +292,6 @@ function getObserverPromise(bookmarkedUri) { observer = { onBeginUpdateBatch() {}, onEndUpdateBatch() {}, - onVisits() { - reject(new Error("Unexpected call to onVisits")); - }, onTitleChanged(aUri) { reject(new Error("Unexpected call to onTitleChanged")); }, diff --git a/toolkit/components/places/tests/history/test_removeVisitsByFilter.js b/toolkit/components/places/tests/history/test_removeVisitsByFilter.js index 7bae4fe74886..1ba3958f05ad 100644 --- a/toolkit/components/places/tests/history/test_removeVisitsByFilter.js +++ b/toolkit/components/places/tests/history/test_removeVisitsByFilter.js @@ -134,9 +134,6 @@ add_task(async function test_removeVisitsByFilter() { deferred: PromiseUtils.defer(), onBeginUpdateBatch() {}, onEndUpdateBatch() {}, - onVisits(aVisits) { - this.deferred.reject(new Error("Unexpected call to onVisits " + aVisits.length)); - }, onTitleChanged(uri) { this.deferred.reject(new Error("Unexpected call to onTitleChanged " + uri.spec)); }, diff --git a/toolkit/components/places/tests/unit/test_454977.js b/toolkit/components/places/tests/unit/test_454977.js index d83af42751a3..5bf93524bd87 100644 --- a/toolkit/components/places/tests/unit/test_454977.js +++ b/toolkit/components/places/tests/unit/test_454977.js @@ -11,11 +11,11 @@ var visit_count = 0; async function task_add_visit(aURI, aVisitType) { // Wait for a visits notification and get the visitId. let visitId; - let visitsPromise = PlacesTestUtils.waitForNotification("onVisits", visits => { + let visitsPromise = PlacesTestUtils.waitForNotification("page-visited", visits => { visitId = visits[0].visitId; - let {uri} = visits[0]; - return uri.equals(aURI); - }, "history"); + let {url} = visits[0]; + return url == aURI.spec; + }, "places"); // Add visits. await PlacesTestUtils.addVisits([{ diff --git a/toolkit/components/places/tests/unit/test_download_history.js b/toolkit/components/places/tests/unit/test_download_history.js index 35576a790321..24b19664443d 100644 --- a/toolkit/components/places/tests/unit/test_download_history.js +++ b/toolkit/components/places/tests/unit/test_download_history.js @@ -20,29 +20,28 @@ const PRIVATE_URI = NetUtil.newURI("http://www.example.net/"); * Callback function to be called with the same arguments of onVisit. */ function waitForOnVisit(aCallback) { - let historyObserver = { - __proto__: NavHistoryObserver.prototype, - onVisits: function HO_onVisit(aVisits) { - Assert.equal(aVisits.length, 1, "Right number of visits notified"); - let { - uri, - visitId, - time, - referrerId, - transitionType, - guid, - hidden, - visitCount, - typed, - lastKnownTitle, - } = aVisits[0]; - PlacesUtils.history.removeObserver(this); - aCallback(uri, visitId, time, 0, referrerId, - transitionType, guid, hidden, visitCount, - typed, lastKnownTitle); - } - }; - PlacesUtils.history.addObserver(historyObserver); + function listener(aEvents) { + Assert.equal(aEvents.length, 1, "Right number of visits notified"); + Assert.equal(aEvents[0].type, "page-visited"); + let { + url, + visitId, + visitTime, + referringVisitId, + transitionType, + pageGuid, + hidden, + visitCount, + typedCount, + lastKnownTitle, + } = aEvents[0]; + PlacesObservers.removeListener(["page-visited"], listener); + let uriArg = NetUtil.newURI(url); + aCallback(uriArg, visitId, visitTime, 0, referringVisitId, + transitionType, pageGuid, hidden, visitCount, + typedCount, lastKnownTitle); + } + PlacesObservers.addListener(["page-visited"], listener); } /** @@ -157,11 +156,11 @@ add_task(async function test_dh_addBookmarkRemoveDownload() { add_task(async function test_dh_addDownload_referrer() { // Wait for visits notification and get the visit id. let visitId; - let referrerPromise = PlacesTestUtils.waitForNotification("onVisits", visits => { + let referrerPromise = PlacesTestUtils.waitForNotification("page-visited", visits => { visitId = visits[0].visitId; - let {uri} = visits[0]; - return uri.equals(REFERRER_URI); - }, "history"); + let {url} = visits[0]; + return url == REFERRER_URI.spec; + }, "places"); await PlacesTestUtils.addVisits([{ uri: REFERRER_URI, @@ -175,16 +174,17 @@ add_task(async function test_dh_addDownload_referrer() { // Wait for visits notification and get the referrer Id. let referrerId; - let downloadPromise = PlacesTestUtils.waitForNotification("onVisits", visits => { - referrerId = visits[0].referrerId; - let {uri} = visits[0]; - return uri.equals(DOWNLOAD_URI); - }, "history"); + let downloadPromise = PlacesTestUtils.waitForNotification("page-visited", visits => { + referrerId = visits[0].referringVisitId; + let {url} = visits[0]; + return url == DOWNLOAD_URI.spec; + }, "places"); gDownloadHistory.addDownload(DOWNLOAD_URI, REFERRER_URI, Date.now() * 1000); await downloadPromise; // Verify results for download uri. + // ensure that we receive the 'page-visited' notification before we call addDownload. Assert.ok(!!PlacesTestUtils.isPageInDB(DOWNLOAD_URI)); Assert.equal(visitId, referrerId); @@ -260,7 +260,6 @@ add_test(function test_dh_details() { let historyObserver = { onBeginUpdateBatch() {}, onEndUpdateBatch() {}, - onVisits() {}, onTitleChanged: function HO_onTitleChanged(aURI, aPageTitle) { if (aURI.equals(SOURCE_URI)) { titleSet = true; diff --git a/toolkit/components/places/tests/unit/test_history_observer.js b/toolkit/components/places/tests/unit/test_history_observer.js index c115717cee55..3f4e0d771f34 100644 --- a/toolkit/components/places/tests/unit/test_history_observer.js +++ b/toolkit/components/places/tests/unit/test_history_observer.js @@ -10,7 +10,6 @@ function NavHistoryObserver() { NavHistoryObserver.prototype = { onBeginUpdateBatch() { }, onEndUpdateBatch() { }, - onVisits() { }, onTitleChanged() { }, onDeleteURI() { }, onClearHistory() { }, @@ -36,6 +35,23 @@ function onNotify(callback) { }); } +/** + * Registers a one-time places observer for 'page-visited', + * which resolves a promise on being called. + */ +function promiseVisitAdded(callback) { + return new Promise(resolve => { + function listener(events) { + PlacesObservers.removeListener(["page-visited"], listener); + Assert.equal(events.length, 1, "Right number of visits notified"); + Assert.equal(events[0].type, "page-visited"); + callback(events[0]); + resolve(); + } + PlacesObservers.addListener(["page-visited"], listener); + }); +} + /** * Asynchronous task that adds a visit to the history database. */ @@ -50,19 +66,18 @@ async function task_add_visit(uri, timestamp, transition) { return [uri, timestamp]; } -add_task(async function test_onVisits() { - let promiseNotify = onNotify(function onVisits(aVisits) { - Assert.equal(aVisits.length, 1, "Right number of visits notified"); - let visit = aVisits[0]; - Assert.ok(visit.uri.equals(testuri)); +add_task(async function test_visitAdded() { + let promiseNotify = promiseVisitAdded(function(visit) { Assert.ok(visit.visitId > 0); - Assert.equal(visit.time, testtime); - Assert.equal(visit.referrerId, 0); + Assert.equal(visit.url, testuri.spec); + Assert.equal(visit.visitTime, testtime / 1000); + Assert.equal(visit.referringVisitId, 0); Assert.equal(visit.transitionType, TRANSITION_TYPED); - do_check_guid_for_uri(visit.uri, visit.guid); + let uri = NetUtil.newURI(visit.url); + do_check_guid_for_uri(uri, visit.pageGuid); Assert.ok(!visit.hidden); Assert.equal(visit.visitCount, 1); - Assert.equal(visit.typed, 1); + Assert.equal(visit.typedCount, 1); }); let testuri = NetUtil.newURI("http://firefox.com/"); let testtime = Date.now() * 1000; @@ -70,19 +85,18 @@ add_task(async function test_onVisits() { await promiseNotify; }); -add_task(async function test_onVisits() { - let promiseNotify = onNotify(function onVisits(aVisits) { - Assert.equal(aVisits.length, 1, "Right number of visits notified"); - let visit = aVisits[0]; - Assert.ok(visit.uri.equals(testuri)); +add_task(async function test_visitAdded() { + let promiseNotify = promiseVisitAdded(function(visit) { Assert.ok(visit.visitId > 0); - Assert.equal(visit.time, testtime); - Assert.equal(visit.referrerId, 0); + Assert.equal(visit.url, testuri.spec); + Assert.equal(visit.visitTime, testtime / 1000); + Assert.equal(visit.referringVisitId, 0); Assert.equal(visit.transitionType, TRANSITION_FRAMED_LINK); - do_check_guid_for_uri(visit.uri, visit.guid); + let uri = NetUtil.newURI(visit.url); + do_check_guid_for_uri(uri, visit.pageGuid); Assert.ok(visit.hidden); Assert.equal(visit.visitCount, 1); - Assert.equal(visit.typed, 0); + Assert.equal(visit.typedCount, 0); }); let testuri = NetUtil.newURI("http://hidden.firefox.com/"); let testtime = Date.now() * 1000; @@ -93,44 +107,43 @@ add_task(async function test_onVisits() { add_task(async function test_multiple_onVisit() { let testuri = NetUtil.newURI("http://self.firefox.com/"); let promiseNotifications = new Promise(resolve => { - let observer = { - __proto__: NavHistoryObserver.prototype, - onVisits(aVisits) { - Assert.equal(aVisits.length, 3, "Right number of visits notified"); - for (let i = 0; i < aVisits.length; i++) { - let visit = aVisits[i]; - Assert.ok(testuri.equals(visit.uri)); - Assert.ok(visit.visitId > 0); - Assert.ok(visit.time > 0); - Assert.ok(!visit.hidden); - do_check_guid_for_uri(visit.uri, visit.guid); - switch (i) { - case 0: - Assert.equal(visit.referrerId, 0); - Assert.equal(visit.transitionType, TRANSITION_LINK); - Assert.equal(visit.visitCount, 1); - Assert.equal(visit.typed, 0); - break; - case 1: - Assert.ok(visit.referrerId > 0); - Assert.equal(visit.transitionType, TRANSITION_LINK); - Assert.equal(visit.visitCount, 2); - Assert.equal(visit.typed, 0); - break; - case 2: - Assert.equal(visit.referrerId, 0); - Assert.equal(visit.transitionType, TRANSITION_TYPED); - Assert.equal(visit.visitCount, 3); - Assert.equal(visit.typed, 1); + function listener(aEvents) { + Assert.equal(aEvents.length, 3, "Right number of visits notified"); + for (let i = 0; i < aEvents.length; i++) { + Assert.equal(aEvents[i].type, "page-visited"); + let visit = aEvents[i]; + Assert.equal(testuri.spec, visit.url); + Assert.ok(visit.visitId > 0); + Assert.ok(visit.visitTime > 0); + Assert.ok(!visit.hidden); + let uri = NetUtil.newURI(visit.url); + do_check_guid_for_uri(uri, visit.pageGuid); + switch (i) { + case 0: + Assert.equal(visit.referringVisitId, 0); + Assert.equal(visit.transitionType, TRANSITION_LINK); + Assert.equal(visit.visitCount, 1); + Assert.equal(visit.typedCount, 0); + break; + case 1: + Assert.ok(visit.referringVisitId > 0); + Assert.equal(visit.transitionType, TRANSITION_LINK); + Assert.equal(visit.visitCount, 2); + Assert.equal(visit.typedCount, 0); + break; + case 2: + Assert.equal(visit.referringVisitId, 0); + Assert.equal(visit.transitionType, TRANSITION_TYPED); + Assert.equal(visit.visitCount, 3); + Assert.equal(visit.typedCount, 1); - PlacesUtils.history.removeObserver(observer, false); - resolve(); - break; - } + PlacesObservers.removeListener(["page-visited"], listener); + resolve(); + break; } - }, - }; - PlacesUtils.history.addObserver(observer); + } + } + PlacesObservers.addListener(["page-visited"], listener); }); await PlacesTestUtils.addVisits([ { uri: testuri, transition: TRANSITION_LINK }, diff --git a/toolkit/components/places/tests/unit/test_markpageas.js b/toolkit/components/places/tests/unit/test_markpageas.js index e0e633eef596..e31aeb977747 100644 --- a/toolkit/components/places/tests/unit/test_markpageas.js +++ b/toolkit/components/places/tests/unit/test_markpageas.js @@ -12,43 +12,24 @@ var gVisits = [{url: "http://www.mozilla.com/", transition: TRANSITION_LINK}]; add_task(async function test_execute() { - let observer; let completionPromise = new Promise(resolveCompletionPromise => { - observer = { - __proto__: NavHistoryObserver.prototype, - _visitCount: 0, - onVisit(aURI, aVisitID, aTime, aSessionID, aReferringID, - aTransitionType, aAdded) { - Assert.equal(aURI.spec, gVisits[this._visitCount].url); - Assert.equal(aTransitionType, gVisits[this._visitCount].transition); - this._visitCount++; + let visitCount = 0; + function listener(aEvents) { + Assert.equal(aEvents.length, 1, "Right number of visits notified"); + Assert.equal(aEvents[0].type, "page-visited"); + let event = aEvents[0]; + Assert.equal(event.url, gVisits[visitCount].url); + Assert.equal(event.transitionType, gVisits[visitCount].transition); + visitCount++; - if (this._visitCount == gVisits.length) { - resolveCompletionPromise(); - } - }, - onVisits(aVisits) { - Assert.equal(aVisits.length, 1, "Right number of visits notified"); - let { - uri, - visitId, - time, - referrerId, - transitionType, - guid, - hidden, - visitCount, - typed, - lastKnownTitle, - } = aVisits[0]; - this.onVisit(uri, visitId, time, 0, referrerId, - transitionType, guid, hidden, visitCount, - typed, lastKnownTitle); - }, - }; + if (visitCount == gVisits.length) { + resolveCompletionPromise(); + PlacesObservers.removeListener(["page-visited"], listener); + } + } + PlacesObservers.addListener(["page-visited"], listener); }); - PlacesUtils.history.addObserver(observer); for (var visit of gVisits) { if (visit.transition == TRANSITION_TYPED) @@ -67,5 +48,4 @@ add_task(async function test_execute() { await completionPromise; - PlacesUtils.history.removeObserver(observer); });