Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: third_party/WebKit/LayoutTests/storage/indexeddb/clone-before-keypath-eval.html

Issue 2667403003: Upstream a couple of IndexedDB layout tests to WPT. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../../resources/testharness.js"></script>
3 <script src="../../resources/testharnessreport.js"></script>
4 <script>
5
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);
14 });
15 openRequest.onsuccess = t.step_func(function() {
16 body_func(t, openRequest.result);
17 });
18 openRequest.onerror = t.unreached_func('open failed');
19 });
20 }, description);
21 }
22
23 function ProbeObject() {
24 this.id_count = 0;
25 this.invalid_id_count = 0;
26 this.prop_count = 0;
27 Object.defineProperties(this, {
28 id: {
29 enumerable: true,
30 get: function() {
31 ++this.id_count;
32 return 1000 + this.id_count;
33 }},
34 invalid_id: {
35 enumerable: true,
36 get: function() {
37 ++this.invalid_id_count;
38 return {};
39 }},
40 prop: {
41 enumerable: true,
42 get: function() {
43 ++this.prop_count;
44 return 2000 + this.prop_count;
45 }}
46 });
47 }
48
49 indexeddb_test(
50 function(t, connection) {
51 connection.createObjectStore(
52 'store', {keyPath: 'id', autoIncrement: true});
53 },
54 function(t, connection) {
55 var trans = connection.transaction('store', 'readwrite');
56 var store = trans.objectStore('store');
57 var obj = new ProbeObject();
58 store.put(obj);
59 assert_equals(
60 obj.id_count, 1,
61 'put() operation should access primary key property once');
62 assert_equals(
63 obj.prop_count, 1,
64 'put() operation should access other properties once');
65 t.done();
66 }, 'Key generator and key path validity check operates on a clone');
67
68 indexeddb_test(
69 function(t, connection) {
70 connection.createObjectStore(
71 'store', {keyPath: 'invalid_id', autoIncrement: true});
72 },
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');
79 assert_equals(
80 obj.invalid_id_count, 1,
81 'put() operation should access primary key property once');
82 assert_equals(
83 obj.prop_count, 1,
84 'put() operation should access other properties once');
85 t.done();
86 }, 'Failing key path validity check operates on a clone');
87
88 indexeddb_test(
89 function(t, connection) {
90 var store = connection.createObjectStore('store');
91 store.createIndex('index', 'prop');
92 },
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');
98 assert_equals(
99 obj.prop_count, 1, 'put() should access index key property once');
100 assert_equals(
101 obj.id_count, 1,
102 'put() operation should access other properties once');
103 t.done();
104 }, 'Index key path evaluations operate on a clone');
105
106 indexeddb_test(
107 function(t, connection) {
108 var store = connection.createObjectStore('store', {keyPath: 'id'});
109 store.createIndex('index', 'prop');
110 },
111 function(t, connection) {
112 var trans = connection.transaction('store', 'readwrite');
113 var store = trans.objectStore('store');
114 var obj = new ProbeObject();
115 store.put(obj);
116 assert_equals(
117 obj.id_count, 1, 'put() should access primary key property once');
118 assert_equals(
119 obj.prop_count, 1, 'put() should access index key property once');
120 t.done();
121 }, 'Store and index key path evaluations operate the same clone');
122
123 indexeddb_test(
124 function(t, connection) {
125 var store = connection.createObjectStore('store', {keyPath: 'id'});
126 store.createIndex('index', 'prop');
127 },
128 function(t, connection) {
129 var trans = connection.transaction('store', 'readwrite');
130 var store = trans.objectStore('store');
131 store.put(new ProbeObject());
132
133 store.openCursor().onsuccess = t.step_func(function(event) {
134 var cursor = event.target.result;
135
136 var obj = new ProbeObject();
137 cursor.update(obj);
138 assert_equals(
139 obj.id_count, 1, 'put() should access primary key property once');
140 assert_equals(
141 obj.prop_count, 1, 'put() should access index key property once');
142
143 t.done();
144 });
145 }, 'Cursor update checks and keypath evaluations operate on a clone');
146 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698