browser_webconsole_block_mixedcontent_securityerrors.js (3947B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // The test loads a web page with mixed active and display content 5 // on it while the "block mixed content" settings are _on_. 6 // It then checks that the blocked mixed content warning messages 7 // are logged to the console and have the correct "Learn More" 8 // url appended to them. After the first test finishes, it invokes 9 // a second test that disables the mixed content blocker by prefs 10 // and validates that the appropriate messages are logged to 11 // console. 12 // Bug 875456 - Log mixed content messages from the Mixed Content 13 // Blocker to the Security Pane in the Web Console. 14 15 "use strict"; 16 17 const TEST_URI = 18 "https://example.com/browser/devtools/client/webconsole/" + 19 "test/browser/test-mixedcontent-securityerrors.html"; 20 const LEARN_MORE_URI = 21 "https://developer.mozilla.org/docs/Web/Security/Mixed_content" + 22 DOCS_GA_PARAMS; 23 24 const blockedActiveContentText = 25 "Blocked loading mixed active content \u201chttp://example.com/\u201d"; 26 const blockedDisplayContentText = 27 "Blocked loading mixed display content " + 28 "\u201chttp://example.com/tests/image/test/mochitest/blue.png\u201d"; 29 const activeContentText = 30 "Loading mixed (insecure) active content " + 31 "\u201chttp://example.com/\u201d on a secure page"; 32 const displayContentText = 33 "Loading mixed (insecure) display content " + 34 "\u201chttp://example.com/tests/image/test/mochitest/blue.png\u201d on a " + 35 "secure page"; 36 37 add_task(async function () { 38 await SpecialPowers.pushPrefEnv({ 39 set: [ 40 ["security.mixed_content.block_active_content", true], 41 ["security.mixed_content.block_display_content", true], 42 ["security.mixed_content.upgrade_display_content", false], 43 ], 44 }); 45 46 const hud = await openNewTabAndConsole(TEST_URI); 47 48 const waitForErrorMessage = text => 49 waitFor(() => findErrorMessage(hud, text), undefined, 100); 50 51 const onBlockedIframe = waitForErrorMessage(blockedActiveContentText); 52 const onBlockedImage = waitForErrorMessage(blockedDisplayContentText); 53 54 await onBlockedImage; 55 ok(true, "Blocked mixed display content error message is visible"); 56 57 const blockedMixedActiveContentMessage = await onBlockedIframe; 58 ok(true, "Blocked mixed active content error message is visible"); 59 60 info("Clicking on the Learn More link"); 61 let learnMoreLink = 62 blockedMixedActiveContentMessage.querySelector(".learn-more-link"); 63 let response = await simulateLinkClick(learnMoreLink); 64 is( 65 response.link, 66 LEARN_MORE_URI, 67 `Clicking the provided link opens ${response.link}` 68 ); 69 70 info("Test disabling mixed content protection"); 71 72 const { gIdentityHandler } = gBrowser.ownerGlobal; 73 ok( 74 gIdentityHandler._identityBox.classList.contains("mixedActiveBlocked"), 75 "Mixed Active Content state appeared on identity box" 76 ); 77 78 // Disabe mixed content protection. 79 await SpecialPowers.pushPrefEnv({ 80 set: [ 81 ["security.mixed_content.block_active_content", false], 82 ["security.mixed_content.block_display_content", false], 83 ["security.mixed_content.upgrade_display_content", false], 84 ], 85 }); 86 87 const waitForWarningMessage = text => 88 waitFor(() => findWarningMessage(hud, text), undefined, 100); 89 90 const onMixedActiveContent = waitForWarningMessage(activeContentText); 91 const onMixedDisplayContent = waitForWarningMessage(displayContentText); 92 93 gBrowser.reload(); 94 95 await onMixedDisplayContent; 96 ok(true, "Mixed display content warning message is visible"); 97 98 const mixedActiveContentMessage = await onMixedActiveContent; 99 ok(true, "Mixed active content warning message is visible"); 100 101 info("Clicking on the Learn More link"); 102 learnMoreLink = mixedActiveContentMessage.querySelector(".learn-more-link"); 103 response = await simulateLinkClick(learnMoreLink); 104 is( 105 response.link, 106 LEARN_MORE_URI, 107 `Clicking the provided link opens ${response.link}` 108 ); 109 });