tor-browser

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

browser_net_url-preview.js (5373B)


      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 the url preview expanded state is persisted across requests selections.
      8 */
      9 
     10 add_task(async function () {
     11  const { monitor, tab } = await initNetMonitor(PARAMS_URL, {
     12    requestCount: 1,
     13  });
     14 
     15  info("Starting test... ");
     16 
     17  const { document, store, windowRequire } = monitor.panelWin;
     18  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     19 
     20  store.dispatch(Actions.batchEnable(false));
     21 
     22  // Execute requests.
     23  await performRequests(monitor, tab, 12);
     24 
     25  let wait = waitForDOM(document, "#headers-panel .url-preview", 1);
     26  EventUtils.sendMouseEvent(
     27    { type: "mousedown" },
     28    document.querySelectorAll(".request-list-item")[0]
     29  );
     30  await wait;
     31 
     32  // Expand preview
     33  await toggleUrlPreview(true, monitor);
     34 
     35  // Select the second request
     36  wait = waitForDOM(document, "#headers-panel .url-preview", 1);
     37  EventUtils.sendMouseEvent(
     38    { type: "mousedown" },
     39    document.querySelectorAll(".request-list-item")[1]
     40  );
     41  await wait;
     42 
     43  // Test that the url is still expanded
     44  const noOfVisibleRowsAfterExpand = document.querySelectorAll(
     45    "#headers-panel .url-preview tr.treeRow"
     46  ).length;
     47  Assert.greater(
     48    noOfVisibleRowsAfterExpand,
     49    1,
     50    "The url preview should still be expanded."
     51  );
     52 
     53  // Collapse preview
     54  await toggleUrlPreview(false, monitor);
     55 
     56  // Select the third request
     57  wait = waitForDOM(document, "#headers-panel .url-preview", 1);
     58  EventUtils.sendMouseEvent(
     59    { type: "mousedown" },
     60    document.querySelectorAll(".request-list-item")[2]
     61  );
     62  await wait;
     63 
     64  // Test that the url is still collapsed
     65  const noOfVisibleRowsAfterCollapse = document.querySelectorAll(
     66    "#headers-panel .url-preview tr.treeRow"
     67  ).length;
     68  Assert.equal(
     69    noOfVisibleRowsAfterCollapse,
     70    1,
     71    "The url preview should still be collapsed."
     72  );
     73 
     74  return teardown(monitor);
     75 });
     76 
     77 /**
     78 *  Checks if the query parameter arrays are formatted as we expected.
     79 */
     80 
     81 add_task(async function () {
     82  const { monitor } = await initNetMonitor(PARAMS_URL, {
     83    requestCount: 1,
     84  });
     85 
     86  info("Starting test... ");
     87 
     88  const { document, store, windowRequire } = monitor.panelWin;
     89  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     90 
     91  store.dispatch(Actions.batchEnable(false));
     92 
     93  const netWorkEvent = waitForNetworkEvents(monitor, 3);
     94  await performRequestsInContent([
     95    // URL with same parameter name with different values
     96    { url: "sjs_content-type-test-server.sjs?a=3&a=45&a=60" },
     97 
     98    // URL with mix of different parameter names
     99    { url: "sjs_content-type-test-server.sjs?x=5&a=3&a=4&a=3&b=3" },
    100 
    101    // URL contains a parameter with `query` as the name. This makes sure
    102    // there is no conflict with the query property on the Url Object in the
    103    // UrlPreview
    104    { url: "sjs_content-type-test-server.sjs?x=5&a=3&a=4&a=3&query=3" },
    105 
    106    // URL contains a paramter with `__proto__` as the name. This makes sure
    107    // there is no conflict with the prototype chain of the JS object.
    108    { url: "sjs_content-type-test-server.sjs?__proto__=5" },
    109  ]);
    110  await netWorkEvent;
    111 
    112  let urlPreview = waitForDOM(document, "#headers-panel .url-preview", 1);
    113  EventUtils.sendMouseEvent(
    114    { type: "mousedown" },
    115    document.querySelectorAll(".request-list-item")[0]
    116  );
    117  let urlPreviewValue = (await urlPreview)[0].textContent;
    118 
    119  ok(
    120    urlPreviewValue.endsWith("?a=3&a=45&a=60"),
    121    "The parameters in the url preview match."
    122  );
    123 
    124  urlPreview = waitForDOM(document, "#headers-panel .url-preview", 1);
    125  EventUtils.sendMouseEvent(
    126    { type: "mousedown" },
    127    document.querySelectorAll(".request-list-item")[1]
    128  );
    129 
    130  urlPreviewValue = (await urlPreview)[0].textContent;
    131  ok(
    132    urlPreviewValue.endsWith("?x=5&a=3&a=4&a=3&b=3"),
    133    "The parameters in the url preview match."
    134  );
    135 
    136  urlPreview = waitForDOM(document, "#headers-panel .url-preview", 1);
    137  EventUtils.sendMouseEvent(
    138    { type: "mousedown" },
    139    document.querySelectorAll(".request-list-item")[2]
    140  );
    141 
    142  urlPreviewValue = (await urlPreview)[0].textContent;
    143  ok(
    144    urlPreviewValue.endsWith("?x=5&a=3&a=4&a=3&query=3"),
    145    "The parameters in the url preview match."
    146  );
    147 
    148  // Expand preview
    149  await toggleUrlPreview(true, monitor);
    150 
    151  // Check if the expanded preview contains the "query" parameter
    152  is(
    153    document.querySelector(
    154      "#headers-panel .url-preview tr#\\/GET\\/query\\/query .treeLabelCell"
    155    ).textContent,
    156    "query",
    157    "Contains the query parameter"
    158  );
    159 
    160  // Collapse preview
    161  await toggleUrlPreview(false, monitor);
    162 
    163  urlPreview = waitForDOM(document, "#headers-panel .url-preview", 1);
    164  EventUtils.sendMouseEvent(
    165    { type: "mousedown" },
    166    document.querySelectorAll(".request-list-item")[3]
    167  );
    168 
    169  urlPreviewValue = (await urlPreview)[0].textContent;
    170  ok(
    171    urlPreviewValue.endsWith("?__proto__=5"),
    172    "The parameters in the url preview match."
    173  );
    174 
    175  // Expand preview
    176  await toggleUrlPreview(true, monitor);
    177 
    178  // Check if the expanded preview contains the "__proto__" parameter
    179  is(
    180    document.querySelector(
    181      "#headers-panel .url-preview tr#\\/GET\\/query\\/__proto__ .treeLabelCell"
    182    ).textContent,
    183    "__proto__",
    184    "Contains the __proto__ parameter"
    185  );
    186 
    187  return teardown(monitor);
    188 });