1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_isvisited.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +function run_test() 1.11 +{ 1.12 + run_next_test(); 1.13 +} 1.14 + 1.15 +add_task(function test_execute() 1.16 +{ 1.17 + var referrer = uri("about:blank"); 1.18 + 1.19 + // add a http:// uri 1.20 + var uri1 = uri("http://mozilla.com"); 1.21 + yield promiseAddVisits({uri: uri1, referrer: referrer}); 1.22 + do_check_guid_for_uri(uri1); 1.23 + do_check_true(yield promiseIsURIVisited(uri1)); 1.24 + 1.25 + // add a https:// uri 1.26 + var uri2 = uri("https://etrade.com"); 1.27 + yield promiseAddVisits({uri: uri2, referrer: referrer}); 1.28 + do_check_guid_for_uri(uri2); 1.29 + do_check_true(yield promiseIsURIVisited(uri2)); 1.30 + 1.31 + // add a ftp:// uri 1.32 + var uri3 = uri("ftp://ftp.mozilla.org"); 1.33 + yield promiseAddVisits({uri: uri3, referrer: referrer}); 1.34 + do_check_guid_for_uri(uri3); 1.35 + do_check_true(yield promiseIsURIVisited(uri3)); 1.36 + 1.37 + // check if a nonexistent uri is visited 1.38 + var uri4 = uri("http://foobarcheese.com"); 1.39 + do_check_false(yield promiseIsURIVisited(uri4)); 1.40 + 1.41 + // check that certain schemes never show up as visited 1.42 + // even if we attempt to add them to history 1.43 + // see CanAddURI() in nsNavHistory.cpp 1.44 + const URLS = [ 1.45 + "about:config", 1.46 + "imap://cyrus.andrew.cmu.edu/archive.imap", 1.47 + "news://new.mozilla.org/mozilla.dev.apps.firefox", 1.48 + "mailbox:Inbox", 1.49 + "moz-anno:favicon:http://mozilla.org/made-up-favicon", 1.50 + "view-source:http://mozilla.org", 1.51 + "chrome://browser/content/browser.xul", 1.52 + "resource://gre-resources/hiddenWindow.html", 1.53 + "data:,Hello%2C%20World!", 1.54 + "wyciwyg:/0/http://mozilla.org", 1.55 + "javascript:alert('hello wolrd!');", 1.56 + ]; 1.57 + for (let currentURL of URLS) { 1.58 + try { 1.59 + var cantAddUri = uri(currentURL); 1.60 + } 1.61 + catch(e) { 1.62 + // nsIIOService.newURI() can throw if e.g. our app knows about imap:// 1.63 + // but the account is not set up and so the URL is invalid for us. 1.64 + // Note this in the log but ignore as it's not the subject of this test. 1.65 + do_log_info("Could not construct URI for '" + currentURL + "'; ignoring"); 1.66 + } 1.67 + if (cantAddUri) { 1.68 + try { 1.69 + yield promiseAddVisits({uri: cantAddUri, referrer: referrer}); 1.70 + do_throw("Should have generated an exception."); 1.71 + } catch(ex if ex && ex.result == Cr.NS_ERROR_ILLEGAL_VALUE) { 1.72 + } 1.73 + do_check_false(yield promiseIsURIVisited(cantAddUri)); 1.74 + } 1.75 + } 1.76 +}); 1.77 +