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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_controller-evaluate-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests the public evaluation API from the debugger controller.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    1.12 +
    1.13 +function test() {
    1.14 +  Task.spawn(function() {
    1.15 +    let [tab, debuggee, panel] = yield initDebugger(TAB_URL);
    1.16 +    let win = panel.panelWin;
    1.17 +    let frames = win.DebuggerController.StackFrames;
    1.18 +    let framesView = win.DebuggerView.StackFrames;
    1.19 +    let sources = win.DebuggerController.SourceScripts;
    1.20 +    let sourcesView = win.DebuggerView.Sources;
    1.21 +    let editorView = win.DebuggerView.editor;
    1.22 +    let events = win.EVENTS;
    1.23 +
    1.24 +    function checkView(frameDepth, selectedSource, caretLine, editorText) {
    1.25 +      is(win.gThreadClient.state, "paused",
    1.26 +        "Should only be getting stack frames while paused.");
    1.27 +      is(framesView.itemCount, 4,
    1.28 +        "Should have four frames.");
    1.29 +      is(framesView.selectedDepth, frameDepth,
    1.30 +        "The correct frame is selected in the widget.");
    1.31 +      is(sourcesView.selectedIndex, selectedSource,
    1.32 +        "The correct source is selected in the widget.");
    1.33 +      ok(isCaretPos(panel, caretLine),
    1.34 +        "Editor caret location is correct.");
    1.35 +      is(editorView.getText().search(editorText[0]), editorText[1],
    1.36 +        "The correct source is not displayed.");
    1.37 +    }
    1.38 +
    1.39 +    // Cache the sources text to avoid having to wait for their retrieval.
    1.40 +    yield promise.all(sourcesView.attachments.map(e => sources.getText(e.source)));
    1.41 +    is(sources._cache.size, 2, "There should be two cached sources in the cache.");
    1.42 +
    1.43 +    // Eval while not paused.
    1.44 +    try {
    1.45 +      yield frames.evaluate("foo");
    1.46 +    } catch (error) {
    1.47 +      is(error.message, "No stack frame available.",
    1.48 +        "Evaluating shouldn't work while the debuggee isn't paused.");
    1.49 +    }
    1.50 +
    1.51 +    // Allow this generator function to yield first.
    1.52 +    executeSoon(() => debuggee.firstCall());
    1.53 +    yield waitForSourceAndCaretAndScopes(panel, "-02.js", 1);
    1.54 +    checkView(0, 1, 1, [/secondCall/, 118]);
    1.55 +
    1.56 +    // Eval in the topmost frame, while paused.
    1.57 +    let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES);
    1.58 +    let result = yield frames.evaluate("foo");
    1.59 +    ok(!result.throw, "The evaluation hasn't thrown.");
    1.60 +    is(result.return.type, "object", "The evaluation return type is correct.");
    1.61 +    is(result.return.class, "Function", "The evaluation return class is correct.");
    1.62 +
    1.63 +    yield updatedView;
    1.64 +    checkView(0, 1, 1, [/secondCall/, 118]);
    1.65 +    ok(true, "Evaluating in the topmost frame works properly.");
    1.66 +
    1.67 +    // Eval in a different frame, while paused.
    1.68 +    let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES);
    1.69 +    try {
    1.70 +      yield frames.evaluate("foo", { depth: 3 }); // oldest frame
    1.71 +    } catch (result) {
    1.72 +      is(result.return.type, "object", "The evaluation thrown type is correct.");
    1.73 +      is(result.return.class, "Error", "The evaluation thrown class is correct.");
    1.74 +      ok(!result.return, "The evaluation hasn't returned.");
    1.75 +    }
    1.76 +
    1.77 +    yield updatedView;
    1.78 +    checkView(0, 1, 1, [/secondCall/, 118]);
    1.79 +    ok(true, "Evaluating in a custom frame works properly.");
    1.80 +
    1.81 +    // Eval in a non-existent frame, while paused.
    1.82 +    waitForDebuggerEvents(panel, events.FETCHED_SCOPES).then(() => {
    1.83 +      ok(false, "Shouldn't have updated the view when trying to evaluate " +
    1.84 +        "an expression in a non-existent stack frame.");
    1.85 +    });
    1.86 +    try {
    1.87 +      yield frames.evaluate("foo", { depth: 4 }); // non-existent frame
    1.88 +    } catch (error) {
    1.89 +      is(error.message, "No stack frame available.",
    1.90 +        "Evaluating shouldn't work if the specified frame doesn't exist.");
    1.91 +    }
    1.92 +
    1.93 +    yield resumeDebuggerThenCloseAndFinish(panel);
    1.94 +  });
    1.95 +}

mercurial