toolkit/components/places/tests/unit/test_isvisited.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.

     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/. */
     7 function run_test()
     8 {
     9   run_next_test();
    10 }
    12 add_task(function test_execute()
    13 {
    14   var referrer = uri("about:blank");
    16   // add a http:// uri 
    17   var uri1 = uri("http://mozilla.com");
    18   yield promiseAddVisits({uri: uri1, referrer: referrer});
    19   do_check_guid_for_uri(uri1);
    20   do_check_true(yield promiseIsURIVisited(uri1));
    22   // add a https:// uri
    23   var uri2 = uri("https://etrade.com");
    24   yield promiseAddVisits({uri: uri2, referrer: referrer});
    25   do_check_guid_for_uri(uri2);
    26   do_check_true(yield promiseIsURIVisited(uri2));
    28   // add a ftp:// uri
    29   var uri3 = uri("ftp://ftp.mozilla.org");
    30   yield promiseAddVisits({uri: uri3, referrer: referrer});
    31   do_check_guid_for_uri(uri3);
    32   do_check_true(yield promiseIsURIVisited(uri3));
    34   // check if a nonexistent uri is visited
    35   var uri4 = uri("http://foobarcheese.com");
    36   do_check_false(yield promiseIsURIVisited(uri4));
    38   // check that certain schemes never show up as visited
    39   // even if we attempt to add them to history
    40   // see CanAddURI() in nsNavHistory.cpp
    41   const URLS = [
    42     "about:config",
    43     "imap://cyrus.andrew.cmu.edu/archive.imap",
    44     "news://new.mozilla.org/mozilla.dev.apps.firefox",
    45     "mailbox:Inbox",
    46     "moz-anno:favicon:http://mozilla.org/made-up-favicon",
    47     "view-source:http://mozilla.org",
    48     "chrome://browser/content/browser.xul",
    49     "resource://gre-resources/hiddenWindow.html",
    50     "data:,Hello%2C%20World!",
    51     "wyciwyg:/0/http://mozilla.org",
    52     "javascript:alert('hello wolrd!');",
    53   ];
    54   for (let currentURL of URLS) {
    55     try {
    56       var cantAddUri = uri(currentURL);
    57     }
    58     catch(e) {
    59       // nsIIOService.newURI() can throw if e.g. our app knows about imap://
    60       // but the account is not set up and so the URL is invalid for us.
    61       // Note this in the log but ignore as it's not the subject of this test.
    62       do_log_info("Could not construct URI for '" + currentURL + "'; ignoring");
    63     }
    64     if (cantAddUri) {
    65       try {
    66         yield promiseAddVisits({uri: cantAddUri, referrer: referrer});
    67         do_throw("Should have generated an exception.");
    68       } catch(ex if ex && ex.result == Cr.NS_ERROR_ILLEGAL_VALUE) {
    69       }
    70       do_check_false(yield promiseIsURIVisited(cantAddUri));
    71     }
    72   }
    73 });

mercurial