Update web-platform-tests to revision 0d318188757a9c996e20b82db201fd04de5aa255

This commit is contained in:
James Graham 2015-03-27 09:15:38 +00:00
parent b2a5225831
commit 1a81b18b9f
12321 changed files with 544385 additions and 6 deletions

View file

@ -0,0 +1,8 @@
This directory contains the Indexed Database API test suite.
To run the tests in this test suite within a browser, go to: <http://w3c-test.org/IndexedDB/>.
The latest Editor's Draft of Indexed Database API is: <http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html>.
The latest W3C Technical Report of Indexed Database API is: <http://www.w3.org/TR/IndexedDB/>.

View file

@ -0,0 +1,35 @@
<!doctype html>
<!-- Submitted from TestTWF Paris -->
<title>Test that an abort in the initial upgradeneeded sets version back to 0</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var db, open_rq = createdb(async_test(), undefined, 2);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
assert_equals(db.version, 2);
transaction = e.target.transaction;
transaction.oncomplete = fail(this, "unexpected transaction.complete");
transaction.onabort = function(e) {
assert_equals(e.target.db.version, 0);
}
db.onabort = function() {}
transaction.abort();
}
open_rq.onerror = function(e) {
assert_equals(open_rq, e.target);
assert_equals(e.target.result, undefined);
assert_equals(e.target.error.name, "AbortError");
assert_equals(db.version, 0);
assert_equals(open_rq.transaction, null);
this.done();
}
</script>
<div id=log></div>

View file

@ -0,0 +1,39 @@
<!doctype html>
<!-- Submitted from TestTWF Paris -->
<title>When db.close is called in upgradeneeded, the db is cleaned up on refresh</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var open_rq = createdb(async_test())
var sawTransactionComplete = false
open_rq.onupgradeneeded = function(e) {
db = e.target.result
assert_equals(db.version, 1)
db.createObjectStore('os')
db.close()
e.target.transaction.oncomplete = function() { sawTransactionComplete = true }
}
open_rq.onerror = function(e) {
assert_true(sawTransactionComplete, "saw transaction.complete")
assert_equals(e.target.error.name, 'AbortError')
assert_equals(e.result, undefined)
assert_true(!!db)
assert_equals(db.version, 1)
assert_equals(db.objectStoreNames.length, 1)
assert_throws("InvalidStateError", function() { db.transaction('os') })
this.done()
}
</script>
<div id=log></div>

View file

@ -0,0 +1,88 @@
<!--
Test converted from WebKit:
http://trac.webkit.org/browser/trunk/LayoutTests/storage/indexeddb/cursor-overloads.html
-->
<!DOCTYPE html>
<!-- Submitted from TestTWF Paris -->
<meta charset=utf-8>
<title>Validate the overloads of IDBObjectStore.openCursor(), IDBIndex.openCursor() and IDBIndex.openKeyCursor()</title>
<link rel=author href="mailto:romain.huet@gmail.com" title="Romain Huet">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var db, trans, store, index;
var t = async_test();
var request = createdb(t);
request.onupgradeneeded = function(e) {
db = request.result;
store = db.createObjectStore('store');
index = store.createIndex('index', 'value');
store.put({value: 0}, 0);
trans = request.transaction;
trans.oncomplete = verifyOverloads;
};
function verifyOverloads() {
trans = db.transaction('store');
store = trans.objectStore('store');
index = store.index('index');
checkCursorDirection("store.openCursor()", "next");
checkCursorDirection("store.openCursor(0)", "next");
checkCursorDirection("store.openCursor(0, 'next')", "next");
checkCursorDirection("store.openCursor(0, 'nextunique')", "nextunique");
checkCursorDirection("store.openCursor(0, 'prev')", "prev");
checkCursorDirection("store.openCursor(0, 'prevunique')", "prevunique");
checkCursorDirection("store.openCursor(IDBKeyRange.only(0))", "next");
checkCursorDirection("store.openCursor(IDBKeyRange.only(0), 'next')", "next");
checkCursorDirection("store.openCursor(IDBKeyRange.only(0), 'nextunique')", "nextunique");
checkCursorDirection("store.openCursor(IDBKeyRange.only(0), 'prev')", "prev");
checkCursorDirection("store.openCursor(IDBKeyRange.only(0), 'prevunique')", "prevunique");
checkCursorDirection("index.openCursor()", "next");
checkCursorDirection("index.openCursor(0)", "next");
checkCursorDirection("index.openCursor(0, 'next')", "next");
checkCursorDirection("index.openCursor(0, 'nextunique')", "nextunique");
checkCursorDirection("index.openCursor(0, 'prev')", "prev");
checkCursorDirection("index.openCursor(0, 'prevunique')", "prevunique");
checkCursorDirection("index.openCursor(IDBKeyRange.only(0))", "next");
checkCursorDirection("index.openCursor(IDBKeyRange.only(0), 'next')", "next");
checkCursorDirection("index.openCursor(IDBKeyRange.only(0), 'nextunique')", "nextunique");
checkCursorDirection("index.openCursor(IDBKeyRange.only(0), 'prev')", "prev");
checkCursorDirection("index.openCursor(IDBKeyRange.only(0), 'prevunique')", "prevunique");
checkCursorDirection("index.openKeyCursor()", "next");
checkCursorDirection("index.openKeyCursor(0)", "next");
checkCursorDirection("index.openKeyCursor(0, 'next')", "next");
checkCursorDirection("index.openKeyCursor(0, 'nextunique')", "nextunique");
checkCursorDirection("index.openKeyCursor(0, 'prev')", "prev");
checkCursorDirection("index.openKeyCursor(0, 'prevunique')", "prevunique");
checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0))", "next");
checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0), 'next')", "next");
checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0), 'nextunique')", "nextunique");
checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0), 'prev')", "prev");
checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0), 'prevunique')", "prevunique");
t.done();
}
function checkCursorDirection(statement, direction) {
request = eval(statement);
request.onsuccess = function(event) {
assert_not_equals(event.target.result, null, "Check the result is not null")
assert_equals(event.target.result.direction, direction, "Check the result direction");
};
}
</script>
<div id=log></div>

View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<title>IndexedDB inside of a WebWorker </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db, count = 0,
t = async_test();
t.step(function() {
var worker = new Worker("idbworker.js");
worker.onmessage = t.step_func(function (e) {
switch(count) {
case 0:
assert_equals(e.data, true, 'worker has idb object')
break
case 1:
assert_equals(e.data, "test", "get(1) in worker")
t.done()
}
count++
});
worker.postMessage(1);
})
</script>
<div id="log"></div>

View file

@ -0,0 +1,186 @@
<!DOCTYPE html>
<title>IDBCursor asyncness</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db, open;
setup(function() {
open = indexedDB.open('testdb-' + new Date().getTime());
open.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test");
objStore.createIndex("index", "");
objStore.add("data", 1);
objStore.add("data2", 2);
};
},
{ explicit_done: true });
open.onsuccess = function() {
async_test(document.title + " - advance").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, 'count');
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "data")
assert_equals(cursor.key, 1)
cursor.advance(1)
assert_equals(cursor.value, "data")
assert_equals(cursor.key, 1)
break
case 1:
assert_equals(cursor.value, "data2")
assert_equals(cursor.key, 2)
cursor.advance(1)
assert_equals(cursor.value, "data2")
assert_equals(cursor.key, 2)
break
default:
assert_unreached("Unexpected count: " + count)
}
count++;
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - continue").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, 'count');
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "data")
assert_equals(cursor.key, "data")
assert_equals(cursor.primaryKey, 1)
cursor.continue("data2")
assert_equals(cursor.value, "data")
assert_equals(cursor.key, "data")
assert_equals(cursor.primaryKey, 1)
break
case 1:
assert_equals(cursor.value, "data2")
assert_equals(cursor.key, "data2")
assert_equals(cursor.primaryKey, 2)
cursor.continue()
assert_equals(cursor.value, "data2")
assert_equals(cursor.key, "data2")
assert_equals(cursor.primaryKey, 2)
break
default:
assert_unreached("Unexpected count: " + count)
}
count++;
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - fresh advance still async").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, 'count');
this.done();
return;
}
var cursor = e.target.result;
cursor.advance(1)
switch(count) {
case 0:
assert_equals(cursor.value, "data")
assert_equals(cursor.key, "data")
assert_equals(cursor.primaryKey, 1)
break
case 1:
assert_equals(cursor.value, "data2")
assert_equals(cursor.key, "data2")
assert_equals(cursor.primaryKey, 2)
break
default:
assert_unreached("Unexpected count: " + count)
}
count++;
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - fresh continue still async").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, 'count');
this.done();
return;
}
var cursor = e.target.result;
cursor.continue()
switch(count) {
case 0:
assert_equals(cursor.value, "data")
assert_equals(cursor.key, 1)
break
case 1:
assert_equals(cursor.value, "data2")
assert_equals(cursor.key, 2)
break
default:
assert_unreached("Unexpected count: " + count)
}
count++;
});
rq.onerror = fail(this, "unexpected error")
});
// Stop blocking the testing system from hereon
done();
}
</script>
<div id=log></div>

View file

