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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/unit/test_markpageas.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +var gVisits = [{url: "http://www.mozilla.com/",
    1.11 +                transition: TRANSITION_TYPED},
    1.12 +               {url: "http://www.google.com/",
    1.13 +                transition: TRANSITION_BOOKMARK},
    1.14 +               {url: "http://www.espn.com/",
    1.15 +                transition: TRANSITION_LINK}];
    1.16 +
    1.17 +function run_test()
    1.18 +{
    1.19 +  run_next_test();
    1.20 +}
    1.21 +
    1.22 +add_task(function test_execute()
    1.23 +{
    1.24 +  let observer;
    1.25 +  let completionPromise = new Promise(resolveCompletionPromise => {
    1.26 +    observer = {
    1.27 +      __proto__: NavHistoryObserver.prototype,
    1.28 +      _visitCount: 0,
    1.29 +      onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID,
    1.30 +                         aTransitionType, aAdded)
    1.31 +      {
    1.32 +        do_check_eq(aURI.spec, gVisits[this._visitCount].url);
    1.33 +        do_check_eq(aTransitionType, gVisits[this._visitCount].transition);
    1.34 +        this._visitCount++;
    1.35 +
    1.36 +        if (this._visitCount == gVisits.length) {
    1.37 +          resolveCompletionPromise();
    1.38 +        }
    1.39 +      },
    1.40 +    };
    1.41 +  });
    1.42 +
    1.43 +  PlacesUtils.history.addObserver(observer, false);
    1.44 +
    1.45 +  for each (var visit in gVisits) {
    1.46 +    if (visit.transition == TRANSITION_TYPED)
    1.47 +      PlacesUtils.history.markPageAsTyped(uri(visit.url));
    1.48 +    else if (visit.transition == TRANSITION_BOOKMARK)
    1.49 +      PlacesUtils.history.markPageAsFollowedBookmark(uri(visit.url))
    1.50 +    else {
    1.51 +     // because it is a top level visit with no referrer,
    1.52 +     // it will result in TRANSITION_LINK
    1.53 +    }
    1.54 +    yield promiseAddVisits({uri: uri(visit.url),
    1.55 +                            transition: visit.transition});
    1.56 +  }
    1.57 +
    1.58 +  yield completionPromise;
    1.59 +
    1.60 +  PlacesUtils.history.removeObserver(observer);
    1.61 +});
    1.62 +

mercurial