mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:06:59 +00:00
Next IndexedDB test - scan with a cursor.
Review URL: https://chromiumcodereview.appspot.com//10079028 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@6609 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
475fbca314
commit
aa51ea5010
|
@ -25,6 +25,7 @@ dom/IsolatesTest: Skip # Timeout because leg does not support web workers.
|
|||
|
||||
dom/IndexedDB1Test: Skip # Timeout because callbacks don't appear to be called.
|
||||
dom/IndexedDB2Test: Skip # Timeout because callbacks don't appear to be called.
|
||||
dom/IndexedDB3Test: Skip # Timeout because callbacks don't appear to be called.
|
||||
|
||||
[ $compiler == dart2js && $runtime == none ]
|
||||
*: Fail, Pass # TODO(ahe): Triage these tests.
|
||||
|
|
|
@ -6,6 +6,7 @@ dom/WebGL1Test: Skip # Issue 1495
|
|||
|
||||
[ $compiler == none && ($runtime == drt || $runtime == dartium) ]
|
||||
html/html_tests: Pass, Fail # Issue 1946.
|
||||
dom/IndexedDB3Test: Fail # UnsupportedOperationException 'IDBCursorImplementation.get:key'
|
||||
|
||||
[ $compiler == none && ($runtime == drt || $runtime == dartium) && $checked ]
|
||||
html/TypedArrays1Test: Fail # Fails only on checked mode.
|
||||
|
@ -53,6 +54,7 @@ dom/HiddenDom1Test: Fail
|
|||
dom/HiddenDom2Test: Fail
|
||||
dom/IndexedDB1Test: Fail # Need window.mozIndexedDB instead of window.webkitIndexedDB
|
||||
dom/IndexedDB2Test: Fail # Need window.mozIndexedDB instead of window.webkitIndexedDB
|
||||
dom/IndexedDB3Test: Fail # Need window.mozIndexedDB instead of window.webkitIndexedDB
|
||||
dom/InstanceOfTest: Fail # Issue 2535
|
||||
# setup code fails. prepare. (DOM callback has errors) Caught [object Event]
|
||||
dom/InnerFrameTest: Fail
|
||||
|
@ -106,8 +108,11 @@ html/frog_html_tests: Skip # Issue 1884
|
|||
*: Skip
|
||||
|
||||
[ $checked ]
|
||||
dom/IndexedDB1Test: Skip # Type check fails for IDBKey, causing Fail or Timeout. Needs to be renamed to Object or Dynamic.
|
||||
dom/IndexedDB2Test: Skip # Type check fails for IDBKey, causing Fail or Timeout. Needs to be renamed to Object or Dynamic.
|
||||
# IndexedDB tests: type check fails for IDBKey, causing Fail or Timeout. Needs
|
||||
# to be renamed to Dynamic.
|
||||
dom/IndexedDB1Test: Skip
|
||||
dom/IndexedDB2Test: Skip
|
||||
dom/IndexedDB3Test: Skip
|
||||
|
||||
[ ($compiler == frog || $compiler == frogsh) && $runtime == none ]
|
||||
*: Skip
|
||||
|
|
119
client/tests/client/dom/IndexedDB3Test.dart
Normal file
119
client/tests/client/dom/IndexedDB3Test.dart
Normal file
|
@ -0,0 +1,119 @@
|
|||
#library('IndexedDB3Test');
|
||||
#import('../../../../lib/unittest/unittest.dart');
|
||||
#import('../../../../lib/unittest/dom_config.dart');
|
||||
#import('dart:dom');
|
||||
#import('dart:coreimpl');
|
||||
|
||||
// Read with cursor.
|
||||
|
||||
final String DB_NAME = 'Test';
|
||||
final String STORE_NAME = 'TEST';
|
||||
final String VERSION = '1';
|
||||
|
||||
class Test {
|
||||
var db;
|
||||
|
||||
start() {
|
||||
var request = window.webkitIndexedDB.open(DB_NAME);
|
||||
Expect.isNotNull(request);
|
||||
request.addEventListener('success', initDb);
|
||||
request.addEventListener('error', fail('open'));
|
||||
}
|
||||
|
||||
initDb(e) {
|
||||
db = e.target.result;
|
||||
// TODO. Some browsers do this the w3 way - passing the VERSION to the
|
||||
// open call and listening to onversionchange. Can we feature-detect the
|
||||
// difference and make it work?
|
||||
var request = db.setVersion(VERSION);
|
||||
request.addEventListener('success', (e) {
|
||||
try {
|
||||
// Nuke object store if it already exists.
|
||||
db.deleteObjectStore(STORE_NAME);
|
||||
} catch (IDBDatabaseException e) { }
|
||||
db.createObjectStore(STORE_NAME);
|
||||
writeItems(0);
|
||||
});
|
||||
request.addEventListener('blocked', fail('setVersion blocked'));
|
||||
request.addEventListener('error', fail('setVersion error'));
|
||||
}
|
||||
|
||||
writeItems(int index) {
|
||||
if (index < 100) {
|
||||
var transaction = db.transaction([STORE_NAME], IDBTransaction.READ_WRITE);
|
||||
var request = transaction.objectStore(STORE_NAME)
|
||||
.put('Item $index', index);
|
||||
request.addEventListener('success', (e) { writeItems(index + 1); });
|
||||
request.addEventListener('error', fail('put'));
|
||||
} else {
|
||||
callbackDone();
|
||||
}
|
||||
}
|
||||
|
||||
fail(message) => (e) {
|
||||
callbackDone();
|
||||
Expect.fail('IndexedDB failure: $message');
|
||||
};
|
||||
|
||||
readAllViaCursor() {
|
||||
IDBTransaction txn = db.transaction(STORE_NAME, IDBTransaction.READ_ONLY);
|
||||
IDBObjectStore objectStore = txn.objectStore(STORE_NAME);
|
||||
IDBRequest cursorRequest = objectStore.openCursor();
|
||||
int itemCount = 0;
|
||||
int sumKeys = 0;
|
||||
int lastKey = null;
|
||||
cursorRequest.addEventListener("success", (e) {
|
||||
var cursor = e.target.result;
|
||||
if (cursor != null) {
|
||||
lastKey = cursor.key;
|
||||
itemCount += 1;
|
||||
sumKeys += cursor.key;
|
||||
Expect.equals('Item ${cursor.key}', cursor.value);
|
||||
cursor.continueFunction();
|
||||
} else {
|
||||
// Done
|
||||
Expect.equals(99, lastKey);
|
||||
Expect.equals(100, itemCount);
|
||||
Expect.equals((100 * 99) ~/ 2, sumKeys);
|
||||
callbackDone();
|
||||
}
|
||||
});
|
||||
cursorRequest.addEventListener('error', fail('openCursor'));
|
||||
}
|
||||
|
||||
readAllReversedViaCursor() {
|
||||
IDBTransaction txn = db.transaction(STORE_NAME, IDBTransaction.READ_ONLY);
|
||||
IDBObjectStore objectStore = txn.objectStore(STORE_NAME);
|
||||
// TODO: create a IDBKeyRange(0,100)
|
||||
IDBRequest cursorRequest = objectStore.openCursor(null, IDBCursor.PREV);
|
||||
int itemCount = 0;
|
||||
int sumKeys = 0;
|
||||
int lastKey = null;
|
||||
cursorRequest.addEventListener("success", (e) {
|
||||
var cursor = e.target.result;
|
||||
if (cursor != null) {
|
||||
lastKey = cursor.key;
|
||||
itemCount += 1;
|
||||
sumKeys += cursor.key;
|
||||
Expect.equals('Item ${cursor.key}', cursor.value);
|
||||
cursor.continueFunction();
|
||||
} else {
|
||||
// Done
|
||||
Expect.equals(0, lastKey); // i.e. first key (scanned in reverse).
|
||||
Expect.equals(100, itemCount);
|
||||
Expect.equals((100 * 99) ~/ 2, sumKeys);
|
||||
callbackDone();
|
||||
}
|
||||
});
|
||||
cursorRequest.addEventListener('error', fail('openCursor'));
|
||||
}
|
||||
}
|
||||
|
||||
main() {
|
||||
useDomConfiguration();
|
||||
|
||||
var test = new Test();
|
||||
asyncTest('prepare', 1, test.start);
|
||||
asyncTest('readAll1', 1, test.readAllViaCursor);
|
||||
asyncTest('readAll2', 1, test.readAllReversedViaCursor);
|
||||
}
|
Loading…
Reference in a new issue