@ -0,0 +1,188 @@
<!DOCTYPE html>
<title>IDBCursor.advance() - invalid</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<link rel=assert title="If the value for count is 0 (zero) or a negative number, this method must throw a JavaScript TypeError exception.">
<link rel=assert title="TypeError The value passed into the count parameter was zero or a negative number.">
<link rel=assert title="InvalidStateError The cursor is currently being iterated, or has iterated past its end.">
<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.">
<link rel=assert title="Before this method returns, unless an exception was thrown, it sets the got value flag on the cursor to false.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db, open;
setup(function() {
open = indexedDB.open('testdb-' + new Date().getTime());
open.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test");
objStore.createIndex("index", "");
objStore.add("data", 1);
objStore.add("data2", 2);
};
},
{ explicit_done: true });
open.onsuccess = function() {
async_test(document.title + " - attempt to call advance twice").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, 'count');
this.done();
return;
}
var cursor = e.target.result;
cursor.advance(1);
// Second try
assert_throws('InvalidStateError',
function() { cursor.advance(1); }, 'second advance');
assert_throws('InvalidStateError',
function() { cursor.advance(3); }, 'third advance');
count++;
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - pass something other than number").step(function(e) {
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
var cursor = e.target.result;
assert_throws({ name: "TypeError" },
function() { cursor.advance(document); });
assert_throws({ name: "TypeError" },
function() { cursor.advance({}); });
assert_throws({ name: "TypeError" },
function() { cursor.advance([]); });
assert_throws({ name: "TypeError" },
function() { cursor.advance(""); });
assert_throws({ name: "TypeError" },
function() { cursor.advance("1 2"); });
this.done();
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - pass null/undefined").step(function(e) {
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
var cursor = e.target.result;
assert_throws({ name: "TypeError" },
function() { cursor.advance(null); });
assert_throws({ name: "TypeError" },
function() { cursor.advance(undefined); });
var myvar = null;
assert_throws({ name: "TypeError" },
function() { cursor.advance(myvar); });
this.done();
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - missing argument").step(function(e) {
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
var cursor = e.target.result;
assert_throws({ name: "TypeError" },
function() { cursor.advance(); });
this.done();
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - pass negative numbers").step(function(e) {
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
var cursor = e.target.result;
assert_throws({ name: "TypeError" },
function() { cursor.advance(-1); });
assert_throws({ name: "TypeError" },
function() { cursor.advance(NaN); });
assert_throws({ name: "TypeError" },
function() { cursor.advance(0); });
assert_throws({ name: "TypeError" },
function() { cursor.advance(-0); });
assert_throws({ name: "TypeError" },
function() { cursor.advance(Infinity); });
assert_throws({ name: "TypeError" },
function() { cursor.advance(-Infinity); });
var myvar = -999999;
assert_throws({ name: "TypeError" },
function() { cursor.advance(myvar); });
this.done();
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - got value not set on exception").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
var cursor = e.target.result;
if (!cursor)
{
assert_equals(count, 2, "count runs");
this.done();
return;
}
assert_throws({ name: "TypeError" },
function() { cursor.advance(0); });
cursor.advance(1);
count++;
});
rq.onerror = fail(this, "unexpected error")
});
// Stop blocking the testing system from hereon
done();
}
</script>
<div id=log></div>

View file

@ -0,0 +1,243 @@
<!DOCTYPE html>
<title>IDBCursor.advance()</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db, open;
setup(function() {
open = indexedDB.open("testdb-" + new Date().getTime());
open.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test");
objStore.createIndex("index", "");
objStore.add("cupcake", 5);
objStore.add("pancake", 3); // Yes, it is intended
objStore.add("pie", 1);
objStore.add("pie", 4);
objStore.add("taco", 2);
};
},
{ explicit_done: true });
open.onsuccess = function() {
async_test(document.title + " - advances").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 3, "count");
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "cupcake");
assert_equals(cursor.primaryKey, 5);
break;
case 1:
assert_equals(cursor.value, "pie");
assert_equals(cursor.primaryKey, 1);
break;
case 2:
assert_equals(cursor.value, "taco");
assert_equals(cursor.primaryKey, 2);
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
cursor.advance(2);
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - advances backwards").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index").openCursor(null, "prev");
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 3, "count");
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "taco");
assert_equals(cursor.primaryKey, 2);
break;
case 1:
assert_equals(cursor.value, "pie");
assert_equals(cursor.primaryKey, 1);
break;
case 2:
assert_equals(cursor.value, "cupcake");
assert_equals(cursor.primaryKey, 5);
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
cursor.advance(2);
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - skip far forward").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index")
.openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 1, "count");
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "cupcake");
assert_equals(cursor.primaryKey, 5);
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
cursor.advance(100000);
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - within range").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index")
.openCursor(IDBKeyRange.lowerBound("cupcake", true));
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, "count");
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "pancake");
assert_equals(cursor.primaryKey, 3);
break;
case 1:
assert_equals(cursor.value, "pie");
assert_equals(cursor.primaryKey, 4);
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
cursor.advance(2);
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - within single key range").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index")
.openCursor("pancake");
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 1, "count");
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "pancake");
assert_equals(cursor.primaryKey, 3);
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
cursor.advance(1);
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - within single key range, with several results").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index")
.openCursor("pie");
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, "count");
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "pie");
assert_equals(cursor.primaryKey, 1);
break;
case 1:
assert_equals(cursor.value, "pie");
assert_equals(cursor.primaryKey, 4);
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
cursor.advance(1);
});
rq.onerror = fail(this, "unexpected error")
});
// Stop blocking the testing system from hereon
done();
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,240 @@
<!DOCTYPE html>
<title>IDBCursor.continue()</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-continue-void-any-key">
<link rel=assert title="The next key to position this cursor at">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db, open;
var store = [ { value: "cupcake", key: 5 },
{ value: "pancake", key: 3 },
{ value: "pie", key: 1 },
{ value: "pie", key: 4 },
{ value: "taco", key: 2 } ];
setup(function() {
open = indexedDB.open('testdb-' + new Date().getTime());
open.onupgradeneeded = function(e) {
var os, i;
db = e.target.result;
os = db.createObjectStore("test");
os.createIndex("index", "");
for (i = 0; i < store.length; i++)
os.add(store[i].value, store[i].key);
};
},
{ explicit_done: true });
open.onsuccess = function() {
async_test(document.title + " - continues").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 5, 'count');
this.done();
return;
}
var cursor = e.target.result;
assert_equals(cursor.value, store[count].value);
assert_equals(cursor.primaryKey, store[count].key);
cursor.continue();
count++;
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - with given key").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index").openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 3, 'count');
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "cupcake");
assert_equals(cursor.primaryKey, 5);
cursor.continue("pie");
break;
case 1:
assert_equals(cursor.value, "pie");
assert_equals(cursor.primaryKey, 1);
cursor.continue("taco");
break;
case 2:
assert_equals(cursor.value, "taco");
assert_equals(cursor.primaryKey, 2);
cursor.continue();
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
});
rq.onerror = fail(this, "unexpected error")
});
async_test(document.title + " - skip far forward").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index")
.openCursor();
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 1, 'count');
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "cupcake");
assert_equals(cursor.primaryKey, 5);
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
cursor.continue([]); // Arrays are always bigger than strings
});
rq.onerror = fail(this, "unexpected error2")
});
async_test(document.title + " - within range").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index")
.openCursor(IDBKeyRange.lowerBound("cupcake", true));
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, 'count');
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "pancake");
assert_equals(cursor.primaryKey, 3);
cursor.continue("pie");
break;
case 1:
assert_equals(cursor.value, "pie");
assert_equals(cursor.primaryKey, 1);
cursor.continue("zzz");
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
});
rq.onerror = fail(this, "unexpected error1")
});
async_test(document.title + " - within single key range").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index")
.openCursor("pancake");
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 1, 'count');
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "pancake");
assert_equals(cursor.primaryKey, 3);
cursor.continue("pie");
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
});
rq.onerror = fail(this, "unexpected error1")
});
async_test(document.title + " - within single key range, with several results").step(function(e) {
var count = 0;
var rq = db.transaction("test").objectStore("test").index("index")
.openCursor("pie");
rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, 'count');
this.done();
return;
}
var cursor = e.target.result;
switch(count) {
case 0:
assert_equals(cursor.value, "pie");
assert_equals(cursor.primaryKey, 1);
cursor.continue();
break;
case 1:
assert_equals(cursor.value, "pie");
assert_equals(cursor.primaryKey, 4);
cursor.continue();
break;
default:
assert_unreached("Unexpected count: " + count);
}
count++;
});
rq.onerror = fail(this, "unexpected error1")
});
// Stop blocking the testing system from hereon
done();
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,82 @@
<!DOCTYPE html>
<title>IDBCursor direction - index with keyrange</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#cursor-iteration-operation">
<link rel=assert title='If direction is "next", let found record be the first record in records which satisfy all of the following requirements'>
<link rel=assert title="If position is defined, and source is an index, the record's key is equal to position and the record's value is greater than object store position or the record's key is greater than position.">
<link rel=assert title='If direction is "prev", let found record be the last record in records which satisfy all of the following requirements'>
<link rel=assert title="If position is defined, and source is an index, the record's key is equal to position and the record's value is less than object store position or the record's key is less than position.">
<link rel=assert title="If range is defined, the record's key is in range.">
<link rel=assert title="If temp record is defined, let found record be the first record in records whose key is equal to temp record's key.">
<link rel=assert title="records is always sorted in ascending key order. In the case of source being an index, records is secondarily sorted in ascending value order.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var records = [ 1337, "Alice", "Bob", "Bob", "Greg", "Åke", ["Anne"] ];
var directions = ["next", "prev", "nextunique", "prevunique"];
var tests = {};
directions.forEach(function(dir) {
tests[dir] = async_test(document.title + ' - ' + dir);
});
var open_rq = indexedDB.open("testdb-" + new Date().getTime() + Math.random());
open_rq.onupgradeneeded = function(e) {
var objStore = e.target.result.createObjectStore("test");
objStore.createIndex("idx", "name");
for (var i = 0; i < records.length; i++)
objStore.add({ name: records[i] }, i);
};
open_rq.onsuccess = function(e) {
var db = e.target.result;
db.onerror = fail_helper("db.onerror");
// The tests
testdir('next', ['Alice:1', 'Bob:2', 'Bob:3', 'Greg:4']);
testdir('prev', ['Greg:4', 'Bob:3', 'Bob:2', 'Alice:1']);
testdir('nextunique', ['Alice:1', 'Bob:2', 'Greg:4']);
testdir('prevunique', ['Greg:4', 'Bob:2', 'Alice:1']);
// Test function
function testdir(dir, expect) {
var count = 0;
var t = tests[dir];
var rq = db.transaction("test").objectStore("test").index("idx").openCursor(IDBKeyRange.bound("AA", "ZZ"), dir);
rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, expect.length, "cursor runs");
t.done();
}
assert_equals(cursor.value.name + ":" + cursor.primaryKey, expect[count], "cursor.value");
count++;
cursor.continue();
});
rq.onerror = t.step_func(function(e) {
e.preventDefault();
e.stopPropagation();
assert_unreached("rq.onerror - " + e.message);
});
}
};
// Fail handling
function fail_helper(name) {
return function() {
directions.forEach(function(dir) {
tests[dir].step(function() { assert_unreached(name); });
});
};
}
open_rq.onblocked = fail_helper('open_rq.onblocked');
open_rq.onerror = fail_helper('open_rq.onerror');
</script>
<div id=log> </div>

