1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_search-basic-03.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,120 @@ 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 that searches which cause a popup to be shown properly handle the 1.9 + * ESCAPE key. 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 gSources, 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 + gSources = gDebugger.DebuggerView.Sources; 1.24 + gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; 1.25 + 1.26 + waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) 1.27 + .then(performFileSearch) 1.28 + .then(escapeAndHide) 1.29 + .then(escapeAndClear) 1.30 + .then(() => verifySourceAndCaret("-01.js", 1, 1)) 1.31 + .then(performFunctionSearch) 1.32 + .then(escapeAndHide) 1.33 + .then(escapeAndClear) 1.34 + .then(() => verifySourceAndCaret("-01.js", 4, 10)) 1.35 + .then(performGlobalSearch) 1.36 + .then(escapeAndClear) 1.37 + .then(() => verifySourceAndCaret("-01.js", 4, 10)) 1.38 + .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) 1.39 + .then(null, aError => { 1.40 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.41 + }); 1.42 + 1.43 + gDebuggee.firstCall(); 1.44 + }); 1.45 +} 1.46 + 1.47 +function performFileSearch() { 1.48 + let finished = promise.all([ 1.49 + ensureSourceIs(gPanel, "-02.js"), 1.50 + ensureCaretAt(gPanel, 1), 1.51 + once(gDebugger, "popupshown"), 1.52 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), 1.53 + waitForSourceShown(gPanel, "-01.js") 1.54 + ]); 1.55 + 1.56 + setText(gSearchBox, "."); 1.57 + 1.58 + return finished.then(() => promise.all([ 1.59 + ensureSourceIs(gPanel, "-01.js"), 1.60 + ensureCaretAt(gPanel, 1) 1.61 + ])); 1.62 +} 1.63 + 1.64 +function performFunctionSearch() { 1.65 + let finished = promise.all([ 1.66 + ensureSourceIs(gPanel, "-01.js"), 1.67 + ensureCaretAt(gPanel, 1), 1.68 + once(gDebugger, "popupshown"), 1.69 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FUNCTION_SEARCH_MATCH_FOUND) 1.70 + ]); 1.71 + 1.72 + setText(gSearchBox, "@"); 1.73 + 1.74 + return finished.then(() => promise.all([ 1.75 + ensureSourceIs(gPanel, "-01.js"), 1.76 + ensureCaretAt(gPanel, 4, 10) 1.77 + ])); 1.78 +} 1.79 + 1.80 +function performGlobalSearch() { 1.81 + let finished = promise.all([ 1.82 + ensureSourceIs(gPanel, "-01.js"), 1.83 + ensureCaretAt(gPanel, 4, 10), 1.84 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND) 1.85 + ]); 1.86 + 1.87 + setText(gSearchBox, "!first"); 1.88 + 1.89 + return finished.then(() => promise.all([ 1.90 + ensureSourceIs(gPanel, "-01.js"), 1.91 + ensureCaretAt(gPanel, 4, 10) 1.92 + ])); 1.93 +} 1.94 + 1.95 +function escapeAndHide() { 1.96 + let finished = once(gDebugger, "popuphidden", true); 1.97 + EventUtils.sendKey("ESCAPE", gDebugger); 1.98 + return finished; 1.99 +} 1.100 + 1.101 +function escapeAndClear() { 1.102 + EventUtils.sendKey("ESCAPE", gDebugger); 1.103 + is(gSearchBox.getAttribute("value"), "", 1.104 + "The searchbox has properly emptied after pressing escape."); 1.105 +} 1.106 + 1.107 +function verifySourceAndCaret(aUrl, aLine, aColumn) { 1.108 + ok(gSources.selectedItem.attachment.label.contains(aUrl), 1.109 + "The selected item's label appears to be correct."); 1.110 + ok(gSources.selectedItem.value.contains(aUrl), 1.111 + "The selected item's value appears to be correct."); 1.112 + ok(isCaretPos(gPanel, aLine, aColumn), 1.113 + "The current caret position appears to be correct."); 1.114 +} 1.115 + 1.116 +registerCleanupFunction(function() { 1.117 + gTab = null; 1.118 + gDebuggee = null; 1.119 + gPanel = null; 1.120 + gDebugger = null; 1.121 + gSources = null; 1.122 + gSearchBox = null; 1.123 +});