michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if the global search results switch back and forth, and wrap around michael@0: * when switching between them. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources, gSearchView, gSearchBox; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gEditor = gDebugger.DebuggerView.editor; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gSearchView = gDebugger.DebuggerView.GlobalSearch; michael@0: gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; michael@0: michael@0: waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) michael@0: .then(firstSearch) michael@0: .then(doFirstJump) michael@0: .then(doSecondJump) michael@0: .then(doWrapAroundJump) michael@0: .then(doBackwardsWrapAroundJump) michael@0: .then(testSearchTokenEmpty) michael@0: .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: michael@0: gDebuggee.firstCall(); michael@0: }); michael@0: } michael@0: michael@0: function firstSearch() { michael@0: let deferred = promise.defer(); michael@0: michael@0: is(gSearchView.itemCount, 0, michael@0: "The global search pane shouldn't have any entries yet."); michael@0: is(gSearchView.widget._parent.hidden, true, michael@0: "The global search pane shouldn't be visible yet."); michael@0: is(gSearchView._splitter.hidden, true, michael@0: "The global search pane splitter shouldn't be visible yet."); michael@0: michael@0: gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { michael@0: // Some operations are synchronously dispatched on the main thread, michael@0: // to avoid blocking UI, thus giving the impression of faster searching. michael@0: executeSoon(() => { michael@0: info("Current source url:\n" + gSources.selectedValue); michael@0: info("Debugger editor text:\n" + gEditor.getText()); michael@0: michael@0: ok(isCaretPos(gPanel, 1), michael@0: "The editor shouldn't have jumped to a matching line yet."); michael@0: ok(gSources.selectedValue.contains("-02.js"), michael@0: "The current source shouldn't have changed after a global search."); michael@0: is(gSources.visibleItems.length, 2, michael@0: "Not all the sources are shown after the global search."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: setText(gSearchBox, "!eval"); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function doFirstJump() { michael@0: let deferred = promise.defer(); michael@0: michael@0: waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => { michael@0: info("Current source url:\n" + gSources.selectedValue); michael@0: info("Debugger editor text:\n" + gEditor.getText()); michael@0: michael@0: ok(gSources.selectedValue.contains("-01.js"), michael@0: "The currently shown source is incorrect (1)."); michael@0: is(gSources.visibleItems.length, 2, michael@0: "Not all the sources are shown after the global search (1)."); michael@0: michael@0: // The editor's selected text takes a tick to update. michael@0: executeSoon(() => { michael@0: ok(isCaretPos(gPanel, 5, 7), michael@0: "The editor didn't jump to the correct line (1)."); michael@0: is(gEditor.getSelection(), "eval", michael@0: "The editor didn't select the correct text (1)."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: EventUtils.sendKey("DOWN", gDebugger); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function doSecondJump() { michael@0: let deferred = promise.defer(); michael@0: michael@0: waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => { michael@0: info("Current source url:\n" + gSources.selectedValue); michael@0: info("Debugger editor text:\n" + gEditor.getText()); michael@0: michael@0: ok(gSources.selectedValue.contains("-02.js"), michael@0: "The currently shown source is incorrect (2)."); michael@0: is(gSources.visibleItems.length, 2, michael@0: "Not all the sources are shown after the global search (2)."); michael@0: michael@0: // The editor's selected text takes a tick to update. michael@0: executeSoon(() => { michael@0: ok(isCaretPos(gPanel, 6, 7), michael@0: "The editor didn't jump to the correct line (2)."); michael@0: is(gEditor.getSelection(), "eval", michael@0: "The editor didn't select the correct text (2)."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: EventUtils.sendKey("DOWN", gDebugger); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function doWrapAroundJump() { michael@0: let deferred = promise.defer(); michael@0: michael@0: waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => { michael@0: info("Current source url:\n" + gSources.selectedValue); michael@0: info("Debugger editor text:\n" + gEditor.getText()); michael@0: michael@0: ok(gSources.selectedValue.contains("-01.js"), michael@0: "The currently shown source is incorrect (3)."); michael@0: is(gSources.visibleItems.length, 2, michael@0: "Not all the sources are shown after the global search (3)."); michael@0: michael@0: // The editor's selected text takes a tick to update. michael@0: executeSoon(() => { michael@0: ok(isCaretPos(gPanel, 5, 7), michael@0: "The editor didn't jump to the correct line (3)."); michael@0: is(gEditor.getSelection(), "eval", michael@0: "The editor didn't select the correct text (3)."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: EventUtils.sendKey("DOWN", gDebugger); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function doBackwardsWrapAroundJump() { michael@0: let deferred = promise.defer(); michael@0: michael@0: waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => { michael@0: info("Current source url:\n" + gSources.selectedValue); michael@0: info("Debugger editor text:\n" + gEditor.getText()); michael@0: michael@0: ok(gSources.selectedValue.contains("-02.js"), michael@0: "The currently shown source is incorrect (4)."); michael@0: is(gSources.visibleItems.length, 2, michael@0: "Not all the sources are shown after the global search (4)."); michael@0: michael@0: // The editor's selected text takes a tick to update. michael@0: executeSoon(() => { michael@0: ok(isCaretPos(gPanel, 6, 7), michael@0: "The editor didn't jump to the correct line (4)."); michael@0: is(gEditor.getSelection(), "eval", michael@0: "The editor didn't select the correct text (4)."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: EventUtils.sendKey("UP", gDebugger); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testSearchTokenEmpty() { michael@0: backspaceText(gSearchBox, 4); michael@0: michael@0: info("Current source url:\n" + gSources.selectedValue); michael@0: info("Debugger editor text:\n" + gEditor.getText()); michael@0: michael@0: ok(gSources.selectedValue.contains("-02.js"), michael@0: "The currently shown source is incorrect (4)."); michael@0: is(gSources.visibleItems.length, 2, michael@0: "Not all the sources are shown after the global search (4)."); michael@0: ok(isCaretPos(gPanel, 6, 7), michael@0: "The editor didn't remain at the correct line (4)."); michael@0: is(gEditor.getSelection(), "", michael@0: "The editor shouldn't keep the previous text selected (4)."); michael@0: michael@0: is(gSearchView.itemCount, 0, michael@0: "The global search pane shouldn't have any child nodes after clearing."); michael@0: is(gSearchView.widget._parent.hidden, true, michael@0: "The global search pane shouldn't be visible after clearing."); michael@0: is(gSearchView._splitter.hidden, true, michael@0: "The global search pane splitter shouldn't be visible after clearing."); michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gEditor = null; michael@0: gSources = null; michael@0: gSearchView = null; michael@0: gSearchBox = null; michael@0: });