michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // The test loads a web page with mixed active and display content michael@0: // on it while the "block mixed content" settings are _on_. michael@0: // It then checks that the blocked mixed content warning messages michael@0: // are logged to the console and have the correct "Learn More" michael@0: // url appended to them. After the first test finishes, it invokes michael@0: // a second test that overrides the mixed content blocker settings michael@0: // by clicking on the doorhanger shield and validates that the michael@0: // appropriate messages are logged to console. michael@0: // Bug 875456 - Log mixed content messages from the Mixed Content michael@0: // Blocker to the Security Pane in the Web Console michael@0: michael@0: const TEST_URI = "https://example.com/browser/browser/devtools/webconsole/test/test-mixedcontent-securityerrors.html"; michael@0: const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Security/MixedContent"; michael@0: michael@0: function test() michael@0: { michael@0: SpecialPowers.pushPrefEnv({"set": [["security.mixed_content.block_active_content", true], michael@0: ["security.mixed_content.block_display_content", true]]}, blockMixedContentTest1); michael@0: } michael@0: michael@0: function blockMixedContentTest1() michael@0: { michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad(aEvent) { michael@0: browser.removeEventListener(aEvent.type, onLoad, true); michael@0: openConsole(null, function testSecurityErrorLogged (hud) { michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [ michael@0: { michael@0: name: "Logged blocking mixed active content", michael@0: text: "Blocked loading mixed active content \"http://example.com/\"", michael@0: category: CATEGORY_SECURITY, michael@0: severity: SEVERITY_ERROR, michael@0: objects: true, michael@0: }, michael@0: { michael@0: name: "Logged blocking mixed passive content - image", michael@0: text: "Blocked loading mixed active content \"http://example.com/\"", michael@0: category: CATEGORY_SECURITY, michael@0: severity: SEVERITY_ERROR, michael@0: objects: true, michael@0: }, michael@0: ], michael@0: }).then(([result]) => { michael@0: testClickOpenNewTab(hud, result); michael@0: // Call the second (MCB override) test. michael@0: mixedContentOverrideTest2(hud); michael@0: }); michael@0: }); michael@0: }, true); michael@0: } michael@0: michael@0: function mixedContentOverrideTest2(hud) michael@0: { michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", browser); michael@0: ok(notification, "Mixed Content Doorhanger didn't appear"); michael@0: // Click on the doorhanger. michael@0: notification.secondaryActions[0].callback(); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [ michael@0: { michael@0: name: "Logged blocking mixed active content", michael@0: text: "Loading mixed (insecure) active content on a secure"+ michael@0: " page \"http://example.com/\"", michael@0: category: CATEGORY_SECURITY, michael@0: severity: SEVERITY_WARNING, michael@0: objects: true, michael@0: }, michael@0: { michael@0: name: "Logged blocking mixed passive content - image", michael@0: text: "Loading mixed (insecure) display content on a secure page"+ michael@0: " \"http://example.com/tests/image/test/mochitest/blue.png\"", michael@0: category: CATEGORY_SECURITY, michael@0: severity: SEVERITY_WARNING, michael@0: objects: true, michael@0: }, michael@0: ], michael@0: }).then(([result]) => { michael@0: testClickOpenNewTab(hud, result); michael@0: finishTest(); michael@0: }); michael@0: } michael@0: michael@0: function testClickOpenNewTab(hud, match) { michael@0: let warningNode = match.clickableElements[0]; michael@0: ok(warningNode, "link element"); michael@0: ok(warningNode.classList.contains("learn-more-link"), "link class name"); michael@0: michael@0: // Invoke the click event and check if a new tab would michael@0: // open to the correct page. michael@0: let linkOpened = false; michael@0: let oldOpenUILinkIn = window.openUILinkIn; michael@0: window.openUILinkIn = function(aLink) { michael@0: if (aLink == LEARN_MORE_URI) { michael@0: linkOpened = true; michael@0: } michael@0: } michael@0: michael@0: EventUtils.synthesizeMouse(warningNode, 2, 2, {}, michael@0: warningNode.ownerDocument.defaultView); michael@0: ok(linkOpened, "Clicking the Learn More Warning node opens the desired page"); michael@0: window.openUILinkIn = oldOpenUILinkIn; michael@0: michael@0: }