1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_search-basic-04.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 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 the selection is dropped for line and token searches, after 1.9 + * pressing backspace enough times. 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, 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 + gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; 1.26 + 1.27 + waitForSourceShown(gPanel, "-01.js") 1.28 + .then(testLineSearch) 1.29 + .then(testTokenSearch) 1.30 + .then(() => closeDebuggerAndFinish(gPanel)) 1.31 + .then(null, aError => { 1.32 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.33 + }); 1.34 + }); 1.35 +} 1.36 + 1.37 +function testLineSearch() { 1.38 + setText(gSearchBox, ":42"); 1.39 + ok(isCaretPos(gPanel, 7), 1.40 + "The editor caret position appears to be correct (1.1)."); 1.41 + ok(isEditorSel(gPanel, [160, 160]), 1.42 + "The editor selection appears to be correct (1.1)."); 1.43 + is(gEditor.getSelection(), "", 1.44 + "The editor selected text appears to be correct (1.1)."); 1.45 + 1.46 + backspaceText(gSearchBox, 1); 1.47 + ok(isCaretPos(gPanel, 4), 1.48 + "The editor caret position appears to be correct (1.2)."); 1.49 + ok(isEditorSel(gPanel, [110, 110]), 1.50 + "The editor selection appears to be correct (1.2)."); 1.51 + is(gEditor.getSelection(), "", 1.52 + "The editor selected text appears to be correct (1.2)."); 1.53 + 1.54 + backspaceText(gSearchBox, 1); 1.55 + ok(isCaretPos(gPanel, 4), 1.56 + "The editor caret position appears to be correct (1.3)."); 1.57 + ok(isEditorSel(gPanel, [110, 110]), 1.58 + "The editor selection appears to be correct (1.3)."); 1.59 + is(gEditor.getSelection(), "", 1.60 + "The editor selected text appears to be correct (1.3)."); 1.61 + 1.62 + setText(gSearchBox, ":4"); 1.63 + ok(isCaretPos(gPanel, 4), 1.64 + "The editor caret position appears to be correct (1.4)."); 1.65 + ok(isEditorSel(gPanel, [110, 110]), 1.66 + "The editor selection appears to be correct (1.4)."); 1.67 + is(gEditor.getSelection(), "", 1.68 + "The editor selected text appears to be correct (1.4)."); 1.69 + 1.70 + gSearchBox.select(); 1.71 + backspaceText(gSearchBox, 1); 1.72 + ok(isCaretPos(gPanel, 4), 1.73 + "The editor caret position appears to be correct (1.5)."); 1.74 + ok(isEditorSel(gPanel, [110, 110]), 1.75 + "The editor selection appears to be correct (1.5)."); 1.76 + is(gEditor.getSelection(), "", 1.77 + "The editor selected text appears to be correct (1.5)."); 1.78 + is(gSearchBox.value, "", 1.79 + "The searchbox should have been cleared."); 1.80 +} 1.81 + 1.82 +function testTokenSearch() { 1.83 + setText(gSearchBox, "#;\""); 1.84 + ok(isCaretPos(gPanel, 5, 23), 1.85 + "The editor caret position appears to be correct (2.1)."); 1.86 + ok(isEditorSel(gPanel, [153, 155]), 1.87 + "The editor selection appears to be correct (2.1)."); 1.88 + is(gEditor.getSelection(), ";\"", 1.89 + "The editor selected text appears to be correct (2.1)."); 1.90 + 1.91 + backspaceText(gSearchBox, 1); 1.92 + ok(isCaretPos(gPanel, 5, 22), 1.93 + "The editor caret position appears to be correct (2.2)."); 1.94 + ok(isEditorSel(gPanel, [153, 154]), 1.95 + "The editor selection appears to be correct (2.2)."); 1.96 + is(gEditor.getSelection(), ";", 1.97 + "The editor selected text appears to be correct (2.2)."); 1.98 + 1.99 + backspaceText(gSearchBox, 1); 1.100 + ok(isCaretPos(gPanel, 5, 22), 1.101 + "The editor caret position appears to be correct (2.3)."); 1.102 + ok(isEditorSel(gPanel, [154, 154]), 1.103 + "The editor selection appears to be correct (2.3)."); 1.104 + is(gEditor.getSelection(), "", 1.105 + "The editor selected text appears to be correct (2.3)."); 1.106 + 1.107 + setText(gSearchBox, "#;"); 1.108 + ok(isCaretPos(gPanel, 5, 22), 1.109 + "The editor caret position appears to be correct (2.4)."); 1.110 + ok(isEditorSel(gPanel, [153, 154]), 1.111 + "The editor selection appears to be correct (2.4)."); 1.112 + is(gEditor.getSelection(), ";", 1.113 + "The editor selected text appears to be correct (2.4)."); 1.114 + 1.115 + gSearchBox.select(); 1.116 + backspaceText(gSearchBox, 1); 1.117 + ok(isCaretPos(gPanel, 5, 22), 1.118 + "The editor caret position appears to be correct (2.5)."); 1.119 + ok(isEditorSel(gPanel, [154, 154]), 1.120 + "The editor selection appears to be correct (2.5)."); 1.121 + is(gEditor.getSelection(), "", 1.122 + "The editor selected text appears to be correct (2.5)."); 1.123 + is(gSearchBox.value, "", 1.124 + "The searchbox should have been cleared."); 1.125 +} 1.126 + 1.127 +registerCleanupFunction(function() { 1.128 + gTab = null; 1.129 + gDebuggee = null; 1.130 + gPanel = null; 1.131 + gDebugger = null; 1.132 + gEditor = null; 1.133 + gSources = null; 1.134 + gSearchBox = null; 1.135 +});