View file

@ -0,0 +1,81 @@
<!DOCTYPE html>
<title>IDBCursor direction - index</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#cursor-iteration-operation">
<link rel=assert title='If direction is "next", let found record be the first record in records which satisfy all of the following requirements'>
<link rel=assert title="If position is defined, and source is an object store, the record's key is greater than position.">
<link rel=assert title='If direction is "prev", let found record be the last record in records which satisfy all of the following requirements'>
<link rel=assert title="If position is defined, and source is an object store, the record's key is less than position.">
<link rel=assert title="Set cursor's position to found record's key. If source is an index, set cursor's object store position to found record's value.">
<link rel=assert title="Set cursor's key to found record's key.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var records = [ "Alice", "Bob", "Bob", "Greg" ];
var directions = ["next", "prev", "nextunique", "prevunique"];
var tests = {};
directions.forEach(function(dir) {
tests[dir] = async_test(document.title + ' - ' + dir);
});
var open_rq = indexedDB.open("testdb-" + new Date().getTime() + Math.random());
open_rq.onupgradeneeded = function(e) {
var objStore = e.target.result.createObjectStore("test");
objStore.createIndex("idx", "name");
for (var i = 0; i < records.length; i++)
objStore.add({ name: records[i] }, i);
};
open_rq.onsuccess = function(e) {
var db = e.target.result;
db.onerror = fail_helper("db.onerror");
// The tests
testdir('next', ['Alice:0', 'Bob:1', 'Bob:2', 'Greg:3']);
testdir('prev', ['Greg:3', 'Bob:2', 'Bob:1', 'Alice:0']);
testdir('nextunique', ['Alice:0', 'Bob:1', 'Greg:3']);
testdir('prevunique', ['Greg:3', 'Bob:1', 'Alice:0']);
// Test function
function testdir(dir, expect) {
var count = 0;
var t = tests[dir];
var rq = db.transaction("test").objectStore("test").index("idx").openCursor(undefined, dir);
rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, expect.length, "cursor runs");
t.done();
}
assert_equals(cursor.value.name + ":" + cursor.primaryKey, expect[count], "cursor.value");
count++;
cursor.continue();
});
rq.onerror = t.step_func(function(e) {
e.preventDefault();
e.stopPropagation();
assert_unreached("rq.onerror - " + e.message);
});
}
};
// Fail handling
function fail_helper(name) {
return function() {
directions.forEach(function(dir) {
tests[dir].step(function() { assert_unreached(name); });
});
};
}
open_rq.onblocked = fail_helper('open_rq.onblocked');
open_rq.onerror = fail_helper('open_rq.onerror');
</script>
<div id=log> </div>

View file

@ -0,0 +1,77 @@
<!DOCTYPE html>
<title>IDBCursor direction - object store with keyrange</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#cursor-iteration-operation">
<link rel=assert title='If direction is "next", let found record be the first record in records which satisfy all of the following requirements'>
<link rel=assert title='If direction is "prev", let found record be the last record in records which satisfy all of the following requirements'>
<link rel=assert title="If range is defined, the record's key is in range.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var records = [ 1337, "Alice", "Bob", "Greg", "Åke", ["Anne"] ];
var directions = ["next", "prev", "nextunique", "prevunique"];
var tests = {};
directions.forEach(function(dir) {
tests[dir] = async_test(document.title + ' - ' + dir);
});
var open_rq = indexedDB.open("testdb-" + new Date().getTime() + Math.random());
open_rq.onupgradeneeded = function(e) {
var objStore = e.target.result.createObjectStore("test");
for (var i = 0; i < records.length; i++)
objStore.add(records[i], records[i]);
};
open_rq.onsuccess = function(e) {
var db = e.target.result;
db.onerror = fail_helper("db.onerror");
// The tests
testdir('next', ['Alice', 'Bob', 'Greg']);
testdir('prev', ['Greg', 'Bob', 'Alice']);
testdir('nextunique', ['Alice', 'Bob', 'Greg']);
testdir('prevunique', ['Greg', 'Bob', 'Alice']);
// Test function
function testdir(dir, expect) {
var count = 0;
var t = tests[dir];
var rq = db.transaction("test").objectStore("test").openCursor(IDBKeyRange.bound("AA", "ZZ"), dir);
rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, expect.length, "cursor runs");
t.done();
}
assert_equals(cursor.value, expect[count], "cursor.value");
count++;
cursor.continue();
});
rq.onerror = t.step_func(function(e) {
e.preventDefault();
e.stopPropagation();
assert_unreached("rq.onerror - " + e.message);
});
}
};
// Fail handling
function fail_helper(name) {
return function() {
directions.forEach(function(dir) {
tests[dir].step(function() { assert_unreached(name); });
});
};
}
open_rq.onblocked = fail_helper('open_rq.onblocked');
open_rq.onerror = fail_helper('open_rq.onerror');
</script>
<div id=log> </div>

View file

@ -0,0 +1,80 @@
<!DOCTYPE html>
<title>IDBCursor direction - object store</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#cursor-iteration-operation">
<link rel=assert title='If direction is "next", let found record be the first record in records which satisfy all of the following requirements'>
<link rel=assert title="If position is defined, and source is an object store, the record's key is greater than position.">
<link rel=assert title='If direction is "prev", let found record be the last record in records which satisfy all of the following requirements'>
<link rel=assert title="If position is defined, and source is an object store, the record's key is less than position.">
<link rel=assert title="Set cursor's position to found record's key. If source is an index, set cursor's object store position to found record's value.">
<link rel=assert title="Set cursor's key to found record's key.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var records = [ "Alice", "Bob", "Greg" ];
var directions = ["next", "prev", "nextunique", "prevunique"];
var tests = {};
directions.forEach(function(dir) {
tests[dir] = async_test(document.title + ' - ' + dir);
});
var open_rq = indexedDB.open("testdb-" + new Date().getTime() + Math.random());
open_rq.onupgradeneeded = function(e) {
var objStore = e.target.result.createObjectStore("test");
for (var i = 0; i < records.length; i++)
objStore.add(records[i], records[i]);
};
open_rq.onsuccess = function(e) {
var db = e.target.result;
db.onerror = fail_helper("db.onerror");
// The tests
testdir('next', ['Alice', 'Bob', 'Greg']);
testdir('prev', ['Greg', 'Bob', 'Alice']);
testdir('nextunique', ['Alice', 'Bob', 'Greg']);
testdir('prevunique', ['Greg', 'Bob', 'Alice']);
// Test function
function testdir(dir, expect) {
var count = 0;
var t = tests[dir];
var rq = db.transaction("test").objectStore("test").openCursor(undefined, dir);
rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, expect.length, "cursor runs");
t.done();
}
assert_equals(cursor.value, expect[count], "cursor.value");
count++;
cursor.continue();
});
rq.onerror = t.step_func(function(e) {
e.preventDefault();
e.stopPropagation();
assert_unreached("rq.onerror - " + e.message);
});
}
};
// Fail handling
function fail_helper(name) {
return function() {
directions.forEach(function(dir) {
tests[dir].step(function() { assert_unreached(name); });
});
};
}
open_rq.onblocked = fail_helper('open_rq.onblocked');
open_rq.onerror = fail_helper('open_rq.onerror');
</script>
<div id=log> </div>

View file

@ -0,0 +1,73 @@
<!DOCTYPE html>
<title>IDBCursor.direction</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
function cursor_direction(constant, dir)
{
var db,
t = async_test(document.title + " - " + dir),
expected = dir ? dir : "next";
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test");
objStore.add("data", "key");
};
open_rq.onsuccess = t.step_func(function(e) {
var cursor_rq, count = 0;
var os = db.transaction("test")
.objectStore("test");
if (dir)
cursor_rq = os.openCursor(undefined, dir);
else
cursor_rq = os.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_equals(cursor.direction, constant, 'direction constant');
assert_equals(cursor.direction, expected, 'direction');
assert_readonly(cursor, 'direction');
count++;
if (count >= 2)
t.done();
});
var cursor_rq2 = db.transaction("test")
.objectStore("test")
.openCursor(undefined, constant);
cursor_rq2.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_equals(cursor.direction, constant, 'direction constant (second try)');
assert_equals(cursor.direction, expected, 'direction (second try)');
assert_readonly(cursor, 'direction');
count++;
if (count >= 2)
t.done();
});
});
}
cursor_direction("next");
cursor_direction("next", "next");
cursor_direction("prev", "prev");
cursor_direction("nextunique", "nextunique");
cursor_direction("prevunique", "prevunique");
</script>
<div id="log"></div>

View file

@ -0,0 +1,57 @@
<!DOCTYPE html>
<title>IDBCursor.key</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
function cursor_key(key)
{
var db,
t = async_test(document.title + " - " + key);
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test");
objStore.add("data", key);
};
open_rq.onsuccess = t.step_func(function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_equals(cursor.value, "data", "prequisite cursor.value");
assert_object_equals(cursor.key, key, 'key');
assert_readonly(cursor, 'key');
if (key instanceof Array) {
cursor.key.push("new");
key.push("new");
assert_object_equals(cursor.key, key, 'key after array push');
// But we can not change key (like readonly, just a bit different)
cursor.key = 10;
assert_object_equals(cursor.key, key, 'key after assignment');
}
t.done();
});
});
}
cursor_key(1);
cursor_key("key");
cursor_key(["my", "key"]);
</script>
<div id="log"></div>

View file

@ -0,0 +1,61 @@
<!DOCTYPE html>
<title>IDBCursor.primaryKey</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
function cursor_primarykey(key)
{
var db,
t = async_test(document.title + " - " + key);
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test");
objStore.createIndex("index", "");
objStore.add("data", key);
};
open_rq.onsuccess = t.step_func(function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_equals(cursor.value, "data", "prequisite cursor.value");
assert_equals(cursor.key, "data", "prequisite cursor.key");
assert_object_equals(cursor.primaryKey, key, 'primaryKey');
assert_readonly(cursor, 'primaryKey');
if (key instanceof Array) {
cursor.primaryKey.push("new");
key.push("new");
assert_object_equals(cursor.primaryKey, key, 'primaryKey after array push');
// But we can not change key (like readonly, just a bit different)
cursor.key = 10;
assert_object_equals(cursor.primaryKey, key, 'key after assignment');
}
t.done();
});
});
}
cursor_primarykey(1);
cursor_primarykey("key");
cursor_primarykey(["my", "key"]);
</script>
<div id="log"></div>

View file

@ -0,0 +1,69 @@
<!DOCTYPE html>
<title>IDBCursor is reused</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<meta rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-continue-void-any-key">
<meta rel=assert title="Otherwise this method runs the steps for asynchronously executing a request. However, the steps are slightly modified such that instead of creating a new IDBRequest, it reuses the request originally created when this cursor was created. The done flag on the request is set to false before the request is returned. The steps are run with the cursor's source as source and the steps for iterating a cursor as operation, using this cursor as cursor and the key parameter as key.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db
var open_rq = createdb(async_test())
open_rq.onupgradeneeded = function(e) {
db = e.target.result
var os = db.createObjectStore("test")
os.add("data", "k")
os.add("data2", "k2")
}
open_rq.onsuccess = function(e) {
var cursor
var count = 0
var rq = db.transaction("test").objectStore("test").openCursor()
rq.onsuccess = this.step_func(function(e)
{
switch(count)
{
case 0:
cursor = e.target.result
assert_equals(cursor.value, "data", "prequisite cursor.value")
cursor.custom_cursor_value = 1
e.target.custom_request_value = 2
cursor.continue()
break
case 1:
assert_equals(cursor.value, "data2", "prequisite cursor.value")
assert_equals(cursor.custom_cursor_value, 1, "custom cursor value")
assert_equals(e.target.custom_request_value, 2, "custom request value")
cursor.advance(1)
break
case 2:
assert_false(!!e.target.result, "got cursor")
assert_equals(cursor.custom_cursor_value, 1, "custom cursor value")
assert_equals(e.target.custom_request_value, 2, "custom request value")
break
}
count++
})
rq.transaction.oncomplete = this.step_func(function() {
assert_equals(count, 3, "cursor callback runs")
assert_equals(rq.custom_request_value, 2, "variable placed on old IDBRequest")
assert_equals(cursor.custom_cursor_value, 1, "custom cursor value (transaction.complete)")
this.done()
})
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,68 @@
<!DOCTYPE html>
<title>IDBCursor.source</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
setup({ explicit_done: true });
var db;
var open_rq = indexedDB.open('testdb-' + new Date().getTime());
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("my_objectstore");
objStore.createIndex("my_index", "");
objStore.add("data", 1);
objStore.add("data2", 2);
};
function cursor_source(name, stringified_object, cursor_rq) {
var cursor;
cursor_rq.onsuccess = this.step_func(function(e) {
if (!e.target.result) {
return;
}
cursor = e.target.result;
assert_readonly(cursor, 'source');
// Direct try
assert_true(cursor.source instanceof Object, "source isobject");
assert_equals(cursor.source + "", stringified_object, "source");
assert_equals(cursor.source.name, name, "name");
cursor.continue();
});
cursor_rq.transaction.oncomplete = this.step_func(function(e) {
this.done();
});
cursor_rq.transaction.onerror = this.step_func(function(e) {
assert_unreached("Transaction got error. " + (e.target.error ? e.target.error.name : "unknown"));
});
}
open_rq.onsuccess = function() {
async_test(document.title + ' - IDBObjectStore').step(function() {
cursor_source.call(this, "my_objectstore", "[object IDBObjectStore]", db.transaction("my_objectstore")
.objectStore("my_objectstore")
.openCursor());
});
async_test(document.title + ' - IDBIndex').step(function() {
cursor_source.call(this, "my_index", "[object IDBIndex]", db.transaction("my_objectstore")
.objectStore("my_objectstore")
.index("my_index")
.openCursor());
});
done();
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,57 @@
<!DOCTYPE html>
<title>IDBCursor.advance() - index - iterate cursor number of times specified by count </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var db,
count = 0,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_2", iKey: "indexKey_2" },
{ pKey: "primaryKey_3", iKey: "indexKey_3" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = event.target.result;
var store = db.createObjectStore("test", {keyPath:"pKey"});
store.createIndex("idx", "iKey");
for(var i = 0; i < records.length; i++) {
store.add(records[i]);
}
};
open_rq.onsuccess = function (e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("idx")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
switch(count) {
case 0:
count += 3;
cursor.advance(3);
break;
case 3:
var record = cursor.value;
assert_equals(record.pKey, records[count].pKey, "record.pKey");
assert_equals(record.iKey, records[count].iKey, "record.iKey");
t.done();
break;
default:
assert_unreached("unexpected count");
break;
}
});
}
</script>
<div id=log></div>

View file

@ -0,0 +1,47 @@
<!DOCTYPE html>
<title>IDBCursor.advance() - attempt to pass a count parameter that is not a number</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<link rel=assert title="The value passed into the count parameter was zero or a negative number.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(document.title, {timeout: 10000}),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
objStore.createIndex("index", "iKey");
for(var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor != null, "cursor exist");
assert_throws(new TypeError(),
function() { cursor.advance(document); });
t.done();
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,47 @@
<!DOCTYPE html>
<title>IDBCursor.advance() - index - attempt to advance backwards</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<link rel=assert title="The value passed into the count parameter was zero or a negative number.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script type="text/javascript">
var db,
t = async_test(document.title, {timeout: 10000}),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath:"pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "next");
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor != null, "cursor exist");
assert_throws(new TypeError(),
function() { cursor.advance(-1); });
t.done();
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,55 @@
<!DOCTYPE html>
<title>IDBCursor.advance() - index - iterate to the next record</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<link rel=assert title="The operation runs the steps for iterating a cursor count number of times with null as key and this cursor as cursor.">
<link rel=assert title="The number of advances forward the cursor should make.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(document.title, {timeout: 10000}),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_1-2", iKey: "indexKey_1" } ],
expected = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1-2", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result
var objStore = db.createObjectStore("test", { keyPath:"pKey" })
objStore.createIndex("index", "iKey")
for (var i = 0; i < records.length; i++)
objStore.add(records[i])
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, expected.length, "cursor run count")
t.done()
}
var record = cursor.value;
assert_equals(record.pKey, expected[count].pKey, "primary key");
assert_equals(record.iKey, expected[count].iKey, "index key");
cursor.advance(2);
count++;
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.advance() - index - throw TypeError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.index("index").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor);
assert_throws(new TypeError(), function() {
cursor.advance(0);
}, "Calling advance() with count argument 0 should throw TypeError.");
t.done();
});
}
</script>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.advance() - index - throw TransactionInactiveError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.index("index").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor);
event.target.transaction.abort();
assert_throws("TransactionInactiveError", function() {
cursor.advance(1);
}, "Calling advance() should throws an exception TransactionInactiveError when the transaction is not active.");
t.done();
});
}
</script>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.advance() - index - throw InvalidStateError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.index("index").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor);
cursor.advance(1);
assert_throws("InvalidStateError", function() {
cursor.advance(1);
}, "Calling advance() should throw DOMException when the cursor is currently being iterated.");
t.done();
});
}
</script>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.advance() - index - throw InvalidStateError caused by object store been deleted</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.index("index").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
db.deleteObjectStore("store");
assert_throws("InvalidStateError", function() {
cursor.advance(1);
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
t.done();
});
}
</script>

View file

@ -0,0 +1,54 @@
<!DOCTYPE html>
<title> IDBCursor.advance() - object store - iterate cursor number of times specified by count </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var db,
count = 0,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" },
{ pKey: "primaryKey_2" },
{ pKey: "primaryKey_3" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = event.target.result;
var store = db.createObjectStore("test", {keyPath:"pKey"});
for(var i = 0; i < records.length; i++) {
store.add(records[i]);
}
};
open_rq.onsuccess = function (e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
switch(count) {
case 0:
count += 3;
cursor.advance(3);
break;
case 3:
assert_equals(cursor.value.pKey, records[count].pKey, "cursor.value.pKey");
t.done();
break;
default:
assert_unreached("unexpected count");
break;
}
});
}
</script>
<div id=log> </div>

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.advance() - object store - throw TypeError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0"},
{ pKey: "primaryKey_1"}];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
}
open_rq.onsuccess = function (event) {
var txn = db.transaction("store", "readwrite");
var rq = txn.objectStore("store").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor);
assert_throws(new TypeError(), function() {
cursor.advance(0);
}, "Calling advance() with count argument 0 should throw TypeError.");
t.done();
});
}
</script>

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.advance() - object store - throw TransactionInactiveError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0"},
{ pKey: "primaryKey_1"}];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
}
open_rq.onsuccess = function (event) {
var txn = db.transaction("store", "readwrite");
var rq = txn.objectStore("store").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor);
event.target.transaction.abort();
assert_throws("TransactionInactiveError", function() {
cursor.advance(1);
}, "Calling advance() should throws an exception TransactionInactiveError when the transaction is not active");
t.done();
});
}
</script>

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.advance() - object store - throw InvalidStateError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-advance-void-unsigned-long-count">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0"},
{ pKey: "primaryKey_1"}];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
}
open_rq.onsuccess = function (event) {
var txn = db.transaction("store", "readwrite");
var rq = txn.objectStore("store").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor);
cursor.advance(1);
assert_throws("InvalidStateError", function() {
cursor.advance(1);
}, "Calling advance() should throw DOMException when the cursor is currently being iterated.");
t.done();
});
}
</script>

View file

@ -0,0 +1,36 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.advance() - object store - throw InvalidStateError caused by object store been deleted</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0"},
{ pKey: "primaryKey_1"}];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
db.deleteObjectStore("store");
assert_throws("InvalidStateError", function() {
cursor.advance(1);
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
t.done();
});
}
</script>

View file

@ -0,0 +1,52 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - index - iterate to the next record</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-continue-void-any-key">
<link rel=assert title="Otherwise this method runs the steps for asynchronously executing a request.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_1-2", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath:"pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, records.length, "cursor run count");
t.done();
}
var record = cursor.value;
assert_equals(record.pKey, records[count].pKey, "primary key");
assert_equals(record.iKey, records[count].iKey, "index key");
cursor.continue();
count++;
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,49 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - index - attempt to pass a key parameter that is not a valid key</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-continue-void-any-key">
<link rel=assert title="If the key parameter is specified and fulfills any of these conditions this method must throw a DOMException of type DataError">
<link rel=assert title="The parameter is not a valid key.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
objStore.createIndex("index", "iKey");
for(var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_throws("DataError",
function() { cursor.continue(document); });
assert_true(cursor instanceof IDBCursorWithValue, "cursor");
t.done();
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,54 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - index - attempt to iterate to the previous record when the direction is set for the next record </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-continue-void-any-key">
<link rel=assert title="The parameter is less than or equal to this cursor's position and this cursor's direction is 'next' or 'nextunique'.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var count = 0;
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "next"); // XXX: Fx has issue with "undefined"
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, 2, "ran number of times");
t.done();
}
// First time checks key equal, second time checks key less than
assert_throws("DataError",
function() { cursor.continue(records[0].iKey); });
cursor.continue();
count++;
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,65 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - index - attempt to iterate to the next record when the direction is set for the previous record</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-continue-void-any-key">
<link rel=assert title="The parameter is greater than or equal to this cursor's position and this cursor's direction is 'prev' or 'prevunique'.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_2", iKey: "indexKey_2" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var count = 0,
cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "prev"); // XXX Fx issues w undefined
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result,
record = cursor.value;
switch(count) {
case 0:
assert_equals(record.pKey, records[2].pKey, "first pKey");
assert_equals(record.iKey, records[2].iKey, "first iKey");
cursor.continue();
break;
case 1:
assert_equals(record.pKey, records[1].pKey, "second pKey");
assert_equals(record.iKey, records[1].iKey, "second iKey");
assert_throws("DataError",
function() { cursor.continue("indexKey_2"); });
t.done();
break;
default:
assert_unreached("Unexpected count value: " + count);
}
count++;
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,64 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - index - iterate using 'prevunique'</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#cursor-iteration-operation">
<link rel=assert title='If direction is "prevunique", let temp record be the last record in records which satisfy all of the following requirements:'>
<link rel=assert title="If position is defined, the record's key is less than position.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(document.title, {timeout: 10000}),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_1-2", iKey: "indexKey_1" },
{ pKey: "primaryKey_2", iKey: "indexKey_2" } ],
expected = [ { pKey: "primaryKey_2", iKey: "indexKey_2" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_0", iKey: "indexKey_0" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var count = 0,
cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, 'prevunique');
cursor_rq.onsuccess = t.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, expected.length, 'count');
t.done();
return;
}
var cursor = e.target.result,
record = cursor.value;
assert_equals(record.pKey, expected[count].pKey, "pKey #" + count);
assert_equals(record.iKey, expected[count].iKey, "iKey #" + count);
assert_equals(cursor.key, expected[count].iKey, "cursor.key #" + count);
assert_equals(cursor.primaryKey, expected[count].pKey, "cursor.primaryKey #" + count);
count++;
cursor.continue(expected[count] ? expected[count].iKey : undefined);
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,64 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - index - iterate using nextunique</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#cursor-iteration-operation">
<link rel=assert title='If direction is "nextunique", let found record be the first record in records which satisfy all of the following requirements:'>
<link rel=assert title="If position is defined, the record's key is greater than position.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(document.title, {timeout: 10000}),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_1-2", iKey: "indexKey_1" },
{ pKey: "primaryKey_2", iKey: "indexKey_2" } ],
expected = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" },
{ pKey: "primaryKey_2", iKey: "indexKey_2" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var count = 0,
cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor(undefined, "nextunique");
cursor_rq.onsuccess = t.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, expected.length, 'count');
t.done();
return;
}
var cursor = e.target.result,
record = cursor.value;
assert_equals(record.pKey, expected[count].pKey, "pKey #" + count);
assert_equals(record.iKey, expected[count].iKey, "iKey #" + count);
assert_equals(cursor.key, expected[count].iKey, "cursor.key #" + count);
assert_equals(cursor.primaryKey, expected[count].pKey, "cursor.primaryKey #" + count);
count++;
cursor.continue(expected[count] ? expected[count].iKey : undefined);
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.continue() - index - throw TransactionInactiveError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.index("index").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor);
event.target.transaction.abort();
assert_throws("TransactionInactiveError", function() {
cursor.continue();
}, "Calling continue() should throws an exception TransactionInactiveError when the transaction is not active.");
t.done();
});
}
</script>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.continue() - index - throw InvalidStateError caused by object store been deleted</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.index("index").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor);
db.deleteObjectStore("store");
assert_throws("InvalidStateError", function() {
cursor.continue();
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
t.done();
});
}
</script>

View file

@ -0,0 +1,54 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - attempt to call continue two times</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(document.title, {timeout: 10000});
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test");
objStore.createIndex("index", "");
objStore.add("data", 1);
objStore.add("data2", 2);
};
open_rq.onsuccess = function(e) {
var count = 0;
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
if (!e.target.result) {
assert_equals(count, 2, 'count');
t.done();
return;
}
var cursor = e.target.result;
cursor.continue(undefined);
// Second try
assert_throws('InvalidStateError',
function() { cursor.continue(); }, 'second continue');
assert_throws('InvalidStateError',
function() { cursor.continue(3); }, 'third continue');
count++;
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,46 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - object store - iterate to the next record</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var db,
count = 0,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {autoIncrement:true, keyPath:"pKey"});
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var store = db.transaction("test")
.objectStore("test");
cursor_rq = store.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, records.length, "cursor run count");
t.done();
}
var record = cursor.value;
assert_equals(record.pKey, records[count].pKey, "primary key");
assert_equals(record.iKey, records[count].iKey, "index key");
cursor.continue();
count++;
});
};
</script>
<div id=log> </div>

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - object store - attempt to pass a key parameter is not a valid key </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exists");
assert_throws("DataError",
function() { cursor.continue(document); });
t.done();
});
};
</script>
<div id="log"> </div>

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - object store - attempt to iterate to the previous record when the direction is set for the next record</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor(undefined, "next");
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
assert_throws("DataError",
function() { cursor.continue(records[0].pKey); });
t.done();
});
};
</script>
<div id="log"> </div>

View file

@ -0,0 +1,57 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - object store - attempt to iterate to the next record when the direction is set for the previous record </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" },
{ pKey: "primaryKey_2" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var count = 0,
cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor(null, "prev");
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor != null, "cursor exist");
switch(count) {
case 0:
assert_equals(cursor.value.pKey, records[2].pKey, "first cursor pkey");
cursor.continue(records[1].pKey);
break;
case 1:
assert_equals(cursor.value.pKey, records[1].pKey, "second cursor pkey");
assert_throws("DataError",
function() { cursor.continue(records[2].pKey); });
t.done();
break;
default:
assert_unreached("Unexpected count value: " + count);
}
count++;
});
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.continue() - object store - throw TransactionInactiveError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"> </div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exists");
e.target.transaction.abort();
assert_throws("TransactionInactiveError", function() {
cursor.continue();
}, "Calling continue() should throws an exception TransactionInactiveError when the transaction is not active.");
t.done();
});
};
</script>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.continue() - object store - throw InvalidStateError caused by object store been deleted</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"> </div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
var cursor_rq = objStore.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exists");
db.deleteObjectStore("test");
assert_throws("InvalidStateError", function() {
cursor.continue();
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
t.done();
});
}
</script>

