tor-browser

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

browser_net_image_cache.js (2524B)


      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 image caches can be displayed in the network monitor
      8 */
      9 
     10 add_task(async function () {
     11  const { monitor } = await initNetMonitor(IMAGE_CACHE_URL, {
     12    enableCache: true,
     13    requestCount: 1,
     14  });
     15  info("Starting test... ");
     16 
     17  const { document, store, windowRequire } = monitor.panelWin;
     18  const { getDisplayedRequests, getSortedRequests } = windowRequire(
     19    "devtools/client/netmonitor/src/selectors/index"
     20  );
     21  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     22  store.dispatch(Actions.batchEnable(false));
     23 
     24  const waitForEvents = waitForNetworkEvents(monitor, 2);
     25 
     26  // Using `BrowserTestUtils.loadURI` instead of `navigateTo` because
     27  // `navigateTo` would use `gBrowser.reloadTab` to reload the tab
     28  // when the current uri is the same as the one that is going to navigate.
     29  // And the issue is that with `gBrowser.reloadTab`, `VALIDATE_ALWAYS`
     30  // flag will be applied to the loadgroup, such that the sub resources
     31  // are forced to be revalidated. So we use `BrowserTestUtils.loadURI` to
     32  // avoid having `VALIDATE_ALWAYS` applied.
     33  BrowserTestUtils.startLoadingURIString(
     34    gBrowser.selectedBrowser,
     35    IMAGE_CACHE_URL
     36  );
     37  await waitForEvents;
     38 
     39  const requests = document.querySelectorAll(".request-list-item");
     40 
     41  // Though there are 3 test-image.png images on the page, only 1 request
     42  // representing the images from the cache should be shown. Therefore we
     43  // expect 2 requests all together (1 for html_image-cache.html and 1 for
     44  // test-image.png)
     45  is(requests.length, 2, "There should be 2 requests");
     46 
     47  const requestData = {
     48    uri: HTTPS_EXAMPLE_URL + "test-image.png",
     49    details: {
     50      status: 200,
     51      statusText: "OK (cached)",
     52      displayedStatus: "cached",
     53      type: "png",
     54      fullMimeType: "image/png",
     55    },
     56  };
     57 
     58  for (let i = 1; i < requests.length; ++i) {
     59    const request = requests[i];
     60 
     61    // mouseover is needed for tooltips to show up.
     62    const requestsListStatus = request.querySelector(".status-code");
     63    EventUtils.sendMouseEvent({ type: "mouseover" }, requestsListStatus);
     64    await waitUntil(() => requestsListStatus.title);
     65 
     66    await verifyRequestItemTarget(
     67      document,
     68      getDisplayedRequests(store.getState()),
     69      getSortedRequests(store.getState())[i],
     70      "GET",
     71      requestData.uri,
     72      requestData.details
     73    );
     74  }
     75  await teardown(monitor);
     76 });