idbcursor-advance-invalid.any.js (4799B)
1 // META: global=window,worker 2 // META: title=IDBCursor.advance() - invalid 3 // META: script=resources/support.js 4 5 // Spec: 6 // https://w3c.github.io/IndexedDB/#widl-IDBCursor-advance-void-unsigned-long-count 7 8 'use strict'; 9 10 function upgrade_func(t, db, tx) { 11 let objStore = db.createObjectStore('test'); 12 objStore.createIndex('index', ''); 13 14 objStore.add('data', 1); 15 objStore.add('data2', 2); 16 } 17 18 indexeddb_test(upgrade_func, function(t, db) { 19 let count = 0; 20 let rq = db.transaction('test', 'readonly') 21 .objectStore('test') 22 .index('index') 23 .openCursor(); 24 25 rq.onsuccess = t.step_func(function(e) { 26 if (!e.target.result) { 27 assert_equals(count, 2, 'count'); 28 t.done(); 29 return; 30 } 31 let cursor = e.target.result; 32 33 cursor.advance(1); 34 35 // Second try 36 assert_throws_dom('InvalidStateError', function() { 37 cursor.advance(1); 38 }, 'second advance'); 39 40 assert_throws_dom('InvalidStateError', function() { 41 cursor.advance(3); 42 }, 'third advance'); 43 44 count++; 45 }); 46 rq.onerror = t.unreached_func('unexpected error'); 47 }, 'IDBCursor.advance() - invalid - attempt to call advance twice'); 48 49 indexeddb_test(upgrade_func, function(t, db) { 50 let rq = db.transaction('test', 'readonly') 51 .objectStore('test') 52 .index('index') 53 .openCursor(); 54 55 rq.onsuccess = t.step_func(function(e) { 56 let cursor = e.target.result; 57 58 assert_throws_js(TypeError, function() { 59 cursor.advance(self); 60 }); 61 62 assert_throws_js(TypeError, function() { 63 cursor.advance({}); 64 }); 65 66 assert_throws_js(TypeError, function() { 67 cursor.advance([]); 68 }); 69 70 assert_throws_js(TypeError, function() { 71 cursor.advance(''); 72 }); 73 74 assert_throws_js(TypeError, function() { 75 cursor.advance('1 2'); 76 }); 77 78 t.done(); 79 }); 80 rq.onerror = t.unreached_func('unexpected error'); 81 }, 'IDBCursor.advance() - invalid - pass something other than number'); 82 83 84 indexeddb_test(upgrade_func, function(t, db) { 85 let rq = db.transaction('test', 'readonly') 86 .objectStore('test') 87 .index('index') 88 .openCursor(); 89 90 rq.onsuccess = t.step_func(function(e) { 91 let cursor = e.target.result; 92 93 assert_throws_js(TypeError, function() { 94 cursor.advance(null); 95 }); 96 97 assert_throws_js(TypeError, function() { 98 cursor.advance(undefined); 99 }); 100 101 let mylet = null; 102 assert_throws_js(TypeError, function() { 103 cursor.advance(mylet); 104 }); 105 106 t.done(); 107 }); 108 rq.onerror = t.unreached_func('unexpected error'); 109 }, 'IDBCursor.advance() - invalid - pass null/undefined'); 110 111 112 indexeddb_test(upgrade_func, function(t, db) { 113 let rq = db.transaction('test', 'readonly') 114 .objectStore('test') 115 .index('index') 116 .openCursor(); 117 118 rq.onsuccess = t.step_func(function(e) { 119 let cursor = e.target.result; 120 121 assert_throws_js(TypeError, function() { 122 cursor.advance(); 123 }); 124 125 t.done(); 126 }); 127 rq.onerror = t.unreached_func('unexpected error'); 128 }, 'IDBCursor.advance() - invalid - missing argument'); 129 130 indexeddb_test(upgrade_func, function(t, db) { 131 let rq = db.transaction('test', 'readonly') 132 .objectStore('test') 133 .index('index') 134 .openCursor(); 135 136 rq.onsuccess = t.step_func(function(e) { 137 let cursor = e.target.result; 138 139 assert_throws_js(TypeError, function() { 140 cursor.advance(-1); 141 }); 142 143 assert_throws_js(TypeError, function() { 144 cursor.advance(NaN); 145 }); 146 147 assert_throws_js(TypeError, function() { 148 cursor.advance(0); 149 }); 150 151 assert_throws_js(TypeError, function() { 152 cursor.advance(-0); 153 }); 154 155 assert_throws_js(TypeError, function() { 156 cursor.advance(Infinity); 157 }); 158 159 assert_throws_js(TypeError, function() { 160 cursor.advance(-Infinity); 161 }); 162 163 let mylet = -999999; 164 assert_throws_js(TypeError, function() { 165 cursor.advance(mylet); 166 }); 167 168 t.done(); 169 }); 170 rq.onerror = t.unreached_func('unexpected error'); 171 }, 'IDBCursor.advance() - invalid - pass negative numbers'); 172 173 indexeddb_test(upgrade_func, function(t, db) { 174 let count = 0; 175 let rq = db.transaction('test', 'readonly') 176 .objectStore('test') 177 .index('index') 178 .openCursor(); 179 180 rq.onsuccess = t.step_func(function(e) { 181 let cursor = e.target.result; 182 if (!cursor) { 183 assert_equals(count, 2, 'count runs'); 184 t.done(); 185 return; 186 } 187 188 assert_throws_js(TypeError, function() { 189 cursor.advance(0); 190 }); 191 192 cursor.advance(1); 193 count++; 194 }); 195 rq.onerror = t.unreached_func('unexpected error'); 196 }, 'IDBCursor.advance() - invalid - got value not set on exception');