View file

@ -0,0 +1,69 @@
<!DOCTYPE html>
<title>IDBCursor.delete() - index - remove a record from the object store</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = t.step_func(CursorDeleteRecord);
function CursorDeleteRecord(e) {
var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
cursor.delete();
});
txn.oncomplete = t.step_func(VerifyRecordWasDeleted);
}
function VerifyRecordWasDeleted(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, 1, 'count');
t.done();
}
assert_equals(cursor.value.pKey, records[1].pKey);
assert_equals(cursor.value.iKey, records[1].iKey);
cursor.continue();
count++;
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<title>IDBCursor.delete() - index - attempt to remove a record in a read-only transaction</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
assert_throws('ReadOnlyError', function() { cursor.delete(); });
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>IDBCursor.delete() - index - attempt to remove a record in an inactive transaction</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
var index = objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
var cursor_rq = index.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
window.cursor = cursor;
});
e.target.transaction.oncomplete = t.step_func(function(e) {
assert_throws('TransactionInactiveError', function() { window.cursor.delete(); })
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.delete() - index - throw InvalidStateError caused by object store been deleted</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.index("index").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
db.deleteObjectStore("store");
assert_throws("InvalidStateError", function() {
cursor.delete();
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
t.done();
});
}
</script>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.delete() - index - throw InvalidStateError when the cursor is being iterated</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-delete-IDBRequest">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.index("index").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
cursor.continue();
assert_throws("InvalidStateError", function() {
cursor.delete();
});
t.done();
});
}
</script>

View file

@ -0,0 +1,65 @@
<!DOCTYPE html>
<title>IDBCursor.delete() - object store - remove a record from the object store </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = t.step_func(CursorDeleteRecord);
function CursorDeleteRecord(e) {
var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test").openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor != null, "cursor exist");
cursor.delete();
});
txn.oncomplete = t.step_func(VerifyRecordWasDeleted);
}
function VerifyRecordWasDeleted(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, 1, 'count');
t.done();
}
assert_equals(cursor.value.pKey, records[1].pKey);
count++;
cursor.continue();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>IDBCursor.delete() - object store - attempt to remove a record in a read-only transaction</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor != null, "cursor exist");
assert_throws('ReadOnlyError', function() { cursor.delete(); });
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<title>IDBCursor.delete() - index - attempt to remove a record in an inactive transaction</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
var cursor_rq = objStore.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
window.cursor = cursor;
});
e.target.transaction.oncomplete = t.step_func(function(e) {
assert_throws('TransactionInactiveError', function() { window.cursor.delete(); })
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.delete() - object store - throw InvalidStateError caused by object store been deleted</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0"},
{ pKey: "primaryKey_1"}];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
db.deleteObjectStore("store");
assert_throws("InvalidStateError", function() {
cursor.delete();
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
t.done();
});
}
</script>

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.delete() - object store - throw InvalidStateError when the cursor is being iterated</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-delete-IDBRequest">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0"},
{ pKey: "primaryKey_1"}];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
}
open_rq.onsuccess = function (event) {
var txn = db.transaction("store", "readwrite");
var rq = txn.objectStore("store").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
cursor.continue();
assert_throws("InvalidStateError", function() {
cursor.delete();
});
t.done();
});
}
</script>

View file

@ -0,0 +1,110 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - objectstore - delete next element, and iterate to it</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(document.title, {timeout: 10000});
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "key" });
for (var i = 0; i < 500; i++)
objStore.add({ key: i, val: "val_"+i });
var rq = objStore.add({ key: 500, val: "val_500" });
rq.onsuccess = t.step_func(function() {
for (var i = 999; i > 500; i--)
objStore.add({ key: i, val: "val_"+i });
});
objStore.createIndex('index', ['key', 'val']);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result,
store = e.target.source;
if (!cursor) {
assert_equals(count, 997, "cursor run count");
var rq = e.target.source.count();
rq.onsuccess = t.step_func(function(e) {
assert_equals(e.target.result, 995, "object count");
t.done();
});
return;
}
switch (cursor.key) {
case 10:
assert_equals(count, cursor.key, "count");
store.delete(11);
break;
case 12:
case 499:
case 500:
case 501:
assert_equals(count, cursor.key - 1, "count");
break;
// Delete the next key
case 510:
store.delete(511);
break;
// Delete randomly
case 512:
store.delete(611);
store.delete(499);
store.delete(500);
break;
// Delete and add a new key
case 520:
store.delete(521);
store.add({ key: 521, val: "new"});
break;
case 521:
assert_equals(cursor.value.val, "new");
break;
// We should only be here once although we're basically making the index
// "heavier" with its new key.
case 530:
assert_equals(cursor.value.val, "val_530");
cursor.update({ key: 530, val: "val_531" })
store.get(530).onsuccess = t.step_func(function(e) {
assert_equals(e.target.result.val, "val_531");
});
break;
// Shouldn't happen.
case 11:
case 511:
case 611:
assert_unreached(cursor.key + " should be deleted and never run");
break;
}
cursor.continue();
count++;
});
};
</script>
<div id="log"> </div>

View file

@ -0,0 +1,53 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - index - delete next element, and iterate to it</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(document.title, {timeout: 10000}),
records = [ { pKey: "primaryKey_0", obj: { iKey: "iKey_0" }},
{ pKey: "primaryKey_1", obj: { iKey: "iKey_1" }},
{ pKey: "primaryKey_2", obj: { iKey: "iKey_2" }} ],
expected = [ [ "primaryKey_2", "iKey_2" ],
[ "primaryKey_0", "iKey_0" ] ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:["pKey", "obj.iKey"]});
objStore.createIndex("index", [ "pKey", "obj.iKey" ]);
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.index("index")
.openCursor(null, "prev");
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, 2, "cursor run count");
t.done();
}
if (count === 0) {
e.target.source.objectStore.delete(["primaryKey_1", "iKey_1"]);
}
assert_array_equals(cursor.key, expected[count], "primary key");
cursor.continue();
count++;
});
};
</script>
<div id="log"> </div>

View file

@ -0,0 +1,53 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - index - add next element, and iterate to it</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(document.title, {timeout: 10000}),
records = [ { pKey: "primaryKey_0", obj: { iKey: "iKey_0" }},
{ pKey: "primaryKey_2", obj: { iKey: "iKey_2" }} ],
expected = [ [ "primaryKey_2", "iKey_2" ],
[ "primaryKey_1", "iKey_1" ],
[ "primaryKey_0", "iKey_0" ] ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
objStore.createIndex("index", [ "pKey", "obj.iKey" ]);
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.index("index")
.openCursor(null, "prev");
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, 3, "cursor run count");
t.done();
}
if (count === 0) {
e.target.source.objectStore.add({ pKey: "primaryKey_1", obj: { iKey: "iKey_1" } });
}
assert_array_equals(cursor.key, expected[count], "primary key");
cursor.continue();
count++;
});
};
</script>
<div id="log"> </div>

View file

@ -0,0 +1,51 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - objectstore - delete next element, and iterate to it</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(document.title, {timeout: 10000}),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" },
{ pKey: "primaryKey_2" } ],
expected_records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_2" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, 2, "cursor run count");
t.done();
}
var record = cursor.value;
if (record.pKey == "primaryKey_0") {
e.target.source.delete("primaryKey_1");
}
assert_equals(record.pKey, expected_records[count].pKey, "primary key");
cursor.continue();
count++;
});
};
</script>
<div id="log"> </div>

View file

@ -0,0 +1,51 @@
<!DOCTYPE html>
<title>IDBCursor.continue() - objectstore - add next element, and iterate to it</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(document.title, {timeout: 10000}),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_2" } ],
expected_records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" },
{ pKey: "primaryKey_2" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, 3, "cursor run count");
t.done();
}
var record = cursor.value;
if (record.pKey == "primaryKey_0") {
e.target.source.add({ pKey: "primaryKey_1" });
}
assert_equals(record.pKey, expected_records[count].pKey, "primary key");
cursor.continue();
count++;
});
};
</script>
<div id="log"> </div>

View file

@ -0,0 +1,64 @@
<!DOCTYPE html>
<title>IDBCursor.update() - index - modify a record in the object store </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
count = 0,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
// XXX: Gecko doesn't like this
//e.target.transaction.oncomplete = t.step_func(CursorUpdateRecord);
};
open_rq.onsuccess = CursorUpdateRecord;
function CursorUpdateRecord(e) {
var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
cursor.value.iKey += "_updated";
cursor.update(cursor.value);
});
txn.oncomplete = t.step_func(VerifyRecordWasUpdated);
}
function VerifyRecordWasUpdated(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_equals(cursor.value.iKey, records[0].iKey + "_updated");
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>IDBCursor.update() - index - attempt to modify a record in a read-only transaction</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_throws('ReadOnlyError', function() { cursor.update(cursor.value); });
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<title>IDBCursor.update() - index - attempt to modify a record in an inactive transaction</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
var index = objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
var cursor_rq = index.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
window.cursor = cursor;
window.record = cursor.value;
});
e.target.transaction.oncomplete = t.step_func(function(e) {
assert_throws('TransactionInactiveError', function() { window.cursor.update(window.record); })
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.update() - index - attempt to modify a record when object store been deleted</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
var rq = objStore.index("index").openCursor();
rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor);
db.deleteObjectStore("store");
cursor.value.iKey += "_updated";
assert_throws("InvalidStateError", function() {
cursor.update(cursor.value);
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
t.done();
});
}
</script>

