browser_identity_web_controlled_blank.js (4370B)
1 /* 2 * This work is marked with CC0 1.0. To view a copy of this license, 3 * visit http://creativecommons.org/publicdomain/zero/1.0 4 * 5 * 6 * Tests for correct behaviour of web-controlled about:blank pages in identity panel. 7 * Getting into a testable state is different enough that we test all the behaviors here 8 * separately, rather than with the usual (secure, insecure, etc.) cases 9 */ 10 11 const TEST_HOST = "example.com"; 12 const TEST_ORIGIN = "https://" + TEST_HOST; 13 const TEST_PATH = getRootDirectory(gTestPath).replace( 14 "chrome://mochitests/content", 15 TEST_ORIGIN 16 ); 17 const LOCALHOST_PATH = getRootDirectory(gTestPath).replace( 18 "chrome://mochitests/content", 19 "http://127.0.0.1:8888" 20 ); 21 const TEST_URI = TEST_PATH + "test_web_controlled_blank.html"; 22 const DUMMY_URI = LOCALHOST_PATH + "dummy_page.html"; 23 24 // Open a new tab of `test_web_controlled_blank.html` and click 25 // an element with a particular ID to open an about:blank popup 26 // that is controlled by that first tab. 27 // 28 // Then test that the UI elements are all correct. And make sure 29 // we don't have anything odd going on after navigating away in the 30 // popup. 31 async function web_controlled_about_blank_helper(id_to_click) { 32 // Open a new tab that will control about:blank pages 33 await BrowserTestUtils.withNewTab(TEST_URI, async browser => { 34 // Open a new popup by clicking the provided id_to_click from the content 35 let popupWindowPromise = BrowserTestUtils.waitForNewWindow(); 36 await SpecialPowers.spawn(browser, [id_to_click], async function (id) { 37 content.document.getElementById(id).click(); 38 }); 39 let popupWindow = await popupWindowPromise; 40 41 // Validate the icon in the urlbar 42 let identityIcon = popupWindow.document.querySelector("#identity-icon"); 43 let identityIconImageURL = popupWindow 44 .getComputedStyle(identityIcon) 45 .getPropertyValue("list-style-image"); 46 is( 47 identityIconImageURL, 48 `url("chrome://global/skin/icons/info.svg")`, 49 "The identity icon has a correct image url." 50 ); 51 52 // Open the identity panel 53 let popupShown = BrowserTestUtils.waitForEvent( 54 popupWindow, 55 "popupshown", 56 true, 57 event => event.target == popupWindow.gIdentityHandler._identityPopup 58 ); 59 popupWindow.gIdentityHandler._identityIconBox.click(); 60 info("Waiting for the Control Center to be shown"); 61 await popupShown; 62 ok( 63 !popupWindow.gIdentityHandler._identityPopup.hidden, 64 "Control Center is visible" 65 ); 66 67 // Validate that the predecessor is shown in the identity panel 68 ok( 69 popupWindow.gIdentityHandler._identityPopupMainViewHeaderLabel.textContent.includes( 70 TEST_HOST 71 ), 72 "Identity UI header shows the host of the predecessor" 73 ); 74 75 // Validate that the correct message is displayed 76 is( 77 popupWindow.gIdentityHandler._identityPopup.getAttribute("connection"), 78 "associated", 79 "Identity UI shows associated message." 80 ); 81 82 // Validate that there is no additional security info 83 let securityButton = popupWindow.gBrowser.ownerDocument.querySelector( 84 "#identity-popup-security-button" 85 ); 86 is( 87 securityButton.disabled, 88 true, 89 "Security button has correct disabled state" 90 ); 91 92 // Navigate away to a localhost page and make sure the identity icon changes 93 let loaded = BrowserTestUtils.browserLoaded( 94 popupWindow.gBrowser.selectedBrowser, 95 false, 96 DUMMY_URI 97 ); 98 await SpecialPowers.spawn( 99 popupWindow.gBrowser.selectedBrowser, 100 [DUMMY_URI], 101 async function (uri) { 102 content.location = uri; 103 } 104 ); 105 info("Waiting for the navigation to a dummy page to complete."); 106 await loaded; 107 108 identityIconImageURL = popupWindow.gBrowser.ownerGlobal 109 .getComputedStyle(identityIcon) 110 .getPropertyValue("list-style-image"); 111 is( 112 identityIconImageURL, 113 `url("chrome://global/skin/icons/page-portrait.svg")`, 114 "The identity icon has a correct image url after navigating away." 115 ); 116 117 // Exit this test, cleaning up as we go. 118 await BrowserTestUtils.closeWindow(popupWindow); 119 }); 120 } 121 122 add_task(async function test_document_write() { 123 await web_controlled_about_blank_helper("document_write"); 124 }); 125 126 add_task(async function test_innerHTML() { 127 await web_controlled_about_blank_helper("innerhtml"); 128 });