michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: /* Tests that errors about invalid HSTS security headers are logged michael@0: * to the web console */ michael@0: const TEST_URI = "https://example.com/browser/browser/devtools/webconsole/test/test-bug-846918-hsts-invalid-headers.html"; michael@0: const HSTS_INVALID_HEADER_MSG = "The site specified an invalid Strict-Transport-Security header."; michael@0: const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Security/HTTP_Strict_Transport_Security"; michael@0: michael@0: function test() 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 testHSTSErrorLogged (hud) { michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [ michael@0: { michael@0: name: "Invalid HSTS header error displayed successfully", michael@0: text: HSTS_INVALID_HEADER_MSG, michael@0: category: CATEGORY_SECURITY, michael@0: severity: SEVERITY_WARNING, michael@0: objects: true, michael@0: }, michael@0: ], michael@0: }).then((results) => testClickOpenNewTab(hud, results)); michael@0: }); michael@0: }, true); michael@0: } michael@0: michael@0: function testClickOpenNewTab(hud, results) { michael@0: let warningNode = results[0].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: finishTest(); michael@0: }