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