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. 4 5"""Runs Chromium's IndexedDB performance test. These test: 6 7Databases: 8 create/delete 9Keys: 10 create/delete 11Indexes: 12 create/delete 13Data access: 14 Random read/write 15 Sporadic writes 16 Read cache 17Cursors: 18 Read & random writes 19 Walking multiple 20 Seeking. 21""" 22 23import json 24import os 25 26from telemetry import test 27from telemetry.core import util 28from telemetry.page import page_measurement 29from telemetry.page import page_set 30 31 32class _IndexedDbMeasurement(page_measurement.PageMeasurement): 33 def MeasurePage(self, _, tab, results): 34 tab.WaitForDocumentReadyStateToBeComplete() 35 tab.WaitForJavaScriptExpression( 36 'window.document.cookie.indexOf("__done=1") >= 0', 600) 37 38 js_get_results = "JSON.stringify(automation.getResults());" 39 result_dict = json.loads(tab.EvaluateJavaScript(js_get_results)) 40 total = 0.0 41 for key in result_dict: 42 if key == 'OverallTestDuration': 43 continue 44 msec = float(result_dict[key]) 45 results.Add(key, 'ms', msec, data_type='unimportant') 46 total += msec 47 results.Add('Total', 'ms', total) 48 49class IndexedDb(test.Test): 50 """Chromium's IndexedDB Performance tests.""" 51 test = _IndexedDbMeasurement 52 53 def CreatePageSet(self, options): 54 indexeddb_dir = os.path.join(util.GetChromiumSrcDir(), 'chrome', 'test', 55 'data', 'indexeddb') 56 return page_set.PageSet.FromDict({ 57 'pages': [ 58 { 'url': 'file://perf_test.html' } 59 ] 60 }, indexeddb_dir) 61