Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const NS_DOWNLOADHISTORY_CID = "{2ee83680-2af0-4bcb-bfa0-c9705f6554f1}";
7 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
9 XPCOMUtils.defineLazyGetter(this, "Services", function() {
10 Components.utils.import("resource://gre/modules/Services.jsm");
11 return Services;
12 });
14 function testLinkVistedObserver()
15 {
16 const NS_LINK_VISITED_EVENT_TOPIC = "link-visited";
17 var ios = Cc["@mozilla.org/network/io-service;1"].
18 getService(Ci.nsIIOService);
19 var testURI = ios.newURI("http://google.com/", null, null);
21 var gh = Cc["@mozilla.org/browser/global-history;2"].
22 getService(Ci.nsIGlobalHistory2);
23 do_check_false(gh.isVisited(testURI));
25 var topicReceived = false;
26 var obs = {
27 observe: function tlvo_observe(aSubject, aTopic, aData)
28 {
29 if (NS_LINK_VISITED_EVENT_TOPIC == aTopic) {
30 do_check_eq(testURI, aSubject);
31 topicReceived = true;
32 }
33 }
34 };
36 var os = Cc["@mozilla.org/observer-service;1"].
37 getService(Ci.nsIObserverService);
38 os.addObserver(obs, NS_LINK_VISITED_EVENT_TOPIC, false);
40 var dh = Components.classesByID[NS_DOWNLOADHISTORY_CID].
41 getService(Ci.nsIDownloadHistory);
42 dh.addDownload(testURI);
43 do_check_true(topicReceived);
44 do_check_true(gh.isVisited(testURI));
45 }
47 var tests = [testLinkVistedObserver];
49 function run_test()
50 {
51 // Not everyone uses/defines an nsGlobalHistory* service. Especially if
52 // MOZ_PLACES is not defined. If getService fails, then abort gracefully.
53 try {
54 Cc["@mozilla.org/browser/global-history;2"].
55 getService(Ci.nsIGlobalHistory2);
56 }
57 catch (ex) {
58 return;
59 }
61 // Needed to properly setup and shutdown the profile.
62 do_get_profile();
64 for (var i = 0; i < tests.length; i++)
65 tests[i]();
67 cleanup();
68 }