Skip to content

Commit 8765d7e

Browse files
author
Parashuram
committed
Added directions to indexes
1 parent 25a7ff6 commit 8765d7e

File tree

3 files changed

+70
-27
lines changed

3 files changed

+70
-27
lines changed

jquery.indexeddb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@
557557
"each": function(callback, range, direction){
558558
return indexOp("each", indexName, [callback, range, direction]);
559559
},
560-
"eachKey": function(callback, range){
561-
return indexOp("eachKey", indexName, [callback, range]);
560+
"eachKey": function(callback, range, direction){
561+
return indexOp("eachKey", indexName, [callback, range, direction]);
562562
}
563563
};
564564
}

lib/queuedUnit.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* Once the current test is over, call nextTest() to start running the next test
4848
*/
4949
var timer = null;
50+
var testCount = 1;
5051
function nextTest(){
5152
window.clearTimeout(timer);
5253
if (testQueue.length <= 0) {
@@ -56,22 +57,17 @@
5657
}
5758
var current = testQueue.splice(0, 1)[0];
5859
console.groupEnd();
59-
console.groupCollapsed("=========", current.module, ":", current.name, "============");
60+
console.groupCollapsed("=========", testCount++, current.module, ":", current.name, "============");
6061
module(current.module);
6162
// Expected asserts specified or not
6263
if (current.args.length === 2) {
6364
asyncTest(current.name, current.args[1]);
6465
} else if (current.args.length === 3) {
65-
asyncTest(current.name, currentargs[1], current.args[2]);
66+
asyncTest(current.name, current.args[1], current.args[2]);
6667
}
67-
/*timer = window.setTimeout(function(){
68-
ok(false, "Timeout exceeded for this test, so moving on to next test");
69-
start();
70-
nextTest();
71-
}, 1000);*/
7268
}
7369

74-
window["queuedAsyncTest"] = queuedAsyncTest;
75-
window["queuedModule"] = queuedModule;
76-
window["nextTest"] = nextTest;
70+
window.queuedAsyncTest = queuedAsyncTest;
71+
window.queuedModule = queuedModule;
72+
window.nextTest = nextTest;
7773
}(window, console));

test/index.html

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
});
152152

153153
queuedAsyncTest("Open a lower version schema", function(){
154-
155154
$.indexedDB(DB.NAME, 1).then(function(res, e){
156155
ok(false, "Should not have opened as DB was lower version");
157156
_("Should not have opened as DB was lower version");
@@ -220,6 +219,7 @@
220219
ok(true, "Added " + res + " to the database");
221220
_("Added" + res + "to the database ");
222221
start();
222+
stop();
223223
$.indexedDB(DB.NAME).objectStore(DB.OBJECT_STORE_1).get(res).then(function(val){
224224
deepEqual(val, value, "Value of the returned object " + val);
225225
_("Got object using" + res + " key");
@@ -386,12 +386,12 @@
386386
ok(true, "Object Deleted " + elem.key);
387387
_("Object Deleted");
388388
start();
389-
nextTest();
389+
stop();
390390
}, function(){
391391
ok(false, "Object NOT Deleted " + elem.key);
392392
_("Object NOT Deleted");
393393
start();
394-
nextTest();
394+
stop();
395395
});
396396
} else {
397397
var val = elem.value;
@@ -400,12 +400,12 @@
400400
ok(true, "Object updated " + elem.key);
401401
_("Object updated");
402402
start();
403-
nextTest();
403+
stop();
404404
}, function(){
405405
ok(false, "Object NOT updated " + elem.key);
406406
_("Object NOT updated");
407407
start();
408-
nextTest();
408+
stop();
409409
});
410410
}
411411
ok(true, "Looking at " + elem.key);
@@ -414,9 +414,11 @@
414414
}).then(function(){
415415
ok(true, "Iteration complete success");
416416
start();
417+
nextTest();
417418
}, function(){
418419
ok(false, "Iteration complete failure");
419420
start();
421+
nextTest();
420422
});
421423
});
422424

