1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/unit/test_nsDefaultURIFixup.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +let urifixup = Cc["@mozilla.org/docshell/urifixup;1"]. 1.5 + getService(Ci.nsIURIFixup); 1.6 +let prefs = Cc["@mozilla.org/preferences-service;1"]. 1.7 + getService(Ci.nsIPrefBranch); 1.8 + 1.9 +let pref = "browser.fixup.typo.scheme"; 1.10 + 1.11 +let data = [ 1.12 + { 1.13 + // ttp -> http. 1.14 + wrong: 'ttp://www.example.com/', 1.15 + fixed: 'http://www.example.com/', 1.16 + }, 1.17 + { 1.18 + // ttps -> https. 1.19 + wrong: 'ttps://www.example.com/', 1.20 + fixed: 'https://www.example.com/', 1.21 + }, 1.22 + { 1.23 + // tps -> https. 1.24 + wrong: 'tps://www.example.com/', 1.25 + fixed: 'https://www.example.com/', 1.26 + }, 1.27 + { 1.28 + // ps -> https. 1.29 + wrong: 'ps://www.example.com/', 1.30 + fixed: 'https://www.example.com/', 1.31 + }, 1.32 + { 1.33 + // ile -> file. 1.34 + wrong: 'ile:///this/is/a/test.html', 1.35 + fixed: 'file:///this/is/a/test.html', 1.36 + }, 1.37 + { 1.38 + // le -> file. 1.39 + wrong: 'le:///this/is/a/test.html', 1.40 + fixed: 'file:///this/is/a/test.html', 1.41 + }, 1.42 + { 1.43 + // Valid should not be changed. 1.44 + wrong: 'https://example.com/this/is/a/test.html', 1.45 + fixed: 'https://example.com/this/is/a/test.html', 1.46 + }, 1.47 + { 1.48 + // Unmatched should not be changed. 1.49 + wrong: 'whatever://this/is/a/test.html', 1.50 + fixed: 'whatever://this/is/a/test.html', 1.51 + }, 1.52 +]; 1.53 + 1.54 +let len = data.length; 1.55 + 1.56 +function run_test() { 1.57 + run_next_test(); 1.58 +} 1.59 + 1.60 +// Make sure we fix what needs fixing when there is no pref set. 1.61 +add_task(function test_unset_pref_fixes_typos() { 1.62 + prefs.clearUserPref(pref); 1.63 + for (let i = 0; i < len; ++i) { 1.64 + let item = data[i]; 1.65 + let result = 1.66 + urifixup.createFixupURI(item.wrong, 1.67 + urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec; 1.68 + do_check_eq(result, item.fixed); 1.69 + } 1.70 +}); 1.71 + 1.72 +// Make sure we don't do anything when the pref is explicitly 1.73 +// set to false. 1.74 +add_task(function test_false_pref_keeps_typos() { 1.75 + prefs.setBoolPref(pref, false); 1.76 + for (let i = 0; i < len; ++i) { 1.77 + let item = data[i]; 1.78 + let result = 1.79 + urifixup.createFixupURI(item.wrong, 1.80 + urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec; 1.81 + do_check_eq(result, item.wrong); 1.82 + } 1.83 +}); 1.84 + 1.85 +// Finally, make sure we still fix what needs fixing if the pref is 1.86 +// explicitly set to true. 1.87 +add_task(function test_true_pref_fixes_typos() { 1.88 + prefs.setBoolPref(pref, true); 1.89 + for (let i = 0; i < len; ++i) { 1.90 + let item = data[i]; 1.91 + let result = 1.92 + urifixup.createFixupURI(item.wrong, 1.93 + urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec; 1.94 + do_check_eq(result, item.fixed); 1.95 + } 1.96 +});