summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-outline-focus.js
blob: 368928a60cba14254acd48cc75f6a8697718e4b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

// Tests that after clicking a function in edtior, outline focuses that function

add_task(async function() {
  const dbg = await initDebugger("doc-sources.html", "long");

  await selectSource(dbg, "long", 1);
  findElementWithSelector(dbg, ".outline-tab").click();
  is(getItems(dbg).length, 9, "9 items in the outline list");

  info("Clicking inside a function in editor should focus the outline");
  clickAtPos(dbg, { line: 15, ch: 2 });
  await waitForElementWithSelector(dbg, ".outline-list__element.focused");
  ok(
    getFocusedFunction(dbg).includes("addTodo"),
    "The right function is focused"
  );

  info("Clicking an empty line in the editor should unfocus the outline");
  await clickAtPos(dbg, { line: 13, ch: 2 });
  is(getFocusedNode(dbg), null, "should not exist");
});

function getItems(dbg) {
  return findAllElements(dbg, "outlineItems");
}

function getFocusedNode(dbg) {
  return findElementWithSelector(dbg, ".outline-list__element.focused");
}

function getFocusedFunction(dbg) {
  return getFocusedNode(dbg).innerText;
}