summaryrefslogtreecommitdiffstats
path: root/docshell/test/unit/test_nsDefaultURIFixup.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_nsDefaultURIFixup.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_nsDefaultURIFixup.js')
-rw-r--r--docshell/test/unit/test_nsDefaultURIFixup.js93
1 files changed, 93 insertions, 0 deletions
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);
+ }
+});