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

Unified Diff: client/tests/client/dom/IndexedDB1Test.dart

Issue 10008012: First indexeddb test (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/testing/dart/browser_test.dart » ('j') | tools/testing/dart/browser_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/tests/client/dom/IndexedDB1Test.dart
diff --git a/client/tests/client/dom/IndexedDB1Test.dart b/client/tests/client/dom/IndexedDB1Test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f89221ce78bcea8d7d4b3bc7da743888bfc702ee
--- /dev/null
+++ b/client/tests/client/dom/IndexedDB1Test.dart
@@ -0,0 +1,67 @@
+#library('IndexedDB1Test');
+#import('../../../../lib/unittest/unittest_dom.dart');
+#import('dart:dom');
+
+final String dbName = 'Test';
+final String storeName = 'TEST';
+final String VERSION = '1';
vsm 2012/04/05 20:11:28 Consistent all caps for constants?
sra1 2012/04/05 21:23:08 Done.
+
+testReadWrite(key, value, check,
+ [dbName = dbName,
+ storeName = storeName,
+ version = VERSION]) => () {
+ var db;
+
+ onFail(e) {
+ callbackDone();
+ Expect.fail('IndexedDB failure');
+ }
+
+ createObjectStore(e) {
vsm 2012/04/05 20:11:28 Drop argument if unused / unnecessary.
sra1 2012/04/05 21:23:08 Done.
+ var store = db.createObjectStore(storeName);
+ Expect.isNotNull(store);
+ }
+
+ initDb(e, andThen) {
+ db = e.target.result;
+ if (version != db.version) {
+ var request = db.setVersion(VERSION);
vsm 2012/04/05 20:11:28 Do you mean to use the uppercase VERSION in this l
sra1 2012/04/05 21:23:08 Done.
+ request.onsuccess = (e) { createObjectStore(e); andThen(); };
vsm 2012/04/05 20:11:28 Perhaps just call step1 directly instead of the an
sra1 2012/04/05 21:23:08 Done.
+ request.onerror = onFail;
+ } else {
+ andThen();
+ }
+ }
+
+ step2() {
+ var transaction = db.transaction(storeName, IDBTransaction.READ_ONLY);
+ var request = transaction.objectStore(storeName).getObject(key);
+ request.onsuccess = (e) {
+ var object = e.target.result;
+ check(value, object);
+ callbackDone();
+ };
+ request.onerror = onFail;
+ }
+
+ step1() {
+ var transaction = db.transaction([storeName], IDBTransaction.READ_WRITE);
+ var request = transaction.objectStore(storeName).put(value, key);
+ request.onsuccess = (e) { step2(); };
+ request.onerror = onFail;
+ }
+
+ var request = window.webkitIndexedDB.open(dbName);
+ Expect.isNotNull(request);
+ request.onsuccess = (e) { initDb(e, step1); };
+ request.onerror = onFail;
+};
+
+main() {
+ forLayoutTests();
+
+ asyncTest('test1', 1, testReadWrite(123, 'Hoot!', Expect.equals));
+ asyncTest('test2', 1, testReadWrite(123, 12345, Expect.equals));
+ asyncTest('test3', 1, testReadWrite(123, [1,2,3], Expect.listEquals));
+ asyncTest('test4', 1, testReadWrite(123, const [2, 3, 4], Expect.listEquals));
+}
« no previous file with comments | « no previous file | tools/testing/dart/browser_test.dart » ('j') | tools/testing/dart/browser_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698