summaryrefslogtreecommitdiffstats
path: root/docshell/test/unit/test_nsIDownloadHistory.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /docshell/test/unit/test_nsIDownloadHistory.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'docshell/test/unit/test_nsIDownloadHistory.js')
-rw-r--r--docshell/test/unit/test_nsIDownloadHistory.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/docshell/test/unit/test_nsIDownloadHistory.js b/docshell/test/unit/test_nsIDownloadHistory.js
new file mode 100644
index 000000000..2030f0702
--- /dev/null
+++ b/docshell/test/unit/test_nsIDownloadHistory.js
@@ -0,0 +1,68 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const NS_DOWNLOADHISTORY_CID = "{2ee83680-2af0-4bcb-bfa0-c9705f6554f1}";
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyGetter(this, "Services", function() {
+ Components.utils.import("resource://gre/modules/Services.jsm");
+ return Services;
+});
+
+function testLinkVistedObserver()
+{
+ const NS_LINK_VISITED_EVENT_TOPIC = "link-visited";
+ var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+ var testURI = ios.newURI("http://google.com/", null, null);
+
+ var gh = Cc["@mozilla.org/browser/global-history;2"].
+ getService(Ci.nsIGlobalHistory2);
+ do_check_false(gh.isVisited(testURI));
+
+ var topicReceived = false;
+ var obs = {
+ observe: function tlvo_observe(aSubject, aTopic, aData)
+ {
+ if (NS_LINK_VISITED_EVENT_TOPIC == aTopic) {
+ do_check_eq(testURI, aSubject);
+ topicReceived = true;
+ }
+ }
+ };
+
+ var os = Cc["@mozilla.org/observer-service;1"].
+ getService(Ci.nsIObserverService);
+ os.addObserver(obs, NS_LINK_VISITED_EVENT_TOPIC, false);
+
+ var dh = Components.classesByID[NS_DOWNLOADHISTORY_CID].
+ getService(Ci.nsIDownloadHistory);
+ dh.addDownload(testURI);
+ do_check_true(topicReceived);
+ do_check_true(gh.isVisited(testURI));
+}
+
+var tests = [testLinkVistedObserver];
+
+function run_test()
+{
+ // Not everyone uses/defines an nsGlobalHistory* service. Especially if
+ // MOZ_PLACES is not defined. If getService fails, then abort gracefully.
+ try {
+ Cc["@mozilla.org/browser/global-history;2"].
+ getService(Ci.nsIGlobalHistory2);
+ }
+ catch (ex) {
+ return;
+ }
+
+ // Needed to properly setup and shutdown the profile.
+ do_get_profile();
+
+ for (var i = 0; i < tests.length; i++)
+ tests[i]();
+
+ cleanup();
+}