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 core
import perf_benchmark
27 from telemetry
.core
import util
28 from telemetry
import page
as page_module
29 from telemetry
.page
import page_test
30 from telemetry
import story
31 from telemetry
.value
import scalar
33 from metrics
import memory
34 from metrics
import power
37 class _IndexedDbMeasurement(page_test
.PageTest
):
39 super(_IndexedDbMeasurement
, self
).__init
__()
40 self
._memory
_metric
= None
41 self
._power
_metric
= None
43 def WillStartBrowser(self
, platform
):
44 """Initialize metrics once right before the browser has been launched."""
45 self
._power
_metric
= power
.PowerMetric(platform
)
47 def DidStartBrowser(self
, browser
):
48 """Initialize metrics once right after the browser has been launched."""
49 self
._memory
_metric
= memory
.MemoryMetric(browser
)
51 def DidNavigateToPage(self
, page
, tab
):
52 self
._memory
_metric
.Start(page
, tab
)
53 self
._power
_metric
.Start(page
, tab
)
55 def ValidateAndMeasurePage(self
, page
, tab
, results
):
56 tab
.WaitForDocumentReadyStateToBeComplete()
57 tab
.WaitForJavaScriptExpression(
58 'window.document.cookie.indexOf("__done=1") >= 0', 600)
60 self
._power
_metric
.Stop(page
, tab
)
61 self
._memory
_metric
.Stop(page
, tab
)
63 self
._memory
_metric
.AddResults(tab
, results
)
64 self
._power
_metric
.AddResults(tab
, results
)
66 js_get_results
= "JSON.stringify(automation.getResults());"
67 result_dict
= json
.loads(tab
.EvaluateJavaScript(js_get_results
))
69 for key
in result_dict
:
70 if key
== 'OverallTestDuration':
72 msec
= float(result_dict
[key
])
73 results
.AddValue(scalar
.ScalarValue(
74 results
.current_page
, key
, 'ms', msec
, important
=False))
77 results
.AddValue(scalar
.ScalarValue(
78 results
.current_page
, 'Total Perf', 'ms', total
))
81 def CustomizeBrowserOptions(self
, options
):
82 memory
.MemoryMetric
.CustomizeBrowserOptions(options
)
83 power
.PowerMetric
.CustomizeBrowserOptions(options
)
85 class IndexedDb(perf_benchmark
.PerfBenchmark
):
86 """Chromium's IndexedDB Performance tests."""
87 test
= _IndexedDbMeasurement
91 return 'indexeddb_perf'
93 def CreateStorySet(self
, options
):
94 indexeddb_dir
= os
.path
.join(util
.GetChromiumSrcDir(), 'chrome', 'test',
96 ps
= story
.StorySet(base_dir
=indexeddb_dir
)
97 ps
.AddStory(page_module
.Page('file://perf_test.html', ps
, ps
.base_dir
))