1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_allow_mixedcontent_securityerrors.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 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 _off_. 1.9 +// It then checks that the loading mixed content warning messages 1.10 +// are logged to the console and have the correct "Learn More" 1.11 +// url appended to them. 1.12 +// Bug 875456 - Log mixed content messages from the Mixed Content 1.13 +// Blocker to the Security Pane in the Web Console 1.14 + 1.15 +const TEST_URI = "https://example.com/browser/browser/devtools/webconsole/test/test-mixedcontent-securityerrors.html"; 1.16 +const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Security/MixedContent"; 1.17 + 1.18 +function test() 1.19 +{ 1.20 + SpecialPowers.pushPrefEnv({"set": 1.21 + [["security.mixed_content.block_active_content", false], 1.22 + ["security.mixed_content.block_display_content", false] 1.23 + ]}, loadingMixedContentTest); 1.24 +} 1.25 + 1.26 +function loadingMixedContentTest() 1.27 +{ 1.28 + addTab(TEST_URI); 1.29 + browser.addEventListener("load", function onLoad(aEvent) { 1.30 + browser.removeEventListener(aEvent.type, onLoad, true); 1.31 + openConsole(null, function testSecurityErrorLogged (hud) { 1.32 + waitForMessages({ 1.33 + webconsole: hud, 1.34 + messages: [ 1.35 + { 1.36 + name: "Logged mixed active content", 1.37 + text: "Loading mixed (insecure) active content on a secure page \"http://example.com/\"", 1.38 + category: CATEGORY_SECURITY, 1.39 + severity: SEVERITY_WARNING, 1.40 + objects: true, 1.41 + }, 1.42 + { 1.43 + name: "Logged mixed passive content - image", 1.44 + text: "Loading mixed (insecure) display content on a secure page \"http://example.com/tests/image/test/mochitest/blue.png\"", 1.45 + category: CATEGORY_SECURITY, 1.46 + severity: SEVERITY_WARNING, 1.47 + objects: true, 1.48 + }, 1.49 + ], 1.50 + }).then((results) => testClickOpenNewTab(hud, results)); 1.51 + }); 1.52 + }, true); 1.53 +} 1.54 + 1.55 +function testClickOpenNewTab(hud, results) { 1.56 + let warningNode = results[0].clickableElements[0]; 1.57 + ok(warningNode, "link element"); 1.58 + ok(warningNode.classList.contains("learn-more-link"), "link class name"); 1.59 + 1.60 + // Invoke the click event and check if a new tab would open to the correct page. 1.61 + let linkOpened = false; 1.62 + let oldOpenUILinkIn = window.openUILinkIn; 1.63 + window.openUILinkIn = function(aLink) { 1.64 + if (aLink == LEARN_MORE_URI) { 1.65 + linkOpened = true; 1.66 + } 1.67 + } 1.68 + 1.69 + EventUtils.synthesizeMouse(warningNode, 2, 2, {}, 1.70 + warningNode.ownerDocument.defaultView); 1.71 + ok(linkOpened, "Clicking the Learn More Warning node opens the desired page"); 1.72 + window.openUILinkIn = oldOpenUILinkIn; 1.73 + 1.74 + finishTest(); 1.75 +}