1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_isURIVisited.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Tests functionality of the isURIVisited API. 1.8 + 1.9 +const SCHEMES = { 1.10 + "http://": true, 1.11 + "https://": true, 1.12 + "ftp://": true, 1.13 + "file:///": true, 1.14 + "about:": false, 1.15 +// nsIIOService.newURI() can throw if e.g. the app knows about imap:// 1.16 +// but the account is not set up and so the URL is invalid for it. 1.17 +// "imap://": false, 1.18 + "news://": false, 1.19 + "mailbox:": false, 1.20 + "moz-anno:favicon:http://": false, 1.21 + "view-source:http://": false, 1.22 + "chrome://browser/content/browser.xul?": false, 1.23 + "resource://": false, 1.24 + "data:,": false, 1.25 + "wyciwyg:/0/http://": false, 1.26 + "javascript:": false, 1.27 +}; 1.28 + 1.29 +const TRANSITIONS = [ 1.30 + TRANSITION_LINK, 1.31 + TRANSITION_TYPED, 1.32 + TRANSITION_BOOKMARK, 1.33 + TRANSITION_EMBED, 1.34 + TRANSITION_FRAMED_LINK, 1.35 + TRANSITION_REDIRECT_PERMANENT, 1.36 + TRANSITION_REDIRECT_TEMPORARY, 1.37 + TRANSITION_DOWNLOAD, 1.38 +]; 1.39 + 1.40 +let gRunner; 1.41 +function run_test() 1.42 +{ 1.43 + do_test_pending(); 1.44 + gRunner = step(); 1.45 + gRunner.next(); 1.46 +} 1.47 + 1.48 +function step() 1.49 +{ 1.50 + let history = Cc["@mozilla.org/browser/history;1"] 1.51 + .getService(Ci.mozIAsyncHistory); 1.52 + 1.53 + for (let scheme in SCHEMES) { 1.54 + do_log_info("Testing scheme " + scheme); 1.55 + for (let i = 0; i < TRANSITIONS.length; i++) { 1.56 + let transition = TRANSITIONS[i]; 1.57 + do_log_info("With transition " + transition); 1.58 + 1.59 + let uri = NetUtil.newURI(scheme + "mozilla.org/"); 1.60 + 1.61 + history.isURIVisited(uri, function(aURI, aIsVisited) { 1.62 + do_check_true(uri.equals(aURI)); 1.63 + do_check_false(aIsVisited); 1.64 + 1.65 + let callback = { 1.66 + handleError: function () {}, 1.67 + handleResult: function () {}, 1.68 + handleCompletion: function () { 1.69 + do_log_info("Added visit to " + uri.spec); 1.70 + 1.71 + history.isURIVisited(uri, function (aURI, aIsVisited) { 1.72 + do_check_true(uri.equals(aURI)); 1.73 + let checker = SCHEMES[scheme] ? do_check_true : do_check_false; 1.74 + checker(aIsVisited); 1.75 + 1.76 + promiseClearHistory().then(function () { 1.77 + history.isURIVisited(uri, function(aURI, aIsVisited) { 1.78 + do_check_true(uri.equals(aURI)); 1.79 + do_check_false(aIsVisited); 1.80 + gRunner.next(); 1.81 + }); 1.82 + }); 1.83 + }); 1.84 + }, 1.85 + }; 1.86 + 1.87 + history.updatePlaces({ uri: uri 1.88 + , visits: [ { transitionType: transition 1.89 + , visitDate: Date.now() * 1000 1.90 + } ] 1.91 + }, callback); 1.92 + }); 1.93 + yield undefined; 1.94 + } 1.95 + } 1.96 + 1.97 + do_test_finished(); 1.98 +}