tor-browser

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

browser_dbg-expressions-thread.js (2937B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 /**
      6 * Test the watch expressions update when selecting a different thread in the thread panel.
      7 */
      8 
      9 "use strict";
     10 
     11 const TEST_COM_URI = `${URL_ROOT_COM_SSL}examples/doc_dbg-fission-frame-sources.html`;
     12 const TEST_ORG_IFRAME_URI = `${URL_ROOT_ORG_SSL}examples/doc_dbg-fission-frame-sources-frame.html`;
     13 const DATA_URI = "data:text/html,<title>foo</title>";
     14 
     15 add_task(async function () {
     16  // Make sure that the thread section is expanded
     17  await pushPref("devtools.debugger.threads-visible", true);
     18 
     19  // Load a test page with a remote frame and wait for both sources to be visible.
     20  // simple1.js is imported by the main page. simple2.js comes from the frame.
     21  const dbg = await initDebuggerWithAbsoluteURL(
     22    TEST_COM_URI,
     23    "simple1.js",
     24    "simple2.js"
     25  );
     26 
     27  const threadsPaneEl = await waitForElementWithSelector(
     28    dbg,
     29    ".threads-pane .header-label"
     30  );
     31 
     32  await waitForElement(dbg, "threadsPaneItems");
     33  const threadsEl = findAllElements(dbg, "threadsPaneItems");
     34  is(threadsEl.length, 2, "There are two threads in the thread panel");
     35  const [mainThreadEl, remoteThreadEl] = threadsEl;
     36  is(
     37    mainThreadEl.textContent,
     38    "Main Thread",
     39    "first thread displayed is the main thread"
     40  );
     41  is(
     42    remoteThreadEl.textContent,
     43    "Test remote frame sources",
     44    "second thread displayed is the remote thread"
     45  );
     46 
     47  await addExpression(dbg, "document.location.href");
     48 
     49  is(
     50    getWatchExpressionValue(dbg, 1),
     51    JSON.stringify(TEST_COM_URI),
     52    "expression is evaluated on the expected thread"
     53  );
     54 
     55  info(
     56    "Select the remote frame thread and check that the expression is updated"
     57  );
     58  let onExpressionsEvaluated = waitForDispatch(
     59    dbg.store,
     60    "EVALUATE_EXPRESSIONS"
     61  );
     62  remoteThreadEl.click();
     63  await onExpressionsEvaluated;
     64 
     65  is(
     66    getWatchExpressionValue(dbg, 1),
     67    JSON.stringify(TEST_ORG_IFRAME_URI),
     68    "expression is evaluated on the remote origin thread"
     69  );
     70 
     71  info("Select the main thread again and check that the expression is updated");
     72  onExpressionsEvaluated = waitForDispatch(dbg.store, "EVALUATE_EXPRESSIONS");
     73  mainThreadEl.click();
     74  await onExpressionsEvaluated;
     75 
     76  is(
     77    getWatchExpressionValue(dbg, 1),
     78    JSON.stringify(TEST_COM_URI),
     79    "expression is evaluated on the main thread again"
     80  );
     81 
     82  // close the threads pane so following test don't have it open
     83  threadsPaneEl.click();
     84 
     85  await navigateToAbsoluteURL(dbg, DATA_URI);
     86 
     87  is(
     88    getWatchExpressionValue(dbg, 1),
     89    JSON.stringify(DATA_URI),
     90    "The location.host expression is updated after a navigaiton"
     91  );
     92 
     93  await addExpression(dbg, "document.title");
     94 
     95  is(
     96    getWatchExpressionValue(dbg, 2),
     97    `"foo"`,
     98    "We can add expressions after a navigation"
     99  );
    100 });