Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // The test loads a web page with mixed active and display content |
michael@0 | 5 | // on it while the "block mixed content" settings are _on_. |
michael@0 | 6 | // It then checks that the blocked mixed content warning messages |
michael@0 | 7 | // are logged to the console and have the correct "Learn More" |
michael@0 | 8 | // url appended to them. After the first test finishes, it invokes |
michael@0 | 9 | // a second test that overrides the mixed content blocker settings |
michael@0 | 10 | // by clicking on the doorhanger shield and validates that the |
michael@0 | 11 | // appropriate messages are logged to console. |
michael@0 | 12 | // Bug 875456 - Log mixed content messages from the Mixed Content |
michael@0 | 13 | // Blocker to the Security Pane in the Web Console |
michael@0 | 14 | |
michael@0 | 15 | const TEST_URI = "https://example.com/browser/browser/devtools/webconsole/test/test-mixedcontent-securityerrors.html"; |
michael@0 | 16 | const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Security/MixedContent"; |
michael@0 | 17 | |
michael@0 | 18 | function test() |
michael@0 | 19 | { |
michael@0 | 20 | SpecialPowers.pushPrefEnv({"set": [["security.mixed_content.block_active_content", true], |
michael@0 | 21 | ["security.mixed_content.block_display_content", true]]}, blockMixedContentTest1); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function blockMixedContentTest1() |
michael@0 | 25 | { |
michael@0 | 26 | addTab(TEST_URI); |
michael@0 | 27 | browser.addEventListener("load", function onLoad(aEvent) { |
michael@0 | 28 | browser.removeEventListener(aEvent.type, onLoad, true); |
michael@0 | 29 | openConsole(null, function testSecurityErrorLogged (hud) { |
michael@0 | 30 | waitForMessages({ |
michael@0 | 31 | webconsole: hud, |
michael@0 | 32 | messages: [ |
michael@0 | 33 | { |
michael@0 | 34 | name: "Logged blocking mixed active content", |
michael@0 | 35 | text: "Blocked loading mixed active content \"http://example.com/\"", |
michael@0 | 36 | category: CATEGORY_SECURITY, |
michael@0 | 37 | severity: SEVERITY_ERROR, |
michael@0 | 38 | objects: true, |
michael@0 | 39 | }, |
michael@0 | 40 | { |
michael@0 | 41 | name: "Logged blocking mixed passive content - image", |
michael@0 | 42 | text: "Blocked loading mixed active content \"http://example.com/\"", |
michael@0 | 43 | category: CATEGORY_SECURITY, |
michael@0 | 44 | severity: SEVERITY_ERROR, |
michael@0 | 45 | objects: true, |
michael@0 | 46 | }, |
michael@0 | 47 | ], |
michael@0 | 48 | }).then(([result]) => { |
michael@0 | 49 | testClickOpenNewTab(hud, result); |
michael@0 | 50 | // Call the second (MCB override) test. |
michael@0 | 51 | mixedContentOverrideTest2(hud); |
michael@0 | 52 | }); |
michael@0 | 53 | }); |
michael@0 | 54 | }, true); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function mixedContentOverrideTest2(hud) |
michael@0 | 58 | { |
michael@0 | 59 | var notification = PopupNotifications.getNotification("mixed-content-blocked", browser); |
michael@0 | 60 | ok(notification, "Mixed Content Doorhanger didn't appear"); |
michael@0 | 61 | // Click on the doorhanger. |
michael@0 | 62 | notification.secondaryActions[0].callback(); |
michael@0 | 63 | |
michael@0 | 64 | waitForMessages({ |
michael@0 | 65 | webconsole: hud, |
michael@0 | 66 | messages: [ |
michael@0 | 67 | { |
michael@0 | 68 | name: "Logged blocking mixed active content", |
michael@0 | 69 | text: "Loading mixed (insecure) active content on a secure"+ |
michael@0 | 70 | " page \"http://example.com/\"", |
michael@0 | 71 | category: CATEGORY_SECURITY, |
michael@0 | 72 | severity: SEVERITY_WARNING, |
michael@0 | 73 | objects: true, |
michael@0 | 74 | }, |
michael@0 | 75 | { |
michael@0 | 76 | name: "Logged blocking mixed passive content - image", |
michael@0 | 77 | text: "Loading mixed (insecure) display content on a secure page"+ |
michael@0 | 78 | " \"http://example.com/tests/image/test/mochitest/blue.png\"", |
michael@0 | 79 | category: CATEGORY_SECURITY, |
michael@0 | 80 | severity: SEVERITY_WARNING, |
michael@0 | 81 | objects: true, |
michael@0 | 82 | }, |
michael@0 | 83 | ], |
michael@0 | 84 | }).then(([result]) => { |
michael@0 | 85 | testClickOpenNewTab(hud, result); |
michael@0 | 86 | finishTest(); |
michael@0 | 87 | }); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function testClickOpenNewTab(hud, match) { |
michael@0 | 91 | let warningNode = match.clickableElements[0]; |
michael@0 | 92 | ok(warningNode, "link element"); |
michael@0 | 93 | ok(warningNode.classList.contains("learn-more-link"), "link class name"); |
michael@0 | 94 | |
michael@0 | 95 | // Invoke the click event and check if a new tab would |
michael@0 | 96 | // open to the correct page. |
michael@0 | 97 | let linkOpened = false; |
michael@0 | 98 | let oldOpenUILinkIn = window.openUILinkIn; |
michael@0 | 99 | window.openUILinkIn = function(aLink) { |
michael@0 | 100 | if (aLink == LEARN_MORE_URI) { |
michael@0 | 101 | linkOpened = true; |
michael@0 | 102 | } |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | EventUtils.synthesizeMouse(warningNode, 2, 2, {}, |
michael@0 | 106 | warningNode.ownerDocument.defaultView); |
michael@0 | 107 | ok(linkOpened, "Clicking the Learn More Warning node opens the desired page"); |
michael@0 | 108 | window.openUILinkIn = oldOpenUILinkIn; |
michael@0 | 109 | |
michael@0 | 110 | } |