2 <script src=
"../../resources/testharness.js"></script>
3 <script src=
"../../resources/testharnessreport.js"></script>
6 function indexeddb_test(upgrade_func
, body_func
, description
) {
7 async_test(function(t
) {
8 var dbname
= location
.pathname
+ ' - ' + description
;
9 var deleteRequest
= indexedDB
.deleteDatabase(dbname
);
10 deleteRequest
.onsuccess
= t
.step_func(function() {
11 var openRequest
= indexedDB
.open(dbname
);
12 openRequest
.onupgradeneeded
= t
.step_func(function() {
13 upgrade_func(t
, openRequest
.result
);
15 openRequest
.onsuccess
= t
.step_func(function() {
16 body_func(t
, openRequest
.result
);
18 openRequest
.onerror
= t
.unreached_func('open failed');
23 function ProbeObject() {
25 this.invalid_id_count
= 0;
27 Object
.defineProperties(this, {
32 return 1000 + this.id_count
;
37 ++this.invalid_id_count
;
44 return 2000 + this.prop_count
;
50 function(t
, connection
) {
51 connection
.createObjectStore(
52 'store', {keyPath
: 'id', autoIncrement
: true});
54 function(t
, connection
) {
55 var trans
= connection
.transaction('store', 'readwrite');
56 var store
= trans
.objectStore('store');
57 var obj
= new ProbeObject();
61 'put() operation should access primary key property once');
64 'put() operation should access other properties once');
66 }, 'Key generator and key path validity check operates on a clone');
69 function(t
, connection
) {
70 connection
.createObjectStore(
71 'store', {keyPath
: 'invalid_id', autoIncrement
: true});
73 function(t
, connection
) {
74 var trans
= connection
.transaction('store', 'readwrite');
75 var store
= trans
.objectStore('store');
76 var obj
= new ProbeObject();
77 assert_throws('DataError', function() { store
.put(obj
); },
78 'put() should throw if primary key cannot be injected');
80 obj
.invalid_id_count
, 1,
81 'put() operation should access primary key property once');
84 'put() operation should access other properties once');
86 }, 'Failing key path validity check operates on a clone');
89 function(t
, connection
) {
90 var store
= connection
.createObjectStore('store');
91 store
.createIndex('index', 'prop');
93 function(t
, connection
) {
94 var trans
= connection
.transaction('store', 'readwrite');
95 var store
= trans
.objectStore('store');
96 var obj
= new ProbeObject();
97 store
.put(obj
, 'key');
99 obj
.prop_count
, 1, 'put() should access index key property once');
102 'put() operation should access other properties once');
104 }, 'Index key path evaluations operate on a clone');
107 function(t
, connection
) {
108 var store
= connection
.createObjectStore('store', {keyPath
: 'id'});
109 store
.createIndex('index', 'prop');
111 function(t
, connection
) {
112 var trans
= connection
.transaction('store', 'readwrite');
113 var store
= trans
.objectStore('store');
114 var obj
= new ProbeObject();
117 obj
.id_count
, 1, 'put() should access primary key property once');
119 obj
.prop_count
, 1, 'put() should access index key property once');
121 }, 'Store and index key path evaluations operate the same clone');
124 function(t
, connection
) {
125 var store
= connection
.createObjectStore('store', {keyPath
: 'id'});
126 store
.createIndex('index', 'prop');
128 function(t
, connection
) {
129 var trans
= connection
.transaction('store', 'readwrite');
130 var store
= trans
.objectStore('store');
131 store
.put(new ProbeObject());
133 store
.openCursor().onsuccess
= t
.step_func(function(event
) {
134 var cursor
= event
.target
.result
;
136 var obj
= new ProbeObject();
139 obj
.id_count
, 1, 'put() should access primary key property once');
141 obj
.prop_count
, 1, 'put() should access index key property once');
145 }, 'Cursor update checks and keypath evaluations operate on a clone');