tor-browser

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

browser_net_data_uri.js (3984B)


      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 that navigation request to a data uri is correctly logged in the
      8 * network monitor.
      9 */
     10 add_task(async function test_navigation_to_data_uri() {
     11  const URL = "data:text/html,Hello from data-url!";
     12  const { monitor } = await initNetMonitor(URL, {
     13    requestCount: 1,
     14    waitForLoad: false,
     15  });
     16  info("Starting test... ");
     17 
     18  const { document, store, windowRequire } = monitor.panelWin;
     19  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     20 
     21  store.dispatch(Actions.batchEnable(false));
     22 
     23  const wait = waitForNetworkEvents(monitor, 1);
     24  reloadBrowser({ waitForLoad: false });
     25  await wait;
     26 
     27  const firstItem = document.querySelectorAll(".request-list-item")[0];
     28 
     29  is(
     30    firstItem.querySelector(".requests-list-url").innerText,
     31    URL,
     32    "The url in the displayed request is correct"
     33  );
     34  is(
     35    firstItem.querySelector(".requests-list-scheme").innerText,
     36    "data",
     37    "The scheme in the displayed request is correct"
     38  );
     39  is(
     40    firstItem.querySelector(".requests-list-file").innerText,
     41    URL,
     42    "The file in the displayed request is correct"
     43  );
     44  ok(hasValidSize(firstItem), "The request shows a valid size");
     45 
     46  await teardown(monitor);
     47 });
     48 
     49 /**
     50 * Tests that requests to data URIs made from a content page are logged in the
     51 * network monitor.
     52 */
     53 add_task(async function test_content_request_to_data_uri() {
     54  const IMAGE_URL =
     55    "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
     56  const URL = `https://example.com/document-builder.sjs?html=
     57  <h1>Test page for content data uri request</h1>`;
     58 
     59  const { monitor, tab } = await initNetMonitor(URL, {
     60    requestCount: 1,
     61    waitForLoad: false,
     62  });
     63  info("Starting test... ");
     64 
     65  const { document, store, windowRequire } = monitor.panelWin;
     66  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     67 
     68  store.dispatch(Actions.batchEnable(false));
     69 
     70  let onNetworkEvents = waitForNetworkEvents(monitor, 1);
     71  reloadBrowser({ waitForLoad: false });
     72  await onNetworkEvents;
     73 
     74  info("Load an image in content with a data URI");
     75  onNetworkEvents = waitForNetworkEvents(monitor, 1);
     76  await SpecialPowers.spawn(tab.linkedBrowser, [IMAGE_URL], imageURL => {
     77    const img = content.document.createElement("img");
     78    img.src = imageURL;
     79    content.document.body.appendChild(img);
     80  });
     81  await onNetworkEvents;
     82 
     83  const firstItem = document.querySelectorAll(".request-list-item")[1];
     84 
     85  is(
     86    firstItem.querySelector(".requests-list-url").innerText,
     87    IMAGE_URL,
     88    "The url in the displayed request is correct"
     89  );
     90  is(
     91    firstItem.querySelector(".requests-list-scheme").innerText,
     92    "data",
     93    "The scheme in the displayed request is correct"
     94  );
     95  is(
     96    firstItem.querySelector(".requests-list-file").innerText,
     97    IMAGE_URL,
     98    "The file in the displayed request is correct"
     99  );
    100  ok(hasValidSize(firstItem), "The request shows a valid size");
    101 
    102  info("Check that image details are properly displayed in the response panel");
    103  const waitDOM = waitForDOM(document, "#response-panel .response-image");
    104  store.dispatch(Actions.selectRequestByIndex(1));
    105  document.querySelector("#response-tab").click();
    106  const [imageNode] = await waitDOM;
    107 
    108  // Wait for the image to load.
    109  await once(imageNode, "load");
    110 
    111  const [name, dimensions, mime] = document.querySelectorAll(
    112    ".response-image-box .tabpanel-summary-value"
    113  );
    114 
    115  // Bug 1975453: Name is truncated to yH5BAEAAAAALAAAAAABAAEAAAIBRAA7.
    116  todo_is(
    117    name.textContent,
    118    "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
    119    "The image name matches the base 64 string"
    120  );
    121  is(mime.textContent, "image/gif", "The image mime info is image/gif");
    122  is(
    123    dimensions.textContent,
    124    "1" + " \u00D7 " + "1",
    125    "The image dimensions are correct"
    126  );
    127 
    128  await teardown(monitor);
    129 });