browser/devtools/debugger/test/browser_dbg_search-global-05.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Tests if the global search results are expanded/collapsed on click, and
     6  * clicking matches makes the source editor shows the correct source and
     7  * makes a selection based on the match.
     8  */
    10 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    12 let gTab, gDebuggee, gPanel, gDebugger;
    13 let gEditor, gSources, gSearchView, gSearchBox;
    15 function test() {
    16   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    17     gTab = aTab;
    18     gDebuggee = aDebuggee;
    19     gPanel = aPanel;
    20     gDebugger = gPanel.panelWin;
    21     gEditor = gDebugger.DebuggerView.editor;
    22     gSources = gDebugger.DebuggerView.Sources;
    23     gSearchView = gDebugger.DebuggerView.GlobalSearch;
    24     gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
    26     waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
    27       .then(doSearch)
    28       .then(testExpandCollapse)
    29       .then(testClickLineToJump)
    30       .then(testClickMatchToJump)
    31       .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    32       .then(null, aError => {
    33         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    34       });
    36     gDebuggee.firstCall();
    37   });
    38 }
    40 function doSearch() {
    41   let deferred = promise.defer();
    43   gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
    44     // Some operations are synchronously dispatched on the main thread,
    45     // to avoid blocking UI, thus giving the impression of faster searching.
    46     executeSoon(() => {
    47       info("Current source url:\n" + gSources.selectedValue);
    48       info("Debugger editor text:\n" + gEditor.getText());
    50       ok(isCaretPos(gPanel, 1),
    51         "The editor shouldn't have jumped to a matching line yet.");
    52       ok(gSources.selectedValue.contains("-02.js"),
    53         "The current source shouldn't have changed after a global search.");
    54       is(gSources.visibleItems.length, 2,
    55         "Not all the sources are shown after the global search.");
    57       deferred.resolve();
    58     });
    59   });
    61   setText(gSearchBox, "!a");
    63   return deferred.promise;
    64 }
    66 function testExpandCollapse() {
    67   let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
    68   let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]);
    69   let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]);
    70   let firstHeader = sourceResults[0].querySelector(".dbg-results-header");
    71   let secondHeader = sourceResults[1].querySelector(".dbg-results-header");
    73   EventUtils.sendMouseEvent({ type: "click" }, firstHeader);
    74   EventUtils.sendMouseEvent({ type: "click" }, secondHeader);
    76   is(item0.instance.expanded, false,
    77     "The first source results should be collapsed on click.")
    78   is(item1.instance.expanded, false,
    79     "The second source results should be collapsed on click.")
    81   EventUtils.sendMouseEvent({ type: "click" }, firstHeader);
    82   EventUtils.sendMouseEvent({ type: "click" }, secondHeader);
    84   is(item0.instance.expanded, true,
    85     "The first source results should be expanded on an additional click.");
    86   is(item1.instance.expanded, true,
    87     "The second source results should be expanded on an additional click.");
    88 }
    90 function testClickLineToJump() {
    91   let deferred = promise.defer();
    93   let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
    94   let firstHeader = sourceResults[0].querySelector(".dbg-results-header");
    95   let firstLine = sourceResults[0].querySelector(".dbg-results-line-contents");
    97   waitForSourceAndCaret(gPanel, "-01.js", 1, 1).then(() => {
    98     info("Current source url:\n" + gSources.selectedValue);
    99     info("Debugger editor text:\n" + gEditor.getText());
   101     ok(isCaretPos(gPanel, 1, 1),
   102       "The editor didn't jump to the correct line (1).");
   103     is(gEditor.getSelection(), "",
   104       "The editor didn't select the correct text (1).");
   105     ok(gSources.selectedValue.contains("-01.js"),
   106       "The currently shown source is incorrect (1).");
   107     is(gSources.visibleItems.length, 2,
   108       "Not all the sources are shown after the global search (1).");
   110     deferred.resolve();
   111   });
   113   EventUtils.sendMouseEvent({ type: "click" }, firstLine);
   115   return deferred.promise;
   116 }
   118 function testClickMatchToJump() {
   119   let deferred = promise.defer();
   121   let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
   122   let secondHeader = sourceResults[1].querySelector(".dbg-results-header");
   123   let secondMatches = sourceResults[1].querySelectorAll(".dbg-results-line-contents-string[match=true]");
   124   let lastMatch = Array.slice(secondMatches).pop();
   126   waitForSourceAndCaret(gPanel, "-02.js", 1, 1).then(() => {
   127     info("Current source url:\n" + gSources.selectedValue);
   128     info("Debugger editor text:\n" + gEditor.getText());
   130     ok(isCaretPos(gPanel, 1, 1),
   131       "The editor didn't jump to the correct line (2).");
   132     is(gEditor.getSelection(), "",
   133       "The editor didn't select the correct text (2).");
   134     ok(gSources.selectedValue.contains("-02.js"),
   135       "The currently shown source is incorrect (2).");
   136     is(gSources.visibleItems.length, 2,
   137       "Not all the sources are shown after the global search (2).");
   139     deferred.resolve();
   140   });
   142   EventUtils.sendMouseEvent({ type: "click" }, lastMatch);
   144   return deferred.promise;
   145 }
   147 registerCleanupFunction(function() {
   148   gTab = null;
   149   gDebuggee = null;
   150   gPanel = null;
   151   gDebugger = null;
   152   gEditor = null;
   153   gSources = null;
   154   gSearchView = null;
   155   gSearchBox = null;
   156 });

mercurial