1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_search-global-06.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 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 hidden when they're supposed to 1.9 + * (after a focus lost, or when ESCAPE is pressed). 1.10 + */ 1.11 + 1.12 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; 1.13 + 1.14 +let gTab, gDebuggee, gPanel, gDebugger; 1.15 +let gEditor, gSources, gSearchView, gSearchBox; 1.16 + 1.17 +function test() { 1.18 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.19 + gTab = aTab; 1.20 + gDebuggee = aDebuggee; 1.21 + gPanel = aPanel; 1.22 + gDebugger = gPanel.panelWin; 1.23 + gEditor = gDebugger.DebuggerView.editor; 1.24 + gSources = gDebugger.DebuggerView.Sources; 1.25 + gSearchView = gDebugger.DebuggerView.GlobalSearch; 1.26 + gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; 1.27 + 1.28 + waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) 1.29 + .then(doSearch) 1.30 + .then(testFocusLost) 1.31 + .then(doSearch) 1.32 + .then(testEscape) 1.33 + .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) 1.34 + .then(null, aError => { 1.35 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.36 + }); 1.37 + 1.38 + gDebuggee.firstCall(); 1.39 + }); 1.40 +} 1.41 + 1.42 +function doSearch() { 1.43 + let deferred = promise.defer(); 1.44 + 1.45 + is(gSearchView.itemCount, 0, 1.46 + "The global search pane shouldn't have any entries yet."); 1.47 + is(gSearchView.widget._parent.hidden, true, 1.48 + "The global search pane shouldn't be visible yet."); 1.49 + is(gSearchView._splitter.hidden, true, 1.50 + "The global search pane splitter shouldn't be visible yet."); 1.51 + 1.52 + gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { 1.53 + // Some operations are synchronously dispatched on the main thread, 1.54 + // to avoid blocking UI, thus giving the impression of faster searching. 1.55 + executeSoon(() => { 1.56 + info("Current source url:\n" + gSources.selectedValue); 1.57 + info("Debugger editor text:\n" + gEditor.getText()); 1.58 + 1.59 + ok(isCaretPos(gPanel, 1), 1.60 + "The editor shouldn't have jumped to a matching line yet."); 1.61 + ok(gSources.selectedValue.contains("-02.js"), 1.62 + "The current source shouldn't have changed after a global search."); 1.63 + is(gSources.visibleItems.length, 2, 1.64 + "Not all the sources are shown after the global search."); 1.65 + 1.66 + deferred.resolve(); 1.67 + }); 1.68 + }); 1.69 + 1.70 + setText(gSearchBox, "!a"); 1.71 + 1.72 + return deferred.promise; 1.73 +} 1.74 + 1.75 +function testFocusLost() { 1.76 + is(gSearchView.itemCount, 2, 1.77 + "The global search pane should have some entries from the previous search."); 1.78 + is(gSearchView.widget._parent.hidden, false, 1.79 + "The global search pane should be visible from the previous search."); 1.80 + is(gSearchView._splitter.hidden, false, 1.81 + "The global search pane splitter should be visible from the previous search."); 1.82 + 1.83 + gDebugger.DebuggerView.editor.focus(); 1.84 + 1.85 + info("Current source url:\n" + gSources.selectedValue); 1.86 + info("Debugger editor text:\n" + gEditor.getText()); 1.87 + 1.88 + is(gSearchView.itemCount, 0, 1.89 + "The global search pane shouldn't have any child nodes after clearing."); 1.90 + is(gSearchView.widget._parent.hidden, true, 1.91 + "The global search pane shouldn't be visible after clearing."); 1.92 + is(gSearchView._splitter.hidden, true, 1.93 + "The global search pane splitter shouldn't be visible after clearing."); 1.94 +} 1.95 + 1.96 +function testEscape() { 1.97 + is(gSearchView.itemCount, 2, 1.98 + "The global search pane should have some entries from the previous search."); 1.99 + is(gSearchView.widget._parent.hidden, false, 1.100 + "The global search pane should be visible from the previous search."); 1.101 + is(gSearchView._splitter.hidden, false, 1.102 + "The global search pane splitter should be visible from the previous search."); 1.103 + 1.104 + gSearchBox.focus(); 1.105 + EventUtils.sendKey("ESCAPE", gDebugger); 1.106 + 1.107 + is(gSearchView.itemCount, 0, 1.108 + "The global search pane shouldn't have any child nodes after clearing."); 1.109 + is(gSearchView.widget._parent.hidden, true, 1.110 + "The global search pane shouldn't be visible after clearing."); 1.111 + is(gSearchView._splitter.hidden, true, 1.112 + "The global search pane splitter shouldn't be visible after clearing."); 1.113 +} 1.114 + 1.115 +registerCleanupFunction(function() { 1.116 + gTab = null; 1.117 + gDebuggee = null; 1.118 + gPanel = null; 1.119 + gDebugger = null; 1.120 + gEditor = null; 1.121 + gSources = null; 1.122 + gSearchView = null; 1.123 + gSearchBox = null; 1.124 +});