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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 function run_test()
michael@0 8 {
michael@0 9 run_next_test();
michael@0 10 }
michael@0 11
michael@0 12 add_task(function test_execute()
michael@0 13 {
michael@0 14 var referrer = uri("about:blank");
michael@0 15
michael@0 16 // add a http:// uri
michael@0 17 var uri1 = uri("http://mozilla.com");
michael@0 18 yield promiseAddVisits({uri: uri1, referrer: referrer});
michael@0 19 do_check_guid_for_uri(uri1);
michael@0 20 do_check_true(yield promiseIsURIVisited(uri1));
michael@0 21
michael@0 22 // add a https:// uri
michael@0 23 var uri2 = uri("https://etrade.com");
michael@0 24 yield promiseAddVisits({uri: uri2, referrer: referrer});
michael@0 25 do_check_guid_for_uri(uri2);
michael@0 26 do_check_true(yield promiseIsURIVisited(uri2));
michael@0 27
michael@0 28 // add a ftp:// uri
michael@0 29 var uri3 = uri("ftp://ftp.mozilla.org");
michael@0 30 yield promiseAddVisits({uri: uri3, referrer: referrer});
michael@0 31 do_check_guid_for_uri(uri3);
michael@0 32 do_check_true(yield promiseIsURIVisited(uri3));
michael@0 33
michael@0 34 // check if a nonexistent uri is visited
michael@0 35 var uri4 = uri("http://foobarcheese.com");
michael@0 36 do_check_false(yield promiseIsURIVisited(uri4));
michael@0 37
michael@0 38 // check that certain schemes never show up as visited
michael@0 39 // even if we attempt to add them to history
michael@0 40 // see CanAddURI() in nsNavHistory.cpp
michael@0 41 const URLS = [
michael@0 42 "about:config",
michael@0 43 "imap://cyrus.andrew.cmu.edu/archive.imap",
michael@0 44 "news://new.mozilla.org/mozilla.dev.apps.firefox",
michael@0 45 "mailbox:Inbox",
michael@0 46 "moz-anno:favicon:http://mozilla.org/made-up-favicon",
michael@0 47 "view-source:http://mozilla.org",
michael@0 48 "chrome://browser/content/browser.xul",
michael@0 49 "resource://gre-resources/hiddenWindow.html",
michael@0 50 "data:,Hello%2C%20World!",
michael@0 51 "wyciwyg:/0/http://mozilla.org",
michael@0 52 "javascript:alert('hello wolrd!');",
michael@0 53 ];
michael@0 54 for (let currentURL of URLS) {
michael@0 55 try {
michael@0 56 var cantAddUri = uri(currentURL);
michael@0 57 }
michael@0 58 catch(e) {
michael@0 59 // nsIIOService.newURI() can throw if e.g. our app knows about imap://
michael@0 60 // but the account is not set up and so the URL is invalid for us.
michael@0 61 // Note this in the log but ignore as it's not the subject of this test.
michael@0 62 do_log_info("Could not construct URI for '" + currentURL + "'; ignoring");
michael@0 63 }
michael@0 64 if (cantAddUri) {
michael@0 65 try {
michael@0 66 yield promiseAddVisits({uri: cantAddUri, referrer: referrer});
michael@0 67 do_throw("Should have generated an exception.");
michael@0 68 } catch(ex if ex && ex.result == Cr.NS_ERROR_ILLEGAL_VALUE) {
michael@0 69 }
michael@0 70 do_check_false(yield promiseIsURIVisited(cantAddUri));
michael@0 71 }
michael@0 72 }
michael@0 73 });
michael@0 74

mercurial