michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var gVisits = [{url: "http://www.mozilla.com/", michael@0: transition: TRANSITION_TYPED}, michael@0: {url: "http://www.google.com/", michael@0: transition: TRANSITION_BOOKMARK}, michael@0: {url: "http://www.espn.com/", michael@0: transition: TRANSITION_LINK}]; michael@0: michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_execute() michael@0: { michael@0: let observer; michael@0: let completionPromise = new Promise(resolveCompletionPromise => { michael@0: observer = { michael@0: __proto__: NavHistoryObserver.prototype, michael@0: _visitCount: 0, michael@0: onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID, michael@0: aTransitionType, aAdded) michael@0: { michael@0: do_check_eq(aURI.spec, gVisits[this._visitCount].url); michael@0: do_check_eq(aTransitionType, gVisits[this._visitCount].transition); michael@0: this._visitCount++; michael@0: michael@0: if (this._visitCount == gVisits.length) { michael@0: resolveCompletionPromise(); michael@0: } michael@0: }, michael@0: }; michael@0: }); michael@0: michael@0: PlacesUtils.history.addObserver(observer, false); michael@0: michael@0: for each (var visit in gVisits) { michael@0: if (visit.transition == TRANSITION_TYPED) michael@0: PlacesUtils.history.markPageAsTyped(uri(visit.url)); michael@0: else if (visit.transition == TRANSITION_BOOKMARK) michael@0: PlacesUtils.history.markPageAsFollowedBookmark(uri(visit.url)) michael@0: else { michael@0: // because it is a top level visit with no referrer, michael@0: // it will result in TRANSITION_LINK michael@0: } michael@0: yield promiseAddVisits({uri: uri(visit.url), michael@0: transition: visit.transition}); michael@0: } michael@0: michael@0: yield completionPromise; michael@0: michael@0: PlacesUtils.history.removeObserver(observer); michael@0: }); michael@0: