Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Tests basic file search functionality. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
michael@0 | 9 | |
michael@0 | 10 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 11 | let gSources, gSearchBox; |
michael@0 | 12 | |
michael@0 | 13 | function test() { |
michael@0 | 14 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 15 | gTab = aTab; |
michael@0 | 16 | gDebuggee = aDebuggee; |
michael@0 | 17 | gPanel = aPanel; |
michael@0 | 18 | gDebugger = gPanel.panelWin; |
michael@0 | 19 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 20 | gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; |
michael@0 | 21 | |
michael@0 | 22 | waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) |
michael@0 | 23 | .then(performSimpleSearch) |
michael@0 | 24 | .then(() => verifySourceAndCaret("-01.js", 1, 1, [1, 1])) |
michael@0 | 25 | .then(combineWithLineSearch) |
michael@0 | 26 | .then(() => verifySourceAndCaret("-01.js", 2, 1, [53, 53])) |
michael@0 | 27 | .then(combineWithTokenSearch) |
michael@0 | 28 | .then(() => verifySourceAndCaret("-01.js", 2, 48, [96, 100])) |
michael@0 | 29 | .then(combineWithTokenColonSearch) |
michael@0 | 30 | .then(() => verifySourceAndCaret("-01.js", 2, 11, [56, 63])) |
michael@0 | 31 | .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
michael@0 | 32 | .then(null, aError => { |
michael@0 | 33 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | gDebuggee.firstCall(); |
michael@0 | 37 | }); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function performSimpleSearch() { |
michael@0 | 41 | let finished = promise.all([ |
michael@0 | 42 | ensureSourceIs(gPanel, "-02.js"), |
michael@0 | 43 | ensureCaretAt(gPanel, 1), |
michael@0 | 44 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
michael@0 | 45 | waitForSourceShown(gPanel, "-01.js") |
michael@0 | 46 | ]); |
michael@0 | 47 | |
michael@0 | 48 | setText(gSearchBox, "1"); |
michael@0 | 49 | |
michael@0 | 50 | return finished.then(() => promise.all([ |
michael@0 | 51 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 52 | ensureCaretAt(gPanel, 1) |
michael@0 | 53 | ])); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function combineWithLineSearch() { |
michael@0 | 57 | let finished = promise.all([ |
michael@0 | 58 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 59 | ensureCaretAt(gPanel, 1), |
michael@0 | 60 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
michael@0 | 61 | waitForCaretUpdated(gPanel, 2) |
michael@0 | 62 | ]); |
michael@0 | 63 | |
michael@0 | 64 | typeText(gSearchBox, ":2"); |
michael@0 | 65 | |
michael@0 | 66 | return finished.then(() => promise.all([ |
michael@0 | 67 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 68 | ensureCaretAt(gPanel, 2) |
michael@0 | 69 | ])); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | function combineWithTokenSearch() { |
michael@0 | 73 | let finished = promise.all([ |
michael@0 | 74 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 75 | ensureCaretAt(gPanel, 2), |
michael@0 | 76 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
michael@0 | 77 | waitForCaretUpdated(gPanel, 2, 48) |
michael@0 | 78 | ]); |
michael@0 | 79 | |
michael@0 | 80 | backspaceText(gSearchBox, 2); |
michael@0 | 81 | typeText(gSearchBox, "#zero"); |
michael@0 | 82 | |
michael@0 | 83 | return finished.then(() => promise.all([ |
michael@0 | 84 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 85 | ensureCaretAt(gPanel, 2, 48) |
michael@0 | 86 | ])); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function combineWithTokenColonSearch() { |
michael@0 | 90 | let finished = promise.all([ |
michael@0 | 91 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 92 | ensureCaretAt(gPanel, 2, 48), |
michael@0 | 93 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
michael@0 | 94 | waitForCaretUpdated(gPanel, 2, 11) |
michael@0 | 95 | ]); |
michael@0 | 96 | |
michael@0 | 97 | backspaceText(gSearchBox, 4); |
michael@0 | 98 | typeText(gSearchBox, "http://"); |
michael@0 | 99 | |
michael@0 | 100 | return finished.then(() => promise.all([ |
michael@0 | 101 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 102 | ensureCaretAt(gPanel, 2, 11) |
michael@0 | 103 | ])); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | function verifySourceAndCaret(aUrl, aLine, aColumn, aSelection) { |
michael@0 | 107 | ok(gSources.selectedItem.attachment.label.contains(aUrl), |
michael@0 | 108 | "The selected item's label appears to be correct."); |
michael@0 | 109 | ok(gSources.selectedItem.value.contains(aUrl), |
michael@0 | 110 | "The selected item's value appears to be correct."); |
michael@0 | 111 | ok(isCaretPos(gPanel, aLine, aColumn), |
michael@0 | 112 | "The current caret position appears to be correct."); |
michael@0 | 113 | ok(isEditorSel(gPanel, aSelection), |
michael@0 | 114 | "The current editor selection appears to be correct."); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | registerCleanupFunction(function() { |
michael@0 | 118 | gTab = null; |
michael@0 | 119 | gDebuggee = null; |
michael@0 | 120 | gPanel = null; |
michael@0 | 121 | gDebugger = null; |
michael@0 | 122 | gSources = null; |
michael@0 | 123 | gSearchBox = null; |
michael@0 | 124 | }); |