|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 /* Tests that errors about invalid HSTS security headers are logged |
|
4 * to the web console */ |
|
5 const TEST_URI = "https://example.com/browser/browser/devtools/webconsole/test/test-bug-846918-hsts-invalid-headers.html"; |
|
6 const HSTS_INVALID_HEADER_MSG = "The site specified an invalid Strict-Transport-Security header."; |
|
7 const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Security/HTTP_Strict_Transport_Security"; |
|
8 |
|
9 function test() |
|
10 { |
|
11 addTab(TEST_URI); |
|
12 browser.addEventListener("load", function onLoad(aEvent) { |
|
13 browser.removeEventListener(aEvent.type, onLoad, true); |
|
14 openConsole(null, function testHSTSErrorLogged (hud) { |
|
15 waitForMessages({ |
|
16 webconsole: hud, |
|
17 messages: [ |
|
18 { |
|
19 name: "Invalid HSTS header error displayed successfully", |
|
20 text: HSTS_INVALID_HEADER_MSG, |
|
21 category: CATEGORY_SECURITY, |
|
22 severity: SEVERITY_WARNING, |
|
23 objects: true, |
|
24 }, |
|
25 ], |
|
26 }).then((results) => testClickOpenNewTab(hud, results)); |
|
27 }); |
|
28 }, true); |
|
29 } |
|
30 |
|
31 function testClickOpenNewTab(hud, results) { |
|
32 let warningNode = results[0].clickableElements[0]; |
|
33 ok(warningNode, "link element"); |
|
34 ok(warningNode.classList.contains("learn-more-link"), "link class name"); |
|
35 |
|
36 // Invoke the click event and check if a new tab would |
|
37 // open to the correct page. |
|
38 let linkOpened = false; |
|
39 let oldOpenUILinkIn = window.openUILinkIn; |
|
40 window.openUILinkIn = function(aLink) { |
|
41 if (aLink == LEARN_MORE_URI) { |
|
42 linkOpened = true; |
|
43 } |
|
44 } |
|
45 |
|
46 EventUtils.synthesizeMouse(warningNode, 2, 2, {}, |
|
47 warningNode.ownerDocument.defaultView); |
|
48 ok(linkOpened, "Clicking the Learn More Warning node opens the desired page"); |
|
49 window.openUILinkIn = oldOpenUILinkIn; |
|
50 |
|
51 finishTest(); |
|
52 } |