tor-browser

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

browser_net_streaming-response.js (2543B)


      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 reponses from streaming content types (MPEG-DASH, HLS) are
      8 * displayed as XML or plain text
      9 */
     10 
     11 add_task(async function () {
     12  const { tab, monitor } = await initNetMonitor(CUSTOM_GET_URL, {
     13    requestCount: 1,
     14  });
     15 
     16  info("Starting test... ");
     17  const { document, store, windowRequire } = monitor.panelWin;
     18  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     19  const { getDisplayedRequests, getSortedRequests } = windowRequire(
     20    "devtools/client/netmonitor/src/selectors/index"
     21  );
     22 
     23  store.dispatch(Actions.batchEnable(false));
     24 
     25  const REQUESTS = [
     26    ["hls-m3u8", /^#EXTM3U/],
     27    ["mpeg-dash", /^<\?xml/],
     28  ];
     29 
     30  let wait = waitForNetworkEvents(monitor, REQUESTS.length);
     31  for (const [fmt] of REQUESTS) {
     32    const url = CONTENT_TYPE_SJS + "?fmt=" + fmt;
     33    await SpecialPowers.spawn(
     34      tab.linkedBrowser,
     35      [{ url }],
     36      async function (args) {
     37        content.wrappedJSObject.performRequests(1, args.url);
     38      }
     39    );
     40  }
     41  await wait;
     42 
     43  const requestItems = document.querySelectorAll(".request-list-item");
     44  for (const requestItem of requestItems) {
     45    requestItem.scrollIntoView();
     46    const requestsListStatus = requestItem.querySelector(".status-code");
     47    EventUtils.sendMouseEvent({ type: "mouseover" }, requestsListStatus);
     48    await waitUntil(() => requestsListStatus.title);
     49    await waitForDOMIfNeeded(requestItem, ".requests-list-timings-total");
     50  }
     51 
     52  for (const [i, [fmt]] of REQUESTS.entries()) {
     53    await verifyRequestItemTarget(
     54      document,
     55      getDisplayedRequests(store.getState()),
     56      getSortedRequests(store.getState())[i],
     57      "GET",
     58      CONTENT_TYPE_SJS + "?fmt=" + fmt,
     59      {
     60        status: 200,
     61        statusText: "OK",
     62      }
     63    );
     64  }
     65 
     66  wait = waitForDOM(document, "#response-panel");
     67  store.dispatch(Actions.toggleNetworkDetails());
     68  clickOnSidebarTab(document, "response");
     69  await wait;
     70 
     71  store.dispatch(Actions.selectRequest(null));
     72 
     73  await selectIndexAndWaitForSourceEditor(monitor, 0);
     74  // the hls-m3u8 part
     75  testEditorContent(REQUESTS[0]);
     76 
     77  await selectIndexAndWaitForSourceEditor(monitor, 1);
     78  // the mpeg-dash part
     79  testEditorContent(REQUESTS[1]);
     80 
     81  return teardown(monitor);
     82 
     83  function testEditorContent([fmt, textRe]) {
     84    ok(
     85      getCodeMirrorValue(monitor).match(textRe),
     86      "The text shown in the source editor for " + fmt + " is correct."
     87    );
     88  }
     89 });