browser_captivePortal_https_only.js (2552B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 const { PermissionTestUtils } = ChromeUtils.importESModule( 6 "resource://testing-common/PermissionTestUtils.sys.mjs" 7 ); 8 const testPath = getRootDirectory(gTestPath).replace( 9 "chrome://mochitests/content", 10 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 11 "http://example.com" 12 ); 13 const CANONICAL_URI = Services.io.newURI(testPath); 14 const PERMISSION_NAME = "https-only-load-insecure"; 15 16 add_setup(async function () { 17 await SpecialPowers.pushPrefEnv({ 18 // That changes the canoncicalURL from "http://{server}/captive-detect/success.txt" 19 // to http://example.com 20 set: [ 21 ["captivedetect.canonicalURL", testPath], 22 ["dom.security.https_only_mode", true], 23 ], 24 }); 25 }); 26 27 // This test checks if https-only exempts the canoncial uri. 28 add_task(async function checkCaptivePortalExempt() { 29 await portalDetected(); 30 info("Checking that the canonical uri is exempt by https-only mode"); 31 let tab = await openCaptivePortalErrorTab(); 32 let browser = tab.linkedBrowser; 33 let portalTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, testPath); 34 35 await SpecialPowers.spawn(browser, [], async () => { 36 let doc = content.document; 37 let loginButton = doc.getElementById("openPortalLoginPageButton"); 38 await ContentTaskUtils.waitForCondition( 39 () => ContentTaskUtils.isVisible(loginButton), 40 "Captive portal error page UI is visible" 41 ); 42 43 if (!Services.focus.focusedElement == loginButton) { 44 await ContentTaskUtils.waitForEvent(loginButton, "focus"); 45 } 46 47 Assert.ok(true, "openPortalLoginPageButton has focus"); 48 info("Clicking the Open Login Page button"); 49 await EventUtils.synthesizeMouseAtCenter(loginButton, {}, content); 50 }); 51 is( 52 PermissionTestUtils.testPermission(CANONICAL_URI, PERMISSION_NAME), 53 Services.perms.ALLOW_ACTION, 54 "Check permission in perm. manager if canoncial uri is set as exempt." 55 ); 56 let portalTab = await portalTabPromise; 57 is( 58 gBrowser.selectedTab, 59 portalTab, 60 "Login page should be open in a new foreground tab." 61 ); 62 is( 63 gBrowser.currentURI.spec, 64 testPath, 65 "Opened the right URL without upgrading it." 66 ); 67 // Close all tabs 68 await BrowserTestUtils.removeTab(portalTab); 69 let tabReloaded = BrowserTestUtils.waitForErrorPage(tab.linkedBrowser); 70 Services.obs.notifyObservers(null, "captive-portal-login-success"); 71 await tabReloaded; 72 await BrowserTestUtils.removeTab(tab); 73 });