michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_execute() michael@0: { michael@0: var referrer = uri("about:blank"); michael@0: michael@0: // add a http:// uri michael@0: var uri1 = uri("http://mozilla.com"); michael@0: yield promiseAddVisits({uri: uri1, referrer: referrer}); michael@0: do_check_guid_for_uri(uri1); michael@0: do_check_true(yield promiseIsURIVisited(uri1)); michael@0: michael@0: // add a https:// uri michael@0: var uri2 = uri("https://etrade.com"); michael@0: yield promiseAddVisits({uri: uri2, referrer: referrer}); michael@0: do_check_guid_for_uri(uri2); michael@0: do_check_true(yield promiseIsURIVisited(uri2)); michael@0: michael@0: // add a ftp:// uri michael@0: var uri3 = uri("ftp://ftp.mozilla.org"); michael@0: yield promiseAddVisits({uri: uri3, referrer: referrer}); michael@0: do_check_guid_for_uri(uri3); michael@0: do_check_true(yield promiseIsURIVisited(uri3)); michael@0: michael@0: // check if a nonexistent uri is visited michael@0: var uri4 = uri("http://foobarcheese.com"); michael@0: do_check_false(yield promiseIsURIVisited(uri4)); michael@0: michael@0: // check that certain schemes never show up as visited michael@0: // even if we attempt to add them to history michael@0: // see CanAddURI() in nsNavHistory.cpp michael@0: const URLS = [ michael@0: "about:config", michael@0: "imap://cyrus.andrew.cmu.edu/archive.imap", michael@0: "news://new.mozilla.org/mozilla.dev.apps.firefox", michael@0: "mailbox:Inbox", michael@0: "moz-anno:favicon:http://mozilla.org/made-up-favicon", michael@0: "view-source:http://mozilla.org", michael@0: "chrome://browser/content/browser.xul", michael@0: "resource://gre-resources/hiddenWindow.html", michael@0: "data:,Hello%2C%20World!", michael@0: "wyciwyg:/0/http://mozilla.org", michael@0: "javascript:alert('hello wolrd!');", michael@0: ]; michael@0: for (let currentURL of URLS) { michael@0: try { michael@0: var cantAddUri = uri(currentURL); michael@0: } michael@0: catch(e) { michael@0: // nsIIOService.newURI() can throw if e.g. our app knows about imap:// michael@0: // but the account is not set up and so the URL is invalid for us. michael@0: // Note this in the log but ignore as it's not the subject of this test. michael@0: do_log_info("Could not construct URI for '" + currentURL + "'; ignoring"); michael@0: } michael@0: if (cantAddUri) { michael@0: try { michael@0: yield promiseAddVisits({uri: cantAddUri, referrer: referrer}); michael@0: do_throw("Should have generated an exception."); michael@0: } catch(ex if ex && ex.result == Cr.NS_ERROR_ILLEGAL_VALUE) { michael@0: } michael@0: do_check_false(yield promiseIsURIVisited(cantAddUri)); michael@0: } michael@0: } michael@0: }); michael@0: