1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_urlHighlight.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +function testVal(aExpected) { 1.9 + gURLBar.value = aExpected.replace(/[<>]/g, ""); 1.10 + 1.11 + let selectionController = gURLBar.editor.selectionController; 1.12 + let selection = selectionController.getSelection(selectionController.SELECTION_URLSECONDARY); 1.13 + let value = gURLBar.editor.rootElement.textContent; 1.14 + let result = ""; 1.15 + for (let i = 0; i < selection.rangeCount; i++) { 1.16 + let range = selection.getRangeAt(i).toString(); 1.17 + let pos = value.indexOf(range); 1.18 + result += value.substring(0, pos) + "<" + range + ">"; 1.19 + value = value.substring(pos + range.length); 1.20 + } 1.21 + result += value; 1.22 + is(result, aExpected); 1.23 +} 1.24 + 1.25 +function test() { 1.26 + const prefname = "browser.urlbar.formatting.enabled"; 1.27 + 1.28 + registerCleanupFunction(function () { 1.29 + Services.prefs.clearUserPref(prefname); 1.30 + URLBarSetURI(); 1.31 + }); 1.32 + 1.33 + Services.prefs.setBoolPref(prefname, true); 1.34 + 1.35 + gURLBar.focus(); 1.36 + 1.37 + testVal("https://mozilla.org"); 1.38 + 1.39 + gBrowser.selectedBrowser.focus(); 1.40 + 1.41 + testVal("<https://>mozilla.org"); 1.42 + testVal("<https://>mözilla.org"); 1.43 + testVal("<https://>mozilla.imaginatory"); 1.44 + 1.45 + testVal("<https://www.>mozilla.org"); 1.46 + testVal("<https://sub.>mozilla.org"); 1.47 + testVal("<https://sub1.sub2.sub3.>mozilla.org"); 1.48 + testVal("<www.>mozilla.org"); 1.49 + testVal("<sub.>mozilla.org"); 1.50 + testVal("<sub1.sub2.sub3.>mozilla.org"); 1.51 + 1.52 + testVal("<http://ftp.>mozilla.org"); 1.53 + testVal("<ftp://ftp.>mozilla.org"); 1.54 + 1.55 + testVal("<https://sub.>mozilla.org"); 1.56 + testVal("<https://sub1.sub2.sub3.>mozilla.org"); 1.57 + testVal("<https://user:pass@sub1.sub2.sub3.>mozilla.org"); 1.58 + testVal("<https://user:pass@>mozilla.org"); 1.59 + 1.60 + testVal("<https://>mozilla.org</file.ext>"); 1.61 + testVal("<https://>mozilla.org</sub/file.ext>"); 1.62 + testVal("<https://>mozilla.org</sub/file.ext?foo>"); 1.63 + testVal("<https://>mozilla.org</sub/file.ext?foo&bar>"); 1.64 + testVal("<https://>mozilla.org</sub/file.ext?foo&bar#top>"); 1.65 + testVal("<https://>mozilla.org</sub/file.ext?foo&bar#top>"); 1.66 + 1.67 + testVal("<https://sub.>mozilla.org<:666/file.ext>"); 1.68 + testVal("<sub.>mozilla.org<:666/file.ext>"); 1.69 + testVal("localhost<:666/file.ext>"); 1.70 + 1.71 + let IPs = ["192.168.1.1", 1.72 + "[::]", 1.73 + "[::1]", 1.74 + "[1::]", 1.75 + "[::]", 1.76 + "[::1]", 1.77 + "[1::]", 1.78 + "[1:2:3:4:5:6:7::]", 1.79 + "[::1:2:3:4:5:6:7]", 1.80 + "[1:2:a:B:c:D:e:F]", 1.81 + "[1::8]", 1.82 + "[1:2::8]", 1.83 + "[fe80::222:19ff:fe11:8c76]", 1.84 + "[0000:0123:4567:89AB:CDEF:abcd:ef00:0000]", 1.85 + "[::192.168.1.1]", 1.86 + "[1::0.0.0.0]", 1.87 + "[1:2::255.255.255.255]", 1.88 + "[1:2:3::255.255.255.255]", 1.89 + "[1:2:3:4::255.255.255.255]", 1.90 + "[1:2:3:4:5::255.255.255.255]", 1.91 + "[1:2:3:4:5:6:255.255.255.255]"]; 1.92 + IPs.forEach(function (IP) { 1.93 + testVal(IP); 1.94 + testVal(IP + "</file.ext>"); 1.95 + testVal(IP + "<:666/file.ext>"); 1.96 + testVal("<https://>" + IP); 1.97 + testVal("<https://>" + IP + "</file.ext>"); 1.98 + testVal("<https://user:pass@>" + IP + "<:666/file.ext>"); 1.99 + testVal("<http://user:pass@>" + IP + "<:666/file.ext>"); 1.100 + }); 1.101 + 1.102 + testVal("mailto:admin@mozilla.org"); 1.103 + testVal("gopher://mozilla.org/"); 1.104 + testVal("about:config"); 1.105 + testVal("jar:http://mozilla.org/example.jar!/"); 1.106 + testVal("view-source:http://mozilla.org/"); 1.107 + testVal("foo9://mozilla.org/"); 1.108 + testVal("foo+://mozilla.org/"); 1.109 + testVal("foo.://mozilla.org/"); 1.110 + testVal("foo-://mozilla.org/"); 1.111 + 1.112 + Services.prefs.setBoolPref(prefname, false); 1.113 + 1.114 + testVal("https://mozilla.org"); 1.115 +}