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