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>
19 open
= indexedDB
.open('testdb-' + new Date().getTime());
20 open
.onupgradeneeded = function(e
) {
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
) {
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');
44 var cursor
= e
.target
.result
;
49 assert_throws('InvalidStateError',
50 function() { cursor
.advance(1); }, 'second advance');
52 assert_throws('InvalidStateError',
53 function() { cursor
.advance(3); }, 'third advance');
57 rq
.onerror
= fail(this, "unexpected error")
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"); });
84 rq
.onerror
= fail(this, "unexpected error")
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); });
101 assert_throws({ name
: "TypeError" },
102 function() { cursor
.advance(myvar
); });
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(); });
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
); });
150 assert_throws({ name
: "TypeError" },
151 function() { cursor
.advance(myvar
); });
155 rq
.onerror
= fail(this, "unexpected error")
159 async_test(document
.title
+ " - got value not set on exception").step(function(e
) {
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
;
167 assert_equals(count
, 2, "count runs");
172 assert_throws({ name
: "TypeError" },
173 function() { cursor
.advance(0); });
178 rq
.onerror
= fail(this, "unexpected error")
182 // Stop blocking the testing system from hereon