tor-browser

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

browser_dbg-expressions-watch.js (2378B)


      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 "refresh" button:
      7 * - hidden when no expression is available
      8 * - visible with one or more expressions
      9 * - updates expressions values after clicking on it
     10 * - disappears when all expressions are removed
     11 */
     12 
     13 "use strict";
     14 
     15 add_task(async function () {
     16  const dbg = await initDebugger("doc-script-switching.html");
     17 
     18  invokeInTab("firstCall");
     19  await waitForPaused(dbg);
     20 
     21  ok(
     22    !getRefreshExpressionsElement(dbg),
     23    "No refresh button is displayed when there are no watch expressions"
     24  );
     25 
     26  await addExpression(dbg, "someVariable");
     27 
     28  ok(
     29    getRefreshExpressionsElement(dbg),
     30    "Refresh button is displayed after adding a watch expression"
     31  );
     32 
     33  is(
     34    getWatchExpressionLabel(dbg, 1),
     35    "someVariable",
     36    "Watch expression was added"
     37  );
     38  is(
     39    getWatchExpressionValue(dbg, 1),
     40    "(unavailable)",
     41    "Watch expression has no value"
     42  );
     43 
     44  info("Switch to the console and update the value of the watched variable");
     45  const { hud } = await dbg.toolbox.selectTool("webconsole");
     46  await evaluateExpressionInConsole(hud, "var someVariable = 1");
     47 
     48  info("Switch back to the debugger");
     49  await dbg.toolbox.selectTool("jsdebugger");
     50 
     51  is(
     52    getWatchExpressionLabel(dbg, 1),
     53    "someVariable",
     54    "Watch expression is still available"
     55  );
     56  is(
     57    getWatchExpressionValue(dbg, 1),
     58    "(unavailable)",
     59    "Watch expression still has no value"
     60  );
     61 
     62  info(
     63    "Click on the watch expression refresh button and wait for the " +
     64      "expression to update."
     65  );
     66  const refreshed = waitForDispatch(dbg.store, "EVALUATE_EXPRESSIONS");
     67  await clickElement(dbg, "expressionRefresh");
     68  await refreshed;
     69 
     70  is(
     71    getWatchExpressionLabel(dbg, 1),
     72    "someVariable",
     73    "Watch expression is still available"
     74  );
     75  is(
     76    getWatchExpressionValue(dbg, 1),
     77    "1",
     78    "Watch expression value has been updated"
     79  );
     80 
     81  await deleteExpression(dbg, "someVariable");
     82 
     83  ok(
     84    !getRefreshExpressionsElement(dbg),
     85    "The refresh button is no longer displayed after removing watch expressions"
     86  );
     87 });
     88 
     89 function getRefreshExpressionsElement(dbg) {
     90  return findElement(dbg, "expressionRefresh", 1);
     91 }