@@ -498,11 +500,34 @@
498500
var value = sample.obj();
499501
var objectStore = $.indexedDB(DB.NAME).objectStore(DB.OBJECT_STORE_1);
500502
objectStore.index("Int").each(function(elem){
501-
equal(elem.key >= 30 && elem.key <= 70, true, elem.value.Int + " is between 30 and 70");
503+
equal(elem.key >= 10 && elem.key <= 90, true, elem.value.Int + " is between 10 and 90");
504+
_("Iterating on " + JSON.stringify(elem.value));
505+
start();
506+
stop();
507+
}, [10, 90]).then(function(res, e){
508+
ok(true, "Index Iteration completed");
509+
start();
510+
nextTest();
511+
}, function(err, e){
512+
ok(false, "Index Iteration NOT completed");
513+
_("Index Iteration NOT completed");
514+
start();
515+
nextTest();
516+
});
517+
});
518+
519+
queuedAsyncTest("Index Iteration with range, reverse", function(){
520+
var key = sample.integer();
521+
var value = sample.obj();
522+
var objectStore = $.indexedDB(DB.NAME).objectStore(DB.OBJECT_STORE_1);
523+
var prev = Infinity;
524+
objectStore.index("Int").each(function(elem){
525+
equal(prev > elem.key, true, elem.key + " is less that the previous value and in range " + prev);
526+
prev = elem.key;
502527
_("Iterating on " + JSON.stringify(elem.value));
503528
start();
504529
stop();
505-
}, [30, 70]).then(function(res, e){
530+
}, [10, 90], $.indexedDB.IDBCursor.PREV).then(function(res, e){
506531
ok(true, "Index Iteration completed");
507532
start();
508533
nextTest();
@@ -517,8 +542,8 @@
517542
queuedAsyncTest("Index iteration with keyCursor", function(){
518543
var key = sample.integer();
519544
var value = sample.obj();
520-
var objectStore = $.indexedDB(DB.NAME).objectStore(DB.OBJECT_STORE_2);
521-
objectStore.index(DB.INDEX1_ON_OBJECT_STORE_2).eachKey(function(elem){
545+
var objectStore = $.indexedDB(DB.NAME).objectStore(DB.OBJECT_STORE_1);
546+
objectStore.index("Int").eachKey(function(elem){
522547
ok(true, "Iterating on " + elem.key + ":" + elem.value);
523548
start();
524549
stop();
@@ -534,6 +559,28 @@
534559
});
535560
});
536561

562+
queuedAsyncTest("Index iteration with keyCursor and range, reverse", function(){
563+
var key = sample.integer();
564+
var value = sample.obj();
565+
var objectStore = $.indexedDB(DB.NAME).objectStore(DB.OBJECT_STORE_1);
566+
var prev = Infinity;
567+
objectStore.index("Int").eachKey(function(elem){
568+
equal(prev > elem.key, true, elem.key + " is less that the previous value " + prev);
569+
prev = elem.key
570+
start();
571+
stop();
572+
}, [10, 90], $.indexedDB.IDBCursor.PREV).then(function(res, e){
573+
ok(true, "Index Iteration completed");
574+
start();
575+
nextTest();
576+
}, function(err, e){
577+
ok(false, "Index Iteration NOT completed");
578+
_("Index Iteration NOT completed");
579+
start();
580+
nextTest();
581+
});
582+
});
583+
537584
queuedModule("Transactions");
538585
queuedAsyncTest("Simple transaction", function(){
539586
$.indexedDB(DB.NAME).transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2, DB.OBJECT_STORE_3]).then(function(e){
@@ -564,7 +611,6 @@
564611
});
565612

566613
queuedAsyncTest("Simple transaction with mode", function(){
567-
568614
$.indexedDB(DB.NAME).transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2, DB.OBJECT_STORE_3], $.indexedDB.IDBTransaction.READ_WRITE).then(function(e){
569615
equal(e.type, "complete", "Transaction completed successfully");
570616
start();
@@ -582,7 +628,6 @@
582628
});
583629

584630
queuedAsyncTest("Aborted transaction", function(){
585-
586631
$.indexedDB(DB.NAME).transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2, DB.OBJECT_STORE_3]).then(function(e){
587632
notEqual(e.type, "complete", "Transaction completed successfully");
588633
start();
@@ -605,7 +650,6 @@
605650
});
606651

607652
queuedAsyncTest("Transaction with non-existant object store", function(){
608-
609653
$.indexedDB(DB.NAME).transaction(["Error ", DB.OBJECT_STORE_2, DB.OBJECT_STORE_3]).then(function(e){
610654
notEqual(e.type, "complete", "Transaction completed successfully");
611655
start();
@@ -620,7 +664,6 @@
620664
});
621665

622666
queuedAsyncTest("Transaction aborts due to exception when in progress", function(){
623-
624667
$.indexedDB(DB.NAME).transaction([DB.OBJECT_STORE_1, DB.OBJECT_STORE_2, DB.OBJECT_STORE_3]).then(function(e){
625668
notEqual(e.type, "complete", "Transaction completed successfully");
626669
start();
@@ -637,7 +680,6 @@
637680
});
638681

639682
queuedAsyncTest("Multiple object store ops", function(){
640-
641683
var testCount = 0;
642684
for (var i = 0; i < 10; i++) {
643685
(function(mode, count){
@@ -681,7 +723,6 @@
681723
});
682724

683725
queuedAsyncTest("Multiple transactions at same time", function(){
684-
685726
var testCount = 0;
686727
for (var i = 0; i < 10; i++) {
687728
(function(mode, count){
@@ -705,14 +746,20 @@
705746
transaction.objectStore(DB.OBJECT_STORE_1).add(sample.obj(), count).then(function(res, e){
706747
_(count + "> Added to Object Store 1: " + mode);
707748
ok(true, count + "> Added to Object Store 1: " + mode);
749+
start();
750+
stop();
708751
}, function(err, e){
709752
_(count + "> Could not add to Object Store 1: " + mode);
710753
ok(false, count + "> Could not add in transaction to Object Store 1: " + mode);
754+
start();
755+
stop();
711756
});
712757
} else {
713758
transaction.objectStore(DB.OBJECT_STORE_1).each(function(elem){
714759
_(count + "> Reading " + elem.key);
715760
ok(true, count + "> Reading " + elem.key);
761+
start();
762+
stop();
716763
return false;
717764
});
718765
}

0 commit comments

Comments
 (0)