1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_search-global-05.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,156 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Tests if the global search results are expanded/collapsed on click, and 1.9 + * clicking matches makes the source editor shows the correct source and 1.10 + * makes a selection based on the match. 1.11 + */ 1.12 + 1.13 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; 1.14 + 1.15 +let gTab, gDebuggee, gPanel, gDebugger; 1.16 +let gEditor, gSources, gSearchView, gSearchBox; 1.17 + 1.18 +function test() { 1.19 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.20 + gTab = aTab; 1.21 + gDebuggee = aDebuggee; 1.22 + gPanel = aPanel; 1.23 + gDebugger = gPanel.panelWin; 1.24 + gEditor = gDebugger.DebuggerView.editor; 1.25 + gSources = gDebugger.DebuggerView.Sources; 1.26 + gSearchView = gDebugger.DebuggerView.GlobalSearch; 1.27 + gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; 1.28 + 1.29 + waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) 1.30 + .then(doSearch) 1.31 + .then(testExpandCollapse) 1.32 + .then(testClickLineToJump) 1.33 + .then(testClickMatchToJump) 1.34 + .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) 1.35 + .then(null, aError => { 1.36 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.37 + }); 1.38 + 1.39 + gDebuggee.firstCall(); 1.40 + }); 1.41 +} 1.42 + 1.43 +function doSearch() { 1.44 + let deferred = promise.defer(); 1.45 + 1.46 + gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { 1.47 + // Some operations are synchronously dispatched on the main thread, 1.48 + // to avoid blocking UI, thus giving the impression of faster searching. 1.49 + executeSoon(() => { 1.50 + info("Current source url:\n" + gSources.selectedValue); 1.51 + info("Debugger editor text:\n" + gEditor.getText()); 1.52 + 1.53 + ok(isCaretPos(gPanel, 1), 1.54 + "The editor shouldn't have jumped to a matching line yet."); 1.55 + ok(gSources.selectedValue.contains("-02.js"), 1.56 + "The current source shouldn't have changed after a global search."); 1.57 + is(gSources.visibleItems.length, 2, 1.58 + "Not all the sources are shown after the global search."); 1.59 + 1.60 + deferred.resolve(); 1.61 + }); 1.62 + }); 1.63 + 1.64 + setText(gSearchBox, "!a"); 1.65 + 1.66 + return deferred.promise; 1.67 +} 1.68 + 1.69 +function testExpandCollapse() { 1.70 + let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); 1.71 + let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]); 1.72 + let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]); 1.73 + let firstHeader = sourceResults[0].querySelector(".dbg-results-header"); 1.74 + let secondHeader = sourceResults[1].querySelector(".dbg-results-header"); 1.75 + 1.76 + EventUtils.sendMouseEvent({ type: "click" }, firstHeader); 1.77 + EventUtils.sendMouseEvent({ type: "click" }, secondHeader); 1.78 + 1.79 + is(item0.instance.expanded, false, 1.80 + "The first source results should be collapsed on click.") 1.81 + is(item1.instance.expanded, false, 1.82 + "The second source results should be collapsed on click.") 1.83 + 1.84 + EventUtils.sendMouseEvent({ type: "click" }, firstHeader); 1.85 + EventUtils.sendMouseEvent({ type: "click" }, secondHeader); 1.86 + 1.87 + is(item0.instance.expanded, true, 1.88 + "The first source results should be expanded on an additional click."); 1.89 + is(item1.instance.expanded, true, 1.90 + "The second source results should be expanded on an additional click."); 1.91 +} 1.92 + 1.93 +function testClickLineToJump() { 1.94 + let deferred = promise.defer(); 1.95 + 1.96 + let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); 1.97 + let firstHeader = sourceResults[0].querySelector(".dbg-results-header"); 1.98 + let firstLine = sourceResults[0].querySelector(".dbg-results-line-contents"); 1.99 + 1.100 + waitForSourceAndCaret(gPanel, "-01.js", 1, 1).then(() => { 1.101 + info("Current source url:\n" + gSources.selectedValue); 1.102 + info("Debugger editor text:\n" + gEditor.getText()); 1.103 + 1.104 + ok(isCaretPos(gPanel, 1, 1), 1.105 + "The editor didn't jump to the correct line (1)."); 1.106 + is(gEditor.getSelection(), "", 1.107 + "The editor didn't select the correct text (1)."); 1.108 + ok(gSources.selectedValue.contains("-01.js"), 1.109 + "The currently shown source is incorrect (1)."); 1.110 + is(gSources.visibleItems.length, 2, 1.111 + "Not all the sources are shown after the global search (1)."); 1.112 + 1.113 + deferred.resolve(); 1.114 + }); 1.115 + 1.116 + EventUtils.sendMouseEvent({ type: "click" }, firstLine); 1.117 + 1.118 + return deferred.promise; 1.119 +} 1.120 + 1.121 +function testClickMatchToJump() { 1.122 + let deferred = promise.defer(); 1.123 + 1.124 + let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); 1.125 + let secondHeader = sourceResults[1].querySelector(".dbg-results-header"); 1.126 + let secondMatches = sourceResults[1].querySelectorAll(".dbg-results-line-contents-string[match=true]"); 1.127 + let lastMatch = Array.slice(secondMatches).pop(); 1.128 + 1.129 + waitForSourceAndCaret(gPanel, "-02.js", 1, 1).then(() => { 1.130 + info("Current source url:\n" + gSources.selectedValue); 1.131 + info("Debugger editor text:\n" + gEditor.getText()); 1.132 + 1.133 + ok(isCaretPos(gPanel, 1, 1), 1.134 + "The editor didn't jump to the correct line (2)."); 1.135 + is(gEditor.getSelection(), "", 1.136 + "The editor didn't select the correct text (2)."); 1.137 + ok(gSources.selectedValue.contains("-02.js"), 1.138 + "The currently shown source is incorrect (2)."); 1.139 + is(gSources.visibleItems.length, 2, 1.140 + "Not all the sources are shown after the global search (2)."); 1.141 + 1.142 + deferred.resolve(); 1.143 + }); 1.144 + 1.145 + EventUtils.sendMouseEvent({ type: "click" }, lastMatch); 1.146 + 1.147 + return deferred.promise; 1.148 +} 1.149 + 1.150 +registerCleanupFunction(function() { 1.151 + gTab = null; 1.152 + gDebuggee = null; 1.153 + gPanel = null; 1.154 + gDebugger = null; 1.155 + gEditor = null; 1.156 + gSources = null; 1.157 + gSearchView = null; 1.158 + gSearchBox = null; 1.159 +});