tor-browser

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

browser_net_stylesheet_cache.js (2680B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test the stylesheet caches in the network monitor.
      7 add_task(async function () {
      8  const { monitor } = await initNetMonitor(STYLESHEET_CACHE_URL, {
      9    enableCache: true,
     10    requestCount: 1,
     11  });
     12  info("Starting test... ");
     13 
     14  const { document, store, windowRequire } = monitor.panelWin;
     15  const { getDisplayedRequests, getSortedRequests } = windowRequire(
     16    "devtools/client/netmonitor/src/selectors/index"
     17  );
     18  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     19  store.dispatch(Actions.batchEnable(false));
     20 
     21  const waitForEvents = waitForNetworkEvents(monitor, 2);
     22 
     23  BrowserTestUtils.startLoadingURIString(
     24    gBrowser.selectedBrowser,
     25    STYLESHEET_CACHE_URL
     26  );
     27  await waitForEvents;
     28 
     29  const requests = document.querySelectorAll(".request-list-item");
     30 
     31  is(requests.length, 2, "There should be 2 requests");
     32 
     33  const requestData = {
     34    uri: HTTPS_EXAMPLE_URL + "test-stylesheet.css",
     35    details: {
     36      status: 200,
     37      statusText: "OK (cached)",
     38      displayedStatus: "cached",
     39      type: "css",
     40      fullMimeType: "text/css",
     41    },
     42  };
     43 
     44  const cssIndex = 1;
     45  const request = requests[cssIndex];
     46 
     47  const requestsListStatus = request.querySelector(".status-code");
     48  EventUtils.sendMouseEvent({ type: "mouseover" }, requestsListStatus);
     49  await waitUntil(() => requestsListStatus.title);
     50 
     51  await verifyRequestItemTarget(
     52    document,
     53    getDisplayedRequests(store.getState()),
     54    getSortedRequests(store.getState())[cssIndex],
     55    "GET",
     56    requestData.uri,
     57    requestData.details
     58  );
     59 
     60  EventUtils.sendMouseEvent({ type: "mousedown" }, request);
     61 
     62  const wait = waitForDOM(document, "#responseHeaders");
     63  clickOnSidebarTab(document, "headers");
     64  await wait;
     65 
     66  const responseScope = document.querySelectorAll(
     67    "#headers-panel .accordion tr[id^='/responseHeaders']"
     68  );
     69 
     70  const responseHeaders = [
     71    {
     72      name: "connection",
     73      value: "close",
     74      index: 1,
     75    },
     76    {
     77      name: "content-length",
     78      value: "37",
     79      index: 2,
     80    },
     81    {
     82      name: "content-type",
     83      value: "text/css",
     84      index: 3,
     85    },
     86    {
     87      name: "server",
     88      value: "httpd.js",
     89      index: 6,
     90    },
     91  ];
     92  responseHeaders.forEach(header => {
     93    is(
     94      responseScope[header.index - 1].querySelector(".treeLabel").innerHTML,
     95      header.name,
     96      `${header.name} label`
     97    );
     98    is(
     99      responseScope[header.index - 1].querySelector(".objectBox").innerHTML,
    100      `${header.value}`,
    101      `${header.name} value`
    102    );
    103  });
    104 
    105  await teardown(monitor);
    106 });