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