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
6function cursorSuccess()
7{
8    debug("Cursor opened successfully.")
9    // FIXME: check that we can iterate the cursor.
10    shouldBe("event.target.result.direction", "'next'");
11    shouldBe("event.target.result.key", "'myKey' + count");
12    shouldBe("event.target.result.value.keyPath", "'myKey' + count");
13    shouldBe("event.target.result.value.value", "'myValue' + count");
14    if (++count >= 5)
15        done();
16    else
17        openCursor();
18}
19
20function openCursor()
21{
22    debug("Opening cursor #" + count);
23    keyRange = webkitIDBKeyRange.lowerBound("myKey" + count);
24    request = objectStore.openCursor(keyRange);
25    request.onsuccess = cursorSuccess;
26    request.onerror = unexpectedErrorCallback;
27}
28
29function populateObjectStore()
30{
31    debug("Populating object store #" + count);
32    obj = {'keyPath': 'myKey' + count, 'value': 'myValue' + count};
33    request = objectStore.add(obj);
34    request.onerror = unexpectedErrorCallback;
35    if (++count >= 5) {
36        count = 0;
37        request.onsuccess = openCursor;
38    } else {
39        request.onsuccess = populateObjectStore;
40    }
41}
42
43function createObjectStore()
44{
45    debug('createObjectStore');
46    db = event.target.result;
47    window.objectStore = db.createObjectStore('test', {keyPath: 'keyPath'});
48    count = 0;
49    populateObjectStore();
50}
51
52function test()
53{
54    indexedDBTest(createObjectStore);
55}
56