summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/inspector/tracing.html
blob: c0fb91148914a1188996f88c6587467985d6a981 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<html>
<head>
<style>
div#test {
    display: none;
    background-color: blue;
    width: 100px;
    height: 100px;
}
</style>
<script src="../http/tests/inspector/inspector-test.js"></script>
<script src="../http/tests/inspector/timeline-test.js"></script>
<script src="tracing-test.js"></script>
<script>
function initialize_TracingManagerClient()
{

InspectorTest.TracingManagerClient = function(tracingManager, callback)
{
    this._tracingManager = tracingManager;
    this._completionCallback = callback;
    this._tracingModel = InspectorTest.createTracingModel();
}

InspectorTest.TracingManagerClient.prototype = {
    tracingStarted: function()
    {
        this._tracingModel.reset();
        InspectorTest.evaluateInPage("doWork()", this._tracingManager.stop.bind(this._tracingManager));
    },

    traceEventsCollected: function(events)
    {
        this._tracingModel.addEvents(events);
    },

    tracingComplete: function()
    {
        InspectorTest.addResult("Tracing complete");
        this._completionCallback(this._tracingModel);
    },

    tracingBufferUsage: function(usage) { },
    eventsRetrievalProgress: function(progress) { }
}
}

function doWork()
{
    var element = document.getElementById("test");
    element.style.display = "block";
    var unused = element.clientWidth;
}

function test()
{
    var tracingClient = new InspectorTest.TracingManagerClient(InspectorTest.tracingManager, runEventsSanityCheck);
    InspectorTest.tracingManager.start(tracingClient, "", "", onTracingStarted);

    function onTracingStarted(error)
    {
        InspectorTest.addResult("Tracing started (error: " + JSON.stringify(error) + ")");
    }

    function runEventsSanityCheck(tracingModel)
    {
        var events = [];
        var phaseComplete = 0;
        var knownEvents = {};
        var processes = 0;
        var threads = 0;

        tracingModel.sortedProcesses().forEach(function(process) {
            processes++;
            process.sortedThreads().forEach(function(thread) {
                threads++;
                events = events.concat(thread.events());
            });
        });

        knownEvents["MessageLoop::PostTask"] = 0;
        knownEvents["v8.callFunction"] = 0;
        knownEvents["UpdateLayoutTree"] = 0;
        knownEvents["FrameView::layout"] = 0;

        for (var i = 0; i < events.length; ++i) {
            var event = events[i];
            if (event.phase === WebInspector.TracingModel.Phase.Complete)
                ++phaseComplete;
            if (event.name in knownEvents)
                ++knownEvents[event.name];
        }
        InspectorTest.assertGreaterOrEqual(events.length, 100, "Too few trace events recorded");
        InspectorTest.assertGreaterOrEqual(knownEvents["UpdateLayoutTree"], 1, "Too few UpdateLayoutTree");
        InspectorTest.assertGreaterOrEqual(knownEvents["FrameView::layout"], 1, "Too few FrameView::layout");
        InspectorTest.assertGreaterOrEqual(phaseComplete, 50, "Too few begin events");
        InspectorTest.assertGreaterOrEqual(processes, 2, "Too few processes");
        InspectorTest.assertGreaterOrEqual(threads, 4, "Too few threads");
        InspectorTest.addResult("Event sanity test done");
        InspectorTest.completeTest();
    }
}

</script>
</head>
<body onload="runTest()">
<div id="test">
</div>
</body>
</html>