tor-browser

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

browser_net_details_copy.js (8241B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 /**
      6 * Test that the URL Preview can be copied
      7 */
      8 add_task(async function () {
      9  const { monitor } = await initNetMonitor(SIMPLE_URL, {
     10    requestCount: 1,
     11  });
     12 
     13  info("Starting the url preview copy test... ");
     14 
     15  const { document, store, windowRequire } = monitor.panelWin;
     16  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     17 
     18  store.dispatch(Actions.batchEnable(false));
     19 
     20  const wait = waitForNetworkEvents(monitor, 1);
     21  await reloadBrowser();
     22  await wait;
     23 
     24  store.dispatch(Actions.toggleNetworkDetails());
     25 
     26  await waitForDOM(document, "#headers-panel .url-preview", 1);
     27 
     28  const urlPreview = document.querySelector("#headers-panel .url-preview");
     29  const urlRow = urlPreview.querySelector(".objectRow");
     30 
     31  /* Test for copy value on the url */
     32  EventUtils.sendMouseEvent({ type: "contextmenu" }, urlRow);
     33  await waitForClipboardPromise(async function setup() {
     34    await selectContextMenuItem(
     35      monitor,
     36      "properties-view-context-menu-copyvalue"
     37    );
     38  }, "http://example.com/browser/devtools/client/netmonitor/test/html_simple-test-page.html");
     39 
     40  ok(true, "The copy value action put expected url string into clipboard");
     41 
     42  /* Test for copy all */
     43  EventUtils.sendMouseEvent({ type: "contextmenu" }, urlRow);
     44  const expected = JSON.stringify(
     45    {
     46      GET: {
     47        scheme: "http",
     48        host: "example.com",
     49        filename:
     50          "/browser/devtools/client/netmonitor/test/html_simple-test-page.html",
     51        remote: {
     52          Address: "127.0.0.1:8888",
     53        },
     54      },
     55    },
     56    null,
     57    "\t"
     58  );
     59  await waitForClipboardPromise(async function setup() {
     60    await selectContextMenuItem(
     61      monitor,
     62      "properties-view-context-menu-copyall"
     63    );
     64  }, expected);
     65 
     66  ok(true, "The copy all action put expected json data into clipboard");
     67 
     68  await teardown(monitor);
     69 });
     70 
     71 /**
     72 * Test that the Headers summary can be copied
     73 */
     74 
     75 add_task(async function () {
     76  const { monitor } = await initNetMonitor(SIMPLE_URL, {
     77    requestCount: 1,
     78  });
     79 
     80  info("Starting the headers summary copy test... ");
     81 
     82  const { document, store, windowRequire } = monitor.panelWin;
     83  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     84 
     85  store.dispatch(Actions.batchEnable(false));
     86 
     87  const wait = waitForNetworkEvents(monitor, 1);
     88  await reloadBrowser();
     89  await wait;
     90 
     91  store.dispatch(Actions.toggleNetworkDetails());
     92 
     93  await waitForDOM(document, "#headers-panel .summary", 1);
     94 
     95  const headersSummary = document.querySelector("#headers-panel .summary");
     96  const httpSummaryValue = headersSummary.querySelectorAll(
     97    ".tabpanel-summary-value"
     98  )[1];
     99 
    100  /* Test for copy value */
    101  EventUtils.sendMouseEvent({ type: "contextmenu" }, httpSummaryValue);
    102  await waitForClipboardPromise(async function setup() {
    103    await selectContextMenuItem(
    104      monitor,
    105      "headers-panel-context-menu-copyvalue"
    106    );
    107  }, "HTTP/1.1");
    108 
    109  ok(true, "The copy value action put expected text into clipboard");
    110 
    111  /* Test for copy all */
    112  EventUtils.sendMouseEvent({ type: "contextmenu" }, httpSummaryValue);
    113  const expected = JSON.stringify(
    114    {
    115      Status: "200OK",
    116      Version: "HTTP/1.1",
    117      Transferred: "650 B (465 B size)",
    118      "Request Priority": "Highest",
    119      "DNS Resolution": "System",
    120    },
    121    null,
    122    "\t"
    123  );
    124  await waitForClipboardPromise(async function setup() {
    125    await selectContextMenuItem(monitor, "headers-panel-context-menu-copyall");
    126  }, expected);
    127 
    128  ok(true, "The copy all action put expected json into clipboard");
    129 
    130  await teardown(monitor);
    131 });
    132 
    133 /**
    134 * Test if response JSON in PropertiesView can be copied
    135 */
    136 
    137 add_task(async function () {
    138  const { tab, monitor } = await initNetMonitor(
    139    JSON_BASIC_URL + "?name=nogrip",
    140    { requestCount: 1 }
    141  );
    142  info("Starting the json in properties view copy test... ");
    143 
    144  const { document, store, windowRequire } = monitor.panelWin;
    145  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
    146 
    147  store.dispatch(Actions.batchEnable(false));
    148 
    149  await performRequests(monitor, tab, 1);
    150 
    151  const onResponsePanelReady = waitForDOM(
    152    document,
    153    "#response-panel .treeTable"
    154  );
    155  store.dispatch(Actions.toggleNetworkDetails());
    156  clickOnSidebarTab(document, "response");
    157  await onResponsePanelReady;
    158 
    159  const responsePanel = document.querySelector("#response-panel");
    160 
    161  const objectRow = responsePanel.querySelectorAll(".objectRow")[0];
    162 
    163  // Open the node to get the string
    164  const waitOpenNode = waitForDOM(document, ".stringRow");
    165  const toggleButton = objectRow.querySelector("td span.treeIcon");
    166  toggleButton.click();
    167  await waitOpenNode;
    168  const stringRow = responsePanel.querySelectorAll(".stringRow")[0];
    169 
    170  /* Test for copy value on an object */
    171  EventUtils.sendMouseEvent({ type: "contextmenu" }, objectRow);
    172  const expected = JSON.stringify({ obj: { type: "string" } }, null, "\t");
    173  await waitForClipboardPromise(async function setup() {
    174    await selectContextMenuItem(
    175      monitor,
    176      "properties-view-context-menu-copyvalue"
    177    );
    178  }, expected);
    179 
    180  ok(true, "The copy value action put expected json into clipboard");
    181 
    182  /* Test for copy all */
    183  EventUtils.sendMouseEvent({ type: "contextmenu" }, objectRow);
    184  await waitForClipboardPromise(async function setup() {
    185    await selectContextMenuItem(
    186      monitor,
    187      "properties-view-context-menu-copyall"
    188    );
    189  }, expected);
    190 
    191  ok(true, "The copy all action put expected json into clipboard");
    192 
    193  /* Test for copy value of a single row */
    194  EventUtils.sendMouseEvent({ type: "contextmenu" }, stringRow);
    195  await waitForClipboardPromise(async function setup() {
    196    await selectContextMenuItem(
    197      monitor,
    198      "properties-view-context-menu-copyvalue"
    199    );
    200  }, "string");
    201 
    202  ok(true, "The copy value action put expected text into clipboard");
    203 
    204  await teardown(monitor);
    205 });
    206 
    207 /**
    208 * Test if response/request Cookies in PropertiesView can be copied
    209 */
    210 
    211 add_task(async function () {
    212  const { monitor } = await initNetMonitor(SIMPLE_UNSORTED_COOKIES_SJS, {
    213    requestCount: 1,
    214  });
    215  info(
    216    "Starting the request/response  cookies in properties view copy test... "
    217  );
    218 
    219  const { document, store, windowRequire } = monitor.panelWin;
    220  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
    221 
    222  store.dispatch(Actions.batchEnable(false));
    223 
    224  let wait = waitForNetworkEvents(monitor, 1);
    225  await reloadBrowser();
    226  await wait;
    227 
    228  wait = waitForDOM(document, ".headers-overview");
    229  EventUtils.sendMouseEvent(
    230    { type: "mousedown" },
    231    document.querySelectorAll(".request-list-item")[0]
    232  );
    233  await wait;
    234 
    235  EventUtils.sendMouseEvent(
    236    { type: "mousedown" },
    237    document.querySelectorAll(".request-list-item")[0]
    238  );
    239  clickOnSidebarTab(document, "cookies");
    240 
    241  const cookiesPanel = document.querySelector("#cookies-panel");
    242 
    243  const objectRows = cookiesPanel.querySelectorAll(".objectRow");
    244  const stringRows = cookiesPanel.querySelectorAll(".stringRow");
    245 
    246  const expectedResponseCookies = [
    247    `{
    248 "__proto__": {
    249 	"httpOnly": true,
    250 	"value": "2"
    251 }
    252 }`,
    253    `{
    254 "bob": {
    255 	"httpOnly": true,
    256 	"value": "true"
    257 }
    258 }`,
    259    `{
    260 "foo": {
    261 	"httpOnly": true,
    262 	"value": "bar"
    263 }
    264 }`,
    265    `{
    266 "tom": {
    267 	"httpOnly": true,
    268 	"value": "cool"
    269 }
    270 }`,
    271  ];
    272  for (let i = 0; i < objectRows.length; i++) {
    273    const cur = objectRows[i];
    274    EventUtils.sendMouseEvent({ type: "contextmenu" }, cur);
    275    await waitForClipboardPromise(async function setup() {
    276      await selectContextMenuItem(
    277        monitor,
    278        "properties-view-context-menu-copyvalue"
    279      );
    280    }, expectedResponseCookies[i]);
    281  }
    282 
    283  const expectedRequestCookies = ["2", "true", "bar", "cool"];
    284  for (let i = 0; i < expectedRequestCookies.length; i++) {
    285    const cur = stringRows[objectRows.length + i];
    286    EventUtils.sendMouseEvent({ type: "contextmenu" }, cur);
    287    await waitForClipboardPromise(async function setup() {
    288      await selectContextMenuItem(
    289        monitor,
    290        "properties-view-context-menu-copyvalue"
    291      );
    292    }, expectedRequestCookies[i]);
    293  }
    294 
    295  await teardown(monitor);
    296 });