michael@0: let urifixup = Cc["@mozilla.org/docshell/urifixup;1"]. michael@0: getService(Ci.nsIURIFixup); michael@0: let prefs = Cc["@mozilla.org/preferences-service;1"]. michael@0: getService(Ci.nsIPrefBranch); michael@0: michael@0: let pref = "browser.fixup.typo.scheme"; michael@0: michael@0: let data = [ michael@0: { michael@0: // ttp -> http. michael@0: wrong: 'ttp://www.example.com/', michael@0: fixed: 'http://www.example.com/', michael@0: }, michael@0: { michael@0: // ttps -> https. michael@0: wrong: 'ttps://www.example.com/', michael@0: fixed: 'https://www.example.com/', michael@0: }, michael@0: { michael@0: // tps -> https. michael@0: wrong: 'tps://www.example.com/', michael@0: fixed: 'https://www.example.com/', michael@0: }, michael@0: { michael@0: // ps -> https. michael@0: wrong: 'ps://www.example.com/', michael@0: fixed: 'https://www.example.com/', michael@0: }, michael@0: { michael@0: // ile -> file. michael@0: wrong: 'ile:///this/is/a/test.html', michael@0: fixed: 'file:///this/is/a/test.html', michael@0: }, michael@0: { michael@0: // le -> file. michael@0: wrong: 'le:///this/is/a/test.html', michael@0: fixed: 'file:///this/is/a/test.html', michael@0: }, michael@0: { michael@0: // Valid should not be changed. michael@0: wrong: 'https://example.com/this/is/a/test.html', michael@0: fixed: 'https://example.com/this/is/a/test.html', michael@0: }, michael@0: { michael@0: // Unmatched should not be changed. michael@0: wrong: 'whatever://this/is/a/test.html', michael@0: fixed: 'whatever://this/is/a/test.html', michael@0: }, michael@0: ]; michael@0: michael@0: let len = data.length; michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: // Make sure we fix what needs fixing when there is no pref set. michael@0: add_task(function test_unset_pref_fixes_typos() { michael@0: prefs.clearUserPref(pref); michael@0: for (let i = 0; i < len; ++i) { michael@0: let item = data[i]; michael@0: let result = michael@0: urifixup.createFixupURI(item.wrong, michael@0: urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec; michael@0: do_check_eq(result, item.fixed); michael@0: } michael@0: }); michael@0: michael@0: // Make sure we don't do anything when the pref is explicitly michael@0: // set to false. michael@0: add_task(function test_false_pref_keeps_typos() { michael@0: prefs.setBoolPref(pref, false); michael@0: for (let i = 0; i < len; ++i) { michael@0: let item = data[i]; michael@0: let result = michael@0: urifixup.createFixupURI(item.wrong, michael@0: urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec; michael@0: do_check_eq(result, item.wrong); michael@0: } michael@0: }); michael@0: michael@0: // Finally, make sure we still fix what needs fixing if the pref is michael@0: // explicitly set to true. michael@0: add_task(function test_true_pref_fixes_typos() { michael@0: prefs.setBoolPref(pref, true); michael@0: for (let i = 0; i < len; ++i) { michael@0: let item = data[i]; michael@0: let result = michael@0: urifixup.createFixupURI(item.wrong, michael@0: urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec; michael@0: do_check_eq(result, item.fixed); michael@0: } michael@0: });