docshell/test/unit/test_nsDefaultURIFixup.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 let urifixup = Cc["@mozilla.org/docshell/urifixup;1"].
michael@0 2 getService(Ci.nsIURIFixup);
michael@0 3 let prefs = Cc["@mozilla.org/preferences-service;1"].
michael@0 4 getService(Ci.nsIPrefBranch);
michael@0 5
michael@0 6 let pref = "browser.fixup.typo.scheme";
michael@0 7
michael@0 8 let data = [
michael@0 9 {
michael@0 10 // ttp -> http.
michael@0 11 wrong: 'ttp://www.example.com/',
michael@0 12 fixed: 'http://www.example.com/',
michael@0 13 },
michael@0 14 {
michael@0 15 // ttps -> https.
michael@0 16 wrong: 'ttps://www.example.com/',
michael@0 17 fixed: 'https://www.example.com/',
michael@0 18 },
michael@0 19 {
michael@0 20 // tps -> https.
michael@0 21 wrong: 'tps://www.example.com/',
michael@0 22 fixed: 'https://www.example.com/',
michael@0 23 },
michael@0 24 {
michael@0 25 // ps -> https.
michael@0 26 wrong: 'ps://www.example.com/',
michael@0 27 fixed: 'https://www.example.com/',
michael@0 28 },
michael@0 29 {
michael@0 30 // ile -> file.
michael@0 31 wrong: 'ile:///this/is/a/test.html',
michael@0 32 fixed: 'file:///this/is/a/test.html',
michael@0 33 },
michael@0 34 {
michael@0 35 // le -> file.
michael@0 36 wrong: 'le:///this/is/a/test.html',
michael@0 37 fixed: 'file:///this/is/a/test.html',
michael@0 38 },
michael@0 39 {
michael@0 40 // Valid should not be changed.
michael@0 41 wrong: 'https://example.com/this/is/a/test.html',
michael@0 42 fixed: 'https://example.com/this/is/a/test.html',
michael@0 43 },
michael@0 44 {
michael@0 45 // Unmatched should not be changed.
michael@0 46 wrong: 'whatever://this/is/a/test.html',
michael@0 47 fixed: 'whatever://this/is/a/test.html',
michael@0 48 },
michael@0 49 ];
michael@0 50
michael@0 51 let len = data.length;
michael@0 52
michael@0 53 function run_test() {
michael@0 54 run_next_test();
michael@0 55 }
michael@0 56
michael@0 57 // Make sure we fix what needs fixing when there is no pref set.
michael@0 58 add_task(function test_unset_pref_fixes_typos() {
michael@0 59 prefs.clearUserPref(pref);
michael@0 60 for (let i = 0; i < len; ++i) {
michael@0 61 let item = data[i];
michael@0 62 let result =
michael@0 63 urifixup.createFixupURI(item.wrong,
michael@0 64 urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec;
michael@0 65 do_check_eq(result, item.fixed);
michael@0 66 }
michael@0 67 });
michael@0 68
michael@0 69 // Make sure we don't do anything when the pref is explicitly
michael@0 70 // set to false.
michael@0 71 add_task(function test_false_pref_keeps_typos() {
michael@0 72 prefs.setBoolPref(pref, false);
michael@0 73 for (let i = 0; i < len; ++i) {
michael@0 74 let item = data[i];
michael@0 75 let result =
michael@0 76 urifixup.createFixupURI(item.wrong,
michael@0 77 urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec;
michael@0 78 do_check_eq(result, item.wrong);
michael@0 79 }
michael@0 80 });
michael@0 81
michael@0 82 // Finally, make sure we still fix what needs fixing if the pref is
michael@0 83 // explicitly set to true.
michael@0 84 add_task(function test_true_pref_fixes_typos() {
michael@0 85 prefs.setBoolPref(pref, true);
michael@0 86 for (let i = 0; i < len; ++i) {
michael@0 87 let item = data[i];
michael@0 88 let result =
michael@0 89 urifixup.createFixupURI(item.wrong,
michael@0 90 urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS).spec;
michael@0 91 do_check_eq(result, item.fixed);
michael@0 92 }
michael@0 93 });

mercurial