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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:1c7bb5803e61
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 // Tests functionality of the isURIVisited API.
5
6 const SCHEMES = {
7 "http://": true,
8 "https://": true,
9 "ftp://": true,
10 "file:///": true,
11 "about:": false,
12 // nsIIOService.newURI() can throw if e.g. the app knows about imap://
13 // but the account is not set up and so the URL is invalid for it.
14 // "imap://": false,
15 "news://": false,
16 "mailbox:": false,
17 "moz-anno:favicon:http://": false,
18 "view-source:http://": false,
19 "chrome://browser/content/browser.xul?": false,
20 "resource://": false,
21 "data:,": false,
22 "wyciwyg:/0/http://": false,
23 "javascript:": false,
24 };
25
26 const TRANSITIONS = [
27 TRANSITION_LINK,
28 TRANSITION_TYPED,
29 TRANSITION_BOOKMARK,
30 TRANSITION_EMBED,
31 TRANSITION_FRAMED_LINK,
32 TRANSITION_REDIRECT_PERMANENT,
33 TRANSITION_REDIRECT_TEMPORARY,
34 TRANSITION_DOWNLOAD,
35 ];
36
37 let gRunner;
38 function run_test()
39 {
40 do_test_pending();
41 gRunner = step();
42 gRunner.next();
43 }
44
45 function step()
46 {
47 let history = Cc["@mozilla.org/browser/history;1"]
48 .getService(Ci.mozIAsyncHistory);
49
50 for (let scheme in SCHEMES) {
51 do_log_info("Testing scheme " + scheme);
52 for (let i = 0; i < TRANSITIONS.length; i++) {
53 let transition = TRANSITIONS[i];
54 do_log_info("With transition " + transition);
55
56 let uri = NetUtil.newURI(scheme + "mozilla.org/");
57
58 history.isURIVisited(uri, function(aURI, aIsVisited) {
59 do_check_true(uri.equals(aURI));
60 do_check_false(aIsVisited);
61
62 let callback = {
63 handleError: function () {},
64 handleResult: function () {},
65 handleCompletion: function () {
66 do_log_info("Added visit to " + uri.spec);
67
68 history.isURIVisited(uri, function (aURI, aIsVisited) {
69 do_check_true(uri.equals(aURI));
70 let checker = SCHEMES[scheme] ? do_check_true : do_check_false;
71 checker(aIsVisited);
72
73 promiseClearHistory().then(function () {
74 history.isURIVisited(uri, function(aURI, aIsVisited) {
75 do_check_true(uri.equals(aURI));
76 do_check_false(aIsVisited);
77 gRunner.next();
78 });
79 });
80 });
81 },
82 };
83
84 history.updatePlaces({ uri: uri
85 , visits: [ { transitionType: transition
86 , visitDate: Date.now() * 1000
87 } ]
88 }, callback);
89 });
90 yield undefined;
91 }
92 }
93
94 do_test_finished();
95 }

mercurial