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

Side by Side Diff: LayoutTests/imported/web-platform-tests/IndexedDB/idbcursor-advance.htm

Issue 560893005: First checked-in import of the W3C's test suites. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add new expectations for newly failing w3c tests Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>IDBCursor.advance()</title>
3 <link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
4 <script src="../../../resources/testharness.js"></script>
5 <script src="../../../resources/testharnessreport.js"></script>
6 <script src="support.js"></script>
7
8 <script>
9
10 var db, open;
11
12 setup(function() {
13 open = indexedDB.open("testdb-" + new Date().getTime());
14 open.onupgradeneeded = function(e) {
15 db = e.target.result;
16 var objStore = db.createObjectStore("test");
17 objStore.createIndex("index", "");
18
19 objStore.add("cupcake", 5);
20 objStore.add("pancake", 3); // Yes, it is intended
21 objStore.add("pie", 1);
22 objStore.add("pie", 4);
23 objStore.add("taco", 2);
24 };
25 },
26 { explicit_done: true });
27
28
29 open.onsuccess = function() {
30
31 async_test(document.title + " - advances").step(function(e) {
32 var count = 0;
33 var rq = db.transaction("test").objectStore("test").index("index").o penCursor();
34
35 rq.onsuccess = this.step_func(function(e) {
36 if (!e.target.result) {
37 assert_equals(count, 3, "count");
38 this.done();
39 return;
40 }
41 var cursor = e.target.result;
42
43 switch(count) {
44 case 0:
45 assert_equals(cursor.value, "cupcake");
46 assert_equals(cursor.primaryKey, 5);
47 break;
48
49 case 1:
50 assert_equals(cursor.value, "pie");
51 assert_equals(cursor.primaryKey, 1);
52 break;
53
54 case 2:
55 assert_equals(cursor.value, "taco");
56 assert_equals(cursor.primaryKey, 2);
57 break;
58
59 default:
60 assert_unreached("Unexpected count: " + count);
61 }
62
63 count++;
64 cursor.advance(2);
65 });
66 rq.onerror = fail(this, "unexpected error")
67 });
68
69 async_test(document.title + " - advances backwards").step(function(e) {
70 var count = 0;
71 var rq = db.transaction("test").objectStore("test").index("index").o penCursor(null, "prev");
72
73 rq.onsuccess = this.step_func(function(e) {
74 if (!e.target.result) {
75 assert_equals(count, 3, "count");
76 this.done();
77 return;
78 }
79 var cursor = e.target.result;
80
81 switch(count) {
82 case 0:
83 assert_equals(cursor.value, "taco");
84 assert_equals(cursor.primaryKey, 2);
85 break;
86
87 case 1:
88 assert_equals(cursor.value, "pie");
89 assert_equals(cursor.primaryKey, 1);
90 break;
91
92 case 2:
93 assert_equals(cursor.value, "cupcake");
94 assert_equals(cursor.primaryKey, 5);
95 break;
96
97 default:
98 assert_unreached("Unexpected count: " + count);
99 }
100
101 count++;
102 cursor.advance(2);
103 });
104 rq.onerror = fail(this, "unexpected error")
105 });
106
107 async_test(document.title + " - skip far forward").step(function(e) {
108 var count = 0;
109 var rq = db.transaction("test").objectStore("test").index("index")
110 .openCursor();
111
112 rq.onsuccess = this.step_func(function(e) {
113 if (!e.target.result) {
114 assert_equals(count, 1, "count");
115 this.done();
116 return;
117 }
118 var cursor = e.target.result;
119
120 switch(count) {
121 case 0:
122 assert_equals(cursor.value, "cupcake");
123 assert_equals(cursor.primaryKey, 5);
124 break;
125
126 default:
127 assert_unreached("Unexpected count: " + count);
128 }
129
130 count++;
131 cursor.advance(100000);
132 });
133 rq.onerror = fail(this, "unexpected error")
134 });
135
136
137 async_test(document.title + " - within range").step(function(e) {
138 var count = 0;
139 var rq = db.transaction("test").objectStore("test").index("index")
140 .openCursor(IDBKeyRange.lowerBound("cupcake", true));
141
142 rq.onsuccess = this.step_func(function(e) {
143 if (!e.target.result) {
144 assert_equals(count, 2, "count");
145 this.done();
146 return;
147 }
148 var cursor = e.target.result;
149
150 switch(count) {
151 case 0:
152 assert_equals(cursor.value, "pancake");
153 assert_equals(cursor.primaryKey, 3);
154 break;
155
156 case 1:
157 assert_equals(cursor.value, "pie");
158 assert_equals(cursor.primaryKey, 4);
159 break;
160
161 default:
162 assert_unreached("Unexpected count: " + count);
163 }
164
165 count++;
166 cursor.advance(2);
167 });
168 rq.onerror = fail(this, "unexpected error")
169 });
170
171
172 async_test(document.title + " - within single key range").step(function( e) {
173 var count = 0;
174 var rq = db.transaction("test").objectStore("test").index("index")
175 .openCursor("pancake");
176
177 rq.onsuccess = this.step_func(function(e) {
178 if (!e.target.result) {
179 assert_equals(count, 1, "count");
180 this.done();
181 return;
182 }
183 var cursor = e.target.result;
184
185 switch(count) {
186 case 0:
187 assert_equals(cursor.value, "pancake");
188 assert_equals(cursor.primaryKey, 3);
189 break;
190
191 default:
192 assert_unreached("Unexpected count: " + count);
193 }
194
195 count++;
196 cursor.advance(1);
197 });
198 rq.onerror = fail(this, "unexpected error")
199 });
200
201
202 async_test(document.title + " - within single key range, with several re sults").step(function(e) {
203 var count = 0;
204 var rq = db.transaction("test").objectStore("test").index("index")
205 .openCursor("pie");
206
207 rq.onsuccess = this.step_func(function(e) {
208 if (!e.target.result) {
209 assert_equals(count, 2, "count");
210 this.done();
211 return;
212 }
213 var cursor = e.target.result;
214
215 switch(count) {
216 case 0:
217 assert_equals(cursor.value, "pie");
218 assert_equals(cursor.primaryKey, 1);
219 break;
220
221 case 1:
222 assert_equals(cursor.value, "pie");
223 assert_equals(cursor.primaryKey, 4);
224 break;
225
226 default:
227 assert_unreached("Unexpected count: " + count);
228 }
229
230 count++;
231 cursor.advance(1);
232 });
233 rq.onerror = fail(this, "unexpected error")
234 });
235
236
237 // Stop blocking the testing system from hereon
238 done();
239 }
240
241 </script>
242
243 <div id="log"></div>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698