browser/devtools/debugger/test/browser_dbg_controller-evaluate-02.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-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     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(selectedFrame, 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, selectedFrame,
    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 +    // Allow this generator function to yield first.
    1.44 +    executeSoon(() => debuggee.firstCall());
    1.45 +    yield waitForSourceAndCaretAndScopes(panel, "-02.js", 1);
    1.46 +    checkView(0, 1, 1, [/secondCall/, 118]);
    1.47 +
    1.48 +    // Change the selected frame and eval inside it.
    1.49 +    let updatedFrame = waitForDebuggerEvents(panel, events.FETCHED_SCOPES);
    1.50 +    framesView.selectedDepth = 3; // oldest frame
    1.51 +    yield updatedFrame;
    1.52 +    checkView(3, 0, 5, [/firstCall/, 118]);
    1.53 +
    1.54 +    let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES);
    1.55 +    try {
    1.56 +      yield frames.evaluate("foo");
    1.57 +    } catch (result) {
    1.58 +      is(result.return.type, "object", "The evaluation thrown type is correct.");
    1.59 +      is(result.return.class, "Error", "The evaluation thrown class is correct.");
    1.60 +      ok(!result.return, "The evaluation hasn't returned.");
    1.61 +    }
    1.62 +
    1.63 +    yield updatedView;
    1.64 +    checkView(3, 0, 5, [/firstCall/, 118]);
    1.65 +    ok(true, "Evaluating while in a user-selected frame works properly.");
    1.66 +
    1.67 +    yield resumeDebuggerThenCloseAndFinish(panel);
    1.68 +  });
    1.69 +}

mercurial