| OLD | NEW |
| (Empty) | |
| 1 <!doctype html> |
| 2 <meta charset=utf-8> |
| 3 <title>IndexedDB: </title> |
| 4 <meta name="help" href="https://w3c.github.io/IndexedDB/#dom-idbobjectstore-put"
> |
| 5 <meta name="help" href="https://w3c.github.io/IndexedDB/#dom-idbcursor-update"> |
| 6 <script src="/resources/testharness.js"></script> |
| 7 <script src="/resources/testharnessreport.js"></script> |
| 8 <script src="support.js"></script> |
| 9 <script> |
| 10 |
| 11 function ProbeObject() { |
| 12 this.id_count = 0; |
| 13 this.invalid_id_count = 0; |
| 14 this.prop_count = 0; |
| 15 Object.defineProperties(this, { |
| 16 id: { |
| 17 enumerable: true, |
| 18 get() { |
| 19 ++this.id_count; |
| 20 return 1000 + this.id_count; |
| 21 }, |
| 22 }, |
| 23 invalid_id: { |
| 24 enumerable: true, |
| 25 get() { |
| 26 ++this.invalid_id_count; |
| 27 return {}; |
| 28 }, |
| 29 }, |
| 30 prop: { |
| 31 enumerable: true, |
| 32 get() { |
| 33 ++this.prop_count; |
| 34 return 2000 + this.prop_count; |
| 35 }, |
| 36 }, |
| 37 }); |
| 38 } |
| 39 |
| 40 indexeddb_test( |
| 41 (t, db) => { |
| 42 db.createObjectStore('store', {keyPath: 'id', autoIncrement: true}); |
| 43 }, |
| 44 (t, db) => { |
| 45 const tx = db.transaction('store', 'readwrite'); |
| 46 const store = tx.objectStore('store'); |
| 47 const obj = new ProbeObject(); |
| 48 store.put(obj); |
| 49 assert_equals( |
| 50 obj.id_count, 1, |
| 51 'put() operation should access primary key property once'); |
| 52 assert_equals( |
| 53 obj.prop_count, 1, |
| 54 'put() operation should access other properties once'); |
| 55 t.done(); |
| 56 }, 'Key generator and key path validity check operates on a clone'); |
| 57 |
| 58 indexeddb_test( |
| 59 (t, db) => { |
| 60 db.createObjectStore('store', {keyPath: 'invalid_id', autoIncrement: true}); |
| 61 }, |
| 62 (t, db) => { |
| 63 const tx = db.transaction('store', 'readwrite'); |
| 64 const store = tx.objectStore('store'); |
| 65 const obj = new ProbeObject(); |
| 66 assert_throws('DataError', () => { store.put(obj); }, |
| 67 'put() should throw if primary key cannot be injected'); |
| 68 assert_equals( |
| 69 obj.invalid_id_count, 1, |
| 70 'put() operation should access primary key property once'); |
| 71 assert_equals( |
| 72 obj.prop_count, 1, |
| 73 'put() operation should access other properties once'); |
| 74 t.done(); |
| 75 }, 'Failing key path validity check operates on a clone'); |
| 76 |
| 77 indexeddb_test( |
| 78 (t, db) => { |
| 79 const store = db.createObjectStore('store'); |
| 80 store.createIndex('index', 'prop'); |
| 81 }, |
| 82 (t, db) => { |
| 83 const tx = db.transaction('store', 'readwrite'); |
| 84 const store = tx.objectStore('store'); |
| 85 const obj = new ProbeObject(); |
| 86 store.put(obj, 'key'); |
| 87 assert_equals( |
| 88 obj.prop_count, 1, 'put() should access index key property once'); |
| 89 assert_equals( |
| 90 obj.id_count, 1, |
| 91 'put() operation should access other properties once'); |
| 92 t.done(); |
| 93 }, 'Index key path evaluations operate on a clone'); |
| 94 |
| 95 indexeddb_test( |
| 96 (t, db) => { |
| 97 const store = db.createObjectStore('store', {keyPath: 'id'}); |
| 98 store.createIndex('index', 'prop'); |
| 99 }, |
| 100 (t, db) => { |
| 101 const tx = db.transaction('store', 'readwrite'); |
| 102 const store = tx.objectStore('store'); |
| 103 const obj = new ProbeObject(); |
| 104 store.put(obj); |
| 105 assert_equals( |
| 106 obj.id_count, 1, 'put() should access primary key property once'); |
| 107 assert_equals( |
| 108 obj.prop_count, 1, 'put() should access index key property once'); |
| 109 t.done(); |
| 110 }, 'Store and index key path evaluations operate on the same clone'); |
| 111 |
| 112 indexeddb_test( |
| 113 (t, db) => { |
| 114 const store = db.createObjectStore('store', {keyPath: 'id'}); |
| 115 store.createIndex('index', 'prop'); |
| 116 }, |
| 117 (t, db) => { |
| 118 const tx = db.transaction('store', 'readwrite'); |
| 119 const store = tx.objectStore('store'); |
| 120 store.put(new ProbeObject()); |
| 121 |
| 122 store.openCursor().onsuccess = t.step_func((event) => { |
| 123 const cursor = event.target.result; |
| 124 |
| 125 const obj = new ProbeObject(); |
| 126 cursor.update(obj); |
| 127 assert_equals( |
| 128 obj.id_count, 1, 'put() should access primary key property once'); |
| 129 assert_equals( |
| 130 obj.prop_count, 1, 'put() should access index key property once'); |
| 131 |
| 132 t.done(); |
| 133 }); |
| 134 }, 'Cursor update checks and keypath evaluations operate on a clone'); |
| 135 </script> |
| OLD | NEW |