summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_variables-view-popup-10.js
blob: 15dd02c44eb16c33e982c597a7691c298b08c76b (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
60
61
62
63
64
65
66
67
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Makes sure the source editor's scroll location doesn't change when
 * a variable inspection popup is opened and a watch expression is
 * also evaluated at the same time.
 */

const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html";

function test() {
  Task.spawn(function* () {
    let options = {
      source: TAB_URL,
      line: 1
    };
    let [tab,, panel] = yield initDebugger(TAB_URL, options);
    let win = panel.panelWin;
    let events = win.EVENTS;
    let editor = win.DebuggerView.editor;
    let editorContainer = win.document.getElementById("editor");
    let bubble = win.DebuggerView.VariableBubble;
    let expressions = win.DebuggerView.WatchExpressions;
    let tooltip = bubble._tooltip.panel;

    let onCaretAndScopes = waitForCaretAndScopes(panel, 24);
    callInTab(tab, "start");
    yield onCaretAndScopes;

    let expressionsEvaluated = waitForDebuggerEvents(panel, events.FETCHED_WATCH_EXPRESSIONS);
    expressions.addExpression("this");
    editor.focus();
    yield expressionsEvaluated;

    // Scroll to the top of the editor and inspect variables.
    let breakpointScrollPosition = editor.getScrollInfo().top;
    editor.setFirstVisibleLine(0);
    let topmostScrollPosition = editor.getScrollInfo().top;

    ok(topmostScrollPosition < breakpointScrollPosition,
      "The editor is now scrolled to the top (0).");
    is(editor.getFirstVisibleLine(), 0,
      "The editor is now scrolled to the top (1).");

    let failPopup = () => ok(false, "The popup has got unexpectedly hidden.");
    let failScroll = () => ok(false, "The editor has got unexpectedly scrolled.");
    tooltip.addEventListener("popuphiding", failPopup);
    editorContainer.addEventListener("scroll", failScroll);
    editor.on("scroll", () => {
      if (editor.getScrollInfo().top > topmostScrollPosition) {
        ok(false, "The editor scrolled back to the breakpoint location.");
      }
    });

    expressionsEvaluated = waitForDebuggerEvents(panel, events.FETCHED_WATCH_EXPRESSIONS);
    yield openVarPopup(panel, { line: 14, ch: 15 });
    yield expressionsEvaluated;

    tooltip.removeEventListener("popuphiding", failPopup);
    editorContainer.removeEventListener("scroll", failScroll);

    yield resumeDebuggerThenCloseAndFinish(panel);
  });
}