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 if the global search results are expanded/collapsed on click, and |
michael@0 | 6 | * clicking matches makes the source editor shows the correct source and |
michael@0 | 7 | * makes a selection based on the match. |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
michael@0 | 11 | |
michael@0 | 12 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 13 | let gEditor, gSources, gSearchView, gSearchBox; |
michael@0 | 14 | |
michael@0 | 15 | function test() { |
michael@0 | 16 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 17 | gTab = aTab; |
michael@0 | 18 | gDebuggee = aDebuggee; |
michael@0 | 19 | gPanel = aPanel; |
michael@0 | 20 | gDebugger = gPanel.panelWin; |
michael@0 | 21 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 22 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 23 | gSearchView = gDebugger.DebuggerView.GlobalSearch; |
michael@0 | 24 | gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; |
michael@0 | 25 | |
michael@0 | 26 | waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) |
michael@0 | 27 | .then(doSearch) |
michael@0 | 28 | .then(testExpandCollapse) |
michael@0 | 29 | .then(testClickLineToJump) |
michael@0 | 30 | .then(testClickMatchToJump) |
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 doSearch() { |
michael@0 | 41 | let deferred = promise.defer(); |
michael@0 | 42 | |
michael@0 | 43 | gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { |
michael@0 | 44 | // Some operations are synchronously dispatched on the main thread, |
michael@0 | 45 | // to avoid blocking UI, thus giving the impression of faster searching. |
michael@0 | 46 | executeSoon(() => { |
michael@0 | 47 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 48 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 49 | |
michael@0 | 50 | ok(isCaretPos(gPanel, 1), |
michael@0 | 51 | "The editor shouldn't have jumped to a matching line yet."); |
michael@0 | 52 | ok(gSources.selectedValue.contains("-02.js"), |
michael@0 | 53 | "The current source shouldn't have changed after a global search."); |
michael@0 | 54 | is(gSources.visibleItems.length, 2, |
michael@0 | 55 | "Not all the sources are shown after the global search."); |
michael@0 | 56 | |
michael@0 | 57 | deferred.resolve(); |
michael@0 | 58 | }); |
michael@0 | 59 | }); |
michael@0 | 60 | |
michael@0 | 61 | setText(gSearchBox, "!a"); |
michael@0 | 62 | |
michael@0 | 63 | return deferred.promise; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function testExpandCollapse() { |
michael@0 | 67 | let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
michael@0 | 68 | let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]); |
michael@0 | 69 | let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]); |
michael@0 | 70 | let firstHeader = sourceResults[0].querySelector(".dbg-results-header"); |
michael@0 | 71 | let secondHeader = sourceResults[1].querySelector(".dbg-results-header"); |
michael@0 | 72 | |
michael@0 | 73 | EventUtils.sendMouseEvent({ type: "click" }, firstHeader); |
michael@0 | 74 | EventUtils.sendMouseEvent({ type: "click" }, secondHeader); |
michael@0 | 75 | |
michael@0 | 76 | is(item0.instance.expanded, false, |
michael@0 | 77 | "The first source results should be collapsed on click.") |
michael@0 | 78 | is(item1.instance.expanded, false, |
michael@0 | 79 | "The second source results should be collapsed on click.") |
michael@0 | 80 | |
michael@0 | 81 | EventUtils.sendMouseEvent({ type: "click" }, firstHeader); |
michael@0 | 82 | EventUtils.sendMouseEvent({ type: "click" }, secondHeader); |
michael@0 | 83 | |
michael@0 | 84 | is(item0.instance.expanded, true, |
michael@0 | 85 | "The first source results should be expanded on an additional click."); |
michael@0 | 86 | is(item1.instance.expanded, true, |
michael@0 | 87 | "The second source results should be expanded on an additional click."); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function testClickLineToJump() { |
michael@0 | 91 | let deferred = promise.defer(); |
michael@0 | 92 | |
michael@0 | 93 | let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
michael@0 | 94 | let firstHeader = sourceResults[0].querySelector(".dbg-results-header"); |
michael@0 | 95 | let firstLine = sourceResults[0].querySelector(".dbg-results-line-contents"); |
michael@0 | 96 | |
michael@0 | 97 | waitForSourceAndCaret(gPanel, "-01.js", 1, 1).then(() => { |
michael@0 | 98 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 99 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 100 | |
michael@0 | 101 | ok(isCaretPos(gPanel, 1, 1), |
michael@0 | 102 | "The editor didn't jump to the correct line (1)."); |
michael@0 | 103 | is(gEditor.getSelection(), "", |
michael@0 | 104 | "The editor didn't select the correct text (1)."); |
michael@0 | 105 | ok(gSources.selectedValue.contains("-01.js"), |
michael@0 | 106 | "The currently shown source is incorrect (1)."); |
michael@0 | 107 | is(gSources.visibleItems.length, 2, |
michael@0 | 108 | "Not all the sources are shown after the global search (1)."); |
michael@0 | 109 | |
michael@0 | 110 | deferred.resolve(); |
michael@0 | 111 | }); |
michael@0 | 112 | |
michael@0 | 113 | EventUtils.sendMouseEvent({ type: "click" }, firstLine); |
michael@0 | 114 | |
michael@0 | 115 | return deferred.promise; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | function testClickMatchToJump() { |
michael@0 | 119 | let deferred = promise.defer(); |
michael@0 | 120 | |
michael@0 | 121 | let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
michael@0 | 122 | let secondHeader = sourceResults[1].querySelector(".dbg-results-header"); |
michael@0 | 123 | let secondMatches = sourceResults[1].querySelectorAll(".dbg-results-line-contents-string[match=true]"); |
michael@0 | 124 | let lastMatch = Array.slice(secondMatches).pop(); |
michael@0 | 125 | |
michael@0 | 126 | waitForSourceAndCaret(gPanel, "-02.js", 1, 1).then(() => { |
michael@0 | 127 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 128 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 129 | |
michael@0 | 130 | ok(isCaretPos(gPanel, 1, 1), |
michael@0 | 131 | "The editor didn't jump to the correct line (2)."); |
michael@0 | 132 | is(gEditor.getSelection(), "", |
michael@0 | 133 | "The editor didn't select the correct text (2)."); |
michael@0 | 134 | ok(gSources.selectedValue.contains("-02.js"), |
michael@0 | 135 | "The currently shown source is incorrect (2)."); |
michael@0 | 136 | is(gSources.visibleItems.length, 2, |
michael@0 | 137 | "Not all the sources are shown after the global search (2)."); |
michael@0 | 138 | |
michael@0 | 139 | deferred.resolve(); |
michael@0 | 140 | }); |
michael@0 | 141 | |
michael@0 | 142 | EventUtils.sendMouseEvent({ type: "click" }, lastMatch); |
michael@0 | 143 | |
michael@0 | 144 | return deferred.promise; |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | registerCleanupFunction(function() { |
michael@0 | 148 | gTab = null; |
michael@0 | 149 | gDebuggee = null; |
michael@0 | 150 | gPanel = null; |
michael@0 | 151 | gDebugger = null; |
michael@0 | 152 | gEditor = null; |
michael@0 | 153 | gSources = null; |
michael@0 | 154 | gSearchView = null; |
michael@0 | 155 | gSearchBox = null; |
michael@0 | 156 | }); |