[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / tools / perf / benchmarks / indexeddb_perf.py
blobae1d435b45e0848efaf4e977bfb259aee76135fa
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:
7 Databases:
8 create/delete
9 Keys:
10 create/delete
11 Indexes:
12 create/delete
13 Data access:
14 Random read/write
15 Read cache
16 Cursors:
17 Read & random writes
18 Walking multiple
19 Seeking.
20 """
22 import json
23 import os
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):
38 def __init__(self):
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))
68 total = 0.0
69 for key in result_dict:
70 if key == 'OverallTestDuration':
71 continue
72 msec = float(result_dict[key])
73 results.AddValue(scalar.ScalarValue(
74 results.current_page, key, 'ms', msec, important=False))
76 total += msec
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
89 @classmethod
90 def Name(cls):
91 return 'indexeddb_perf'
93 def CreateStorySet(self, options):
94 indexeddb_dir = os.path.join(util.GetChromiumSrcDir(), 'chrome', 'test',
95 'data', 'indexeddb')
96 ps = story.StorySet(base_dir=indexeddb_dir)
97 ps.AddStory(page_module.Page('file://perf_test.html', ps, ps.base_dir))
98 return ps