Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/test/data/indexeddb/perf_shared.js

Issue 10575043: Initial checkin of a perf test suite for Indexed Database. This just has a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added copyright header Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/data/indexeddb/perf_test.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 window.indexedDB = window.indexedDB || window.webkitIndexedDB ||
6 window.mozIndexedDB || window.msIndexedDB;
7
8 var automation = {
9 results: {}
10 };
11
12 automation.setDone = function() {
13 this.setStatus("Test complete.");
14 document.cookie = '__done=1; path=/';
15 };
16
17 automation.addResult = function(name, result) {
18 result = "" + result;
19 this.results[name] = result;
20 var elt = document.getElementById('results');
21 var div = document.createElement('div');
22 div.innerText = name + ": " + result;
23 elt.appendChild(div);
24 };
25
26 automation.getResults = function() {
27 return this.results;
28 };
29
30 automation.setStatus = function(s) {
31 document.getElementById('status').innerText = s;
32 };
33
34 function assert(t) {
35 if (!t) {
36 var e = new Error("Assertion failed!");
37 console.log(e.stack);
38 throw e;
39 }
40 }
41
42 function onError(e) {
43 console.log(e);
44 e.stopPropagation();
45 throw new Error(e);
46 }
47
48 var version = 2; // The version with our object stores.
49 var db;
50
51 function createDatabase(name, objectStores, handler, errorHandler) {
52 var openRequest = indexedDB.open(name, version);
53 openRequest.onblocked = errorHandler;
54 function createObjectStores(db) {
55 for (var store in objectStores) {
56 var name = objectStores[store];
57 assert(!db.objectStoreNames.contains(name));
58 db.createObjectStore(name);
59 }
60 }
61 openRequest.onupgradeneeded = function(ev) {
62 // TODO: This is the spec-compliant path, which doesn't yet work in Chrome,
63 // and isn't yet tested, as this function won't currently be called.
64 assert(openRequest == ev.target);
65 db = openRequest.result;
66 createObjectStores(db);
67 // onsuccess will get called after this exits.
68 };
69 openRequest.onsuccess = function(ev) {
70 assert(openRequest == ev.target);
71 db = openRequest.result;
72 db.onerror = function(ev) {
73 console.log("db error", arguments, openRequest.webkitErrorMessage);
74 errorHandler();
75 }
76 if (db.version != version) {
77 // This is the current Chrome path.
78 var setVersionRequest = db.setVersion(version);
79 setVersionRequest.onfailure = errorHandler;
80 setVersionRequest.onsuccess =
81 function(e) {
82 assert(setVersionRequest == e.target);
83 createObjectStores(db);
84 var versionTransaction = setVersionRequest.result;
85 versionTransaction.oncomplete = function() {handler(db); };
86 versionTransaction.onerror = onError;
87 }
88 } else {
89 handler(db);
90 }
91 }
92 }
93
94 function getTransaction(db, objectStoreNames, mode, opt_handler) {
95 var transaction = db.transaction(objectStoreNames, mode);
96 transaction.onerror = onError;
97 transaction.onabort = onError;
98 if (opt_handler) {
99 transaction.oncomplete = opt_handler;
100 }
101 return transaction;
102 }
103
104 function deleteDatabase(name, opt_handler) {
105 var deleteRequest = indexedDB.deleteDatabase(name);
106 deleteRequest.onerror = onError;
107 if (opt_handler) {
108 deleteRequest.onsuccess = opt_handler;
109 }
110 }
111
112 function cleanUp(opt_handler) {
113 if (db) {
114 deleteDatabase(db, opt_handler);
115 db = null;
116 }
117 }
118
119 function stringOfLength(n) {
120 assert(n > 0);
121 assert(n == Math.floor(n));
122 return new Array(n + 1).join('0');
123 }
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/data/indexeddb/perf_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698