зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1340498 - Update onVisits tests to use 'page-visited' r=mak
MozReview-Commit-ID: FxC3gcUF9hl --HG-- extra : rebase_source : 126587e26e6625dee53a7e40d8a9d5bdf426978a
This commit is contained in:
Родитель
abe46fa52a
Коммит
c4f5b4ecdb
|
@ -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));
|
||||
},
|
||||
|
|
|
@ -55,7 +55,6 @@ function test() {
|
|||
var historyObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {},
|
||||
onVisits: function() {},
|
||||
onTitleChanged: function(aURI, aPageTitle) {},
|
||||
onDeleteURI: function(aURI) {},
|
||||
onClearHistory: function() {},
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -48,7 +48,6 @@ function test() {
|
|||
|
||||
onBeginUpdateBatch: function() { },
|
||||
onEndUpdateBatch: function() { },
|
||||
onVisits: function() { },
|
||||
onTitleChanged: function() { },
|
||||
onDeleteURI: function() { },
|
||||
onClearHistory: function() { },
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -23,7 +23,6 @@ add_task(async function() {
|
|||
|
||||
onBeginUpdateBatch() { },
|
||||
onEndUpdateBatch() { },
|
||||
onVisits() { },
|
||||
onDeleteURI() { },
|
||||
onClearHistory() { },
|
||||
onPageChanged() { },
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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 });
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -77,7 +77,6 @@ function NavHistoryObserver() {}
|
|||
NavHistoryObserver.prototype = {
|
||||
onBeginUpdateBatch() {},
|
||||
onEndUpdateBatch() {},
|
||||
onVisits() {},
|
||||
onTitleChanged() {},
|
||||
onDeleteURI() {},
|
||||
onClearHistory() {},
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -734,7 +734,6 @@ function NavHistoryObserver() {}
|
|||
NavHistoryObserver.prototype = {
|
||||
onBeginUpdateBatch() {},
|
||||
onEndUpdateBatch() {},
|
||||
onVisits() {},
|
||||
onTitleChanged() {},
|
||||
onDeleteURI() {},
|
||||
onClearHistory() {},
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
},
|
||||
|
|
|
@ -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"));
|
||||
},
|
||||
|
|
|
@ -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));
|
||||
},
|
||||
|
|
|
@ -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([{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче