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: const NS_DOWNLOADHISTORY_CID = "{2ee83680-2af0-4bcb-bfa0-c9705f6554f1}"; michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "Services", function() { michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: return Services; michael@0: }); michael@0: michael@0: function testLinkVistedObserver() michael@0: { michael@0: const NS_LINK_VISITED_EVENT_TOPIC = "link-visited"; michael@0: var ios = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: var testURI = ios.newURI("http://google.com/", null, null); michael@0: michael@0: var gh = Cc["@mozilla.org/browser/global-history;2"]. michael@0: getService(Ci.nsIGlobalHistory2); michael@0: do_check_false(gh.isVisited(testURI)); michael@0: michael@0: var topicReceived = false; michael@0: var obs = { michael@0: observe: function tlvo_observe(aSubject, aTopic, aData) michael@0: { michael@0: if (NS_LINK_VISITED_EVENT_TOPIC == aTopic) { michael@0: do_check_eq(testURI, aSubject); michael@0: topicReceived = true; michael@0: } michael@0: } michael@0: }; michael@0: michael@0: var os = Cc["@mozilla.org/observer-service;1"]. michael@0: getService(Ci.nsIObserverService); michael@0: os.addObserver(obs, NS_LINK_VISITED_EVENT_TOPIC, false); michael@0: michael@0: var dh = Components.classesByID[NS_DOWNLOADHISTORY_CID]. michael@0: getService(Ci.nsIDownloadHistory); michael@0: dh.addDownload(testURI); michael@0: do_check_true(topicReceived); michael@0: do_check_true(gh.isVisited(testURI)); michael@0: } michael@0: michael@0: var tests = [testLinkVistedObserver]; michael@0: michael@0: function run_test() michael@0: { michael@0: // Not everyone uses/defines an nsGlobalHistory* service. Especially if michael@0: // MOZ_PLACES is not defined. If getService fails, then abort gracefully. michael@0: try { michael@0: Cc["@mozilla.org/browser/global-history;2"]. michael@0: getService(Ci.nsIGlobalHistory2); michael@0: } michael@0: catch (ex) { michael@0: return; michael@0: } michael@0: michael@0: // Needed to properly setup and shutdown the profile. michael@0: do_get_profile(); michael@0: michael@0: for (var i = 0; i < tests.length; i++) michael@0: tests[i](); michael@0: michael@0: cleanup(); michael@0: }