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.
michael@0 | 1 | /* Tests for correct behaviour of getEffectiveHost on identity handler */ |
michael@0 | 2 | function test() { |
michael@0 | 3 | waitForExplicitFinish(); |
michael@0 | 4 | |
michael@0 | 5 | ok(gIdentityHandler, "gIdentityHandler should exist"); |
michael@0 | 6 | |
michael@0 | 7 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 8 | gBrowser.selectedBrowser.addEventListener("load", checkResult, true); |
michael@0 | 9 | |
michael@0 | 10 | nextTest(); |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | // Greek IDN for 'example.test'. |
michael@0 | 14 | var idnDomain = "\u03C0\u03B1\u03C1\u03AC\u03B4\u03B5\u03B9\u03B3\u03BC\u03B1.\u03B4\u03BF\u03BA\u03B9\u03BC\u03AE"; |
michael@0 | 15 | var tests = [ |
michael@0 | 16 | { |
michael@0 | 17 | name: "normal domain", |
michael@0 | 18 | location: "http://test1.example.org/", |
michael@0 | 19 | effectiveHost: "example.org" |
michael@0 | 20 | }, |
michael@0 | 21 | { |
michael@0 | 22 | name: "view-source", |
michael@0 | 23 | location: "view-source:http://example.com/", |
michael@0 | 24 | effectiveHost: null |
michael@0 | 25 | }, |
michael@0 | 26 | { |
michael@0 | 27 | name: "normal HTTPS", |
michael@0 | 28 | location: "https://example.com/", |
michael@0 | 29 | effectiveHost: "example.com", |
michael@0 | 30 | isHTTPS: true |
michael@0 | 31 | }, |
michael@0 | 32 | { |
michael@0 | 33 | name: "IDN subdomain", |
michael@0 | 34 | location: "http://sub1." + idnDomain + "/", |
michael@0 | 35 | effectiveHost: idnDomain |
michael@0 | 36 | }, |
michael@0 | 37 | { |
michael@0 | 38 | name: "subdomain with port", |
michael@0 | 39 | location: "http://sub1.test1.example.org:8000/", |
michael@0 | 40 | effectiveHost: "example.org" |
michael@0 | 41 | }, |
michael@0 | 42 | { |
michael@0 | 43 | name: "subdomain HTTPS", |
michael@0 | 44 | location: "https://test1.example.com/", |
michael@0 | 45 | |
michael@0 | 46 | effectiveHost: "example.com", |
michael@0 | 47 | isHTTPS: true |
michael@0 | 48 | }, |
michael@0 | 49 | { |
michael@0 | 50 | name: "view-source HTTPS", |
michael@0 | 51 | location: "view-source:https://example.com/", |
michael@0 | 52 | effectiveHost: null, |
michael@0 | 53 | isHTTPS: true |
michael@0 | 54 | }, |
michael@0 | 55 | { |
michael@0 | 56 | name: "IP address", |
michael@0 | 57 | location: "http://127.0.0.1:8888/", |
michael@0 | 58 | effectiveHost: "127.0.0.1" |
michael@0 | 59 | }, |
michael@0 | 60 | ] |
michael@0 | 61 | |
michael@0 | 62 | let gCurrentTest, gCurrentTestIndex = -1, gTestDesc; |
michael@0 | 63 | // Go through the tests in both directions, to add additional coverage for |
michael@0 | 64 | // transitions between different states. |
michael@0 | 65 | let gForward = true; |
michael@0 | 66 | let gCheckETLD = false; |
michael@0 | 67 | function nextTest() { |
michael@0 | 68 | if (!gCheckETLD) { |
michael@0 | 69 | if (gForward) |
michael@0 | 70 | gCurrentTestIndex++; |
michael@0 | 71 | else |
michael@0 | 72 | gCurrentTestIndex--; |
michael@0 | 73 | |
michael@0 | 74 | if (gCurrentTestIndex == tests.length) { |
michael@0 | 75 | // Went too far, reverse |
michael@0 | 76 | gCurrentTestIndex--; |
michael@0 | 77 | gForward = false; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | if (gCurrentTestIndex == -1) { |
michael@0 | 81 | gBrowser.selectedBrowser.removeEventListener("load", checkResult, true); |
michael@0 | 82 | gBrowser.removeCurrentTab(); |
michael@0 | 83 | finish(); |
michael@0 | 84 | return; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | gCurrentTest = tests[gCurrentTestIndex]; |
michael@0 | 88 | gTestDesc = "#" + gCurrentTestIndex + " (" + gCurrentTest.name + ")"; |
michael@0 | 89 | if (!gForward) |
michael@0 | 90 | gTestDesc += " (second time)"; |
michael@0 | 91 | if (gCurrentTest.isHTTPS) { |
michael@0 | 92 | gCheckETLD = true; |
michael@0 | 93 | } |
michael@0 | 94 | content.location = gCurrentTest.location; |
michael@0 | 95 | } else { |
michael@0 | 96 | gCheckETLD = false; |
michael@0 | 97 | gTestDesc = "#" + gCurrentTestIndex + " (" + gCurrentTest.name + " without eTLD in identity icon label)"; |
michael@0 | 98 | if (!gForward) |
michael@0 | 99 | gTestDesc += " (second time)"; |
michael@0 | 100 | content.location.reload(true); |
michael@0 | 101 | } |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | function checkResult() { |
michael@0 | 105 | // Sanity check other values, and the value of gIdentityHandler.getEffectiveHost() |
michael@0 | 106 | is(gIdentityHandler._lastUri.spec, gCurrentTest.location, "location matches for test " + gTestDesc); |
michael@0 | 107 | // getEffectiveHost can't be called for all modes |
michael@0 | 108 | if (gCurrentTest.effectiveHost === null) |
michael@0 | 109 | is(gIdentityHandler._mode == gIdentityHandler.IDENTITY_MODE_UNKNOWN || gIdentityHandler._mode == gIdentityHandler.IDENTITY_MODE_CHROMEUI, true, "mode matched"); |
michael@0 | 110 | else |
michael@0 | 111 | is(gIdentityHandler.getEffectiveHost(), gCurrentTest.effectiveHost, "effectiveHost matches for test " + gTestDesc); |
michael@0 | 112 | |
michael@0 | 113 | executeSoon(nextTest); |
michael@0 | 114 | } |