browser/devtools/debugger/test/browser_dbg_controller-evaluate-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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(frameDepth, 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, frameDepth,
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 // Eval while not paused.
michael@0 41 try {
michael@0 42 yield frames.evaluate("foo");
michael@0 43 } catch (error) {
michael@0 44 is(error.message, "No stack frame available.",
michael@0 45 "Evaluating shouldn't work while the debuggee isn't paused.");
michael@0 46 }
michael@0 47
michael@0 48 // Allow this generator function to yield first.
michael@0 49 executeSoon(() => debuggee.firstCall());
michael@0 50 yield waitForSourceAndCaretAndScopes(panel, "-02.js", 1);
michael@0 51 checkView(0, 1, 1, [/secondCall/, 118]);
michael@0 52
michael@0 53 // Eval in the topmost frame, while paused.
michael@0 54 let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES);
michael@0 55 let result = yield frames.evaluate("foo");
michael@0 56 ok(!result.throw, "The evaluation hasn't thrown.");
michael@0 57 is(result.return.type, "object", "The evaluation return type is correct.");
michael@0 58 is(result.return.class, "Function", "The evaluation return class is correct.");
michael@0 59
michael@0 60 yield updatedView;
michael@0 61 checkView(0, 1, 1, [/secondCall/, 118]);
michael@0 62 ok(true, "Evaluating in the topmost frame works properly.");
michael@0 63
michael@0 64 // Eval in a different frame, while paused.
michael@0 65 let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES);
michael@0 66 try {
michael@0 67 yield frames.evaluate("foo", { depth: 3 }); // oldest frame
michael@0 68 } catch (result) {
michael@0 69 is(result.return.type, "object", "The evaluation thrown type is correct.");
michael@0 70 is(result.return.class, "Error", "The evaluation thrown class is correct.");
michael@0 71 ok(!result.return, "The evaluation hasn't returned.");
michael@0 72 }
michael@0 73
michael@0 74 yield updatedView;
michael@0 75 checkView(0, 1, 1, [/secondCall/, 118]);
michael@0 76 ok(true, "Evaluating in a custom frame works properly.");
michael@0 77
michael@0 78 // Eval in a non-existent frame, while paused.
michael@0 79 waitForDebuggerEvents(panel, events.FETCHED_SCOPES).then(() => {
michael@0 80 ok(false, "Shouldn't have updated the view when trying to evaluate " +
michael@0 81 "an expression in a non-existent stack frame.");
michael@0 82 });
michael@0 83 try {
michael@0 84 yield frames.evaluate("foo", { depth: 4 }); // non-existent frame
michael@0 85 } catch (error) {
michael@0 86 is(error.message, "No stack frame available.",
michael@0 87 "Evaluating shouldn't work if the specified frame doesn't exist.");
michael@0 88 }
michael@0 89
michael@0 90 yield resumeDebuggerThenCloseAndFinish(panel);
michael@0 91 });
michael@0 92 }

mercurial