1 Test IndexedDB's IDBObjectStore.count().
3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
6 dbname = "objectstore-count.html"
7 indexedDB.deleteDatabase(dbname)
9 store = db.createObjectStore('storeName', null)
12 verifying count without range
13 trans = db.transaction('storeName', 'readonly')
14 PASS trans is non-null.
15 store = trans.objectStore('storeName')
16 PASS store is non-null.
17 request = store.count()
18 PASS typeof request.result is "number"
19 PASS request.result is 100
21 verifying count with range
22 trans = db.transaction('storeName', 'readonly')
23 PASS trans is non-null.
24 store = trans.objectStore('storeName')
25 PASS store is non-null.
27 test = {"lower":0,"lowerOpen":false,"upper":99,"upperOpen":false,"expected":100}
28 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
29 PASS typeof request.result is "number"
30 PASS request.result is 100
32 test = {"lower":0,"lowerOpen":true,"upper":99,"upperOpen":false,"expected":99}
33 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
34 PASS typeof request.result is "number"
35 PASS request.result is 99
37 test = {"lower":0,"lowerOpen":false,"upper":99,"upperOpen":true,"expected":99}
38 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
39 PASS typeof request.result is "number"
40 PASS request.result is 99
42 test = {"lower":0,"lowerOpen":true,"upper":99,"upperOpen":true,"expected":98}
43 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
44 PASS typeof request.result is "number"
45 PASS request.result is 98
47 test = {"lower":0,"lowerOpen":false,"upper":100,"upperOpen":false,"expected":100}
48 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
49 PASS typeof request.result is "number"
50 PASS request.result is 100
52 test = {"lower":0,"lowerOpen":false,"upper":100,"upperOpen":false,"expected":100}
53 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
54 PASS typeof request.result is "number"
55 PASS request.result is 100
57 test = {"lower":10,"lowerOpen":false,"upper":100,"upperOpen":false,"expected":90}
58 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
59 PASS typeof request.result is "number"
60 PASS request.result is 90
62 test = {"lower":0,"lowerOpen":false,"upper":0,"upperOpen":false,"expected":1}
63 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
64 PASS typeof request.result is "number"
65 PASS request.result is 1
67 test = {"lower":500,"lowerOpen":false,"upper":500,"upperOpen":false,"expected":0}
68 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
69 PASS typeof request.result is "number"
70 PASS request.result is 0
72 verifying count with key
73 trans = db.transaction('storeName', 'readonly')
74 PASS trans is non-null.
75 store = trans.objectStore('storeName')
76 PASS store is non-null.
77 Expecting exception from store.count(NaN)
78 PASS Exception was thrown.
80 PASS ename is 'DataError'
81 Exception message: Failed to execute 'count' on 'IDBObjectStore': The parameter is not a valid key.
82 Expecting exception from store.count({})
83 PASS Exception was thrown.
85 PASS ename is 'DataError'
86 Exception message: Failed to execute 'count' on 'IDBObjectStore': The parameter is not a valid key.
87 Expecting exception from store.count(/regex/)
88 PASS Exception was thrown.
90 PASS ename is 'DataError'
91 Exception message: Failed to execute 'count' on 'IDBObjectStore': The parameter is not a valid key.
93 test = {"key":0,"expected":1}
94 request = store.count(test.key)
95 PASS typeof request.result is "number"
96 PASS request.result is 1
98 test = {"key":100,"expected":0}
99 request = store.count(test.key)
100 PASS typeof request.result is "number"
101 PASS request.result is 0
103 test = {"key":null,"expected":100}
104 request = store.count(test.key)
105 PASS typeof request.result is "number"
106 PASS request.result is 100
107 PASS successfullyParsed is true