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

mercurial