idbobjectstore_count.any.js (2599B)
1 // META: global=window,worker 2 // META: title=IDBObjectStore.count() 3 // META: script=resources/support.js 4 5 'use strict'; 6 7 async_test(t => { 8 let db; 9 10 let open_rq = createdb(t); 11 12 open_rq.onupgradeneeded = function(e) { 13 db = e.target.result; 14 let store = db.createObjectStore("store"); 15 16 for(let i = 0; i < 10; i++) { 17 store.add({ data: "data" + i }, i); 18 } 19 } 20 21 open_rq.onsuccess = function(e) { 22 let rq = db.transaction("store", "readonly") 23 .objectStore("store") 24 .count(); 25 26 rq.onsuccess = t.step_func(function(e) { 27 assert_equals(e.target.result, 10); 28 t.done(); 29 }); 30 } 31 }, "Returns the number of records in the object store "); 32 33 async_test(t => { 34 let db; 35 36 let open_rq = createdb(t); 37 38 open_rq.onupgradeneeded = function(e) { 39 db = e.target.result; 40 let store = db.createObjectStore("store"); 41 42 for(let i = 0; i < 10; i++) { 43 store.add({ data: "data" + i }, i); 44 } 45 } 46 47 open_rq.onsuccess = function(e) { 48 let rq = db.transaction("store", "readonly") 49 .objectStore("store") 50 .count(IDBKeyRange.bound(5, 20)); 51 52 rq.onsuccess = t.step_func(function(e) { 53 assert_equals(e.target.result, 5); 54 t.done(); 55 }); 56 } 57 }, "Returns the number of records that have keys within the range "); 58 59 async_test(t => { 60 let db 61 62 createdb(t).onupgradeneeded = function(e) { 63 db = e.target.result 64 65 let store = db.createObjectStore("store", { keyPath: "k" }) 66 67 for (let i = 0; i < 5; i++) 68 store.add({ k: "key_" + i }); 69 70 store.count("key_2").onsuccess = t.step_func(function(e) { 71 assert_equals(e.target.result, 1, "count(key_2)") 72 73 store.count("key_").onsuccess = t.step_func(function(e) { 74 assert_equals(e.target.result, 0, "count(key_)") 75 t.done() 76 }) 77 }) 78 } 79 80 }, "Returns the number of records that have keys with the key"); 81 82 async_test(t => { 83 let db, ostore; 84 85 let open_rq = createdb(t); 86 open_rq.onupgradeneeded = function (event) { 87 db = event.target.result; 88 ostore = db.createObjectStore("store", {keyPath:"pKey"}); 89 db.deleteObjectStore("store"); 90 assert_throws_dom("InvalidStateError", function(){ 91 ostore.count(); 92 }); 93 t.done(); 94 } 95 }, "If the object store has been deleted, the implementation must throw a DOMException of type InvalidStateError ");