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

mercurial