1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_846918_hsts_invalid-headers.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 + /* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 +/* Tests that errors about invalid HSTS security headers are logged 1.7 + * to the web console */ 1.8 +const TEST_URI = "https://example.com/browser/browser/devtools/webconsole/test/test-bug-846918-hsts-invalid-headers.html"; 1.9 +const HSTS_INVALID_HEADER_MSG = "The site specified an invalid Strict-Transport-Security header."; 1.10 +const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Security/HTTP_Strict_Transport_Security"; 1.11 + 1.12 +function test() 1.13 +{ 1.14 + addTab(TEST_URI); 1.15 + browser.addEventListener("load", function onLoad(aEvent) { 1.16 + browser.removeEventListener(aEvent.type, onLoad, true); 1.17 + openConsole(null, function testHSTSErrorLogged (hud) { 1.18 + waitForMessages({ 1.19 + webconsole: hud, 1.20 + messages: [ 1.21 + { 1.22 + name: "Invalid HSTS header error displayed successfully", 1.23 + text: HSTS_INVALID_HEADER_MSG, 1.24 + category: CATEGORY_SECURITY, 1.25 + severity: SEVERITY_WARNING, 1.26 + objects: true, 1.27 + }, 1.28 + ], 1.29 + }).then((results) => testClickOpenNewTab(hud, results)); 1.30 + }); 1.31 + }, true); 1.32 +} 1.33 + 1.34 +function testClickOpenNewTab(hud, results) { 1.35 + let warningNode = results[0].clickableElements[0]; 1.36 + ok(warningNode, "link element"); 1.37 + ok(warningNode.classList.contains("learn-more-link"), "link class name"); 1.38 + 1.39 + // Invoke the click event and check if a new tab would 1.40 + // open to the correct page. 1.41 + let linkOpened = false; 1.42 + let oldOpenUILinkIn = window.openUILinkIn; 1.43 + window.openUILinkIn = function(aLink) { 1.44 + if (aLink == LEARN_MORE_URI) { 1.45 + linkOpened = true; 1.46 + } 1.47 + } 1.48 + 1.49 + EventUtils.synthesizeMouse(warningNode, 2, 2, {}, 1.50 + warningNode.ownerDocument.defaultView); 1.51 + ok(linkOpened, "Clicking the Learn More Warning node opens the desired page"); 1.52 + window.openUILinkIn = oldOpenUILinkIn; 1.53 + 1.54 + finishTest(); 1.55 +}