browser_identity_UI.js (5454B)
1 /* Tests for correct behaviour of getHostForDisplay on identity handler */ 2 3 requestLongerTimeout(2); 4 5 // Greek IDN for 'example.test'. 6 var idnDomain = 7 "\u03C0\u03B1\u03C1\u03AC\u03B4\u03B5\u03B9\u03B3\u03BC\u03B1.\u03B4\u03BF\u03BA\u03B9\u03BC\u03AE"; 8 var tests = [ 9 { 10 name: "normal domain", 11 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 12 location: "http://test1.example.org/", 13 hostForDisplay: "test1.example.org", 14 hasSubview: true, 15 }, 16 { 17 name: "view-source", 18 location: "view-source:http://example.com/", 19 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 20 newURI: "http://example.com/", 21 hostForDisplay: "example.com", 22 hasSubview: true, 23 }, 24 { 25 name: "normal HTTPS", 26 location: "https://example.com/", 27 hostForDisplay: "example.com", 28 hasSubview: true, 29 }, 30 { 31 name: "IDN subdomain", 32 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 33 location: "http://sub1.xn--hxajbheg2az3al.xn--jxalpdlp/", 34 hostForDisplay: "sub1." + idnDomain, 35 hasSubview: true, 36 }, 37 { 38 name: "subdomain with port", 39 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 40 location: "http://sub1.test1.example.org:8000/", 41 hostForDisplay: "sub1.test1.example.org", 42 hasSubview: true, 43 }, 44 { 45 name: "subdomain HTTPS", 46 location: "https://test1.example.com/", 47 hostForDisplay: "test1.example.com", 48 hasSubview: true, 49 }, 50 { 51 name: "view-source HTTPS", 52 location: "view-source:https://example.com/", 53 newURI: "https://example.com/", 54 hostForDisplay: "example.com", 55 hasSubview: true, 56 }, 57 { 58 name: "IP address", 59 location: "http://127.0.0.1:8888/", 60 hostForDisplay: "127.0.0.1", 61 hasSubview: false, 62 }, 63 { 64 name: "about:certificate", 65 location: 66 "about:certificate?cert=MIIHQjCCBiqgAwIBAgIQCgYwQn9bvO&cert=1pVzllk7ZFHzANBgkqhkiG9w0BAQ", 67 hostForDisplay: "about:certificate", 68 hasSubview: false, 69 }, 70 { 71 name: "about:reader", 72 location: "about:reader?url=http://example.com", 73 hostForDisplay: "example.com", 74 hasSubview: false, 75 }, 76 { 77 name: "chrome:", 78 location: "chrome://global/content/mozilla.html", 79 hostForDisplay: "chrome://global/content/mozilla.html", 80 hasSubview: false, 81 }, 82 { 83 name: "about:logo with nested moz-safe-about:logo", 84 location: "about:logo", 85 hostForDisplay: "about:logo", 86 hasSubview: false, 87 }, 88 ]; 89 90 add_task(async function test() { 91 ok(gIdentityHandler, "gIdentityHandler should exist"); 92 93 await BrowserTestUtils.openNewForegroundTab(gBrowser); 94 95 for (let i = 0; i < tests.length; i++) { 96 await runTest(i, true); 97 } 98 99 gBrowser.removeCurrentTab(); 100 await BrowserTestUtils.openNewForegroundTab(gBrowser); 101 102 for (let i = tests.length - 1; i >= 0; i--) { 103 await runTest(i, false); 104 } 105 106 gBrowser.removeCurrentTab(); 107 }); 108 109 async function runTest(i, forward) { 110 let currentTest = tests[i]; 111 let testDesc = "#" + i + " (" + currentTest.name + ")"; 112 if (!forward) { 113 testDesc += " (second time)"; 114 } 115 116 info("Running test " + testDesc); 117 118 let popupHidden = null; 119 if ((forward && i > 0) || (!forward && i < tests.length - 1)) { 120 popupHidden = BrowserTestUtils.waitForEvent( 121 gIdentityHandler._identityPopup, 122 "popuphidden" 123 ); 124 } 125 126 let loaded = BrowserTestUtils.browserLoaded( 127 gBrowser.selectedBrowser, 128 false, 129 currentTest.location 130 ); 131 BrowserTestUtils.startLoadingURIString( 132 gBrowser.selectedBrowser, 133 currentTest.location 134 ); 135 await loaded; 136 await popupHidden; 137 ok( 138 !gIdentityHandler._identityPopup || 139 BrowserTestUtils.isHidden(gIdentityHandler._identityPopup), 140 "Control Center is hidden" 141 ); 142 143 // Sanity check other values, and the value of gIdentityHandler.getHostForDisplay() 144 is( 145 gIdentityHandler._uri.spec, 146 currentTest.newURI || currentTest.location, 147 "location matches for test " + testDesc 148 ); 149 // getHostForDisplay can't be called for all modes 150 if (currentTest.hostForDisplay !== null) { 151 is( 152 gIdentityHandler.getHostForDisplay(), 153 currentTest.hostForDisplay, 154 "hostForDisplay matches for test " + testDesc 155 ); 156 } 157 158 // Open the Control Center and make sure it closes after nav (Bug 1207542). 159 let popupShown = BrowserTestUtils.waitForEvent( 160 window, 161 "popupshown", 162 true, 163 event => event.target == gIdentityHandler._identityPopup 164 ); 165 gIdentityHandler._identityIconBox.click(); 166 info("Waiting for the Control Center to be shown"); 167 await popupShown; 168 ok( 169 !BrowserTestUtils.isHidden(gIdentityHandler._identityPopup), 170 "Control Center is visible" 171 ); 172 let displayedHost = currentTest.hostForDisplay || currentTest.location; 173 ok( 174 gIdentityHandler._identityPopupMainViewHeaderLabel.textContent.includes( 175 displayedHost 176 ), 177 "identity UI header shows the host for test " + testDesc 178 ); 179 180 let securityButton = gBrowser.ownerDocument.querySelector( 181 "#identity-popup-security-button" 182 ); 183 is( 184 securityButton.disabled, 185 !currentTest.hasSubview, 186 "Security button has correct disabled state" 187 ); 188 if (currentTest.hasSubview) { 189 // Show the subview, which is an easy way in automation to reproduce 190 // Bug 1207542, where the CC wouldn't close on navigation. 191 let promiseViewShown = BrowserTestUtils.waitForEvent( 192 gIdentityHandler._identityPopup, 193 "ViewShown" 194 ); 195 securityButton.click(); 196 await promiseViewShown; 197 } 198 }