1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_identity_UI.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* Tests for correct behaviour of getEffectiveHost on identity handler */ 1.5 +function test() { 1.6 + waitForExplicitFinish(); 1.7 + 1.8 + ok(gIdentityHandler, "gIdentityHandler should exist"); 1.9 + 1.10 + gBrowser.selectedTab = gBrowser.addTab(); 1.11 + gBrowser.selectedBrowser.addEventListener("load", checkResult, true); 1.12 + 1.13 + nextTest(); 1.14 +} 1.15 + 1.16 +// Greek IDN for 'example.test'. 1.17 +var idnDomain = "\u03C0\u03B1\u03C1\u03AC\u03B4\u03B5\u03B9\u03B3\u03BC\u03B1.\u03B4\u03BF\u03BA\u03B9\u03BC\u03AE"; 1.18 +var tests = [ 1.19 + { 1.20 + name: "normal domain", 1.21 + location: "http://test1.example.org/", 1.22 + effectiveHost: "example.org" 1.23 + }, 1.24 + { 1.25 + name: "view-source", 1.26 + location: "view-source:http://example.com/", 1.27 + effectiveHost: null 1.28 + }, 1.29 + { 1.30 + name: "normal HTTPS", 1.31 + location: "https://example.com/", 1.32 + effectiveHost: "example.com", 1.33 + isHTTPS: true 1.34 + }, 1.35 + { 1.36 + name: "IDN subdomain", 1.37 + location: "http://sub1." + idnDomain + "/", 1.38 + effectiveHost: idnDomain 1.39 + }, 1.40 + { 1.41 + name: "subdomain with port", 1.42 + location: "http://sub1.test1.example.org:8000/", 1.43 + effectiveHost: "example.org" 1.44 + }, 1.45 + { 1.46 + name: "subdomain HTTPS", 1.47 + location: "https://test1.example.com/", 1.48 + 1.49 + effectiveHost: "example.com", 1.50 + isHTTPS: true 1.51 + }, 1.52 + { 1.53 + name: "view-source HTTPS", 1.54 + location: "view-source:https://example.com/", 1.55 + effectiveHost: null, 1.56 + isHTTPS: true 1.57 + }, 1.58 + { 1.59 + name: "IP address", 1.60 + location: "http://127.0.0.1:8888/", 1.61 + effectiveHost: "127.0.0.1" 1.62 + }, 1.63 +] 1.64 + 1.65 +let gCurrentTest, gCurrentTestIndex = -1, gTestDesc; 1.66 +// Go through the tests in both directions, to add additional coverage for 1.67 +// transitions between different states. 1.68 +let gForward = true; 1.69 +let gCheckETLD = false; 1.70 +function nextTest() { 1.71 + if (!gCheckETLD) { 1.72 + if (gForward) 1.73 + gCurrentTestIndex++; 1.74 + else 1.75 + gCurrentTestIndex--; 1.76 + 1.77 + if (gCurrentTestIndex == tests.length) { 1.78 + // Went too far, reverse 1.79 + gCurrentTestIndex--; 1.80 + gForward = false; 1.81 + } 1.82 + 1.83 + if (gCurrentTestIndex == -1) { 1.84 + gBrowser.selectedBrowser.removeEventListener("load", checkResult, true); 1.85 + gBrowser.removeCurrentTab(); 1.86 + finish(); 1.87 + return; 1.88 + } 1.89 + 1.90 + gCurrentTest = tests[gCurrentTestIndex]; 1.91 + gTestDesc = "#" + gCurrentTestIndex + " (" + gCurrentTest.name + ")"; 1.92 + if (!gForward) 1.93 + gTestDesc += " (second time)"; 1.94 + if (gCurrentTest.isHTTPS) { 1.95 + gCheckETLD = true; 1.96 + } 1.97 + content.location = gCurrentTest.location; 1.98 + } else { 1.99 + gCheckETLD = false; 1.100 + gTestDesc = "#" + gCurrentTestIndex + " (" + gCurrentTest.name + " without eTLD in identity icon label)"; 1.101 + if (!gForward) 1.102 + gTestDesc += " (second time)"; 1.103 + content.location.reload(true); 1.104 + } 1.105 +} 1.106 + 1.107 +function checkResult() { 1.108 + // Sanity check other values, and the value of gIdentityHandler.getEffectiveHost() 1.109 + is(gIdentityHandler._lastUri.spec, gCurrentTest.location, "location matches for test " + gTestDesc); 1.110 + // getEffectiveHost can't be called for all modes 1.111 + if (gCurrentTest.effectiveHost === null) 1.112 + is(gIdentityHandler._mode == gIdentityHandler.IDENTITY_MODE_UNKNOWN || gIdentityHandler._mode == gIdentityHandler.IDENTITY_MODE_CHROMEUI, true, "mode matched"); 1.113 + else 1.114 + is(gIdentityHandler.getEffectiveHost(), gCurrentTest.effectiveHost, "effectiveHost matches for test " + gTestDesc); 1.115 + 1.116 + executeSoon(nextTest); 1.117 +}