tor-browser

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

browser_dbg-expressions.js (3979B)


      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 * tests the watch expressions component
      7 * 1. add watch expressions
      8 * 2. edit watch expressions
      9 * 3. delete watch expressions
     10 * 4. expanding properties when not paused
     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  await addExpression(dbg, "!true");
     22  is(getWatchExpressionLabel(dbg, 1), "!true");
     23  is(getWatchExpressionValue(dbg, 1), "false");
     24  await deleteExpression(dbg, "!true");
     25 
     26  await addExpression(dbg, "1-1");
     27  is(getWatchExpressionLabel(dbg, 1), "1-1");
     28  is(getWatchExpressionValue(dbg, 1), "0");
     29  await deleteExpression(dbg, "1-1");
     30 
     31  await addExpression(dbg, "String()");
     32  is(getWatchExpressionLabel(dbg, 1), "String()");
     33  is(getWatchExpressionValue(dbg, 1), '""');
     34  await deleteExpression(dbg, "String()");
     35 
     36  await addExpression(dbg, "f");
     37  is(getWatchExpressionLabel(dbg, 1), "f");
     38  is(getWatchExpressionValue(dbg, 1), "(unavailable)");
     39 
     40  await editExpression(dbg, "oo");
     41  is(getWatchExpressionLabel(dbg, 1), "foo()");
     42 
     43  // There is no "value" element for functions.
     44  assertEmptyValue(dbg, 1);
     45 
     46  await addExpression(dbg, "location");
     47  is(getWatchExpressionLabel(dbg, 2), "location");
     48  ok(getWatchExpressionValue(dbg, 2).includes("Location"), "has a value");
     49 
     50  // can expand an expression
     51  await toggleExpressionNode(dbg, 2);
     52 
     53  is(findAllElements(dbg, "expressionNodes").length, 37);
     54  is(dbg.selectors.getExpressions(dbg.store.getState()).length, 2);
     55 
     56  await deleteExpression(dbg, "foo");
     57  await deleteExpression(dbg, "location");
     58  is(findAllElements(dbg, "expressionNodes").length, 0);
     59  is(dbg.selectors.getExpressions(dbg.store.getState()).length, 0);
     60 
     61  // Test expanding properties when the debuggee is active
     62  // Wait for full evaluation of the expressions in order to avoid having
     63  // mixed up code between the location being removed and the one being re-added
     64  const evaluated = waitForDispatch(dbg.store, "EVALUATE_EXPRESSIONS");
     65  await resume(dbg);
     66  await evaluated;
     67 
     68  await addExpression(dbg, "location");
     69  is(dbg.selectors.getExpressions(dbg.store.getState()).length, 1);
     70 
     71  is(findAllElements(dbg, "expressionNodes").length, 1);
     72 
     73  await toggleExpressionNode(dbg, 1);
     74  is(findAllElements(dbg, "expressionNodes").length, 36);
     75 
     76  await deleteExpression(dbg, "location");
     77  is(findAllElements(dbg, "expressionNodes").length, 0);
     78 
     79  info(
     80    "Test an expression calling a function with a breakpoint and a debugger statement, which shouldn't pause"
     81  );
     82  await addBreakpoint(dbg, "script-switching-01.js", 7);
     83  // firstCall will call secondCall from script-switching-02.js which has a debugger statement
     84  await addExpression(dbg, "firstCall()");
     85  is(getWatchExpressionLabel(dbg, 1), "firstCall()");
     86  is(getWatchExpressionValue(dbg, 1), "43", "has a value");
     87 
     88  await addExpression(dbg, "$('body')");
     89  is(getWatchExpressionLabel(dbg, 2), "$('body')");
     90  ok(
     91    getWatchExpressionValue(dbg, 2).includes("body"),
     92    "uses console command $() helper"
     93  );
     94 
     95  info("Implement a custom '$' function in the page");
     96  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     97    content.eval("window.$ = function () {return 'page-override';}");
     98  });
     99 
    100  info("Refresh expressions");
    101  const refreshed = waitForDispatch(dbg.store, "EVALUATE_EXPRESSIONS");
    102  await clickElement(dbg, "expressionRefresh");
    103  await refreshed;
    104 
    105  ok(
    106    getWatchExpressionValue(dbg, 2).includes("page-override"),
    107    "the expression uses the page symbols and not the console command '$' function"
    108  );
    109 });
    110 
    111 function assertEmptyValue(dbg, index) {
    112  const value = findElement(dbg, "expressionValue", index);
    113  if (value) {
    114    is(value.innerText, "");
    115    return;
    116  }
    117 
    118  is(value, null);
    119 }