tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_net_header-docs.js (1763B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests if "Learn More" links are correctly displayed
      8 * next to headers.
      9 */
     10 add_task(async function testHeadersLearnMoreLink() {
     11  const { tab, monitor } = await initNetMonitor(POST_DATA_URL, {
     12    requestCount: 1,
     13  });
     14  const { document, store, windowRequire } = monitor.panelWin;
     15  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     16 
     17  store.dispatch(Actions.batchEnable(false));
     18 
     19  await performRequests(monitor, tab, 2);
     20 
     21  // Open Headers panel for the customized request sent by html_post-data-test-page.html.
     22  EventUtils.sendMouseEvent(
     23    { type: "mousedown" },
     24    document.querySelectorAll(".request-list-item")[1]
     25  );
     26 
     27  await waitForDOMIfNeeded(document, "#responseHeaders, #requestHeaders", 2);
     28 
     29  testShowLearnMore(document);
     30 
     31  await teardown(monitor);
     32 });
     33 
     34 /*
     35 * Tests that a "Learn More" button is only shown if
     36 * and only if a header is documented in MDN.
     37 */
     38 function testShowLearnMore(document) {
     39  const {
     40    getHeadersURL,
     41  } = require("resource://devtools/client/netmonitor/src/utils/doc-utils.js");
     42 
     43  const headerRows = document.querySelectorAll(
     44    ".properties-view .treeRow.stringRow"
     45  );
     46  Assert.greater(headerRows.length, 0);
     47 
     48  for (const rowEl of headerRows) {
     49    const headerName = rowEl.querySelectorAll(".treeLabelCell .treeLabel")[0]
     50      .textContent;
     51    const headerDocURL = getHeadersURL(headerName);
     52    const learnMoreEl = rowEl.querySelectorAll(
     53      ".treeValueCell .learn-more-link"
     54    );
     55    Assert.equal(
     56      learnMoreEl.length,
     57      headerDocURL ? 1 : 0,
     58      'Only a documented header should include a "Learn More" button'
     59    );
     60  }
     61 }