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 """Runs Chromium's IndexedDB performance test. These test:
25 from telemetry
import benchmark
26 from telemetry
.core
import util
27 from telemetry
import page
as page_module
28 from telemetry
.page
import page_set
29 from telemetry
.page
import page_test
30 from telemetry
.value
import scalar
32 from metrics
import memory
33 from metrics
import power
36 class _IndexedDbMeasurement(page_test
.PageTest
):
38 super(_IndexedDbMeasurement
, self
).__init
__()
39 self
._memory
_metric
= None
40 self
._power
_metric
= None
42 def WillStartBrowser(self
, platform
):
43 """Initialize metrics once right before the browser has been launched."""
44 self
._power
_metric
= power
.PowerMetric(platform
)
46 def DidStartBrowser(self
, browser
):
47 """Initialize metrics once right after the browser has been launched."""
48 self
._memory
_metric
= memory
.MemoryMetric(browser
)
50 def DidNavigateToPage(self
, page
, tab
):
51 self
._memory
_metric
.Start(page
, tab
)
52 self
._power
_metric
.Start(page
, tab
)
54 def ValidateAndMeasurePage(self
, page
, tab
, results
):
55 tab
.WaitForDocumentReadyStateToBeComplete()
56 tab
.WaitForJavaScriptExpression(
57 'window.document.cookie.indexOf("__done=1") >= 0', 600)
59 self
._power
_metric
.Stop(page
, tab
)
60 self
._memory
_metric
.Stop(page
, tab
)
62 self
._memory
_metric
.AddResults(tab
, results
)
63 self
._power
_metric
.AddResults(tab
, results
)
65 js_get_results
= "JSON.stringify(automation.getResults());"
66 result_dict
= json
.loads(tab
.EvaluateJavaScript(js_get_results
))
68 for key
in result_dict
:
69 if key
== 'OverallTestDuration':
71 msec
= float(result_dict
[key
])
72 results
.AddValue(scalar
.ScalarValue(
73 results
.current_page
, key
, 'ms', msec
, important
=False))
76 results
.AddValue(scalar
.ScalarValue(
77 results
.current_page
, 'Total Perf', 'ms', total
))
80 def CustomizeBrowserOptions(self
, options
):
81 memory
.MemoryMetric
.CustomizeBrowserOptions(options
)
82 power
.PowerMetric
.CustomizeBrowserOptions(options
)
84 class IndexedDb(benchmark
.Benchmark
):
85 """Chromium's IndexedDB Performance tests."""
86 test
= _IndexedDbMeasurement
90 return 'indexeddb_perf'
92 def CreatePageSet(self
, options
):
93 indexeddb_dir
= os
.path
.join(util
.GetChromiumSrcDir(), 'chrome', 'test',
95 ps
= page_set
.PageSet(file_path
=indexeddb_dir
)
96 ps
.AddUserStory(page_module
.Page('file://perf_test.html', ps
, ps
.base_dir
))