summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/history/test_updatePlaces_embed.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/places/tests/history/test_updatePlaces_embed.js')
-rw-r--r--toolkit/components/places/tests/history/test_updatePlaces_embed.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/history/test_updatePlaces_embed.js b/toolkit/components/places/tests/history/test_updatePlaces_embed.js
new file mode 100644
index 0000000000..a2831f2f58
--- /dev/null
+++ b/toolkit/components/places/tests/history/test_updatePlaces_embed.js
@@ -0,0 +1,81 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests that updatePlaces properly handled callbacks for embed visits.
+
+"use strict";
+
+XPCOMUtils.defineLazyServiceGetter(
+ this,
+ "asyncHistory",
+ "@mozilla.org/browser/history;1",
+ "mozIAsyncHistory"
+);
+
+add_task(async function test_embed_visit() {
+ let place = {
+ uri: NetUtil.newURI("http://places.test/"),
+ visits: [
+ {
+ transitionType: PlacesUtils.history.TRANSITIONS.EMBED,
+ visitDate: PlacesUtils.toPRTime(new Date()),
+ },
+ ],
+ };
+ let errors = 0;
+ let results = 0;
+ let updated = await new Promise(resolve => {
+ asyncHistory.updatePlaces(place, {
+ ignoreErrors: true,
+ ignoreResults: true,
+ handleError(aResultCode, aPlace) {
+ errors++;
+ },
+ handleResult(aPlace) {
+ results++;
+ },
+ handleCompletion(resultCount) {
+ resolve(resultCount);
+ },
+ });
+ });
+ Assert.equal(errors, 0, "There should be no error callback");
+ Assert.equal(results, 0, "There should be no result callback");
+ Assert.equal(updated, 1, "The visit should have been added");
+});
+
+add_task(async function test_misc_visits() {
+ let place = {
+ uri: NetUtil.newURI("http://places.test/"),
+ visits: [
+ {
+ transitionType: PlacesUtils.history.TRANSITIONS.EMBED,
+ visitDate: PlacesUtils.toPRTime(new Date()),
+ },
+ {
+ transitionType: PlacesUtils.history.TRANSITIONS.LINK,
+ visitDate: PlacesUtils.toPRTime(new Date()),
+ },
+ ],
+ };
+ let errors = 0;
+ let results = 0;
+ let updated = await new Promise(resolve => {
+ asyncHistory.updatePlaces(place, {
+ ignoreErrors: true,
+ ignoreResults: true,
+ handleError(aResultCode, aPlace) {
+ errors++;
+ },
+ handleResult(aPlace) {
+ results++;
+ },
+ handleCompletion(resultCount) {
+ resolve(resultCount);
+ },
+ });
+ });
+ Assert.equal(errors, 0, "There should be no error callback");
+ Assert.equal(results, 0, "There should be no result callback");
+ Assert.equal(updated, 2, "The visit should have been added");
+});