toolkit/components/places/tests/unit/test_markpageas.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 var gVisits = [{url: "http://www.mozilla.com/",
michael@0 8 transition: TRANSITION_TYPED},
michael@0 9 {url: "http://www.google.com/",
michael@0 10 transition: TRANSITION_BOOKMARK},
michael@0 11 {url: "http://www.espn.com/",
michael@0 12 transition: TRANSITION_LINK}];
michael@0 13
michael@0 14 function run_test()
michael@0 15 {
michael@0 16 run_next_test();
michael@0 17 }
michael@0 18
michael@0 19 add_task(function test_execute()
michael@0 20 {
michael@0 21 let observer;
michael@0 22 let completionPromise = new Promise(resolveCompletionPromise => {
michael@0 23 observer = {
michael@0 24 __proto__: NavHistoryObserver.prototype,
michael@0 25 _visitCount: 0,
michael@0 26 onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID,
michael@0 27 aTransitionType, aAdded)
michael@0 28 {
michael@0 29 do_check_eq(aURI.spec, gVisits[this._visitCount].url);
michael@0 30 do_check_eq(aTransitionType, gVisits[this._visitCount].transition);
michael@0 31 this._visitCount++;
michael@0 32
michael@0 33 if (this._visitCount == gVisits.length) {
michael@0 34 resolveCompletionPromise();
michael@0 35 }
michael@0 36 },
michael@0 37 };
michael@0 38 });
michael@0 39
michael@0 40 PlacesUtils.history.addObserver(observer, false);
michael@0 41
michael@0 42 for each (var visit in gVisits) {
michael@0 43 if (visit.transition == TRANSITION_TYPED)
michael@0 44 PlacesUtils.history.markPageAsTyped(uri(visit.url));
michael@0 45 else if (visit.transition == TRANSITION_BOOKMARK)
michael@0 46 PlacesUtils.history.markPageAsFollowedBookmark(uri(visit.url))
michael@0 47 else {
michael@0 48 // because it is a top level visit with no referrer,
michael@0 49 // it will result in TRANSITION_LINK
michael@0 50 }
michael@0 51 yield promiseAddVisits({uri: uri(visit.url),
michael@0 52 transition: visit.transition});
michael@0 53 }
michael@0 54
michael@0 55 yield completionPromise;
michael@0 56
michael@0 57 PlacesUtils.history.removeObserver(observer);
michael@0 58 });
michael@0 59

mercurial