browser/devtools/webconsole/test/browser_webconsole_bug_846918_hsts_invalid-headers.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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/ */
     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";
     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 }
    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");
    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   }
    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;
    51   finishTest();
    52 }

mercurial