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 the public evaluation API from the debugger controller. |
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 | function test() { |
michael@0 | 11 | Task.spawn(function() { |
michael@0 | 12 | let [tab, debuggee, panel] = yield initDebugger(TAB_URL); |
michael@0 | 13 | let win = panel.panelWin; |
michael@0 | 14 | let frames = win.DebuggerController.StackFrames; |
michael@0 | 15 | let framesView = win.DebuggerView.StackFrames; |
michael@0 | 16 | let sources = win.DebuggerController.SourceScripts; |
michael@0 | 17 | let sourcesView = win.DebuggerView.Sources; |
michael@0 | 18 | let editorView = win.DebuggerView.editor; |
michael@0 | 19 | let events = win.EVENTS; |
michael@0 | 20 | |
michael@0 | 21 | function checkView(selectedFrame, selectedSource, caretLine, editorText) { |
michael@0 | 22 | is(win.gThreadClient.state, "paused", |
michael@0 | 23 | "Should only be getting stack frames while paused."); |
michael@0 | 24 | is(framesView.itemCount, 4, |
michael@0 | 25 | "Should have four frames."); |
michael@0 | 26 | is(framesView.selectedDepth, selectedFrame, |
michael@0 | 27 | "The correct frame is selected in the widget."); |
michael@0 | 28 | is(sourcesView.selectedIndex, selectedSource, |
michael@0 | 29 | "The correct source is selected in the widget."); |
michael@0 | 30 | ok(isCaretPos(panel, caretLine), |
michael@0 | 31 | "Editor caret location is correct."); |
michael@0 | 32 | is(editorView.getText().search(editorText[0]), editorText[1], |
michael@0 | 33 | "The correct source is not displayed."); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | // Cache the sources text to avoid having to wait for their retrieval. |
michael@0 | 37 | yield promise.all(sourcesView.attachments.map(e => sources.getText(e.source))); |
michael@0 | 38 | is(sources._cache.size, 2, "There should be two cached sources in the cache."); |
michael@0 | 39 | |
michael@0 | 40 | // Allow this generator function to yield first. |
michael@0 | 41 | executeSoon(() => debuggee.firstCall()); |
michael@0 | 42 | yield waitForSourceAndCaretAndScopes(panel, "-02.js", 1); |
michael@0 | 43 | checkView(0, 1, 1, [/secondCall/, 118]); |
michael@0 | 44 | |
michael@0 | 45 | // Change the selected frame and eval inside it. |
michael@0 | 46 | let updatedFrame = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); |
michael@0 | 47 | framesView.selectedDepth = 3; // oldest frame |
michael@0 | 48 | yield updatedFrame; |
michael@0 | 49 | checkView(3, 0, 5, [/firstCall/, 118]); |
michael@0 | 50 | |
michael@0 | 51 | let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); |
michael@0 | 52 | try { |
michael@0 | 53 | yield frames.evaluate("foo"); |
michael@0 | 54 | } catch (result) { |
michael@0 | 55 | is(result.return.type, "object", "The evaluation thrown type is correct."); |
michael@0 | 56 | is(result.return.class, "Error", "The evaluation thrown class is correct."); |
michael@0 | 57 | ok(!result.return, "The evaluation hasn't returned."); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | yield updatedView; |
michael@0 | 61 | checkView(3, 0, 5, [/firstCall/, 118]); |
michael@0 | 62 | ok(true, "Evaluating while in a user-selected frame works properly."); |
michael@0 | 63 | |
michael@0 | 64 | yield resumeDebuggerThenCloseAndFinish(panel); |
michael@0 | 65 | }); |
michael@0 | 66 | } |