summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/inspector/sources/debugger-ui/show-function-definition.html
blob: c67bb3c7c5bc98e4465c3e08903197284f44202c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<html>
<head>
<script src="../../../http/tests/inspector/inspector-test.js"></script>
<script src="../../../http/tests/inspector/console-test.js"></script>
<script>

function jumpToMe()
{
    var result = 12345;
    return window.foo || result;
}

function test()
{
    var panel = WebInspector.panels.sources;

    InspectorTest.runTestSuite([
        function testRevealFunctionDefinition(next)
        {
            InspectorTest.addSniffer(panel, "showUISourceCode", showUISourceCodeHook);
            WebInspector.context.flavor(WebInspector.ExecutionContext).evaluate("jumpToMe", "", false, true, false, false, false, didGetFunction);

            function didGetFunction(funcObject, wasThrown)
            {
                var error = !funcObject || wasThrown;
                InspectorTest.assertTrue(!error);
                panel._showFunctionDefinition(funcObject);
            }

            function showUISourceCodeHook(uiSourceCode, lineNumber, columnNumber, forceShowInPanel)
            {
                // lineNumber and columnNumber are 0-based
                ++lineNumber;
                ++columnNumber;
                InspectorTest.addResult("Function location revealed: [" + lineNumber + ":" + columnNumber + "]");
                next();
            }
        },

        function testDumpFunctionDefinition(next)
        {
            InspectorTest.addSniffer(WebInspector.ObjectPropertiesSection, "formatObjectAsFunction", onConsoleMessagesReceived);
            WebInspector.ConsoleModel.evaluateCommandInConsole(WebInspector.context.flavor(WebInspector.ExecutionContext), "jumpToMe");

            function onConsoleMessagesReceived()
            {
                InspectorTest.runAfterPendingDispatches(function() {
                    var messages = [];
                    InspectorTest.disableConsoleViewport();
                    var viewMessages = WebInspector.ConsolePanel._view()._visibleViewMessages;
                    for (var i = 0; i < viewMessages.length; ++i) {
                        var uiMessage = viewMessages[i];
                        var element = uiMessage.contentElement();
                        messages.push(element.deepTextContent());
                    }
                    InspectorTest.addResult(messages.join("\n"));
                    next();
                });
            }
        }
    ]);
}

</script>
</head>

<body onload="runTest()">
<p>
Tests that "Show Function Definition" jumps to the correct location.
</p>

</body>
</html>