1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_block_mixedcontent_securityerrors.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// The test loads a web page with mixed active and display content 1.8 +// on it while the "block mixed content" settings are _on_. 1.9 +// It then checks that the blocked mixed content warning messages 1.10 +// are logged to the console and have the correct "Learn More" 1.11 +// url appended to them. After the first test finishes, it invokes 1.12 +// a second test that overrides the mixed content blocker settings 1.13 +// by clicking on the doorhanger shield and validates that the 1.14 +// appropriate messages are logged to console. 1.15 +// Bug 875456 - Log mixed content messages from the Mixed Content 1.16 +// Blocker to the Security Pane in the Web Console 1.17 + 1.18 +const TEST_URI = "https://example.com/browser/browser/devtools/webconsole/test/test-mixedcontent-securityerrors.html"; 1.19 +const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Security/MixedContent"; 1.20 + 1.21 +function test() 1.22 +{ 1.23 + SpecialPowers.pushPrefEnv({"set": [["security.mixed_content.block_active_content", true], 1.24 + ["security.mixed_content.block_display_content", true]]}, blockMixedContentTest1); 1.25 +} 1.26 + 1.27 +function blockMixedContentTest1() 1.28 +{ 1.29 + addTab(TEST_URI); 1.30 + browser.addEventListener("load", function onLoad(aEvent) { 1.31 + browser.removeEventListener(aEvent.type, onLoad, true); 1.32 + openConsole(null, function testSecurityErrorLogged (hud) { 1.33 + waitForMessages({ 1.34 + webconsole: hud, 1.35 + messages: [ 1.36 + { 1.37 + name: "Logged blocking mixed active content", 1.38 + text: "Blocked loading mixed active content \"http://example.com/\"", 1.39 + category: CATEGORY_SECURITY, 1.40 + severity: SEVERITY_ERROR, 1.41 + objects: true, 1.42 + }, 1.43 + { 1.44 + name: "Logged blocking mixed passive content - image", 1.45 + text: "Blocked loading mixed active content \"http://example.com/\"", 1.46 + category: CATEGORY_SECURITY, 1.47 + severity: SEVERITY_ERROR, 1.48 + objects: true, 1.49 + }, 1.50 + ], 1.51 + }).then(([result]) => { 1.52 + testClickOpenNewTab(hud, result); 1.53 + // Call the second (MCB override) test. 1.54 + mixedContentOverrideTest2(hud); 1.55 + }); 1.56 + }); 1.57 + }, true); 1.58 +} 1.59 + 1.60 +function mixedContentOverrideTest2(hud) 1.61 +{ 1.62 + var notification = PopupNotifications.getNotification("mixed-content-blocked", browser); 1.63 + ok(notification, "Mixed Content Doorhanger didn't appear"); 1.64 + // Click on the doorhanger. 1.65 + notification.secondaryActions[0].callback(); 1.66 + 1.67 + waitForMessages({ 1.68 + webconsole: hud, 1.69 + messages: [ 1.70 + { 1.71 + name: "Logged blocking mixed active content", 1.72 + text: "Loading mixed (insecure) active content on a secure"+ 1.73 + " page \"http://example.com/\"", 1.74 + category: CATEGORY_SECURITY, 1.75 + severity: SEVERITY_WARNING, 1.76 + objects: true, 1.77 + }, 1.78 + { 1.79 + name: "Logged blocking mixed passive content - image", 1.80 + text: "Loading mixed (insecure) display content on a secure page"+ 1.81 + " \"http://example.com/tests/image/test/mochitest/blue.png\"", 1.82 + category: CATEGORY_SECURITY, 1.83 + severity: SEVERITY_WARNING, 1.84 + objects: true, 1.85 + }, 1.86 + ], 1.87 + }).then(([result]) => { 1.88 + testClickOpenNewTab(hud, result); 1.89 + finishTest(); 1.90 + }); 1.91 +} 1.92 + 1.93 +function testClickOpenNewTab(hud, match) { 1.94 + let warningNode = match.clickableElements[0]; 1.95 + ok(warningNode, "link element"); 1.96 + ok(warningNode.classList.contains("learn-more-link"), "link class name"); 1.97 + 1.98 + // Invoke the click event and check if a new tab would 1.99 + // open to the correct page. 1.100 + let linkOpened = false; 1.101 + let oldOpenUILinkIn = window.openUILinkIn; 1.102 + window.openUILinkIn = function(aLink) { 1.103 + if (aLink == LEARN_MORE_URI) { 1.104 + linkOpened = true; 1.105 + } 1.106 + } 1.107 + 1.108 + EventUtils.synthesizeMouse(warningNode, 2, 2, {}, 1.109 + warningNode.ownerDocument.defaultView); 1.110 + ok(linkOpened, "Clicking the Learn More Warning node opens the desired page"); 1.111 + window.openUILinkIn = oldOpenUILinkIn; 1.112 + 1.113 +}