Hide the "Add new services" menu from Files app when running as dialog.
[chromium-blink-merge.git] / tools / perf / benchmarks / dromaeo.py
blobb10f0a0acbd4427bc738371a2ad7a062413ba169
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import math
6 import os
8 from telemetry import benchmark
9 from telemetry import page as page_module
10 from telemetry.page import page_set
11 from telemetry.page import page_test
12 from telemetry.value import scalar
14 from metrics import power
17 class _DromaeoMeasurement(page_test.PageTest):
18 def __init__(self):
19 super(_DromaeoMeasurement, self).__init__()
20 self._power_metric = None
22 def CustomizeBrowserOptions(self, options):
23 power.PowerMetric.CustomizeBrowserOptions(options)
25 def WillStartBrowser(self, platform):
26 self._power_metric = power.PowerMetric(platform)
28 def DidNavigateToPage(self, page, tab):
29 self._power_metric.Start(page, tab)
31 def ValidateAndMeasurePage(self, page, tab, results):
32 tab.WaitForJavaScriptExpression(
33 'window.document.getElementById("pause") &&' +
34 'window.document.getElementById("pause").value == "Run"',
35 120)
37 # Start spying on POST request that will report benchmark results, and
38 # intercept result data.
39 tab.ExecuteJavaScript('(function() {' +
40 ' var real_jquery_ajax_ = window.jQuery;' +
41 ' window.results_ = "";' +
42 ' window.jQuery.ajax = function(request) {' +
43 ' if (request.url == "store.php") {' +
44 ' window.results_ =' +
45 ' decodeURIComponent(request.data);' +
46 ' window.results_ = window.results_.substring(' +
47 ' window.results_.indexOf("=") + 1, ' +
48 ' window.results_.lastIndexOf("&"));' +
49 ' real_jquery_ajax_(request);' +
50 ' }' +
51 ' };' +
52 '})();')
53 # Starts benchmark.
54 tab.ExecuteJavaScript('window.document.getElementById("pause").click();')
56 tab.WaitForJavaScriptExpression('!!window.results_', 600)
58 self._power_metric.Stop(page, tab)
59 self._power_metric.AddResults(tab, results)
61 score = eval(tab.EvaluateJavaScript('window.results_ || "[]"'))
63 def Escape(k):
64 chars = [' ', '.', '-', '/', '(', ')', '*']
65 for c in chars:
66 k = k.replace(c, '_')
67 return k
69 def AggregateData(container, key, value):
70 if key not in container:
71 container[key] = {'count': 0, 'sum': 0}
72 container[key]['count'] += 1
73 container[key]['sum'] += math.log(value)
75 suffix = page.url[page.url.index('?') + 1 :]
76 def AddResult(name, value):
77 important = False
78 if name == suffix:
79 important = True
80 results.AddValue(scalar.ScalarValue(
81 results.current_page, Escape(name), 'runs/s', value, important))
83 aggregated = {}
84 for data in score:
85 AddResult('%s/%s' % (data['collection'], data['name']),
86 data['mean'])
88 top_name = data['collection'].split('-', 1)[0]
89 AggregateData(aggregated, top_name, data['mean'])
91 collection_name = data['collection']
92 AggregateData(aggregated, collection_name, data['mean'])
94 for key, value in aggregated.iteritems():
95 AddResult(key, math.exp(value['sum'] / value['count']))
97 class _DromaeoBenchmark(benchmark.Benchmark):
98 """A base class for Dromaeo benchmarks."""
99 test = _DromaeoMeasurement
101 @classmethod
102 def Name(cls):
103 return 'dromaeo'
105 def CreatePageSet(self, options):
106 """Makes a PageSet for Dromaeo benchmarks."""
107 # Subclasses are expected to define class members called query_param and
108 # tag.
109 if not hasattr(self, 'query_param') or not hasattr(self, 'tag'):
110 raise NotImplementedError('query_param or tag not in Dromaeo benchmark.')
111 archive_data_file = '../page_sets/data/dromaeo.%s.json' % self.tag
112 ps = page_set.PageSet(
113 archive_data_file=archive_data_file,
114 file_path=os.path.abspath(__file__), bucket=page_set.PUBLIC_BUCKET)
115 url = 'http://dromaeo.com?%s' % self.query_param
116 ps.AddUserStory(page_module.Page(
117 url, ps, ps.base_dir, make_javascript_deterministic=False))
118 return ps
121 class DromaeoDomCoreAttr(_DromaeoBenchmark):
122 """Dromaeo DOMCore attr JavaScript benchmark.
124 Tests setting and getting DOM node attributes.
126 tag = 'domcoreattr'
127 query_param = 'dom-attr'
129 @classmethod
130 def Name(cls):
131 return 'dromaeo.domcoreattr'
134 class DromaeoDomCoreModify(_DromaeoBenchmark):
135 """Dromaeo DOMCore modify JavaScript benchmark.
137 Tests creating and injecting DOM nodes.
139 tag = 'domcoremodify'
140 query_param = 'dom-modify'
142 @classmethod
143 def Name(cls):
144 return 'dromaeo.domcoremodify'
147 class DromaeoDomCoreQuery(_DromaeoBenchmark):
148 """Dromaeo DOMCore query JavaScript benchmark.
150 Tests querying DOM elements in a document.
152 tag = 'domcorequery'
153 query_param = 'dom-query'
155 @classmethod
156 def Name(cls):
157 return 'dromaeo.domcorequery'
160 class DromaeoDomCoreTraverse(_DromaeoBenchmark):
161 """Dromaeo DOMCore traverse JavaScript benchmark.
163 Tests traversing a DOM structure.
165 tag = 'domcoretraverse'
166 query_param = 'dom-traverse'
168 @classmethod
169 def Name(cls):
170 return 'dromaeo.domcoretraverse'
173 class DromaeoJslibAttrJquery(_DromaeoBenchmark):
174 """Dromaeo JSLib attr jquery JavaScript benchmark.
176 Tests setting and getting DOM node attributes using the jQuery JavaScript
177 Library.
179 tag = 'jslibattrjquery'
180 query_param = 'jslib-attr-jquery'
182 @classmethod
183 def Name(cls):
184 return 'dromaeo.jslibattrjquery'
187 class DromaeoJslibAttrPrototype(_DromaeoBenchmark):
188 """Dromaeo JSLib attr prototype JavaScript benchmark.
190 Tests setting and getting DOM node attributes using the jQuery JavaScript
191 Library.
193 tag = 'jslibattrprototype'
194 query_param = 'jslib-attr-prototype'
196 @classmethod
197 def Name(cls):
198 return 'dromaeo.jslibattrprototype'
201 class DromaeoJslibEventJquery(_DromaeoBenchmark):
202 """Dromaeo JSLib event jquery JavaScript benchmark.
204 Tests binding, removing, and triggering DOM events using the jQuery JavaScript
205 Library.
207 tag = 'jslibeventjquery'
208 query_param = 'jslib-event-jquery'
210 @classmethod
211 def Name(cls):
212 return 'dromaeo.jslibeventjquery'
215 class DromaeoJslibEventPrototype(_DromaeoBenchmark):
216 """Dromaeo JSLib event prototype JavaScript benchmark.
218 Tests binding, removing, and triggering DOM events using the Prototype
219 JavaScript Library.
221 tag = 'jslibeventprototype'
222 query_param = 'jslib-event-prototype'
224 @classmethod
225 def Name(cls):
226 return 'dromaeo.jslibeventprototype'
229 # xp: crbug.com/389731
230 # win7: http://crbug.com/479796
231 @benchmark.Disabled('xp', 'win7')
232 class DromaeoJslibModifyJquery(_DromaeoBenchmark):
233 """Dromaeo JSLib modify jquery JavaScript benchmark.
235 Tests creating and injecting DOM nodes into a document using the jQuery
236 JavaScript Library.
238 tag = 'jslibmodifyjquery'
239 query_param = 'jslib-modify-jquery'
241 @classmethod
242 def Name(cls):
243 return 'dromaeo.jslibmodifyjquery'
246 class DromaeoJslibModifyPrototype(_DromaeoBenchmark):
247 """Dromaeo JSLib modify prototype JavaScript benchmark.
249 Tests creating and injecting DOM nodes into a document using the Prototype
250 JavaScript Library.
252 tag = 'jslibmodifyprototype'
253 query_param = 'jslib-modify-prototype'
255 @classmethod
256 def Name(cls):
257 return 'dromaeo.jslibmodifyprototype'
260 class DromaeoJslibStyleJquery(_DromaeoBenchmark):
261 """Dromaeo JSLib style jquery JavaScript benchmark.
263 Tests getting and setting CSS information on DOM elements using the jQuery
264 JavaScript Library.
266 tag = 'jslibstylejquery'
267 query_param = 'jslib-style-jquery'
269 @classmethod
270 def Name(cls):
271 return 'dromaeo.jslibstylejquery'
274 class DromaeoJslibStylePrototype(_DromaeoBenchmark):
275 """Dromaeo JSLib style prototype JavaScript benchmark.
277 Tests getting and setting CSS information on DOM elements using the jQuery
278 JavaScript Library.
280 tag = 'jslibstyleprototype'
281 query_param = 'jslib-style-prototype'
283 @classmethod
284 def Name(cls):
285 return 'dromaeo.jslibstyleprototype'
288 class DromaeoJslibTraverseJquery(_DromaeoBenchmark):
289 """Dromaeo JSLib traverse jquery JavaScript benchmark.
292 Tests getting and setting CSS information on DOM elements using the Prototype
293 JavaScript Library.
295 tag = 'jslibtraversejquery'
296 query_param = 'jslib-traverse-jquery'
298 @classmethod
299 def Name(cls):
300 return 'dromaeo.jslibtraversejquery'
303 class DromaeoJslibTraversePrototype(_DromaeoBenchmark):
304 """Dromaeo JSLib traverse prototype JavaScript benchmark.
306 Tests traversing a DOM structure using the jQuery JavaScript Library.
308 tag = 'jslibtraverseprototype'
309 query_param = 'jslib-traverse-prototype'
311 @classmethod
312 def Name(cls):
313 return 'dromaeo.jslibtraverseprototype'
316 class DromaeoCSSQueryJquery(_DromaeoBenchmark):
317 """Dromaeo CSS Query jquery JavaScript benchmark.
319 Tests traversing a DOM structure using the Prototype JavaScript Library.
321 tag = 'cssqueryjquery'
322 query_param = 'cssquery-jquery'
324 @classmethod
325 def Name(cls):
326 return 'dromaeo.cssqueryjquery'