Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / imported / web-platform-tests / IndexedDB / idbcursor-advance-invalid.htm
blobe2504b9e41e68992e70b611a5ad29648ba4f1676
1 <!DOCTYPE html>
2 <title>IDBCursor.advance() - invalid</title>
3 <link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
4 <link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
5 <link rel=assert title="If the value for count is 0 (zero) or a negative number, this method must throw a JavaScript TypeError exception.">
6 <link rel=assert title="TypeError The value passed into the count parameter was zero or a negative number.">
7 <link rel=assert title="InvalidStateError The cursor is currently being iterated, or has iterated past its end.">
8 <link rel=assert title="Calling this method more than once before new cursor data has been loaded is not allowed and results in a DOMException of type InvalidStateError being thrown. For example, calling advance() twice from the same onsuccess handler results in a DOMException of type InvalidStateError being thrown on the second call.">
9 <link rel=assert title="Before this method returns, unless an exception was thrown, it sets the got value flag on the cursor to false.">
10 <script src="../../../resources/testharness.js"></script>
11 <script src="../../../resources/testharnessreport.js"></script>
12 <script src="support.js"></script>
14 <script>
16 var db, open;
18 setup(function() {
19 open = indexedDB.open('testdb-' + new Date().getTime());
20 open.onupgradeneeded = function(e) {
21 db = e.target.result;
22 var objStore = db.createObjectStore("test");
23 objStore.createIndex("index", "");
25 objStore.add("data", 1);
26 objStore.add("data2", 2);
29 { explicit_done: true });
32 open.onsuccess = function() {
34 async_test(document.title + " - attempt to call advance twice").step(function(e) {
35 var count = 0;
36 var rq = db.transaction("test").objectStore("test").index("index").openCursor();
38 rq.onsuccess = this.step_func(function(e) {
39 if (!e.target.result) {
40 assert_equals(count, 2, 'count');
41 this.done();
42 return;
44 var cursor = e.target.result;
46 cursor.advance(1);
48 // Second try
49 assert_throws('InvalidStateError',
50 function() { cursor.advance(1); }, 'second advance');
52 assert_throws('InvalidStateError',
53 function() { cursor.advance(3); }, 'third advance');
55 count++;
56 });
57 rq.onerror = fail(this, "unexpected error")
58 });
61 async_test(document.title + " - pass something other than number").step(function(e) {
62 var rq = db.transaction("test").objectStore("test").index("index").openCursor();
64 rq.onsuccess = this.step_func(function(e) {
65 var cursor = e.target.result;
67 assert_throws({ name: "TypeError" },
68 function() { cursor.advance(document); });
70 assert_throws({ name: "TypeError" },
71 function() { cursor.advance({}); });
73 assert_throws({ name: "TypeError" },
74 function() { cursor.advance([]); });
76 assert_throws({ name: "TypeError" },
77 function() { cursor.advance(""); });
79 assert_throws({ name: "TypeError" },
80 function() { cursor.advance("1 2"); });
82 this.done();
83 });
84 rq.onerror = fail(this, "unexpected error")
85 });
88 async_test(document.title + " - pass null/undefined").step(function(e) {
89 var rq = db.transaction("test").objectStore("test").index("index").openCursor();
91 rq.onsuccess = this.step_func(function(e) {
92 var cursor = e.target.result;
94 assert_throws({ name: "TypeError" },
95 function() { cursor.advance(null); });
97 assert_throws({ name: "TypeError" },
98 function() { cursor.advance(undefined); });
100 var myvar = null;
101 assert_throws({ name: "TypeError" },
102 function() { cursor.advance(myvar); });
104 this.done();
106 rq.onerror = fail(this, "unexpected error")
110 async_test(document.title + " - missing argument").step(function(e) {
111 var rq = db.transaction("test").objectStore("test").index("index").openCursor();
113 rq.onsuccess = this.step_func(function(e) {
114 var cursor = e.target.result;
116 assert_throws({ name: "TypeError" },
117 function() { cursor.advance(); });
119 this.done();
121 rq.onerror = fail(this, "unexpected error")
125 async_test(document.title + " - pass negative numbers").step(function(e) {
126 var rq = db.transaction("test").objectStore("test").index("index").openCursor();
128 rq.onsuccess = this.step_func(function(e) {
129 var cursor = e.target.result;
131 assert_throws({ name: "TypeError" },
132 function() { cursor.advance(-1); });
134 assert_throws({ name: "TypeError" },
135 function() { cursor.advance(NaN); });
137 assert_throws({ name: "TypeError" },
138 function() { cursor.advance(0); });
140 assert_throws({ name: "TypeError" },
141 function() { cursor.advance(-0); });
143 assert_throws({ name: "TypeError" },
144 function() { cursor.advance(Infinity); });
146 assert_throws({ name: "TypeError" },
147 function() { cursor.advance(-Infinity); });
149 var myvar = -999999;
150 assert_throws({ name: "TypeError" },
151 function() { cursor.advance(myvar); });
153 this.done();
155 rq.onerror = fail(this, "unexpected error")
159 async_test(document.title + " - got value not set on exception").step(function(e) {
160 var count = 0;
161 var rq = db.transaction("test").objectStore("test").index("index").openCursor();
163 rq.onsuccess = this.step_func(function(e) {
164 var cursor = e.target.result;
165 if (!cursor)
167 assert_equals(count, 2, "count runs");
168 this.done();
169 return;
172 assert_throws({ name: "TypeError" },
173 function() { cursor.advance(0); });
175 cursor.advance(1);
176 count++;
178 rq.onerror = fail(this, "unexpected error")
182 // Stop blocking the testing system from hereon
183 done();
186 </script>
188 <div id=log></div>