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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Tests functionality of the isURIVisited API.
     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 };
    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 ];
    37 let gRunner;
    38 function run_test()
    39 {
    40   do_test_pending();
    41   gRunner = step();
    42   gRunner.next();
    43 }
    45 function step()
    46 {
    47   let history = Cc["@mozilla.org/browser/history;1"]
    48                   .getService(Ci.mozIAsyncHistory);
    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);
    56       let uri = NetUtil.newURI(scheme + "mozilla.org/");
    58       history.isURIVisited(uri, function(aURI, aIsVisited) {
    59         do_check_true(uri.equals(aURI));
    60         do_check_false(aIsVisited);
    62         let callback = {
    63           handleError:  function () {},
    64           handleResult: function () {},
    65           handleCompletion: function () {
    66             do_log_info("Added visit to " + uri.spec);
    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);
    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         };
    84         history.updatePlaces({ uri:    uri
    85                              , visits: [ { transitionType: transition
    86                                          , visitDate:      Date.now() * 1000
    87                                          } ]
    88                              }, callback);
    89       });
    90       yield undefined;
    91     }
    92   }
    94   do_test_finished();
    95 }

mercurial