summaryrefslogtreecommitdiffstats
path: root/docshell/test/unit
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
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')
-rw-r--r--docshell/test/unit/head_docshell.js11
-rw-r--r--docshell/test/unit/test_bug414201_jfif.js27
-rw-r--r--docshell/test/unit/test_bug442584.js30
-rw-r--r--docshell/test/unit/test_nsDefaultURIFixup.js93
-rw-r--r--docshell/test/unit/test_nsDefaultURIFixup_info.js620
-rw-r--r--docshell/test/unit/test_nsDefaultURIFixup_search.js117
-rw-r--r--docshell/test/unit/test_nsIDownloadHistory.js68
-rw-r--r--docshell/test/unit/test_pb_notification.js23
-rw-r--r--docshell/test/unit/test_privacy_transition.js23
-rw-r--r--docshell/test/unit/test_setUsePrivateBrowsing.js65
-rw-r--r--docshell/test/unit/xpcshell.ini17
11 files changed, 1094 insertions, 0 deletions
diff --git a/docshell/test/unit/head_docshell.js b/docshell/test/unit/head_docshell.js
new file mode 100644
index 000000000..a5c7546c0
--- /dev/null
+++ b/docshell/test/unit/head_docshell.js
@@ -0,0 +1,11 @@
+/* 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/. */
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cr = Components.results;
+
+var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
+ getService(Ci.nsIProperties);
+var profileDir = do_get_profile();
diff --git a/docshell/test/unit/test_bug414201_jfif.js b/docshell/test/unit/test_bug414201_jfif.js
new file mode 100644
index 000000000..6a689ec08
--- /dev/null
+++ b/docshell/test/unit/test_bug414201_jfif.js
@@ -0,0 +1,27 @@
+/* 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/. */
+
+/*
+ * Test for bug 414201
+ */
+
+function run_test()
+{
+ var ms = Components.classes["@mozilla.org/mime;1"].getService(Components.interfaces.nsIMIMEService);
+
+ /* Test a few common image types to make sure that they get the right extension */
+ var types = {
+ "image/jpeg": ["jpg", "jpeg"], /* accept either */
+ "image/gif": ["gif"],
+ "image/png": ["png"]
+ };
+
+ /* Check whether the primary extension is what we'd expect */
+ for (var mimetype in types) {
+ var exts = types[mimetype];
+ var primary = ms.getFromTypeAndExtension(mimetype, null).primaryExtension.toLowerCase();
+
+ do_check_true (exts.indexOf(primary) != -1);
+ }
+}
diff --git a/docshell/test/unit/test_bug442584.js b/docshell/test/unit/test_bug442584.js
new file mode 100644
index 000000000..174bdb7e3
--- /dev/null
+++ b/docshell/test/unit/test_bug442584.js
@@ -0,0 +1,30 @@
+var prefetch = Cc["@mozilla.org/prefetch-service;1"].
+ getService(Ci.nsIPrefetchService);
+var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+var prefs = Cc["@mozilla.org/preferences-service;1"].
+ getService(Ci.nsIPrefBranch);
+
+function run_test() {
+ // Fill up the queue
+ prefs.setBoolPref("network.prefetch-next", true);
+ for (var i = 0; i < 5; i++) {
+ var uri = ios.newURI("http://localhost/" + i, null, null);
+ prefetch.prefetchURI(uri, uri, null, true);
+ }
+
+ // Make sure the queue has items in it...
+ do_check_true(prefetch.hasMoreElements());
+
+ // Now disable the pref to force the queue to empty...
+ prefs.setBoolPref("network.prefetch-next", false);
+ do_check_false(prefetch.hasMoreElements());
+
+ // Now reenable the pref, and add more items to the queue.
+ prefs.setBoolPref("network.prefetch-next", true);
+ for (var i = 0; i < 5; i++) {
+ var uri = ios.newURI("http://localhost/" + i, null, null);
+ prefetch.prefetchURI(uri, uri, null, true);
+ }
+ do_check_true(prefetch.hasMoreElements());
+}
diff --git a/docshell/test/unit/test_nsDefaultURIFixup.js b/docshell/test/unit/test_nsDefaultURIFixup.js
new file mode 100644
index 000000000..371bdea17
--- /dev/null
+++ b/docshell/test/unit/test_nsDefaultURIFixup.js
@@ -0,0 +1,93 @@
+var urifixup = Cc["@mozilla.org/docshell/urifixup;1"].
+ getService(Ci.nsIURIFixup);
+var prefs = Cc["@mozilla.org/preferences-service;1"].
+ getService(Ci.nsIPrefBranch);
+
+var pref = "browser.fixup.typo.scheme";
+
+var data = [
+ {
+ // ttp -> http.
+ wrong: 'ttp://www.example.com/',
+ fixed: 'http://www.example.com/',
+ },
+ {
+ // ttps -> https.
+ wrong: 'ttps://www.example.com/',
+ fixed: 'https://www.example.com/',
+ },
+ {
+ // tps -> https.
+ wrong: 'tps://www.example.com/',
+ fixed: 'https://www.example.com/',
+ },
+ {
+ // ps -> https.
+ wrong: 'ps://www.example.com/',
+ fixed: 'https://www.example.com/',
+ },
+ {
+ // ile -> file.
+ wrong: 'ile:///this/is/a/test.html',
+ fixed: 'file:///this/is/a/test.html',
+ },
+ {
+ // le -> file.
+ wrong: 'le:///this/is/a/test.html',
+ fixed: 'file:///this/is/a/test.html',
+ },
+ {
+ // Valid should not be changed.
+ wrong: 'https://example.com/this/is/a/test.html',
+ fixed: 'https://example.com/this/is/a/test.html',
+ },
+ {
+ // Unmatched should not be changed.
+ wrong: 'whatever://this/is/a/test.html',
+ fixed: 'whatever://this/is/a/test.html',
+ },
+];
+
+var len = data.length;
+
+function run_test() {
+ run_next_test();
+}
+
+// Make sure we fix what needs fixing when there is no pref set.
+add_task(function test_unset_pref_fixes_typos() {
+ prefs.clearUserPref(pref);
+ for (let i = 0; i < len; ++i) {
+ let item = data[i];
+ let result =
+ urifixup.createFixupURI(item.wrong,
+ urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec;
+ do_check_eq(result, item.fixed);
+ }
+});
+
+// Make sure we don't do anything when the pref is explicitly
+// set to false.
+add_task(function test_false_pref_keeps_typos() {
+ prefs.setBoolPref(pref, false);
+ for (let i = 0; i < len; ++i) {
+ let item = data[i];
+ let result =
+ urifixup.createFixupURI(item.wrong,
+ urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec;
+ do_check_eq(result, item.wrong);
+ }
+});
+
+// Finally, make sure we still fix what needs fixing if the pref is
+// explicitly set to true.
+add_task(function test_true_pref_fixes_typos() {
+ prefs.setBoolPref(pref, true);
+ for (let i = 0; i < len; ++i) {
+ let item = data[i];
+ let result =
+ urifixup.createFixupURI(item.wrong,
+ urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec;
+ do_check_eq(result, item.fixed);
+ }
+});
diff --git a/docshell/test/unit/test_nsDefaultURIFixup_info.js b/docshell/test/unit/test_nsDefaultURIFixup_info.js
new file mode 100644
index 000000000..9e33ea484
--- /dev/null
+++ b/docshell/test/unit/test_nsDefaultURIFixup_info.js
@@ -0,0 +1,620 @@
+var urifixup = Cc["@mozilla.org/docshell/urifixup;1"].
+ getService(Ci.nsIURIFixup);
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+var prefList = ["browser.fixup.typo.scheme", "keyword.enabled",
+ "browser.fixup.domainwhitelist.whitelisted"];
+for (let pref of prefList) {
+ Services.prefs.setBoolPref(pref, true);
+}
+
+const kSearchEngineID = "test_urifixup_search_engine";
+const kSearchEngineURL = "http://www.example.org/?search={searchTerms}";
+Services.search.addEngineWithDetails(kSearchEngineID, "", "", "", "get",
+ kSearchEngineURL);
+
+var oldDefaultEngine = Services.search.defaultEngine;
+Services.search.defaultEngine = Services.search.getEngineByName(kSearchEngineID);
+
+var selectedName = Services.search.defaultEngine.name;
+do_check_eq(selectedName, kSearchEngineID);
+
+const kForceHostLookup = "browser.fixup.dns_first_for_single_words";
+do_register_cleanup(function() {
+ if (oldDefaultEngine) {
+ Services.search.defaultEngine = oldDefaultEngine;
+ }
+ let engine = Services.search.getEngineByName(kSearchEngineID);
+ if (engine) {
+ Services.search.removeEngine(engine);
+ }
+ Services.prefs.clearUserPref("keyword.enabled");
+ Services.prefs.clearUserPref("browser.fixup.typo.scheme");
+ Services.prefs.clearUserPref(kForceHostLookup);
+});
+
+var flagInputs = [
+ urifixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP,
+ urifixup.FIXUP_FLAGS_MAKE_ALTERNATE_URI,
+ urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS,
+];
+
+flagInputs.concat([
+ flagInputs[0] | flagInputs[1],
+ flagInputs[1] | flagInputs[2],
+ flagInputs[0] | flagInputs[2],
+ flagInputs[0] | flagInputs[1] | flagInputs[2]
+]);
+
+/*
+ The following properties are supported for these test cases:
+ {
+ input: "", // Input string, required
+ fixedURI: "", // Expected fixedURI
+ alternateURI: "", // Expected alternateURI
+ keywordLookup: false, // Whether a keyword lookup is expected
+ protocolChange: false, // Whether a protocol change is expected
+ inWhitelist: false, // Whether the input host is in the whitelist
+ affectedByDNSForSingleHosts: false, // Whether the input host could be a host, but is normally assumed to be a keyword query
+ }
+*/
+var testcases = [ {
+ input: "http://www.mozilla.org",
+ fixedURI: "http://www.mozilla.org/",
+ }, {
+ input: "http://127.0.0.1/",
+ fixedURI: "http://127.0.0.1/",
+ }, {
+ input: "file:///foo/bar",
+ fixedURI: "file:///foo/bar",
+ }, {
+ input: "://www.mozilla.org",
+ fixedURI: "http://www.mozilla.org/",
+ protocolChange: true,
+ }, {
+ input: "www.mozilla.org",
+ fixedURI: "http://www.mozilla.org/",
+ protocolChange: true,
+ }, {
+ input: "http://mozilla/",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ }, {
+ input: "http://test./",
+ fixedURI: "http://test./",
+ alternateURI: "http://www.test./",
+ }, {
+ input: "127.0.0.1",
+ fixedURI: "http://127.0.0.1/",
+ protocolChange: true,
+ }, {
+ input: "1.2.3.4/",
+ fixedURI: "http://1.2.3.4/",
+ protocolChange: true,
+ }, {
+ input: "1.2.3.4/foo",
+ fixedURI: "http://1.2.3.4/foo",
+ protocolChange: true,
+ }, {
+ input: "1.2.3.4:8000",
+ fixedURI: "http://1.2.3.4:8000/",
+ protocolChange: true,
+ }, {
+ input: "1.2.3.4:8000/",
+ fixedURI: "http://1.2.3.4:8000/",
+ protocolChange: true,
+ }, {
+ input: "1.2.3.4:8000/foo",
+ fixedURI: "http://1.2.3.4:8000/foo",
+ protocolChange: true,
+ }, {
+ input: "192.168.10.110",
+ fixedURI: "http://192.168.10.110/",
+ protocolChange: true,
+ }, {
+ input: "192.168.10.110/123",
+ fixedURI: "http://192.168.10.110/123",
+ protocolChange: true,
+ }, {
+ input: "192.168.10.110/123foo",
+ fixedURI: "http://192.168.10.110/123foo",
+ protocolChange: true,
+ }, {
+ input: "192.168.10.110:1234/123",
+ fixedURI: "http://192.168.10.110:1234/123",
+ protocolChange: true,
+ }, {
+ input: "192.168.10.110:1234/123foo",
+ fixedURI: "http://192.168.10.110:1234/123foo",
+ protocolChange: true,
+ }, {
+ input: "1.2.3",
+ fixedURI: "http://1.2.0.3/",
+ protocolChange: true,
+ }, {
+ input: "1.2.3/",
+ fixedURI: "http://1.2.0.3/",
+ protocolChange: true,
+ }, {
+ input: "1.2.3/foo",
+ fixedURI: "http://1.2.0.3/foo",
+ protocolChange: true,
+ }, {
+ input: "1.2.3/123",
+ fixedURI: "http://1.2.0.3/123",
+ protocolChange: true,
+ }, {
+ input: "1.2.3:8000",
+ fixedURI: "http://1.2.0.3:8000/",
+ protocolChange: true,
+ }, {
+ input: "1.2.3:8000/",
+ fixedURI: "http://1.2.0.3:8000/",
+ protocolChange: true,
+ }, {
+ input: "1.2.3:8000/foo",
+ fixedURI: "http://1.2.0.3:8000/foo",
+ protocolChange: true,
+ }, {
+ input: "1.2.3:8000/123",
+ fixedURI: "http://1.2.0.3:8000/123",
+ protocolChange: true,
+ }, {
+ input: "http://1.2.3",
+ fixedURI: "http://1.2.0.3/",
+ }, {
+ input: "http://1.2.3/",
+ fixedURI: "http://1.2.0.3/",
+ }, {
+ input: "http://1.2.3/foo",
+ fixedURI: "http://1.2.0.3/foo",
+ }, {
+ input: "[::1]",
+ fixedURI: "http://[::1]/",
+ alternateURI: "http://[::1]/",
+ protocolChange: true,
+ }, {
+ input: "[::1]/",
+ fixedURI: "http://[::1]/",
+ alternateURI: "http://[::1]/",
+ protocolChange: true,
+ }, {
+ input: "[::1]:8000",
+ fixedURI: "http://[::1]:8000/",
+ alternateURI: "http://[::1]:8000/",
+ protocolChange: true,
+ }, {
+ input: "[::1]:8000/",
+ fixedURI: "http://[::1]:8000/",
+ alternateURI: "http://[::1]:8000/",
+ protocolChange: true,
+ }, {
+ input: "[[::1]]/",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "[fe80:cd00:0:cde:1257:0:211e:729c]",
+ fixedURI: "http://[fe80:cd00:0:cde:1257:0:211e:729c]/",
+ alternateURI: "http://[fe80:cd00:0:cde:1257:0:211e:729c]/",
+ protocolChange: true,
+ }, {
+ input: "[64:ff9b::8.8.8.8]",
+ fixedURI: "http://[64:ff9b::8.8.8.8]/",
+ protocolChange: true
+ }, {
+ input: "[64:ff9b::8.8.8.8]/~moz",
+ fixedURI: "http://[64:ff9b::8.8.8.8]/~moz",
+ protocolChange: true
+ }, {
+ input: "[::1][::1]",
+ keywordLookup: true,
+ protocolChange: true
+ }, {
+ input: "[::1][100",
+ fixedURI: null,
+ alternateURI: null,
+ keywordLookup: true,
+ protocolChange: true
+ }, {
+ input: "[::1]]",
+ keywordLookup: true,
+ protocolChange: true
+ }, {
+ input: "1234",
+ fixedURI: "http://0.0.4.210/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "host/foo.txt",
+ fixedURI: "http://host/foo.txt",
+ alternateURI: "http://www.host.com/foo.txt",
+ protocolChange: true,
+ }, {
+ input: "mozilla",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "test.",
+ fixedURI: "http://test./",
+ alternateURI: "http://www.test./",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: ".test",
+ fixedURI: "http://.test/",
+ alternateURI: "http://www..test/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "mozilla is amazing",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "search ?mozilla",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "mozilla .com",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "what if firefox?",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "london's map",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "mozilla ",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: " mozilla ",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "mozilla \\",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "mozilla \\ foo.txt",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "mozilla \\\r foo.txt",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "mozilla\n",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "mozilla \r\n",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "moz\r\nfirefox\nos\r",
+ fixedURI: "http://mozfirefoxos/",
+ alternateURI: "http://www.mozfirefoxos.com/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "moz\r\n firefox\n",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "[]",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "http://whitelisted/",
+ fixedURI: "http://whitelisted/",
+ alternateURI: "http://www.whitelisted.com/",
+ inWhitelist: true,
+ }, {
+ input: "café.local",
+ fixedURI: "http://café.local/",
+ alternateURI: "http://www.café.local/",
+ protocolChange: true
+ }, {
+ input: "47.6182,-122.830",
+ fixedURI: "http://47.6182,-122.830/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "-47.6182,-23.51",
+ fixedURI: "http://-47.6182,-23.51/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "-22.14,23.51-",
+ fixedURI: "http://-22.14,23.51-/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "32.7",
+ fixedURI: "http://32.0.0.7/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "5+2",
+ fixedURI: "http://5+2/",
+ alternateURI: "http://www.5+2.com/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "5/2",
+ fixedURI: "http://0.0.0.5/2",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "moz ?.::%27",
+ keywordLookup: true,
+ protocolChange: true
+ }, {
+ input: "mozilla.com/?q=search",
+ fixedURI: "http://mozilla.com/?q=search",
+ alternateURI: "http://www.mozilla.com/?q=search",
+ protocolChange: true
+ }, {
+ input: "mozilla.com?q=search",
+ fixedURI: "http://mozilla.com/?q=search",
+ alternateURI: "http://www.mozilla.com/?q=search",
+ protocolChange: true
+ }, {
+ input: "mozilla.com ?q=search",
+ keywordLookup: true,
+ protocolChange: true
+ }, {
+ input: "mozilla.com.?q=search",
+ fixedURI: "http://mozilla.com./?q=search",
+ protocolChange: true
+ }, {
+ input: "mozilla.com'?q=search",
+ fixedURI: "http://mozilla.com'/?q=search",
+ alternateURI: "http://www.mozilla.com'/?q=search",
+ protocolChange: true
+ }, {
+ input: "mozilla.com':search",
+ keywordLookup: true,
+ protocolChange: true
+ }, {
+ input: "[mozilla]",
+ keywordLookup: true,
+ protocolChange: true
+ }, {
+ input: "':?",
+ fixedURI: "http://'/?",
+ alternateURI: "http://www.'.com/?",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "a?.com",
+ fixedURI: "http://a/?.com",
+ alternateURI: "http://www.a.com/?.com",
+ protocolChange: true,
+ }, {
+ input: "?'.com",
+ fixedURI: "http:///?%27.com",
+ alternateURI: "http://www..com/?%27.com",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "' ?.com",
+ keywordLookup: true,
+ protocolChange: true
+ }, {
+ input: "?mozilla",
+ fixedURI: "http:///?mozilla",
+ alternateURI: "http://www..com/?mozilla",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "??mozilla",
+ fixedURI: "http:///??mozilla",
+ alternateURI: "http://www..com/??mozilla",
+ keywordLookup: true,
+ protocolChange: true,
+ }, {
+ input: "mozilla/",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ protocolChange: true,
+ }, {
+ input: "mozilla",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ protocolChange: true,
+ keywordLookup: true,
+ affectedByDNSForSingleHosts: true,
+ }, {
+ input: "mozilla5/2",
+ fixedURI: "http://mozilla5/2",
+ alternateURI: "http://www.mozilla5.com/2",
+ protocolChange: true,
+ }, {
+ input: "mozilla/foo",
+ fixedURI: "http://mozilla/foo",
+ alternateURI: "http://www.mozilla.com/foo",
+ protocolChange: true,
+ }, {
+ input: "mozilla\\",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ keywordLookup: true,
+ protocolChange: true,
+ affectedByDNSForSingleHosts: true,
+ }];
+
+if (Services.appinfo.OS.toLowerCase().startsWith("win")) {
+ testcases.push({
+ input: "C:\\some\\file.txt",
+ fixedURI: "file:///C:/some/file.txt",
+ protocolChange: true,
+ });
+ testcases.push({
+ input: "//mozilla",
+ fixedURI: "http://mozilla/",
+ alternateURI: "http://www.mozilla.com/",
+ protocolChange: true,
+ });
+} else {
+ testcases.push({
+ input: "/some/file.txt",
+ fixedURI: "file:///some/file.txt",
+ protocolChange: true,
+ });
+ testcases.push({
+ input: "//mozilla",
+ fixedURI: "file:////mozilla",
+ protocolChange: true,
+ });
+}
+
+function sanitize(input) {
+ return input.replace(/\r|\n/g, "").trim();
+}
+
+
+var gSingleWordHostLookup = false;
+function run_test() {
+ // Only keywordlookup things should be affected by requiring a DNS lookup for single-word hosts:
+ do_print("Check only keyword lookup testcases should be affected by requiring DNS for single hosts");
+ let affectedTests = testcases.filter(t => !t.keywordLookup && t.affectedByDNSForSingleHosts);
+ if (affectedTests.length) {
+ for (let testcase of affectedTests) {
+ do_print("Affected: " + testcase.input);
+ }
+ }
+ do_check_eq(affectedTests.length, 0);
+ do_single_test_run();
+ gSingleWordHostLookup = true;
+ do_single_test_run();
+}
+
+function do_single_test_run() {
+ Services.prefs.setBoolPref(kForceHostLookup, gSingleWordHostLookup);
+
+ let relevantTests = gSingleWordHostLookup ? testcases.filter(t => t.keywordLookup) :
+ testcases;
+
+ for (let { input: testInput,
+ fixedURI: expectedFixedURI,
+ alternateURI: alternativeURI,
+ keywordLookup: expectKeywordLookup,
+ protocolChange: expectProtocolChange,
+ inWhitelist: inWhitelist,
+ affectedByDNSForSingleHosts: affectedByDNSForSingleHosts,
+ } of relevantTests) {
+
+ // Explicitly force these into a boolean
+ expectKeywordLookup = !!expectKeywordLookup;
+ expectProtocolChange = !!expectProtocolChange;
+ inWhitelist = !!inWhitelist;
+ affectedByDNSForSingleHosts = !!affectedByDNSForSingleHosts;
+
+ expectKeywordLookup = expectKeywordLookup && (!affectedByDNSForSingleHosts || !gSingleWordHostLookup);
+
+ for (let flags of flagInputs) {
+ let info;
+ let fixupURIOnly = null;
+ try {
+ fixupURIOnly = urifixup.createFixupURI(testInput, flags);
+ } catch (ex) {
+ do_print("Caught exception: " + ex);
+ do_check_eq(expectedFixedURI, null);
+ }
+
+ try {
+ info = urifixup.getFixupURIInfo(testInput, flags);
+ } catch (ex) {
+ // Both APIs should return an error in the same cases.
+ do_print("Caught exception: " + ex);
+ do_check_eq(expectedFixedURI, null);
+ do_check_eq(fixupURIOnly, null);
+ continue;
+ }
+
+ do_print("Checking \"" + testInput + "\" with flags " + flags +
+ " (host lookup for single words: " + (gSingleWordHostLookup ? "yes" : "no") + ")");
+
+ // Both APIs should then also be using the same spec.
+ do_check_eq(!!fixupURIOnly, !!info.preferredURI);
+ if (fixupURIOnly)
+ do_check_eq(fixupURIOnly.spec, info.preferredURI.spec);
+
+ let isFileURL = expectedFixedURI && expectedFixedURI.startsWith("file");
+
+ // Check the fixedURI:
+ let makeAlternativeURI = flags & urifixup.FIXUP_FLAGS_MAKE_ALTERNATE_URI;
+ if (makeAlternativeURI && alternativeURI != null) {
+ do_check_eq(info.fixedURI.spec, alternativeURI);
+ } else {
+ do_check_eq(info.fixedURI && info.fixedURI.spec, expectedFixedURI);
+ }
+
+ // Check booleans on input:
+ let couldDoKeywordLookup = flags & urifixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
+ do_check_eq(!!info.keywordProviderName, couldDoKeywordLookup && expectKeywordLookup);
+ do_check_eq(info.fixupChangedProtocol, expectProtocolChange);
+ do_check_eq(info.fixupCreatedAlternateURI, makeAlternativeURI && alternativeURI != null);
+
+ // Check the preferred URI
+ if (couldDoKeywordLookup) {
+ if (expectKeywordLookup) {
+ if (!inWhitelist) {
+ let urlparamInput = encodeURIComponent(sanitize(testInput)).replace(/%20/g, "+");
+ // If the input starts with `?`, then info.preferredURI.spec will omit it
+ // In order to test this behaviour, remove `?` only if it is the first character
+ if (urlparamInput.startsWith("%3F")) {
+ urlparamInput = urlparamInput.replace("%3F", "");
+ }
+ let searchURL = kSearchEngineURL.replace("{searchTerms}", urlparamInput);
+ let spec = info.preferredURI.spec.replace(/%27/g, "'");
+ do_check_eq(spec, searchURL);
+ } else {
+ do_check_eq(info.preferredURI, null);
+ }
+ } else {
+ do_check_eq(info.preferredURI.spec, info.fixedURI.spec);
+ }
+ } else {
+ // In these cases, we should never be doing a keyword lookup and
+ // the fixed URI should be preferred:
+ do_check_eq(info.preferredURI.spec, info.fixedURI.spec);
+ }
+ do_check_eq(sanitize(testInput), info.originalInput);
+ }
+ }
+}
diff --git a/docshell/test/unit/test_nsDefaultURIFixup_search.js b/docshell/test/unit/test_nsDefaultURIFixup_search.js
new file mode 100644
index 000000000..c00b6a85f
--- /dev/null
+++ b/docshell/test/unit/test_nsDefaultURIFixup_search.js
@@ -0,0 +1,117 @@
+var urifixup = Cc["@mozilla.org/docshell/urifixup;1"].
+ getService(Ci.nsIURIFixup);
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/AppConstants.jsm");
+
+Services.prefs.setBoolPref("keyword.enabled", true);
+
+const kSearchEngineID = "test_urifixup_search_engine";
+const kSearchEngineURL = "http://www.example.org/?search={searchTerms}";
+Services.search.addEngineWithDetails(kSearchEngineID, "", "", "", "get",
+ kSearchEngineURL);
+
+var oldDefaultEngine = Services.search.defaultEngine;
+Services.search.defaultEngine = Services.search.getEngineByName(kSearchEngineID);
+
+var selectedName = Services.search.defaultEngine.name;
+do_check_eq(selectedName, kSearchEngineID);
+
+do_register_cleanup(function() {
+ if (oldDefaultEngine) {
+ Services.search.defaultEngine = oldDefaultEngine;
+ }
+ let engine = Services.search.getEngineByName(kSearchEngineID);
+ if (engine) {
+ Services.search.removeEngine(engine);
+ }
+ Services.prefs.clearUserPref("keyword.enabled");
+});
+
+var isWin = AppConstants.platform == "win";
+
+var data = [
+ {
+ // Valid should not be changed.
+ wrong: 'https://example.com/this/is/a/test.html',
+ fixed: 'https://example.com/this/is/a/test.html',
+ },
+ {
+ // Unrecognized protocols should be changed.
+ wrong: 'whatever://this/is/a/test.html',
+ fixed: kSearchEngineURL.replace("{searchTerms}", encodeURIComponent('whatever://this/is/a/test.html')),
+ },
+
+ // The following tests check that when a user:password is present in the URL
+ // `user:` isn't treated as an unknown protocol thus leaking the user and
+ // password to the search engine.
+ {
+ wrong: 'user:pass@example.com/this/is/a/test.html',
+ fixed: 'http://user:pass@example.com/this/is/a/test.html',
+ },
+ {
+ wrong: 'user@example.com:8080/this/is/a/test.html',
+ fixed: 'http://user@example.com:8080/this/is/a/test.html',
+ },
+ {
+ wrong: 'https:pass@example.com/this/is/a/test.html',
+ fixed: 'https://pass@example.com/this/is/a/test.html',
+ },
+ {
+ wrong: 'user:pass@example.com:8080/this/is/a/test.html',
+ fixed: 'http://user:pass@example.com:8080/this/is/a/test.html',
+ },
+ {
+ wrong: 'http:user:pass@example.com:8080/this/is/a/test.html',
+ fixed: 'http://user:pass@example.com:8080/this/is/a/test.html',
+ },
+ {
+ wrong: 'ttp:user:pass@example.com:8080/this/is/a/test.html',
+ fixed: 'http://user:pass@example.com:8080/this/is/a/test.html',
+ },
+ {
+ wrong: 'gobbledygook:user:pass@example.com:8080/this/is/a/test.html',
+ fixed: 'http://gobbledygook:user%3Apass@example.com:8080/this/is/a/test.html',
+ },
+ {
+ wrong: 'user:@example.com:8080/this/is/a/test.html',
+ fixed: 'http://user:@example.com:8080/this/is/a/test.html',
+ },
+ {
+ wrong: '//user:pass@example.com:8080/this/is/a/test.html',
+ fixed: (isWin ? "http:" : "file://") + '//user:pass@example.com:8080/this/is/a/test.html',
+ },
+ {
+ wrong: '://user:pass@example.com:8080/this/is/a/test.html',
+ fixed: 'http://user:pass@example.com:8080/this/is/a/test.html',
+ },
+ {
+ wrong: 'whatever://this/is/a@b/test.html',
+ fixed: kSearchEngineURL.replace("{searchTerms}", encodeURIComponent('whatever://this/is/a@b/test.html')),
+ },
+];
+
+var extProtocolSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"]
+ .getService(Ci.nsIExternalProtocolService);
+
+if (extProtocolSvc && extProtocolSvc.externalProtocolHandlerExists("mailto")) {
+ data.push({
+ wrong: "mailto:foo@bar.com",
+ fixed: "mailto:foo@bar.com"
+ });
+}
+
+function run_test() {
+ run_next_test();
+}
+
+var len = data.length;
+// Make sure we fix what needs fixing
+add_task(function test_fix_unknown_schemes() {
+ for (let i = 0; i < len; ++i) {
+ let item = data[i];
+ let result =
+ urifixup.createFixupURI(item.wrong,
+ urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec;
+ do_check_eq(result, item.fixed);
+ }
+});
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();
+}
diff --git a/docshell/test/unit/test_pb_notification.js b/docshell/test/unit/test_pb_notification.js
new file mode 100644
index 000000000..82018f585
--- /dev/null
+++ b/docshell/test/unit/test_pb_notification.js
@@ -0,0 +1,23 @@
+if (typeof Cc === "undefined")
+ Cc = Components.classes;
+if (typeof Ci === "undefined")
+ Ci = Components.interfaces;
+
+function destroy_transient_docshell() {
+ var docshell = Cc["@mozilla.org/docshell;1"].createInstance(Ci.nsIDocShell);
+ docshell.setOriginAttributes({privateBrowsingId : 1});
+ do_test_pending();
+ do_timeout(0, Components.utils.forceGC);
+}
+
+function run_test() {
+ var obs = {
+ observe: function(aSubject, aTopic, aData) {
+ do_check_eq(aTopic, "last-pb-context-exited");
+ do_test_finished();
+ }
+ };
+ var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
+ os.addObserver(obs, "last-pb-context-exited", false);
+ destroy_transient_docshell();
+}
diff --git a/docshell/test/unit/test_privacy_transition.js b/docshell/test/unit/test_privacy_transition.js
new file mode 100644
index 000000000..829e25c3c
--- /dev/null
+++ b/docshell/test/unit/test_privacy_transition.js
@@ -0,0 +1,23 @@
+var gNotifications = 0;
+
+var observer = {
+ QueryInterface: function(iid) {
+ if (Ci.nsIPrivacyTransitionObserver.equals(iid) ||
+ Ci.nsISupportsWeakReference.equals(iid) ||
+ Ci.nsISupports.equals(iid))
+ return this;
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ },
+
+ privateModeChanged: function(enabled) {
+ gNotifications++;
+ }
+}
+
+function run_test() {
+ var docshell = Cc["@mozilla.org/docshell;1"].createInstance(Ci.nsIDocShell);
+ docshell.addWeakPrivacyTransitionObserver(observer);
+ docshell.setOriginAttributes({ privateBrowsingId : 1 });
+ docshell.setOriginAttributes({ privateBrowsingId : 0 });
+ do_check_eq(gNotifications, 2);
+} \ No newline at end of file
diff --git a/docshell/test/unit/test_setUsePrivateBrowsing.js b/docshell/test/unit/test_setUsePrivateBrowsing.js
new file mode 100644
index 000000000..739186895
--- /dev/null
+++ b/docshell/test/unit/test_setUsePrivateBrowsing.js
@@ -0,0 +1,65 @@
+"use strict";
+
+const {utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/AppConstants.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+add_task(function*() {
+ let webNav = Services.appShell.createWindowlessBrowser(false);
+
+ let loadContext = webNav.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsILoadContext);
+
+ let docShell = webNav.getInterface(Ci.nsIDocShell);
+
+ equal(loadContext.usePrivateBrowsing, false, "Should start out in non-private mode");
+
+ loadContext.usePrivateBrowsing = true;
+ equal(loadContext.usePrivateBrowsing, true,
+ "Should be able to change to private mode prior to a document load");
+
+ loadContext.usePrivateBrowsing = false;
+ equal(loadContext.usePrivateBrowsing, false,
+ "Should be able to change to non-private mode prior to a document load");
+
+ let oa = docShell.getOriginAttributes();
+
+ oa.privateBrowsingId = 1;
+ docShell.setOriginAttributes(oa);
+
+ equal(loadContext.usePrivateBrowsing, true,
+ "Should be able to change origin attributes prior to a document load");
+
+ oa.privateBrowsingId = 0;
+ docShell.setOriginAttributes(oa);
+
+ equal(loadContext.usePrivateBrowsing, false,
+ "Should be able to change origin attributes prior to a document load");
+
+ webNav.loadURI("data:text/html,", webNav.LOAD_FLAGS_NONE, null, null, null);
+
+ // Return to the event loop so the load can begin.
+ yield new Promise(do_execute_soon);
+
+ // This causes a failed assertion rather than an exception on debug
+ // builds.
+ if (!AppConstants.DEBUG) {
+ Assert.throws(() => { loadContext.usePrivateBrowsing = true; },
+ /NS_ERROR_FAILURE/,
+ "Should not be able to change private browsing state after initial load has started");
+
+ oa.privateBrowsingId = 1;
+ Assert.throws(() => { docShell.setOriginAttributes(oa); },
+ /NS_ERROR_FAILURE/,
+ "Should not be able to change origin attributes after initial load has started");
+
+ equal(loadContext.usePrivateBrowsing, false,
+ "Should not be able to change private browsing state after initial load has started");
+
+ loadContext.usePrivateBrowsing = false;
+ ok(true, "Should be able to set usePrivateBrowsing to its current value even after initial load");
+ }
+
+ webNav.close();
+});
diff --git a/docshell/test/unit/xpcshell.ini b/docshell/test/unit/xpcshell.ini
new file mode 100644
index 000000000..ce8ec8b63
--- /dev/null
+++ b/docshell/test/unit/xpcshell.ini
@@ -0,0 +1,17 @@
+[DEFAULT]
+head = head_docshell.js
+tail =
+
+[test_bug414201_jfif.js]
+[test_bug442584.js]
+[test_nsDefaultURIFixup.js]
+[test_nsDefaultURIFixup_search.js]
+skip-if = os == 'android'
+[test_nsDefaultURIFixup_info.js]
+skip-if = os == 'android'
+[test_nsIDownloadHistory.js]
+[test_pb_notification.js]
+# Bug 751575: unrelated JS changes cause timeouts on random platforms
+skip-if = true
+[test_privacy_transition.js]
+[test_setUsePrivateBrowsing.js]