summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_object_inspector_scroll.js
blob: f4c52b2903cfccb31ee17525a18246df0f24accd (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Check that expanding an objectInspector node doesn't alter the output scroll position.
const TEST_URI =
  "data:text/html;charset=utf8,<!DOCTYPE html>test Object Inspector";

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);

  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.wrappedJSObject.console.log(
      "oi-test",
      content.wrappedJSObject.Math
    );
  });

  const node = await waitFor(() => findConsoleAPIMessage(hud, "oi-test"));
  const objectInspector = node.querySelector(".tree");

  let onOiMutation = waitForNodeMutation(objectInspector, {
    childList: true,
  });

  info("Expanding the object inspector");
  objectInspector.querySelector(".arrow").click();
  await onOiMutation;

  const nodes = objectInspector.querySelectorAll(".node");
  const lastNode = nodes[nodes.length - 1];

  info("Scroll the last node of the ObjectInspector into view");
  lastNode.scrollIntoView();

  const outputContainer = hud.ui.outputNode.querySelector(".webconsole-output");
  ok(hasVerticalOverflow(outputContainer), "There is a vertical overflow");
  const scrollTop = outputContainer.scrollTop;

  onOiMutation = waitForNodeMutation(objectInspector, {
    childList: true,
  });

  info("Expand the last node");
  const view = lastNode.ownerDocument.defaultView;
  EventUtils.synthesizeMouseAtCenter(lastNode, {}, view);
  await onOiMutation;

  is(
    scrollTop,
    outputContainer.scrollTop,
    "Scroll position did not changed when expanding a node"
  );
});

function hasVerticalOverflow(container) {
  return container.scrollHeight > container.clientHeight;
}