1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB primary key ordering and readback from cursors.");
8 indexedDBTest(prepareDatabase, populateStore);
9 function prepareDatabase()
11 db = event.target.result;
12 evalAndLog("store = db.createObjectStore('store')");
13 evalAndLog("index = store.createIndex('index', 'indexKey')");
36 function populateStore()
39 debug("populating store...");
40 evalAndLog("trans = db.transaction('store', 'readwrite')");
41 evalAndLog("store = trans.objectStore('store');");
42 trans.onerror = unexpectedErrorCallback;
43 trans.onabort = unexpectedAbortCallback;
46 var keys = self.keys.slice();
48 keys.forEach(function(key) {
49 var value = { indexKey: indexKey, count: count++ };
50 evalAndLog("store.put(" + JSON.stringify(value) + ", " + key + ")");
52 trans.oncomplete = checkStore;
58 debug("iterating cursor...");
59 evalAndLog("trans = db.transaction('store', 'readonly')");
60 evalAndLog("store = trans.objectStore('store');");
61 evalAndLog("index = store.index('index');");
62 trans.onerror = unexpectedErrorCallback;
63 trans.onabort = unexpectedAbortCallback;
64 cursorRequest = evalAndLog("cursorRequest = index.openCursor()");
65 evalAndLog("count = 0");
67 cursorRequest.onerror = unexpectedErrorCallback;
68 cursorRequest.onsuccess = function() {
69 if (cursorRequest.result) {
70 evalAndLog("cursor = cursorRequest.result");
71 shouldBe("cursor.key", String(indexKey));
72 shouldBe("cursor.primaryKey", self.keys[count++]);
75 shouldBe("count", "keys.length");