1<!DOCTYPE html>
2<!--
3Copyright (c) 2015 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7<link rel="import" href="/tracing/base/base.html">
8<link rel="import" href="/tracing/core/test_utils.html">
9<link rel="import" href="/tracing/model/model.html">
10
11<script>
12'use strict';
13
14/**
15 * @fileoverview Base class for trace data Auditors.
16 */
17tr.exportTo('tr.e.chrome', function() {
18  function ChromeTestUtils() {
19  }
20
21  ChromeTestUtils.newChromeModel = function(customizeModelCallback) {
22    return tr.c.TestUtils.newModel(function(model) {
23      model.browserProcess = model.getOrCreateProcess(1);
24      model.browserMain = model.browserProcess.getOrCreateThread(2);
25      model.browserMain.name = 'CrBrowserMain';
26
27      model.rendererProcess = model.getOrCreateProcess(2);
28      model.rendererMain = model.rendererProcess.getOrCreateThread(3);
29      model.rendererMain.name = 'CrRendererMain';
30
31      model.rendererCompositor = model.rendererProcess.getOrCreateThread(4);
32      model.rendererCompositor.name = 'Compositor';
33
34      model.rasterWorker1 = model.rendererProcess.getOrCreateThread(5);
35      model.rasterWorker1.name = 'CompositorTileWorker1';
36
37      customizeModelCallback(model);
38    });
39  };
40
41  ChromeTestUtils.addEvent = function(thread, dict) {
42    var slice = tr.c.TestUtils.newAsyncSliceEx(dict);
43    thread.asyncSliceGroup.push(slice);
44    return slice;
45  };
46
47  ChromeTestUtils.addNavigationStartEvent = function(model, dict) {
48    dict.title = 'NavigationTiming navigationStart';
49    var event = tr.c.TestUtils.newInstantEvent(dict);
50    model.instantEvents.push(event);
51    return event;
52  };
53
54  ChromeTestUtils.addFirstContentfulPaintEvent = function(model, dict) {
55    dict.title = 'firstContentfulPaint';
56    var event = tr.c.TestUtils.newInstantEvent(dict);
57    model.instantEvents.push(event);
58    return event;
59  };
60
61  ChromeTestUtils.addInputEvent = function(model, typeName, dict) {
62    dict.title = 'InputLatency::' + typeName;
63    dict.isTopLevel = (dict.isTopLevel === undefined);
64    dict.startThread = model.browserMain;
65    var slice = tr.c.TestUtils.newAsyncSliceEx(dict);
66    model.browserMain.asyncSliceGroup.push(slice);
67    return slice;
68  };
69
70  ChromeTestUtils.addFlingAnimationEvent = function(model, dict) {
71    dict.title = 'InputHandlerProxy::HandleGestureFling::started';
72    var slice = tr.c.TestUtils.newAsyncSliceEx(dict);
73    model.rendererCompositor.asyncSliceGroup.push(slice);
74    return slice;
75  };
76
77  ChromeTestUtils.addRenderingEvent = function(model, dict) {
78    dict.title = dict.title || 'DummyEvent';
79    dict.type = tr.model.ThreadSlice;
80    var slice = tr.c.TestUtils.newSliceEx(dict);
81    model.rendererMain.sliceGroup.pushSlice(slice);
82    return slice;
83  };
84
85  ChromeTestUtils.addFrameEvent = function(model, dict) {
86    dict.title = tr.model.helpers.IMPL_RENDERING_STATS;
87    dict.type = tr.model.ThreadSlice;
88    var slice = tr.c.TestUtils.newSliceEx(dict);
89    model.rendererMain.asyncSliceGroup.push(slice);
90    return slice;
91  };
92
93  ChromeTestUtils.addLoadingEvent = function(model, dict) {
94    dict.title = 'WebContentsImpl Loading';
95    var slice = tr.c.TestUtils.newAsyncSliceEx(dict);
96    model.rendererMain.asyncSliceGroup.push(slice);
97    return slice;
98  };
99
100  ChromeTestUtils.addNetworkEvent = function(model, dict) {
101    dict.cat = 'netlog';
102    dict.title = 'Generic Network event';
103    var slice = tr.c.TestUtils.newAsyncSliceEx(dict);
104    model.browserMain.asyncSliceGroup.push(slice);
105    return slice;
106  };
107
108  ChromeTestUtils.addCommitLoadEvent = function(model, dict) {
109    dict.title = 'RenderFrameImpl::didCommitProvisionalLoad';
110    var slice = tr.c.TestUtils.newAsyncSliceEx(dict);
111    model.rendererMain.sliceGroup.pushSlice(slice);
112    return slice;
113  };
114
115  ChromeTestUtils.addCreateChildFrameEvent = function(model, dict) {
116    dict.title = 'RenderFrameImpl::createChildFrame';
117    var slice = tr.c.TestUtils.newAsyncSliceEx(dict);
118    model.rendererMain.sliceGroup.pushSlice(slice);
119    return slice;
120  };
121
122  ChromeTestUtils.addStartProvisionalLoadEvent = function(model, dict) {
123    dict.title = 'RenderFrameImpl::didStartProvisionalLoad';
124    var slice = tr.c.TestUtils.newAsyncSliceEx(dict);
125    model.rendererMain.sliceGroup.pushSlice(slice);
126    return slice;
127  };
128
129  ChromeTestUtils.addFailProvisionalLoadEvent = function(model, dict) {
130    dict.title = 'RenderFrameImpl::didFailProvisionalLoad';
131    var slice = tr.c.TestUtils.newAsyncSliceEx(dict);
132    model.rendererMain.sliceGroup.pushSlice(slice);
133    return slice;
134  };
135
136  ChromeTestUtils.addFinishLoadEvent = function(model, dict) {
137    dict.title = 'RenderFrameImpl::didFinishLoad';
138    var slice = tr.c.TestUtils.newSliceEx(dict);
139    model.rendererMain.sliceGroup.pushSlice(slice);
140    return slice;
141  };
142
143  ChromeTestUtils.addLoadFinishedEvent = function(model, dict) {
144    dict.title = 'LoadFinished';
145    var slice = tr.c.TestUtils.newSliceEx(dict);
146    model.rendererMain.sliceGroup.pushSlice(slice);
147    return slice;
148  };
149
150  ChromeTestUtils.addCreateThreadsEvent = function(model, dict) {
151    dict.title = 'BrowserMainLoop::CreateThreads';
152    var slice = tr.c.TestUtils.newSliceEx(dict);
153    model.rendererMain.sliceGroup.pushSlice(slice);
154    return slice;
155  };
156
157  return {
158    ChromeTestUtils: ChromeTestUtils
159  };
160});
161</script>
162