View file

@ -0,0 +1,45 @@
<!DOCTYPE html>
<title>IDBCursor.update() - index - throw DataCloneError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-update-IDBRequest-any-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
var record = cursor.value;
record.data = document;
assert_throws('DataCloneError', function() {
cursor.update(record);
});
t.done();
});
}
</script>

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<title>IDBCursor.update() - index - no argument</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-update-IDBRequest-any-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
assert_throws(new TypeError(), function() { cursor.update(); });
t.done();
});
}
</script>

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<title>IDBCursor.update() - index - throw DataError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-update-IDBRequest-any-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
assert_throws('DataError', function() { cursor.update(null); });
t.done();
});
}
</script>

View file

@ -0,0 +1,60 @@
<!DOCTYPE html>
<title>IDBCursor.update() - objectstore - modify a record in the object store </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
// XXX: Gecko doesn't like this
//e.target.transaction.oncomplete = t.step_func(CursorUpdateRecord);
};
open_rq.onsuccess = CursorUpdateRecord;
function CursorUpdateRecord(e) {
var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
cursor.value.data = "New information!";
cursor.update(cursor.value);
});
txn.oncomplete = t.step_func(VerifyRecordWasUpdated);
}
function VerifyRecordWasUpdated(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_equals(cursor.value.data, "New information!");
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<title>IDBCursor.update() - object store - attempt to modify a record in a read-only transaction</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_throws('ReadOnlyError', function() { cursor.update(cursor.value); });
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>IDBCursor.update() - object store - attempt to modify a record in an inactive transaction</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
var cursor_rq = objStore.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exist");
window.cursor = cursor;
window.record = cursor.value;
});
e.target.transaction.oncomplete = t.step_func(function(e) {
assert_throws('TransactionInactiveError', function() { window.cursor.update(window.record); })
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<title>IDBCursor.update() - index - modify a record in the object store </title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(document.title, {timeout: 10000})
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test");
objStore.add("data", "key");
};
open_rq.onsuccess = t.step_func(function(e) {
var txn = db.transaction("test", "readwrite"),
cursor_rq = txn.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
cursor.value = "new data!";
cursor.update(cursor.value).onsuccess = t.step_func(function(e) {
assert_equals(e.target.result, "key");
t.done();
});
});
});
</script>
<div id="log"></div>

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.update() - object store - attempt to modify a record when object store been deleted</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
var cursor_rq = objStore.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exists");
db.deleteObjectStore("test");
cursor.value += "_updated";
assert_throws("InvalidStateError", function() {
cursor.update(cursor.value);
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
t.done();
});
}
</script>

View file

@ -0,0 +1,43 @@
<!DOCTYPE html>
<title>IDBCursor.update() - object store - throw DataCloneError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-update-IDBRequest-any-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
var record = cursor.value;
record.data = document;
assert_throws('DataCloneError', function() {
cursor.update(record);
});
t.done();
});
}
</script>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<title>IDBCursor.update() - object store - no argument</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-update-IDBRequest-any-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
assert_throws(new TypeError(), function() { cursor.update(); });
t.done();
});
}
</script>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<title>IDBCursor.update() - object store - throw DataError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBCursor-update-IDBRequest-any-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "pKey" });
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("test", "readwrite")
.objectStore("test")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
assert_throws('DataError', function() { cursor.update(null); });
t.done();
});
}
</script>

View file

