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