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 | * Test that switching between stack frames properly sets the current debugger |
michael@0 | 6 | * location in the source editor. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
michael@0 | 10 | |
michael@0 | 11 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 12 | let gEditor, gSources, gFrames, gClassicFrames; |
michael@0 | 13 | |
michael@0 | 14 | function test() { |
michael@0 | 15 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 16 | gTab = aTab; |
michael@0 | 17 | gDebuggee = aDebuggee; |
michael@0 | 18 | gPanel = aPanel; |
michael@0 | 19 | gDebugger = gPanel.panelWin; |
michael@0 | 20 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 21 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 22 | gFrames = gDebugger.DebuggerView.StackFrames; |
michael@0 | 23 | gClassicFrames = gDebugger.DebuggerView.StackFramesClassicList; |
michael@0 | 24 | |
michael@0 | 25 | waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) |
michael@0 | 26 | .then(initialChecks) |
michael@0 | 27 | .then(testNewestTwoFrames) |
michael@0 | 28 | .then(testOldestTwoFrames) |
michael@0 | 29 | .then(testAfterResume) |
michael@0 | 30 | .then(() => closeDebuggerAndFinish(gPanel)) |
michael@0 | 31 | .then(null, aError => { |
michael@0 | 32 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 33 | }); |
michael@0 | 34 | |
michael@0 | 35 | gDebuggee.firstCall(); |
michael@0 | 36 | }); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function initialChecks() { |
michael@0 | 40 | is(gDebugger.gThreadClient.state, "paused", |
michael@0 | 41 | "Should only be getting stack frames while paused."); |
michael@0 | 42 | is(gFrames.itemCount, 4, |
michael@0 | 43 | "Should have four frames."); |
michael@0 | 44 | is(gClassicFrames.itemCount, 4, |
michael@0 | 45 | "Should also have four frames in the mirrored view."); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function testNewestTwoFrames() { |
michael@0 | 49 | let deferred = promise.defer(); |
michael@0 | 50 | |
michael@0 | 51 | is(gFrames.selectedIndex, 3, |
michael@0 | 52 | "Newest frame should be selected by default."); |
michael@0 | 53 | is(gClassicFrames.selectedIndex, 0, |
michael@0 | 54 | "Newest frame should be selected in the mirrored view as well."); |
michael@0 | 55 | is(gSources.selectedIndex, 1, |
michael@0 | 56 | "The second source is selected in the widget."); |
michael@0 | 57 | ok(isCaretPos(gPanel, 1), |
michael@0 | 58 | "Editor caret location is correct (1)."); |
michael@0 | 59 | |
michael@0 | 60 | // The editor's debug location takes a tick to update. |
michael@0 | 61 | executeSoon(() => { |
michael@0 | 62 | is(gEditor.getDebugLocation(), 0, |
michael@0 | 63 | "Editor debug location is correct."); |
michael@0 | 64 | |
michael@0 | 65 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 66 | gFrames.getItemAtIndex(2).target, |
michael@0 | 67 | gDebugger); |
michael@0 | 68 | |
michael@0 | 69 | is(gFrames.selectedIndex, 2, |
michael@0 | 70 | "Third frame should be selected after click."); |
michael@0 | 71 | is(gClassicFrames.selectedIndex, 1, |
michael@0 | 72 | "Third frame should be selected in the mirrored view as well."); |
michael@0 | 73 | is(gSources.selectedIndex, 1, |
michael@0 | 74 | "The second source is still selected in the widget."); |
michael@0 | 75 | ok(isCaretPos(gPanel, 6), |
michael@0 | 76 | "Editor caret location is correct (2)."); |
michael@0 | 77 | |
michael@0 | 78 | // The editor's debug location takes a tick to update. |
michael@0 | 79 | executeSoon(() => { |
michael@0 | 80 | is(gEditor.getDebugLocation(), 5, |
michael@0 | 81 | "Editor debug location is correct."); |
michael@0 | 82 | |
michael@0 | 83 | deferred.resolve(); |
michael@0 | 84 | }); |
michael@0 | 85 | }); |
michael@0 | 86 | |
michael@0 | 87 | return deferred.promise; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function testOldestTwoFrames() { |
michael@0 | 91 | let deferred = promise.defer(); |
michael@0 | 92 | |
michael@0 | 93 | waitForSourceAndCaret(gPanel, "-01.js", 1).then(waitForTick).then(() => { |
michael@0 | 94 | is(gFrames.selectedIndex, 1, |
michael@0 | 95 | "Second frame should be selected after click."); |
michael@0 | 96 | is(gClassicFrames.selectedIndex, 2, |
michael@0 | 97 | "Second frame should be selected in the mirrored view as well."); |
michael@0 | 98 | is(gSources.selectedIndex, 0, |
michael@0 | 99 | "The first source is now selected in the widget."); |
michael@0 | 100 | ok(isCaretPos(gPanel, 1), |
michael@0 | 101 | "Editor caret location is correct (3)."); |
michael@0 | 102 | |
michael@0 | 103 | // The editor's debug location takes a tick to update. |
michael@0 | 104 | executeSoon(() => { |
michael@0 | 105 | is(gEditor.getDebugLocation(), 0, |
michael@0 | 106 | "Editor debug location is correct."); |
michael@0 | 107 | |
michael@0 | 108 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 109 | gFrames.getItemAtIndex(0).target, |
michael@0 | 110 | gDebugger); |
michael@0 | 111 | |
michael@0 | 112 | is(gFrames.selectedIndex, 0, |
michael@0 | 113 | "Oldest frame should be selected after click."); |
michael@0 | 114 | is(gClassicFrames.selectedIndex, 3, |
michael@0 | 115 | "Oldest frame should be selected in the mirrored view as well."); |
michael@0 | 116 | is(gSources.selectedIndex, 0, |
michael@0 | 117 | "The first source is still selected in the widget."); |
michael@0 | 118 | ok(isCaretPos(gPanel, 5), |
michael@0 | 119 | "Editor caret location is correct (4)."); |
michael@0 | 120 | |
michael@0 | 121 | // The editor's debug location takes a tick to update. |
michael@0 | 122 | executeSoon(() => { |
michael@0 | 123 | is(gEditor.getDebugLocation(), 4, |
michael@0 | 124 | "Editor debug location is correct."); |
michael@0 | 125 | |
michael@0 | 126 | deferred.resolve(); |
michael@0 | 127 | }); |
michael@0 | 128 | }); |
michael@0 | 129 | }); |
michael@0 | 130 | |
michael@0 | 131 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 132 | gDebugger.document.querySelector("#stackframe-2"), |
michael@0 | 133 | gDebugger); |
michael@0 | 134 | |
michael@0 | 135 | return deferred.promise; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | function testAfterResume() { |
michael@0 | 139 | let deferred = promise.defer(); |
michael@0 | 140 | |
michael@0 | 141 | gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => { |
michael@0 | 142 | is(gFrames.itemCount, 0, |
michael@0 | 143 | "Should have no frames after resume."); |
michael@0 | 144 | is(gClassicFrames.itemCount, 0, |
michael@0 | 145 | "Should have no frames in the mirrored view as well."); |
michael@0 | 146 | ok(isCaretPos(gPanel, 5), |
michael@0 | 147 | "Editor caret location is correct after resume."); |
michael@0 | 148 | is(gEditor.getDebugLocation(), null, |
michael@0 | 149 | "Editor debug location is correct after resume."); |
michael@0 | 150 | |
michael@0 | 151 | deferred.resolve(); |
michael@0 | 152 | }, true); |
michael@0 | 153 | |
michael@0 | 154 | gDebugger.gThreadClient.resume(); |
michael@0 | 155 | |
michael@0 | 156 | return deferred.promise; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | registerCleanupFunction(function() { |
michael@0 | 160 | gTab = null; |
michael@0 | 161 | gDebuggee = null; |
michael@0 | 162 | gPanel = null; |
michael@0 | 163 | gDebugger = null; |
michael@0 | 164 | gEditor = null; |
michael@0 | 165 | gSources = null; |
michael@0 | 166 | gFrames = null; |
michael@0 | 167 | gClassicFrames = null; |
michael@0 | 168 | }); |
michael@0 | 169 |