@ -0,0 +1,43 @@
<!DOCTYPE html>
<title>IDBDatabase.close() - unblock the version change transaction created by an open database request</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db;
var versionchange_fired;
var blocked_fired;
var upgradeneeded_fired;
var t = async_test();
var open_rq = createdb(t);
var counter = 0;
open_rq.onupgradeneeded = function() {}
open_rq.onsuccess = function(e) {
db = e.target.result;
db.onversionchange = t.step_func(function(e) {
versionchange_fired = counter++;
});
var rq = window.indexedDB.open(db.name, db.version + 1);
rq.onblocked = t.step_func(function (e) {
blocked_fired = counter++;
db.close();
});
rq.onupgradeneeded = t.step_func(function (e) {
upgradeneeded_fired = counter++;
});
rq.onsuccess = t.step_func(function (e) {
assert_equals(versionchange_fired, 0, 'block event fired #')
assert_equals(blocked_fired, 1, 'block event fired #')
assert_equals(upgradeneeded_fired, 2, 'second upgradeneeded event fired #')
t.done();
});
rq.onerror = fail(t, 'Unexpected database deletion error');
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<title>IDBDatabase.close() - unblock the delete database request</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db;
var blocked_fired = false;
var versionchange_fired = false;
var t = async_test();
var open_rq = createdb(t);
open_rq.onupgradeneeded = t.step_func(function() {});
open_rq.onsuccess = t.step_func(function(e) {
db = e.target.result;
db.onversionchange = t.step_func(function (e) {
versionchange_fired = true;
});
var rq = window.indexedDB.deleteDatabase(db.name);
rq.onblocked = t.step_func(function (e) {
blocked_fired = true;
db.close();
});
rq.onsuccess = t.step_func(function (e) {
assert_true(versionchange_fired, "versionchange event fired")
assert_true(blocked_fired, "block event fired")
t.done();
});
rq.onerror = fail(t, 'Unexpected database deletion error');
});
</script>
<div id="log"></div>

View file

@ -0,0 +1,45 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>IDBDatabase.createObjectStore() and IDBObjectStore.createIndex() - both with empty name</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var db
var open_rq = createdb(async_test())
open_rq.onupgradeneeded = function(e) {
db = e.target.result
var store = db.createObjectStore("")
for (var i = 0; i < 5; i++)
store.add({ idx: "object_" + i }, i)
store.createIndex("", "idx")
store.get(4)
.onsuccess = this.step_func(function(e) {
assert_equals(e.target.result.idx, 'object_4', 'result')
})
assert_equals(store.indexNames[0], "", "indexNames[0]")
assert_equals(store.indexNames.length, 1, "indexNames.length")
}
open_rq.onsuccess = function() {
var store = db.transaction("").objectStore("")
assert_equals(store.indexNames[0], "", "indexNames[0]")
assert_equals(store.indexNames.length, 1, "indexNames.length")
store.index("")
.get('object_4')
.onsuccess = this.step_func(function(e) {
assert_equals(e.target.result.idx, 'object_4', 'result')
this.done()
})
}
</script>
<div id=log></div>

View file

@ -0,0 +1,29 @@
<!DOCTYPE html>
<title>IDBDatabase.createObjectStore() - returns an instance of IDBObjectStore</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var t = async_test(),
open_rq = createdb(t)
open_rq.onupgradeneeded = function(e) {
var db = e.target.result
var objStore = db.createObjectStore('instancetest')
assert_true(objStore instanceof IDBObjectStore, 'instanceof IDBObjectStore')
}
open_rq.onsuccess = function(e) {
var db = e.target.result
var objStore = db.transaction('instancetest').objectStore('instancetest')
assert_true(objStore instanceof IDBObjectStore, 'instanceof IDBObjectStore')
t.done()
}
</script>
<div id=log></div>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<title>IDBDatabase.createObjectStore() - create 1000 object stores, add one item and delete</title>
<meta name=timeout content=long>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(document.title, {timeout: 600000}),
open_rq = createdb(t)
open_rq.onupgradeneeded = function(e) {
db = e.target.result
var st, i;
for (i = 0; i < 1000; i++)
{
st = db.createObjectStore("object_store_" + i)
st.add("test", 1);
}
st.get(1).onsuccess = t.step_func(function(e) {
assert_equals(e.target.result, "test")
})
}
open_rq.onsuccess = function(e) {
db.close()
window.indexedDB.deleteDatabase(db.name).onsuccess = function(e) {
t.done()
}
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>IDBDatabase.createObjectStore() - empty name</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var db
var open_rq = createdb(async_test())
open_rq.onupgradeneeded = function(e) {
db = e.target.result
var store = db.createObjectStore("")
for (var i = 0; i < 5; i++)
store.add("object_" + i, i)
assert_equals(db.objectStoreNames[0], "", "db.objectStoreNames[0]")
assert_equals(db.objectStoreNames.length, 1, "objectStoreNames.length")
}
open_rq.onsuccess = function() {
var store = db.transaction("").objectStore("")
store.get(2).onsuccess = this.step_func(function(e) {
assert_equals(e.target.result, "object_2")
})
assert_equals(db.objectStoreNames[0], "", "db.objectStoreNames[0]")
assert_equals(db.objectStoreNames.length, 1, "objectStoreNames.length")
this.done()
}
</script>
<div id=log></div>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBDatabase.createObjectStore() - Attampt Create Exsists Object Store With Difference keyPath throw ConstraintError </title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBDatabase-createObjectStore-IDBObjectStore-DOMString-name-IDBObjectStoreParameters-optionalParameters">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var t = async_test(),
open_rq = createdb(t);
open_rq.onupgradeneeded = function (e) {
var db = e.target.result;
db.createObjectStore("store");
assert_throws("ConstraintError", function(){
db.createObjectStore("store", {
keyPath: "key1",
});
});
t.done();
}
</script>

View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<title>IDBDatabase.createObjectStore() - object store 'name' and 'keyPath' properties are correctly set </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var t = async_test(),
open_rq = createdb(t)
open_rq.onupgradeneeded = function(e) {
var db = e.target.result,
objStore = db.createObjectStore("prop", { keyPath: "mykeypath" })
assert_equals(objStore.name, "prop", "object store name")
assert_equals(objStore.keyPath, "mykeypath", "key path")
assert_equals(objStore.autoIncrement, false, "auto increment")
}
open_rq.onsuccess = function(e) {
var db = e.target.result
var objStore = db.transaction('prop').objectStore('prop')
assert_equals(objStore.name, "prop", "object store name")
assert_equals(objStore.keyPath, "mykeypath", "key path")
assert_equals(objStore.autoIncrement, false, "auto increment")
t.done()
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,24 @@
<!DOCTYPE html>
<title>IDBDatabase.createObjectStore() - attempt to create an object store outside of a version change transaction </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var t = async_test(),
open_rq = createdb(t)
open_rq.onupgradeneeded = function() {}
open_rq.onsuccess = function (e) {
var db = e.target.result
assert_throws(
'InvalidStateError',
function() { db.createObjectStore('fails') })
t.done();
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,27 @@
<!DOCTYPE html>
<title>IDBDatabase.createObjectStore() - attempt to create an object store that already exists </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var t = async_test(),
open_rq = createdb(t)
open_rq.onupgradeneeded = function(e) {
var db = e.target.result
db.createObjectStore("dupe")
assert_throws(
'ConstraintError',
function() { db.createObjectStore("dupe") })
// Bonus test creating a new objectstore after the exception
db.createObjectStore("dupe ")
t.done()
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<title>IDBDatabase.createObjectStore() - object store's name appears in database's list </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var t = async_test(),
open_rq = createdb(t)
open_rq.onupgradeneeded = function(e) {
var db = e.target.result
db.createObjectStore("My cool object store name")
assert_true(
db.objectStoreNames.contains("My cool object store name"),
'objectStoreNames.contains')
}
open_rq.onsuccess = function(e) {
var db = e.target.result
assert_true(
db.objectStoreNames.contains("My cool object store name"),
'objectStoreNames.contains (in success)')
t.done()
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<title>IDBDatabase.createObjectStore() - attempt to create an object store with an invalid key path </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var t = async_test(),
open_rq = createdb(t)
open_rq.onupgradeneeded = function(e) {
var db = e.target.result
assert_throws('SyntaxError', function() {
db.createObjectStore("invalidkeypath", { keyPath: "Invalid Keypath" })
})
assert_throws('SyntaxError', function() {
db.createObjectStore("invalidkeypath", { autoIncrement: true,
keyPath: "Invalid Keypath" })
})
t.done()
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>IDBDatabase.createObjectStore() - create an object store with an unknown optional parameter </title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var t = async_test(document.title, {timeout: 10000}),
open_rq = createdb(t)
open_rq.onupgradeneeded = function(e) {
var db = e.target.result
db.createObjectStore("with unknown param", { parameter: 0 });
t.done()
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBObjectStoreParameters</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
function optionalParameters(desc, params) {
var t = async_test(document.title + " - " + desc);
createdb(t).onupgradeneeded = function(e) {
e.target.result.createObjectStore("store", params);
this.done();
};
}
optionalParameters("autoInc true", {autoIncrement: true});
optionalParameters("autoInc true, keyPath null", {autoIncrement: true, keyPath: null});
optionalParameters("autoInc true, keyPath undefined", {autoIncrement: true, keyPath: undefined});
optionalParameters("autoInc true, keyPath string", {autoIncrement: true, keyPath: "a"});
optionalParameters("autoInc false, keyPath empty", {autoIncrement: false, keyPath: ""});
optionalParameters("autoInc false, keyPath array", {autoIncrement: false, keyPath: ["h", "j"]});
optionalParameters("autoInc false, keyPath string", {autoIncrement: false, keyPath: "abc"});
optionalParameters("keyPath empty", {keyPath: ""});
optionalParameters("keyPath array", {keyPath: ["a","b"]});
optionalParameters("keyPath string", {keyPath: "abc"});
optionalParameters("keyPath null", {keyPath: null});
optionalParameters("keyPath undefined", {keyPath: undefined});
</script>
<div id="log"></div>

View file

@ -0,0 +1,29 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>createObjectStore: Invalid optionalParameters</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
function invalid_optionalParameters(desc, params) {
var t = async_test(document.title + " - " + desc);
createdb(t).onupgradeneeded = function(e) {
assert_throws(null, function() {
e.target.result.createObjectStore("store", params);
});
this.done();
};
}
invalid_optionalParameters("autoInc and empty keyPath", {autoIncrement: true, keyPath: ""});
invalid_optionalParameters("autoInc and keyPath array", {autoIncrement: true, keyPath: []});
invalid_optionalParameters("autoInc and keyPath array 2", {autoIncrement: true, keyPath: ["hey"]});
invalid_optionalParameters("autoInc and keyPath object", {autoIncrement: true, keyPath: {a:"hey", b:2}});
</script>
<div id=log></div>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>IDBDatabase.deleteObjectStore() - object store's name is removed from database's list </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var t = async_test(),
open_rq = createdb(t)
open_rq.onupgradeneeded = function(e) {
var db = e.target.result
db.createObjectStore("deleted");
db.deleteObjectStore("deleted");
assert_false(db.objectStoreNames.contains("deleted"))
t.done()
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<title>IDBDatabase.deleteObjectStore() - attempt to remove an object store outside of a version change transaction </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var t = async_test(),
open_rq = createdb(t);
open_rq.onupgradeneeded = function(e)
{
var db = e.target.result,
objStore = db.createObjectStore("delete_outside");
e.target.transaction.oncomplete = t.step_func(function (e)
{
assert_throws('InvalidStateError',
function() { db.deleteObjectStore("delete_outside"); });
t.done();
});
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<title>IDBDatabase.deleteObjectStore() - attempt to remove an object store that does not exist </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var t = async_test(),
open_rq = createdb(t);
open_rq.onupgradeneeded = function(e)
{
var db = e.target.result;
assert_throws('NotFoundError',
function() { db.deleteObjectStore('whatever'); });
t.done();
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>IDBDatabase.deleteObjectStore() - the object store is not reused</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>
<script>
var t = async_test(document.title, {timeout: 10000}),
keys = [],
open_rq = createdb(t)
open_rq.onupgradeneeded = function(e) {
var db = e.target.result
var objStore = db.createObjectStore("resurrected", { autoIncrement: true, keyPath: "k" });
objStore.add({k:5}).onsuccess = function(e) { keys.push(e.target.result); }
objStore.add({}).onsuccess = function(e) { keys.push(e.target.result); }
objStore.createIndex("idx", "i");
assert_true(objStore.indexNames.contains("idx"));
assert_equals(objStore.keyPath, "k", "keyPath");
db.deleteObjectStore("resurrected");
var objStore2 = db.createObjectStore("resurrected", { autoIncrement: true });
objStore2.add("Unicorns'R'us").onsuccess = function(e) { keys.push(e.target.result); };
assert_false(objStore2.indexNames.contains("idx"), "index exist on new objstore");
assert_equals(objStore2.keyPath, null, "keyPath");
assert_throws("NotFoundError", function() { objStore2.index("idx"); });
}
open_rq.onsuccess = function(e) {
assert_object_equals(keys, [5, 6, 1], "keys");
t.done();
}
</script>
<div id="log"></div>

View file

@ -0,0 +1,24 @@
<!DOCTYPE html>
<title>IDBDatabase.transaction() - attempt to open a transaction with invalid scope</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
open_rq = createdb(t);
open_rq.onupgradeneeded = function() {};
open_rq.onsuccess = function(e) {
db = e.target.result;
assert_throws('NotFoundError', function() { db.transaction('non-existing'); });
t.done();
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,27 @@
<!DOCTYPE html>
<title>IDBDatabase.transaction() - opening a transaction defaults to a read-only mode </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
db.createObjectStore('readonly');
};
open_rq.onsuccess = function(e) {
var txn = db.transaction('readonly');
assert_equals(txn.mode, "readonly", 'txn.mode');
t.done();
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,28 @@
<!DOCTYPE html>
<title>IDBDatabase.transaction() - attempt to open a transaction from closed database connection </title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(),
open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
db.createObjectStore('test');
};
open_rq.onsuccess = function(e) {
db.close();
assert_throws('InvalidStateError',
function() { db.transaction('test'); });
t.done();
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,26 @@
<!DOCTYPE html>
<title>IDBDatabase.transaction() - attempt to open a transaction with invalid mode </title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
var db,
t = async_test(document.title, {timeout: 10000}),
open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
db.createObjectStore('test');
};
open_rq.onsuccess = function(e) {
assert_throws({ name: 'TypeError' },
function() { db.transaction('test', 'whatever'); });
t.done();
};
</script>
<div id="log"></div>

View file

@ -0,0 +1,22 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBDatabase.transaction() - If storeNames is an empty list, the implementation must throw a DOMException of type InvalidAccessError</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBDatabase-transaction-IDBTransaction-DOMString-sequence-DOMString--storeNames-IDBTransactionMode-mode">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
open_rq = createdb(t);
open_rq.onupgradeneeded = function() {};
open_rq.onsuccess = function(e) {
db = e.target.result;
assert_throws('InvalidAccessError', function() { db.transaction([]); });
t.done();
};
</script>

Some files were not shown because too many files have changed in this diff Show more