summaryrefslogtreecommitdiff
path: root/devtools/client/debugger/test/mochitest/browser_dbg_sources-large.js
blob: 31b64c2fdca7fa3ae96aa80bd251d2b7d7aa97fc (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
68
69
70
71
72
73
74
75
76
77
78
79
80
/* -*- 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/ */

/**
 * Tests that large files are treated differently in the debugger:
 *   1) No parsing to determine current symbol is attempted when
 *      starting a search
 */

const TAB_URL = EXAMPLE_URL + "doc_function-search.html";

function test() {
  let options = {
    source: EXAMPLE_URL + "code_function-search-01.js",
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab, aDebuggee, aPanel]) => {
    const gTab = aTab;
    const gDebuggee = aDebuggee;
    const gPanel = aPanel;
    const gDebugger = gPanel.panelWin;

    const gEditor = gDebugger.DebuggerView.editor;
    const gSources = gDebugger.DebuggerView.Sources;
    const Filtering = gDebugger.DebuggerView.Filtering;

    // Setting max size so that code_function-search-01.js will be
    // considered a large file on first load
    gDebugger.DebuggerView.LARGE_FILE_SIZE = 1;

    function testLargeFile() {
      ok(gEditor.getText().length > gDebugger.DebuggerView.LARGE_FILE_SIZE,
         "First source is considered a large file.");
      is(gEditor.getMode().name, "javascript",
         "Editor is syntax highlighting.");
      ok(gEditor.getText().includes("First source!"),
         "Editor text contents appears to be correct.");

      // Press ctrl+f with the cursor in a token
      gEditor.focus();
      gEditor.setCursor({ line: 3, ch: 10});
      synthesizeKeyFromKeyTag(gDebugger.document.getElementById("tokenSearchKey"));
      is(Filtering._searchbox.value, "#",
        "Search box is NOT prefilled with current token");
    }

    function testSmallFile() {
      ok(gEditor.getText().length < gDebugger.DebuggerView.LARGE_FILE_SIZE,
         "Second source is considered a small file.");
      is(gEditor.getMode().name, "javascript",
         "Editor is syntax highlighting.");
      ok(gEditor.getText().includes("First source!"),
         "Editor text contents appears to be correct.");

      // Press ctrl+f with the cursor in a token
      gEditor.focus();
      gEditor.setCursor({ line: 3, ch: 10});
      synthesizeKeyFromKeyTag(gDebugger.document.getElementById("tokenSearchKey"));
      is(Filtering._searchbox.value, "#test",
        "Search box is prefilled with current token");
    }

    Task.spawn(function* () {
      yield testLargeFile();

      info("Making it appear as a small file and then reselecting 01.js");
      gDebugger.DebuggerView.LARGE_FILE_SIZE = 1000;
      gSources.selectedIndex = 1;
      yield waitForSourceShown(gPanel, "-02.js");
      gSources.selectedIndex = 0;
      yield waitForSourceShown(gPanel, "-01.js");

      yield testSmallFile();

      closeDebuggerAndFinish(gPanel);
    });
  });
}