зеркало из https://github.com/mozilla/pjs.git
Bug 587797 - IndexedDB: Tests for making it possible to access IndexedDB APIs from chrome. r=khuey
This commit is contained in:
Родитель
b70d3404f7
Коммит
8003328fca
|
@ -40,10 +40,15 @@ topsrcdir = @top_srcdir@
|
|||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
relativesrcdir = dom/indexedDB/test
|
||||
DIRS += unit
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
XPCSHELL_TESTS = unit
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
TEST_FILES = \
|
||||
bfcache_iframe1.html \
|
||||
bfcache_iframe2.html \
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function executeSoon(aFun)
|
||||
{
|
||||
SimpleTest.executeSoon(aFun);
|
||||
}
|
||||
|
||||
function runTest()
|
||||
{
|
||||
allowIndexedDB();
|
||||
|
|
|
@ -9,165 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
let openRequest = mozIndexedDB.open(name, 1);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
let trans = event.target.transaction;
|
||||
|
||||
for each (let autoincrement in [true, false]) {
|
||||
for each (let keypath in [false, true, "missing", "invalid"]) {
|
||||
for each (let method in ["put", "add"]) {
|
||||
for each (let explicit in [true, false, undefined, "invalid"]) {
|
||||
for each (let existing in [true, false]) {
|
||||
let speccedNoKey = (keypath == false || keypath == "missing") &&
|
||||
!explicit;
|
||||
|
||||
// We can't do 'existing' checks if we use autogenerated key
|
||||
if (speccedNoKey && autoincrement && existing) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create store
|
||||
if (db.objectStoreNames.contains("mystore"))
|
||||
db.deleteObjectStore("mystore");
|
||||
let store = db.createObjectStore("mystore",
|
||||
{ autoIncrement: autoincrement,
|
||||
keyPath: (keypath ? "id" : null) });
|
||||
|
||||
test = " for test " + JSON.stringify({ autoincrement: autoincrement,
|
||||
keypath: keypath,
|
||||
method: method,
|
||||
explicit: explicit === undefined ? "undefined" : explicit,
|
||||
existing: existing });
|
||||
|
||||
// Insert "existing" data if needed
|
||||
if (existing) {
|
||||
if (keypath)
|
||||
store.add({ existing: "data", id: 5 }).onsuccess = grabEventAndContinueHandler;
|
||||
else
|
||||
store.add({ existing: "data" }, 5).onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
let e = yield;
|
||||
is(e.type, "success", "success inserting existing" + test);
|
||||
is(e.target.result, 5, "inserted correct key" + test);
|
||||
}
|
||||
|
||||
// Set up value to be inserted
|
||||
let value = { theObj: true };
|
||||
if (keypath === true) {
|
||||
value.id = 5;
|
||||
}
|
||||
else if (keypath === "invalid") {
|
||||
value.id = /x/;
|
||||
}
|
||||
|
||||
// Which arguments are passed to function
|
||||
args = [value];
|
||||
if (explicit === true) {
|
||||
args.push(5);
|
||||
}
|
||||
else if (explicit === undefined) {
|
||||
args.push(undefined);
|
||||
}
|
||||
else if (explicit === "invalid") {
|
||||
args.push(/x/);
|
||||
}
|
||||
|
||||
let expected = expectedResult(method, keypath, explicit, autoincrement, existing);
|
||||
|
||||
let valueJSON = JSON.stringify(value);
|
||||
|
||||
ok(true, "making call" + test);
|
||||
|
||||
// Make function call for throwing functions
|
||||
if (expected === "throw") {
|
||||
try {
|
||||
store[method].apply(store, args);
|
||||
ok(false, "should have thrown" + test);
|
||||
}
|
||||
catch (ex) {
|
||||
ok(true, "did throw" + test);
|
||||
ok(ex instanceof IDBDatabaseException, "Got a IDBDatabaseException" + test);
|
||||
is(ex.code, IDBDatabaseException.DATA_ERR, "expect a DATA_ERR" + test);
|
||||
is(JSON.stringify(value), valueJSON, "call didn't modify value" + test);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Make non-throwing function call
|
||||
let req = store[method].apply(store, args);
|
||||
is(JSON.stringify(value), valueJSON, "call didn't modify value" + test);
|
||||
|
||||
req.onsuccess = req.onerror = grabEventAndContinueHandler;
|
||||
let e = yield;
|
||||
|
||||
// Figure out what key we used
|
||||
let key = 5;
|
||||
if (autoincrement && speccedNoKey) {
|
||||
key = 1;
|
||||
}
|
||||
|
||||
// Adjust value if expected
|
||||
if (autoincrement && keypath && speccedNoKey) {
|
||||
value.id = key;
|
||||
}
|
||||
|
||||
// Check result
|
||||
if (expected === "error") {
|
||||
is(e.type, "error", "write should fail" + test);
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
continue;
|
||||
}
|
||||
|
||||
is(e.type, "success", "write should succeed" + test);
|
||||
is(e.target.result, key, "write should return correct key" + test);
|
||||
|
||||
store.get(key).onsuccess = grabEventAndContinueHandler;
|
||||
e = yield;
|
||||
is(e.type, "success", "read back should succeed" + test);
|
||||
is(JSON.stringify(e.target.result),
|
||||
JSON.stringify(value),
|
||||
"read back should return correct value" + test);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function expectedResult(method, keypath, explicit, autoincrement, existing) {
|
||||
if (keypath && explicit)
|
||||
return "throw";
|
||||
if (!keypath && !explicit && !autoincrement)
|
||||
return "throw";
|
||||
if (keypath == "invalid")
|
||||
return "throw";
|
||||
if (keypath == "missing" && !autoincrement)
|
||||
return "throw";
|
||||
if (explicit == "invalid")
|
||||
return "throw";
|
||||
|
||||
if (method == "add" && existing)
|
||||
return "error";
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_add_put.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,40 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = request.result;
|
||||
|
||||
ok(event.target === request, "Good event target");
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: null });
|
||||
let key = 10;
|
||||
|
||||
request = objectStore.add({}, key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(request.result, key, "Correct key");
|
||||
|
||||
request = objectStore.add({}, key);
|
||||
request.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_add_twice_failure.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,193 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const dataCount = 30;
|
||||
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("", { keyPath: "key" });
|
||||
objectStore.createIndex("", "index");
|
||||
|
||||
for (let i = 0; i < dataCount; i++) {
|
||||
objectStore.add({ key: i, index: i });
|
||||
}
|
||||
yield;
|
||||
|
||||
function getObjectStore() {
|
||||
return db.transaction("").objectStore("");
|
||||
}
|
||||
|
||||
function getIndex() {
|
||||
return db.transaction("").objectStore("").index("");
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
|
||||
getObjectStore().openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
count++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount, "Saw all data");
|
||||
|
||||
count = 0;
|
||||
|
||||
getObjectStore().openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count) {
|
||||
count++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
count = 10;
|
||||
cursor.advance(10);
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount, "Saw all data");
|
||||
|
||||
count = 0;
|
||||
|
||||
getIndex().openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count) {
|
||||
count++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
count = 10;
|
||||
cursor.advance(10);
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount, "Saw all data");
|
||||
|
||||
count = 0;
|
||||
|
||||
getIndex().openKeyCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count) {
|
||||
count++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
count = 10;
|
||||
cursor.advance(10);
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount, "Saw all data");
|
||||
|
||||
count = 0;
|
||||
|
||||
getObjectStore().openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count == 0) {
|
||||
cursor.advance(dataCount + 1);
|
||||
}
|
||||
else {
|
||||
ok(false, "Should never get here!");
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, 0, "Saw all data");
|
||||
|
||||
count = dataCount - 1;
|
||||
|
||||
getObjectStore().openCursor(null, IDBCursor.PREV).onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
count--;
|
||||
if (count == dataCount - 2) {
|
||||
cursor.advance(10);
|
||||
count -= 9;
|
||||
}
|
||||
else {
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, -1, "Saw all data");
|
||||
|
||||
count = dataCount - 1;
|
||||
|
||||
getObjectStore().openCursor(null, IDBCursor.PREV).onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count == dataCount - 1) {
|
||||
cursor.advance(dataCount + 1);
|
||||
}
|
||||
else {
|
||||
ok(false, "Should never get here!");
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount - 1, "Saw all data");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_advance.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,391 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function genCheck(key, value, test, options) {
|
||||
return function(event) {
|
||||
is(JSON.stringify(event.target.result), JSON.stringify(key),
|
||||
"correct returned key in " + test);
|
||||
if (options && options.store) {
|
||||
is(event.target.source, options.store, "correct store in " + test);
|
||||
}
|
||||
if (options && options.trans) {
|
||||
is(event.target.transaction, options.trans, "correct transaction in " + test);
|
||||
}
|
||||
|
||||
event.target.source.get(key).onsuccess = function(event) {
|
||||
is(JSON.stringify(event.target.result), JSON.stringify(value),
|
||||
"correct stored value in " + test);
|
||||
continueToNextStepSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const dbname = window.location.pathname;
|
||||
const RW = IDBTransaction.READ_WRITE
|
||||
let c1 = 1;
|
||||
let c2 = 1;
|
||||
|
||||
let openRequest = mozIndexedDB.open(dbname, 1);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
let trans = event.target.transaction;
|
||||
|
||||
// Create test stores
|
||||
let store1 = db.createObjectStore("store1", { autoIncrement: true });
|
||||
let store2 = db.createObjectStore("store2", { autoIncrement: true, keyPath: "id" });
|
||||
let store3 = db.createObjectStore("store3", { autoIncrement: false });
|
||||
is(store1.autoIncrement, true, "store1 .autoIncrement");
|
||||
is(store2.autoIncrement, true, "store2 .autoIncrement");
|
||||
is(store3.autoIncrement, false, "store3 .autoIncrement");
|
||||
|
||||
store1.createIndex("unique1", "unique", { unique: true });
|
||||
store2.createIndex("unique1", "unique", { unique: true });
|
||||
|
||||
// Test simple inserts
|
||||
let test = " for test simple insert"
|
||||
store1.add({ foo: "value1" }).onsuccess =
|
||||
genCheck(c1++, { foo: "value1" }, "first" + test);
|
||||
store1.add({ foo: "value2" }).onsuccess =
|
||||
genCheck(c1++, { foo: "value2" }, "second" + test);
|
||||
|
||||
yield;
|
||||
yield;
|
||||
|
||||
store2.put({ bar: "value1" }).onsuccess =
|
||||
genCheck(c2, { bar: "value1", id: c2 }, "first in store2" + test,
|
||||
{ store: store2 });
|
||||
c2++;
|
||||
store1.put({ foo: "value3" }).onsuccess =
|
||||
genCheck(c1++, { foo: "value3" }, "third" + test,
|
||||
{ store: store1 });
|
||||
|
||||
yield;
|
||||
yield;
|
||||
|
||||
store2.get(IDBKeyRange.lowerBound(c2)).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
is(event.target.result, undefined, "no such value" + test);
|
||||
|
||||
// Close version_change transaction
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
is(event.target, openRequest, "succeeded to open" + test);
|
||||
is(event.type, "success", "succeeded to open" + test);
|
||||
|
||||
// Test inserting explicit keys
|
||||
test = " for test explicit keys";
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 1 }, 100).onsuccess =
|
||||
genCheck(100, { explicit: 1 }, "first" + test);
|
||||
c1 = 101;
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 2 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 2 }, "second" + test);
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 3 }, 200).onsuccess =
|
||||
genCheck(200, { explicit: 3 }, "third" + test);
|
||||
c1 = 201;
|
||||
trans.objectStore("store1").add({ explicit: 4 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 4 }, "fourth" + test);
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 5 }, 150).onsuccess =
|
||||
genCheck(150, { explicit: 5 }, "fifth" + test);
|
||||
yield;
|
||||
trans.objectStore("store1").add({ explicit: 6 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 6 }, "sixth" + test);
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 7 }, "key").onsuccess =
|
||||
genCheck("key", { explicit: 7 }, "seventh" + test);
|
||||
yield;
|
||||
trans.objectStore("store1").add({ explicit: 8 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 8 }, "eighth" + test);
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 7 }, [100000]).onsuccess =
|
||||
genCheck([100000], { explicit: 7 }, "seventh" + test);
|
||||
yield;
|
||||
trans.objectStore("store1").add({ explicit: 8 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 8 }, "eighth" + test);
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 9 }, -100000).onsuccess =
|
||||
genCheck(-100000, { explicit: 9 }, "ninth" + test);
|
||||
yield;
|
||||
trans.objectStore("store1").add({ explicit: 10 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 10 }, "tenth" + test);
|
||||
yield;
|
||||
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit2: 1, id: 300 }).onsuccess =
|
||||
genCheck(300, { explicit2: 1, id: 300 }, "first store2" + test);
|
||||
c2 = 301;
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit2: 2 }).onsuccess =
|
||||
genCheck(c2, { explicit2: 2, id: c2 }, "second store2" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit2: 3, id: 400 }).onsuccess =
|
||||
genCheck(400, { explicit2: 3, id: 400 }, "third store2" + test);
|
||||
c2 = 401;
|
||||
trans.objectStore("store2").add({ explicit2: 4 }).onsuccess =
|
||||
genCheck(c2, { explicit2: 4, id: c2 }, "fourth store2" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit: 5, id: 150 }).onsuccess =
|
||||
genCheck(150, { explicit: 5, id: 150 }, "fifth store2" + test);
|
||||
yield;
|
||||
trans.objectStore("store2").add({ explicit: 6 }).onsuccess =
|
||||
genCheck(c2, { explicit: 6, id: c2 }, "sixth store2" + test);
|
||||
c2++;
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit: 7, id: "key" }).onsuccess =
|
||||
genCheck("key", { explicit: 7, id: "key" }, "seventh store2" + test);
|
||||
yield;
|
||||
trans.objectStore("store2").add({ explicit: 8 }).onsuccess =
|
||||
genCheck(c2, { explicit: 8, id: c2 }, "eighth store2" + test);
|
||||
c2++;
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit: 7, id: [100000] }).onsuccess =
|
||||
genCheck([100000], { explicit: 7, id: [100000] }, "seventh store2" + test);
|
||||
yield;
|
||||
trans.objectStore("store2").add({ explicit: 8 }).onsuccess =
|
||||
genCheck(c2, { explicit: 8, id: c2 }, "eighth store2" + test);
|
||||
c2++;
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit: 9, id: -100000 }).onsuccess =
|
||||
genCheck(-100000, { explicit: 9, id: -100000 }, "ninth store2" + test);
|
||||
yield;
|
||||
trans.objectStore("store2").add({ explicit: 10 }).onsuccess =
|
||||
genCheck(c2, { explicit: 10, id: c2 }, "tenth store2" + test);
|
||||
c2++;
|
||||
yield;
|
||||
|
||||
|
||||
// Test separate transactions doesn't generate overlapping numbers
|
||||
test = " for test non-overlapping counts";
|
||||
trans = db.transaction("store1", RW);
|
||||
trans2 = db.transaction("store1", RW);
|
||||
trans2.objectStore("store1").put({ over: 2 }).onsuccess =
|
||||
genCheck(c1 + 1, { over: 2 }, "first" + test,
|
||||
{ trans: trans2 });
|
||||
trans.objectStore("store1").put({ over: 1 }).onsuccess =
|
||||
genCheck(c1, { over: 1 }, "second" + test,
|
||||
{ trans: trans });
|
||||
c1 += 2;
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans2 = db.transaction("store2", RW);
|
||||
trans2.objectStore("store2").put({ over: 2 }).onsuccess =
|
||||
genCheck(c2 + 1, { over: 2, id: c2 + 1 }, "third" + test,
|
||||
{ trans: trans2 });
|
||||
trans.objectStore("store2").put({ over: 1 }).onsuccess =
|
||||
genCheck(c2, { over: 1, id: c2 }, "fourth" + test,
|
||||
{ trans: trans });
|
||||
c2 += 2;
|
||||
yield; yield;
|
||||
|
||||
// Test that error inserts doesn't increase generator
|
||||
test = " for test error inserts";
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ unique: 1 }, -1);
|
||||
trans.objectStore("store2").add({ unique: 1, id: "unique" });
|
||||
|
||||
trans.objectStore("store1").add({ error: 1, unique: 1 }).onerror =
|
||||
new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
trans.objectStore("store1").add({ error: 2 }).onsuccess =
|
||||
genCheck(c1++, { error: 2 }, "first" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store2").add({ error: 3, unique: 1 }).onerror =
|
||||
new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
trans.objectStore("store2").add({ error: 4 }).onsuccess =
|
||||
genCheck(c2, { error: 4, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ error: 5, unique: 1 }, 100000).onerror =
|
||||
new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
trans.objectStore("store1").add({ error: 6 }).onsuccess =
|
||||
genCheck(c1++, { error: 6 }, "third" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store2").add({ error: 7, unique: 1, id: 100000 }).onerror =
|
||||
new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
trans.objectStore("store2").add({ error: 8 }).onsuccess =
|
||||
genCheck(c2, { error: 8, id: c2 }, "fourth" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
// Test that aborts doesn't increase generator
|
||||
test = " for test aborted transaction";
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ abort: 1 }).onsuccess =
|
||||
genCheck(c1, { abort: 1 }, "first" + test);
|
||||
trans.objectStore("store2").put({ abort: 2 }).onsuccess =
|
||||
genCheck(c2, { abort: 2, id: c2 }, "second" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ abort: 3 }, 500).onsuccess =
|
||||
genCheck(500, { abort: 3 }, "third" + test);
|
||||
trans.objectStore("store2").put({ abort: 4, id: 600 }).onsuccess =
|
||||
genCheck(600, { abort: 4, id: 600 }, "fourth" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ abort: 5 }).onsuccess =
|
||||
genCheck(501, { abort: 5 }, "fifth" + test);
|
||||
trans.objectStore("store2").put({ abort: 6 }).onsuccess =
|
||||
genCheck(601, { abort: 6, id: 601 }, "sixth" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.abort();
|
||||
trans.onabort = grabEventAndContinueHandler;
|
||||
event = yield
|
||||
is(event.type, "abort", "transaction aborted");
|
||||
is(event.target, trans, "correct transaction aborted");
|
||||
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ abort: 1 }).onsuccess =
|
||||
genCheck(c1++, { abort: 1 }, "re-first" + test);
|
||||
trans.objectStore("store2").put({ abort: 2 }).onsuccess =
|
||||
genCheck(c2, { abort: 2, id: c2 }, "re-second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
// Test that delete doesn't decrease generator
|
||||
test = " for test delete items"
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ delete: 1 }).onsuccess =
|
||||
genCheck(c1++, { delete: 1 }, "first" + test);
|
||||
trans.objectStore("store2").put({ delete: 2 }).onsuccess =
|
||||
genCheck(c2, { delete: 2, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").delete(c1 - 1).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").delete(c2 - 1).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ delete: 3 }).onsuccess =
|
||||
genCheck(c1++, { delete: 3 }, "first" + test);
|
||||
trans.objectStore("store2").put({ delete: 4 }).onsuccess =
|
||||
genCheck(c2, { delete: 4, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").delete(c1 - 1).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").delete(c2 - 1).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ delete: 5 }).onsuccess =
|
||||
genCheck(c1++, { delete: 5 }, "first" + test);
|
||||
trans.objectStore("store2").put({ delete: 6 }).onsuccess =
|
||||
genCheck(c2, { delete: 6, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
// Test that clears doesn't decrease generator
|
||||
test = " for test clear stores";
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ clear: 1 }).onsuccess =
|
||||
genCheck(c1++, { clear: 1 }, "first" + test);
|
||||
trans.objectStore("store2").put({ clear: 2 }).onsuccess =
|
||||
genCheck(c2, { clear: 2, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ clear: 3 }).onsuccess =
|
||||
genCheck(c1++, { clear: 3 }, "third" + test);
|
||||
trans.objectStore("store2").put({ clear: 4 }).onsuccess =
|
||||
genCheck(c2, { clear: 4, id: c2 }, "forth" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ clear: 5 }).onsuccess =
|
||||
genCheck(c1++, { clear: 5 }, "fifth" + test);
|
||||
trans.objectStore("store2").put({ clear: 6 }).onsuccess =
|
||||
genCheck(c2, { clear: 6, id: c2 }, "sixth" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
|
||||
// Test that close/reopen doesn't decrease generator
|
||||
test = " for test clear stores";
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
db.close();
|
||||
|
||||
SpecialPowers.gc();
|
||||
|
||||
openRequest = mozIndexedDB.open(dbname, 2);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
event = yield;
|
||||
db = event.target.result;
|
||||
trans = event.target.transaction;
|
||||
|
||||
trans.objectStore("store1").add({ reopen: 1 }).onsuccess =
|
||||
genCheck(c1++, { reopen: 1 }, "first" + test);
|
||||
trans.objectStore("store2").put({ reopen: 2 }).onsuccess =
|
||||
genCheck(c2, { reopen: 2, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_autoIncrement.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,57 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = request.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "id",
|
||||
autoIncrement: true });
|
||||
objectStore.createIndex("first","first");
|
||||
objectStore.createIndex("second","second");
|
||||
objectStore.createIndex("third","third");
|
||||
|
||||
let data = { first: "foo", second: "foo", third: "foo" };
|
||||
|
||||
objectStore.add(data).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1, "Added entry");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
|
||||
let objectStore = db.transaction("foo").objectStore("foo");
|
||||
let first = objectStore.index("first");
|
||||
let second = objectStore.index("second");
|
||||
let third = objectStore.index("third");
|
||||
|
||||
first.get("foo").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is (event.target.result.id, 1, "Entry in first");
|
||||
|
||||
second.get("foo").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is (event.target.result.id, 1, "Entry in second");
|
||||
|
||||
third.get("foo").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is (event.target.result.id, 1, "Entry in third");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_autoIncrement_indexes.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,97 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const entryCount = 1000;
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = request.result;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
let firstKey;
|
||||
for (let i = 0; i < entryCount; i++) {
|
||||
request = objectStore.add({});
|
||||
request.onerror = errorHandler;
|
||||
if (!i) {
|
||||
request.onsuccess = function(event) {
|
||||
firstKey = event.target.result;
|
||||
};
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
isnot(firstKey, undefined, "got first key");
|
||||
|
||||
let seenEntryCount = 0;
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
seenEntryCount++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(seenEntryCount, entryCount, "Correct entry count");
|
||||
|
||||
try {
|
||||
db.transaction("foo").objectStore("foo").clear();
|
||||
ok(false, "clear should throw on READ_ONLY transactions");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "clear should throw on READ_ONLY transactions");
|
||||
}
|
||||
|
||||
request = db.transaction("foo", READ_WRITE).objectStore("foo").clear();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.target.result === undefined, "Correct event.target.result");
|
||||
ok(request.result === undefined, "Correct request.result");
|
||||
ok(request === event.target, "Correct event.target");
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
let cursor = request.result;
|
||||
if (cursor) {
|
||||
ok(false, "Shouldn't have any entries");
|
||||
}
|
||||
continueToNextStep();
|
||||
}
|
||||
yield;
|
||||
|
||||
request = db.transaction("foo", READ_WRITE).objectStore("foo").add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
isnot(event.target.result, firstKey, "Got a different key");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_clear.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<!--
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
|
@ -9,355 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const objectStoreName = "People";
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7738", value: { name: "Mel", height: 66, weight: {} } },
|
||||
{ key: "237-23-7739", value: { name: "Tom", height: 62, weight: 130 } }
|
||||
];
|
||||
|
||||
const indexData = {
|
||||
name: "weight",
|
||||
keyPath: "weight",
|
||||
options: { unique: false }
|
||||
};
|
||||
|
||||
const weightSort = [1, 0, 3, 7, 4, 2];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
is(event.type, "upgradeneeded", "Got correct event type");
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName, { });
|
||||
objectStore.createIndex(indexData.name, indexData.keyPath,
|
||||
indexData.options);
|
||||
|
||||
for each (let data in objectStoreData) {
|
||||
objectStore.add(data.value, data.key);
|
||||
}
|
||||
|
||||
event = yield;
|
||||
|
||||
is(event.type, "success", "Got correct event type");
|
||||
|
||||
objectStore = db.transaction(db.objectStoreNames)
|
||||
.objectStore(objectStoreName);
|
||||
|
||||
objectStore.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length,
|
||||
"Correct number of object store entries for all keys");
|
||||
|
||||
objectStore.count(null).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length,
|
||||
"Correct number of object store entries for null key");
|
||||
|
||||
objectStore.count(objectStoreData[2].key).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of object store entries for single existing key");
|
||||
|
||||
objectStore.count("foo").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of object store entries for single non-existing key");
|
||||
|
||||
let keyRange = IDBKeyRange.only(objectStoreData[2].key);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of object store entries for existing only keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.only("foo");
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of object store entries for non-existing only keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[2].key);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 2,
|
||||
"Correct number of object store entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[2].key, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 3,
|
||||
"Correct number of object store entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound("foo");
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of object store entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[2].key, false);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 3,
|
||||
"Correct number of object store entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[2].key, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 2,
|
||||
"Correct number of object store entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound("foo", true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length,
|
||||
"Correct number of object store entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[0].key,
|
||||
objectStoreData[objectStoreData.length - 1].key);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[0].key,
|
||||
objectStoreData[objectStoreData.length - 1].key,
|
||||
true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 1,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[0].key,
|
||||
objectStoreData[objectStoreData.length - 1].key,
|
||||
true, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 2,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound("foo", "foopy", true, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[0].key, "foo", true, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 1,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
let index = objectStore.index(indexData.name);
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for no key");
|
||||
|
||||
index.count(objectStoreData[7].value.weight).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 2,
|
||||
"Correct number of index entries for duplicate key");
|
||||
|
||||
index.count(objectStoreData[0].value.weight).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of index entries for single key");
|
||||
|
||||
keyRange = IDBKeyRange.only(objectStoreData[0].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of index entries for only existing keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.only("foo");
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for only non-existing keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.only(objectStoreData[7].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 2,
|
||||
"Correct number of index entries for only duplicate keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[0]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[1]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[0]].value.weight - 1);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[0]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight + 1,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[0]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[0]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound("foo");
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound("foo", "foopy");
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[weightSort[0]].value.weight,
|
||||
objectStoreData[weightSort[weightSort.length - 1]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[weightSort[0]].value.weight,
|
||||
objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[weightSort[0]].value.weight,
|
||||
objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true, true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 2,
|
||||
"Correct number of index entries for bound keyRange");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_count.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,126 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const nsIIDBTransaction = Components.interfaces.nsIIDBTransaction;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStoreInfo = [
|
||||
{ name: "a", options: { keyPath: "id", autoIncrement: true } },
|
||||
{ name: "b", options: { keyPath: "id", autoIncrement: false } },
|
||||
];
|
||||
const indexInfo = [
|
||||
{ name: "1", keyPath: "unique_value", options: { unique: true } },
|
||||
{ name: "2", keyPath: "value", options: { unique: false } },
|
||||
{ name: "3", keyPath: "value", options: { unique: false } },
|
||||
{ name: "", keyPath: "value", options: { unique: false } },
|
||||
{ name: null, keyPath: "value", options: { unique: false } },
|
||||
{ name: undefined, keyPath: "value", options: { unique: false } },
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
|
||||
for (let i = 0; i < objectStoreInfo.length; i++) {
|
||||
let info = objectStoreInfo[i];
|
||||
let objectStore = info.hasOwnProperty("options") ?
|
||||
db.createObjectStore(info.name, info.options) :
|
||||
db.createObjectStore(info.name);
|
||||
|
||||
try {
|
||||
request = objectStore.createIndex("Hola");
|
||||
ok(false, "createIndex with no keyPath should throw");
|
||||
}
|
||||
catch(e) {
|
||||
ok(true, "createIndex with no keyPath should throw");
|
||||
}
|
||||
|
||||
try {
|
||||
request = objectStore.createIndex("Hola", ["foo"], { multiEntry: true });
|
||||
ok(false, "createIndex with array keyPath and multiEntry should throw");
|
||||
}
|
||||
catch(e) {
|
||||
ok(true, "createIndex with array keyPath and multiEntry should throw");
|
||||
}
|
||||
|
||||
try {
|
||||
request = objectStore.createIndex("Hola", []);
|
||||
ok(false, "createIndex with empty array keyPath should throw");
|
||||
}
|
||||
catch(e) {
|
||||
ok(true, "createIndex with empty array keyPath should throw");
|
||||
}
|
||||
|
||||
try {
|
||||
request = objectStore.createIndex("foo", "bar", 10);
|
||||
ok(false, "createIndex with bad options should throw");
|
||||
}
|
||||
catch(e) {
|
||||
ok(true, "createIndex with bad options threw");
|
||||
}
|
||||
|
||||
ok(objectStore.createIndex("foo", "bar", { foo: "" }),
|
||||
"createIndex with unknown options should not throw");
|
||||
objectStore.deleteIndex("foo");
|
||||
|
||||
// Test index creation, and that it ends up in indexNames.
|
||||
let objectStoreName = info.name;
|
||||
for (let j = 0; j < indexInfo.length; j++) {
|
||||
let info = indexInfo[j];
|
||||
let count = objectStore.indexNames.length;
|
||||
let index = info.hasOwnProperty("options") ?
|
||||
objectStore.createIndex(info.name, info.keyPath,
|
||||
info.options) :
|
||||
objectStore.createIndex(info.name, info.keyPath);
|
||||
|
||||
let name = info.name;
|
||||
if (name === null) {
|
||||
name = "null";
|
||||
}
|
||||
else if (name === undefined) {
|
||||
name = "undefined";
|
||||
}
|
||||
|
||||
is(index.name, name, "correct name");
|
||||
is(index.keyPath, info.keyPath, "correct keyPath");
|
||||
is(index.unique, info.options.unique, "correct uniqueness");
|
||||
|
||||
is(objectStore.indexNames.length, count + 1,
|
||||
"indexNames grew in size");
|
||||
let found = false;
|
||||
for (let k = 0; k < objectStore.indexNames.length; k++) {
|
||||
if (objectStore.indexNames.item(k) == name) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ok(found, "Name is on objectStore.indexNames");
|
||||
|
||||
ok(event.target.transaction, "event has a transaction");
|
||||
ok(event.target.transaction.db === db,
|
||||
"transaction has the right db");
|
||||
is(event.target.transaction.readyState, nsIIDBTransaction.LOADING,
|
||||
"transaction has the correct readyState");
|
||||
is(event.target.transaction.mode, nsIIDBTransaction.VERSION_CHANGE,
|
||||
"transaction has the correct mode");
|
||||
is(event.target.transaction.objectStoreNames.length, i + 1,
|
||||
"transaction only has one object store");
|
||||
is(event.target.transaction.objectStoreNames.item(0), objectStoreName,
|
||||
"transaction has the correct object store");
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_create_index.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,67 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const data = { id: new Date().getTime(),
|
||||
num: parseInt(Math.random() * 1000) };
|
||||
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
// Make object store, add data.
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "id" });
|
||||
objectStore.add(data);
|
||||
yield;
|
||||
db.close();
|
||||
|
||||
let request = mozIndexedDB.open(window.location.pathname, 2);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db2 = event.target.result;
|
||||
db2.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
// Create index.
|
||||
event.target.transaction.objectStore("foo").createIndex("foo", "num");
|
||||
yield;
|
||||
|
||||
// Make sure our object made it into the index.
|
||||
let seenCount = 0;
|
||||
|
||||
|
||||
db2.transaction("foo").objectStore("foo").index("foo")
|
||||
.openKeyCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, data.num, "Good key");
|
||||
is(cursor.primaryKey, data.id, "Good value");
|
||||
seenCount++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(seenCount, 1, "Saw our entry");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_create_index_with_integer_keys.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,116 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const objectStoreData = [
|
||||
// This one will be removed.
|
||||
{ ss: "237-23-7732", name: "Bob" },
|
||||
|
||||
// These will always be included.
|
||||
{ ss: "237-23-7733", name: "Ann" },
|
||||
{ ss: "237-23-7734", name: "Ron" },
|
||||
{ ss: "237-23-7735", name: "Sue" },
|
||||
{ ss: "237-23-7736", name: "Joe" },
|
||||
|
||||
// This one will be added.
|
||||
{ ss: "237-23-7737", name: "Pat" }
|
||||
];
|
||||
|
||||
// Post-add and post-remove data ordered by name.
|
||||
const objectStoreDataNameSort = [ 1, 4, 5, 2, 3 ];
|
||||
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "ss" });
|
||||
objectStore.createIndex("name", "name", { unique: true });
|
||||
|
||||
for (let i = 0; i < objectStoreData.length - 1; i++) {
|
||||
objectStore.add(objectStoreData[i]);
|
||||
}
|
||||
yield;
|
||||
|
||||
let count = 0;
|
||||
|
||||
let sawAdded = false;
|
||||
let sawRemoved = false;
|
||||
|
||||
db.transaction("foo").objectStore("foo").openCursor().onsuccess =
|
||||
function(event) {
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value.name == objectStoreData[0].name) {
|
||||
sawRemoved = true;
|
||||
}
|
||||
if (cursor.value.name ==
|
||||
objectStoreData[objectStoreData.length - 1].name) {
|
||||
sawAdded = true;
|
||||
}
|
||||
cursor.continue();
|
||||
count++;
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, objectStoreData.length - 1, "Good initial count");
|
||||
is(sawAdded, false, "Didn't see item that is about to be added");
|
||||
is(sawRemoved, true, "Saw item that is about to be removed");
|
||||
|
||||
count = 0;
|
||||
sawAdded = false;
|
||||
sawRemoved = false;
|
||||
|
||||
db.transaction("foo", IDBTransaction.READ_WRITE).objectStore("foo")
|
||||
.index("name").openCursor().onsuccess = function(event) {
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value.name == objectStoreData[0].name) {
|
||||
sawRemoved = true;
|
||||
}
|
||||
if (cursor.value.name ==
|
||||
objectStoreData[objectStoreData.length - 1].name) {
|
||||
sawAdded = true;
|
||||
}
|
||||
|
||||
is(cursor.value.name,
|
||||
objectStoreData[objectStoreDataNameSort[count++]].name,
|
||||
"Correct name");
|
||||
|
||||
if (count == 1) {
|
||||
let objectStore = event.target.transaction.objectStore("foo");
|
||||
objectStore.delete(objectStoreData[0].ss)
|
||||
.onsuccess = function(event) {
|
||||
objectStore.add(objectStoreData[objectStoreData.length - 1])
|
||||
.onsuccess =
|
||||
function(event) {
|
||||
cursor.continue();
|
||||
};
|
||||
};
|
||||
}
|
||||
else {
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, objectStoreData.length - 1, "Good final count");
|
||||
is(sawAdded, true, "Saw item that was added");
|
||||
is(sawRemoved, false, "Didn't see item that was removed");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_cursor_mutation.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,98 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const nsIIDBTransaction = Components.interfaces.nsIIDBTransaction;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const START_DATA = "hi";
|
||||
const END_DATA = "bye";
|
||||
const objectStoreInfo = [
|
||||
{ name: "1", options: { keyPath: null }, key: 1,
|
||||
entry: { data: START_DATA } },
|
||||
{ name: "2", options: { keyPath: "foo" },
|
||||
entry: { foo: 1, data: START_DATA } },
|
||||
{ name: "3", options: { keyPath: null, autoIncrement: true },
|
||||
entry: { data: START_DATA } },
|
||||
{ name: "4", options: { keyPath: "foo", autoIncrement: true },
|
||||
entry: { data: START_DATA } },
|
||||
];
|
||||
|
||||
for (let i = 0; i < objectStoreInfo.length; i++) {
|
||||
// Create our object stores.
|
||||
let info = objectStoreInfo[i];
|
||||
|
||||
ok(true, "1");
|
||||
request = mozIndexedDB.open(name, i + 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
ok(true, "2");
|
||||
let objectStore = info.hasOwnProperty("options") ?
|
||||
db.createObjectStore(info.name, info.options) :
|
||||
db.createObjectStore(info.name);
|
||||
|
||||
// Create the indexes on 'data' on the object store.
|
||||
let index = objectStore.createIndex("data_index", "data",
|
||||
{ unique: false });
|
||||
let uniqueIndex = objectStore.createIndex("unique_data_index", "data",
|
||||
{ unique: true });
|
||||
// Populate the object store with one entry of data.
|
||||
request = info.hasOwnProperty("key") ?
|
||||
objectStore.add(info.entry, info.key) :
|
||||
objectStore.add(info.entry);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "3");
|
||||
|
||||
// Use a cursor to update 'data' to END_DATA.
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "4");
|
||||
|
||||
let cursor = request.result;
|
||||
let obj = cursor.value;
|
||||
obj.data = END_DATA;
|
||||
request = cursor.update(obj);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "5");
|
||||
|
||||
// Check both indexes to make sure that they were updated.
|
||||
request = index.get(END_DATA);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "6");
|
||||
SimpleTest.ok(obj.data, event.target.result.data,
|
||||
"Non-unique index was properly updated.");
|
||||
|
||||
request = uniqueIndex.get(END_DATA);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(true, "7");
|
||||
SimpleTest.ok(obj.data, event.target.result.data,
|
||||
"Unique index was properly updated.");
|
||||
db.close();
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_cursor_update_updates_indexes.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,362 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const keys = [1, -1, 0, 10, 2000, "q", "z", "two", "b", "a"];
|
||||
const sortedKeys = [-1, 0, 1, 10, 2000, "a", "b", "q", "two", "z"];
|
||||
|
||||
is(keys.length, sortedKeys.length, "Good key setup");
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("autoIncrement",
|
||||
{ autoIncrement: true });
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
||||
objectStore = db.createObjectStore("autoIncrementKeyPath",
|
||||
{ keyPath: "foo",
|
||||
autoIncrement: true });
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
||||
objectStore = db.createObjectStore("keyPath", { keyPath: "foo" });
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
||||
objectStore = db.createObjectStore("foo");
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
||||
let keyIndex = 0;
|
||||
|
||||
for (let i in keys) {
|
||||
request = objectStore.add("foo", keys[i]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++keyIndex == keys.length) {
|
||||
testGenerator.next();
|
||||
}
|
||||
};
|
||||
}
|
||||
yield;
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
cursor.continue();
|
||||
|
||||
try {
|
||||
cursor.continue();
|
||||
ok(false, "continue twice should throw");
|
||||
}
|
||||
catch (e) {
|
||||
ok(e instanceof IDBDatabaseException, "got a database exception");
|
||||
is(e.code, IDBDatabaseException.NOT_ALLOWED_ERR, "correct code");
|
||||
}
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex++;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all added items");
|
||||
|
||||
keyIndex = 4;
|
||||
|
||||
let range = IDBKeyRange.bound(2000, "q");
|
||||
request = objectStore.openCursor(range);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
cursor.continue();
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex++;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, 8, "Saw all the expected keys");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex) {
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
cursor.continue("b");
|
||||
}
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex += keyIndex ? 1: 6;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex) {
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
cursor.continue(10);
|
||||
}
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex += keyIndex ? 1: 3;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex) {
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
cursor.continue("c");
|
||||
}
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex += keyIndex ? 1 : 7;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex == 4) {
|
||||
request = cursor.update("bar");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
keyIndex++;
|
||||
cursor.continue();
|
||||
};
|
||||
}
|
||||
else {
|
||||
keyIndex++;
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
|
||||
request = objectStore.get(sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, "bar", "Update succeeded");
|
||||
|
||||
request = objectStore.put("foo", sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
let gotRemoveEvent = false;
|
||||
let retval = false;
|
||||
|
||||
request = objectStore.openCursor(null, IDBCursor.NEXT);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex == 4) {
|
||||
request = cursor.delete();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
ok(event.target.result === undefined, "Should be undefined");
|
||||
is(keyIndex, 5, "Got result of remove before next continue");
|
||||
gotRemoveEvent = true;
|
||||
};
|
||||
}
|
||||
|
||||
keyIndex++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
is(gotRemoveEvent, true, "Saw the remove event");
|
||||
|
||||
request = objectStore.get(sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, undefined, "Entry was deleted");
|
||||
|
||||
request = objectStore.add("foo", sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
keyIndex = sortedKeys.length - 1;
|
||||
|
||||
request = objectStore.openCursor(null, IDBCursor.PREV);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
cursor.continue();
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex--;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, -1, "Saw all added items");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_cursors.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,34 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
var request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
var event = yield;
|
||||
|
||||
is(event.target.source, null, "correct event.target.source");
|
||||
|
||||
var db = event.target.result;
|
||||
var objectStore = db.createObjectStore(objectStoreName,
|
||||
{ autoIncrement: true });
|
||||
request = objectStore.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.target.source === objectStore, "correct event.source");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_event_source.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,161 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
const values = [ "a", "1", 1, "foo", 300, true, false, 4.5, null ];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
request = objectStore.getAll();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 0, "No elements");
|
||||
|
||||
let addedCount = 0;
|
||||
|
||||
for (let i in values) {
|
||||
request = objectStore.add(values[i]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedCount == values.length) {
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
yield;
|
||||
yield;
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, values.length, "Same length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[i], "Same value");
|
||||
}
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(null, 5);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 5, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[i], "Same value");
|
||||
}
|
||||
|
||||
let keyRange = IDBKeyRange.bound(1, 9);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, values.length, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[i], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
// Get should take a key range also but it doesn't return an array.
|
||||
request = db.transaction("foo").objectStore("foo").get(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, false, "Not an array object");
|
||||
is(event.target.result, values[3], "Correct value");
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 50);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 0);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 0, "Correct length");
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7, true, true);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 4], "Same value");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_getAll.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,59 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStore = { name: "Objects",
|
||||
options: { keyPath: "id", autoIncrement: true } };
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db1 = event.target.result;
|
||||
|
||||
is(db1.objectStoreNames.length, 0, "No objectStores in db1");
|
||||
|
||||
db1.createObjectStore(objectStore.name, objectStore.options);
|
||||
|
||||
continueToNextStep();
|
||||
yield;
|
||||
|
||||
request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let db2 = event.target.result;
|
||||
|
||||
ok(db1 !== db2, "Databases are not the same object");
|
||||
|
||||
is(db1.objectStoreNames.length, 1, "1 objectStore in db1");
|
||||
is(db1.objectStoreNames.item(0), objectStore.name, "Correct name");
|
||||
|
||||
is(db2.objectStoreNames.length, 1, "1 objectStore in db2");
|
||||
is(db2.objectStoreNames.item(0), objectStore.name, "Correct name");
|
||||
|
||||
let objectStore1 = db1.transaction(objectStore.name)
|
||||
.objectStore(objectStore.name);
|
||||
is(objectStore1.name, objectStore.name, "Same name");
|
||||
is(objectStore1.keyPath, objectStore.options.keyPath, "Same keyPath");
|
||||
|
||||
let objectStore2 = db2.transaction(objectStore.name)
|
||||
.objectStore(objectStore.name);
|
||||
|
||||
ok(objectStore1 !== objectStore2, "Different objectStores");
|
||||
is(objectStore1.name, objectStore2.name, "Same name");
|
||||
is(objectStore1.keyPath, objectStore2.keyPath, "Same keyPath");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_global_data.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,84 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "1", value: "foo" },
|
||||
{ key: "2", value: "bar" },
|
||||
{ key: "3", value: "baz" }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield; // upgradeneeded
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("data", { keyPath: null });
|
||||
|
||||
// First, add all our data to the object store.
|
||||
let addedData = 0;
|
||||
for (let i in objectStoreData) {
|
||||
request = objectStore.add(objectStoreData[i].value,
|
||||
objectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == objectStoreData.length) {
|
||||
testGenerator.send(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
event = yield; // testGenerator.send
|
||||
|
||||
// Now create the index.
|
||||
objectStore.createIndex("set", "", { unique: true });
|
||||
yield; // success
|
||||
|
||||
let trans = db.transaction("data", IDBTransaction.READ_WRITE);
|
||||
objectStore = trans.objectStore("data");
|
||||
index = objectStore.index("set");
|
||||
|
||||
let request = index.get("bar");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
let event = yield;
|
||||
|
||||
is(event.target.result, "bar", "Got correct result");
|
||||
|
||||
let request = objectStore.add("foopy", 4);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
|
||||
let request = index.get("foopy");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
let event = yield;
|
||||
|
||||
is(event.target.result, "foopy", "Got correct result");
|
||||
|
||||
let request = objectStore.add("foopy", 5);
|
||||
request.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
|
||||
trans.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_index_empty_keyPath.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,151 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "People";
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } }
|
||||
];
|
||||
|
||||
const indexData = [
|
||||
{ name: "name", keyPath: "name", options: { unique: true } },
|
||||
{ name: "height", keyPath: "height", options: { unique: false } },
|
||||
{ name: "weight", keyPath: "weight", options: { unique: false } }
|
||||
];
|
||||
|
||||
const objectStoreDataNameSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }
|
||||
];
|
||||
|
||||
const objectStoreDataWeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
const objectStoreDataHeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName);
|
||||
|
||||
// First, add all our data to the object store.
|
||||
let addedData = 0;
|
||||
for (let i in objectStoreData) {
|
||||
request = objectStore.add(objectStoreData[i].value,
|
||||
objectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == objectStoreData.length) {
|
||||
testGenerator.send(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
yield;
|
||||
ok(true, "1");
|
||||
|
||||
// Now create the indexes.
|
||||
for (let i in indexData) {
|
||||
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
|
||||
indexData[i].options);
|
||||
}
|
||||
|
||||
is(objectStore.indexNames.length, indexData.length, "Good index count");
|
||||
yield;
|
||||
|
||||
ok(true, "2");
|
||||
objectStore = db.transaction(objectStoreName)
|
||||
.objectStore(objectStoreName);
|
||||
|
||||
request = objectStore.index("height").getAllKeys(65);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "3");
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
||||
"Correct key");
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAllKeys();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "4");
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, objectStoreDataHeightSort.length,
|
||||
"Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAllKeys(null, 4);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(true, "5");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAllKeys(65, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(true, "6");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 1, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
||||
"Correct key");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_index_getAll.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,175 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "People";
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } }
|
||||
];
|
||||
|
||||
const indexData = [
|
||||
{ name: "name", keyPath: "name", options: { unique: true } },
|
||||
{ name: "height", keyPath: "height", options: { unique: false } },
|
||||
{ name: "weight", keyPath: "weight", options: { unique: false } }
|
||||
];
|
||||
|
||||
const objectStoreDataNameSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }
|
||||
];
|
||||
|
||||
const objectStoreDataWeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
const objectStoreDataHeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName, {});
|
||||
|
||||
// First, add all our data to the object store.
|
||||
let addedData = 0;
|
||||
for (let i in objectStoreData) {
|
||||
request = objectStore.add(objectStoreData[i].value,
|
||||
objectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == objectStoreData.length) {
|
||||
testGenerator.send(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
event = yield;
|
||||
|
||||
// Now create the indexes.
|
||||
for (let i in indexData) {
|
||||
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
|
||||
indexData[i].options);
|
||||
}
|
||||
|
||||
is(objectStore.indexNames.length, indexData.length, "Good index count");
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction(objectStoreName)
|
||||
.objectStore(objectStoreName);
|
||||
|
||||
request = objectStore.index("height").getAll(65);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
is(result.height, testObj.height, "Correct height");
|
||||
|
||||
if (testObj.hasOwnProperty("weight")) {
|
||||
is(result.weight, testObj.weight, "Correct weight");
|
||||
}
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAll();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, objectStoreDataHeightSort.length,
|
||||
"Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[i].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
is(result.height, testObj.height, "Correct height");
|
||||
|
||||
if (testObj.hasOwnProperty("weight")) {
|
||||
is(result.weight, testObj.weight, "Correct weight");
|
||||
}
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAll(null, 4);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[i].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
is(result.height, testObj.height, "Correct height");
|
||||
|
||||
if (testObj.hasOwnProperty("weight")) {
|
||||
is(result.weight, testObj.weight, "Correct weight");
|
||||
}
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAll(65, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 1, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
is(result.height, testObj.height, "Correct height");
|
||||
|
||||
if (testObj.hasOwnProperty("weight")) {
|
||||
is(result.weight, testObj.weight, "Correct weight");
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_index_getAllObjects.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,146 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const objectStoreData = [
|
||||
{ name: "", options: { keyPath: "id", autoIncrement: true } },
|
||||
{ name: null, options: { keyPath: "ss" } },
|
||||
{ name: undefined, options: { } },
|
||||
{ name: "4", options: { autoIncrement: true } },
|
||||
];
|
||||
|
||||
const indexData = [
|
||||
{ name: "", keyPath: "name", options: { unique: true } },
|
||||
{ name: null, keyPath: "height", options: { } }
|
||||
];
|
||||
|
||||
const data = [
|
||||
{ ss: "237-23-7732", name: "Ann", height: 60 },
|
||||
{ ss: "237-23-7733", name: "Bob", height: 65 }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
for (let objectStoreIndex in objectStoreData) {
|
||||
const objectStoreInfo = objectStoreData[objectStoreIndex];
|
||||
let objectStore = db.createObjectStore(objectStoreInfo.name,
|
||||
objectStoreInfo.options);
|
||||
for (let indexIndex in indexData) {
|
||||
const indexInfo = indexData[indexIndex];
|
||||
let index = objectStore.createIndex(indexInfo.name,
|
||||
indexInfo.keyPath,
|
||||
indexInfo.options);
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
ok(true, "Initial setup");
|
||||
|
||||
for (let objectStoreIndex in objectStoreData) {
|
||||
const info = objectStoreData[objectStoreIndex];
|
||||
|
||||
for (let indexIndex in indexData) {
|
||||
const objectStoreName = objectStoreData[objectStoreIndex].name;
|
||||
const indexName = indexData[indexIndex].name;
|
||||
|
||||
let objectStore =
|
||||
db.transaction(objectStoreName, IDBTransaction.READ_WRITE)
|
||||
.objectStore(objectStoreName);
|
||||
ok(true, "Got objectStore " + objectStoreName);
|
||||
|
||||
for (let dataIndex in data) {
|
||||
const obj = data[dataIndex];
|
||||
let key;
|
||||
if (!info.options.keyPath && !info.options.autoIncrement) {
|
||||
key = obj.ss;
|
||||
}
|
||||
objectStore.add(obj, key);
|
||||
}
|
||||
|
||||
let index = objectStore.index(indexName);
|
||||
ok(true, "Got index " + indexName);
|
||||
|
||||
let keyIndex = 0;
|
||||
|
||||
index.openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (!cursor) {
|
||||
continueToNextStep();
|
||||
return;
|
||||
}
|
||||
|
||||
is(cursor.key, data[keyIndex][indexData[indexIndex].keyPath],
|
||||
"Good key");
|
||||
is(cursor.value.ss, data[keyIndex].ss, "Correct ss");
|
||||
is(cursor.value.name, data[keyIndex].name, "Correct name");
|
||||
is(cursor.value.height, data[keyIndex].height, "Correct height");
|
||||
|
||||
if (!keyIndex) {
|
||||
let obj = cursor.value;
|
||||
obj.updated = true;
|
||||
|
||||
cursor.update(obj).onsuccess = function(event) {
|
||||
ok(true, "Object updated");
|
||||
cursor.continue();
|
||||
keyIndex++
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cursor.delete().onsuccess = function(event) {
|
||||
ok(true, "Object deleted");
|
||||
cursor.continue();
|
||||
keyIndex++
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(keyIndex, 2, "Saw all the items");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
db.transaction(objectStoreName).objectStore(objectStoreName)
|
||||
.openCursor()
|
||||
.onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (!cursor) {
|
||||
continueToNextStep();
|
||||
return;
|
||||
}
|
||||
|
||||
is(cursor.value.ss, data[keyIndex].ss, "Correct ss");
|
||||
is(cursor.value.name, data[keyIndex].name, "Correct name");
|
||||
is(cursor.value.height, data[keyIndex].height, "Correct height");
|
||||
is(cursor.value.updated, true, "Correct updated flag");
|
||||
|
||||
cursor.continue();
|
||||
keyIndex++;
|
||||
};
|
||||
yield;
|
||||
|
||||
is(keyIndex, 1, "Saw all the items");
|
||||
|
||||
db.transaction(objectStoreName, IDBTransaction.READ_WRITE)
|
||||
.objectStore(objectStoreName).clear()
|
||||
.onsuccess = continueToNextStep();
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_index_object_cursors.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,168 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
for each (let autoIncrement in [false, true]) {
|
||||
let objectStore =
|
||||
db.createObjectStore(autoIncrement, { keyPath: "id",
|
||||
autoIncrement: autoIncrement });
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
objectStore.add({ id: i, index: i });
|
||||
}
|
||||
|
||||
for each (let unique in [false, true]) {
|
||||
objectStore.createIndex(unique, "index", { unique: unique });
|
||||
}
|
||||
|
||||
for (let i = 10; i < 20; i++) {
|
||||
objectStore.add({ id: i, index: i });
|
||||
}
|
||||
}
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
|
||||
for each (let autoIncrement in [false, true]) {
|
||||
let objectStore = db.transaction(autoIncrement)
|
||||
.objectStore(autoIncrement);
|
||||
|
||||
objectStore.count().onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
is(event.target.result, 20, "Correct number of entries in objectStore");
|
||||
|
||||
let objectStoreCount = event.target.result;
|
||||
let indexCount = event.target.result;
|
||||
|
||||
for each (let unique in [false, true]) {
|
||||
let index = db.transaction(autoIncrement, IDBTransaction.READ_WRITE)
|
||||
.objectStore(autoIncrement)
|
||||
.index(unique);
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
is(event.target.result, indexCount,
|
||||
"Correct number of entries in index");
|
||||
|
||||
let modifiedEntry = unique ? 5 : 10;
|
||||
let keyRange = IDBKeyRange.only(modifiedEntry);
|
||||
|
||||
let sawEntry = false;
|
||||
index.openCursor(keyRange).onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
sawEntry = true;
|
||||
is(cursor.key, modifiedEntry, "Correct key");
|
||||
|
||||
cursor.value.index = unique ? 30 : 35;
|
||||
cursor.update(cursor.value).onsuccess = function(event) {
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(sawEntry, true, "Saw entry for key value " + modifiedEntry);
|
||||
|
||||
// Recount index. Shouldn't change.
|
||||
index = db.transaction(autoIncrement, IDBTransaction.READ_WRITE)
|
||||
.objectStore(autoIncrement)
|
||||
.index(unique);
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, indexCount,
|
||||
"Correct number of entries in index");
|
||||
|
||||
modifiedEntry = unique ? 30 : 35;
|
||||
keyRange = IDBKeyRange.only(modifiedEntry);
|
||||
|
||||
sawEntry = false;
|
||||
index.openCursor(keyRange).onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
sawEntry = true;
|
||||
is(cursor.key, modifiedEntry, "Correct key");
|
||||
|
||||
delete cursor.value.index;
|
||||
cursor.update(cursor.value).onsuccess = function(event) {
|
||||
indexCount--;
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(sawEntry, true, "Saw entry for key value " + modifiedEntry);
|
||||
|
||||
// Recount objectStore. Should be unchanged.
|
||||
objectStore = db.transaction(autoIncrement, IDBTransaction.READ_WRITE)
|
||||
.objectStore(autoIncrement);
|
||||
|
||||
objectStore.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreCount,
|
||||
"Correct number of entries in objectStore");
|
||||
|
||||
// Recount index. Should be one item less.
|
||||
index = objectStore.index(unique);
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, indexCount,
|
||||
"Correct number of entries in index");
|
||||
|
||||
modifiedEntry = objectStoreCount - 1;
|
||||
|
||||
objectStore.delete(modifiedEntry).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
objectStoreCount--;
|
||||
indexCount--;
|
||||
|
||||
objectStore.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreCount,
|
||||
"Correct number of entries in objectStore");
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, indexCount,
|
||||
"Correct number of entries in index");
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_index_update_delete.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -9,136 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const CONSTRAINT_ERR =
|
||||
Components.interfaces.nsIIDBDatabaseException.CONSTRAINT_ERR;
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
const objectStoreName = "People";
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7738", value: { name: "Mel", height: 66, weight: {} } }
|
||||
];
|
||||
|
||||
const badObjectStoreData = [
|
||||
{ key: "237-23-7739", value: { name: "Rob", height: 65 } },
|
||||
{ key: "237-23-7740", value: { name: "Jen", height: 66, weight: {} } }
|
||||
];
|
||||
|
||||
const indexData = [
|
||||
{ name: "weight", keyPath: "weight", options: { unique: false } }
|
||||
];
|
||||
|
||||
const objectStoreDataWeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName, { } );
|
||||
|
||||
let addedData = 0;
|
||||
for (let i in objectStoreData) {
|
||||
request = objectStore.add(objectStoreData[i].value,
|
||||
objectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == objectStoreData.length) {
|
||||
testGenerator.send(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
event = yield;
|
||||
|
||||
for (let i in indexData) {
|
||||
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
|
||||
indexData[i].options);
|
||||
}
|
||||
|
||||
addedData = 0;
|
||||
for (let i in badObjectStoreData) {
|
||||
request = objectStore.add(badObjectStoreData[i].value,
|
||||
badObjectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == badObjectStoreData.length) {
|
||||
SimpleTest.executeSoon(function() { testGenerator.next() });
|
||||
}
|
||||
}
|
||||
}
|
||||
yield;
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction(objectStoreName)
|
||||
.objectStore(objectStoreName);
|
||||
|
||||
let keyIndex = 0;
|
||||
|
||||
request = objectStore.index("weight").openKeyCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
|
||||
"Correct key");
|
||||
is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key,
|
||||
"Correct value");
|
||||
keyIndex++;
|
||||
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, objectStoreDataWeightSort.length, "Saw all weights");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
keyIndex++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, objectStoreData.length + badObjectStoreData.length,
|
||||
"Saw all people");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_indexes_bad_values.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,283 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.addEventListener("error", function(event) {
|
||||
event.preventDefault();
|
||||
}, false);
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
request = objectStore.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let key1 = event.target.result;
|
||||
|
||||
request = objectStore.put({}, key1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "put gave the same key back");
|
||||
|
||||
let key2 = 10;
|
||||
|
||||
request = objectStore.put({}, key2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key2, "put gave the same key back");
|
||||
|
||||
key2 = 100;
|
||||
|
||||
request = objectStore.add({}, key2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key2, "put gave the same key back");
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(true, "put with no key should not throw with autoIncrement!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(false, "put with no key threw with autoIncrement");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(true, "put with no key should not throw with autoIncrement!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(false, "put with no key threw with autoIncrement");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete();
|
||||
ok(false, "remove with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with no key threw");
|
||||
}
|
||||
|
||||
objectStore = db.createObjectStore("bar");
|
||||
|
||||
try {
|
||||
objectStore.add({});
|
||||
ok(false, "add with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(false, "put with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(false, "put with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete();
|
||||
ok(false, "remove with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with no key threw");
|
||||
}
|
||||
|
||||
objectStore = db.createObjectStore("baz", { keyPath: "id" });
|
||||
|
||||
try {
|
||||
objectStore.add({});
|
||||
ok(false, "add with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.add({id:5}, 5);
|
||||
ok(false, "add with inline key and passed key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with inline key and passed key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(false, "put with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(false, "put with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete();
|
||||
ok(false, "remove with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with no key threw");
|
||||
}
|
||||
|
||||
key1 = 10;
|
||||
|
||||
request = objectStore.add({id:key1});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "add gave back the same key");
|
||||
|
||||
request = objectStore.put({id:10});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "put gave back the same key");
|
||||
|
||||
request = objectStore.put({id:10});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "put gave back the same key");
|
||||
|
||||
request = objectStore.add({id:10});
|
||||
request.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
event = yield;
|
||||
|
||||
try {
|
||||
objectStore.add({}, null);
|
||||
ok(false, "add with null key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with null key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({}, null);
|
||||
ok(false, "put with null key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with null key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({}, null);
|
||||
ok(false, "put with null key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with null key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete({}, null);
|
||||
ok(false, "remove with null key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with null key threw");
|
||||
}
|
||||
|
||||
objectStore = db.createObjectStore("bazing", { keyPath: "id",
|
||||
autoIncrement: true });
|
||||
|
||||
request = objectStore.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
key1 = event.target.result;
|
||||
|
||||
request = objectStore.put({id:key1});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "put gave the same key back");
|
||||
|
||||
key2 = 10;
|
||||
|
||||
request = objectStore.put({id:key2});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key2, "put gave the same key back");
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(true, "put with no key should not throw with autoIncrement!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(false, "put with no key threw with autoIncrement");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(true, "put with no key should not throw with autoIncrement!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(false, "put with no key threw with autoIncrement");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete();
|
||||
ok(false, "remove with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.add({id:5}, 5);
|
||||
ok(false, "add with inline key and passed key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with inline key and passed key threw");
|
||||
}
|
||||
|
||||
request = objectStore.delete(key2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_key_requirements.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,265 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const dbname = window.location.pathname;
|
||||
const RW = IDBTransaction.READ_WRITE
|
||||
let c1 = 1;
|
||||
let c2 = 1;
|
||||
|
||||
let openRequest = mozIndexedDB.open(dbname, 1);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
let trans = event.target.transaction;
|
||||
|
||||
// Create test stores
|
||||
let store = db.createObjectStore("store");
|
||||
|
||||
// Test simple inserts
|
||||
var keys = [
|
||||
-1/0,
|
||||
-1.7e308,
|
||||
-10000,
|
||||
-2,
|
||||
-1.5,
|
||||
-1,
|
||||
-1.00001e-200,
|
||||
-1e-200,
|
||||
0,
|
||||
1e-200,
|
||||
1.00001e-200,
|
||||
1,
|
||||
2,
|
||||
10000,
|
||||
1.7e308,
|
||||
1/0,
|
||||
new Date("1750-01-02"),
|
||||
new Date("1800-12-31T12:34:56.001"),
|
||||
new Date(-1000),
|
||||
new Date(-10),
|
||||
new Date(-1),
|
||||
new Date(0),
|
||||
new Date(1),
|
||||
new Date(2),
|
||||
new Date(1000),
|
||||
new Date("1971-01-01"),
|
||||
new Date("1971-01-01T01:01:01"),
|
||||
new Date("1971-01-01T01:01:01.001"),
|
||||
new Date("1971-01-01T01:01:01.01"),
|
||||
new Date("1971-01-01T01:01:01.1"),
|
||||
new Date("1980-02-02"),
|
||||
new Date("3333-03-19T03:33:33.333"),
|
||||
"",
|
||||
"\x00",
|
||||
"\x00\x00",
|
||||
"\x00\x01",
|
||||
"\x01",
|
||||
"\x02",
|
||||
"\x03",
|
||||
"\x04",
|
||||
"\x07",
|
||||
"\x08",
|
||||
"\x0F",
|
||||
"\x10",
|
||||
"\x1F",
|
||||
"\x20",
|
||||
"01234",
|
||||
"\x3F",
|
||||
"\x40",
|
||||
"A",
|
||||
"A\x00",
|
||||
"A1",
|
||||
"ZZZZ",
|
||||
"a",
|
||||
"a\x00",
|
||||
"aa",
|
||||
"azz",
|
||||
"}",
|
||||
"\x7E",
|
||||
"\x7F",
|
||||
"\x80",
|
||||
"\xFF",
|
||||
"\u0100",
|
||||
"\u01FF",
|
||||
"\u0200",
|
||||
"\u03FF",
|
||||
"\u0400",
|
||||
"\u07FF",
|
||||
"\u0800",
|
||||
"\u0FFF",
|
||||
"\u1000",
|
||||
"\u1FFF",
|
||||
"\u2000",
|
||||
"\u3FFF",
|
||||
"\u4000",
|
||||
"\u7FFF",
|
||||
"\u8000",
|
||||
"\uD800",
|
||||
"\uD800a",
|
||||
"\uD800\uDC01",
|
||||
"\uDBFF",
|
||||
"\uDC00",
|
||||
"\uDFFF\uD800",
|
||||
"\uFFFE",
|
||||
"\uFFFF",
|
||||
"\uFFFF\x00",
|
||||
"\uFFFFZZZ",
|
||||
[],
|
||||
[-1/0],
|
||||
[-1],
|
||||
[0],
|
||||
[1],
|
||||
[1, "a"],
|
||||
[1, []],
|
||||
[1, [""]],
|
||||
[2, 3],
|
||||
[2, 3.0000000000001],
|
||||
[12, [[]]],
|
||||
[12, [[[]]]],
|
||||
[12, [[[""]]]],
|
||||
[12, [[["foo"]]]],
|
||||
[12, [[[[[3]]]]]],
|
||||
[12, [[[[[[3]]]]]]],
|
||||
[new Date(-1)],
|
||||
[new Date(1)],
|
||||
[""],
|
||||
["", [[]]],
|
||||
["", [[[]]]],
|
||||
["abc"],
|
||||
["abc", "def"],
|
||||
["abc\x00"],
|
||||
["abc\x00", "\x00\x01"],
|
||||
["abc\x00", "\x00def"],
|
||||
["abc\x00\x00def"],
|
||||
["x", [[]]],
|
||||
["x", [[[]]]],
|
||||
[[]],
|
||||
[[],"foo"],
|
||||
[[],[]],
|
||||
[[[]]],
|
||||
[[[]], []],
|
||||
[[[]], [[]]],
|
||||
[[[]], [[1]]],
|
||||
[[[]], [[[]]]],
|
||||
[[[1]]],
|
||||
[[[[]], []]],
|
||||
];
|
||||
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
let keyI = keys[i];
|
||||
is(mozIndexedDB.cmp(keyI, keyI), 0, i + " compared to self");
|
||||
|
||||
function doCompare(keyI) {
|
||||
for (var j = i-1; j >= i-10 && j >= 0; --j) {
|
||||
is(mozIndexedDB.cmp(keyI, keys[j]), 1, i + " compared to " + j);
|
||||
is(mozIndexedDB.cmp(keys[j], keyI), -1, j + " compared to " + i);
|
||||
}
|
||||
}
|
||||
|
||||
doCompare(keyI);
|
||||
store.add(i, keyI).onsuccess = function(e) {
|
||||
is(mozIndexedDB.cmp(e.target.result, keyI), 0,
|
||||
"Returned key should cmp as equal");
|
||||
ok(compareKeys(e.target.result, keyI),
|
||||
"Returned key should actually be equal");
|
||||
};
|
||||
|
||||
// Test that -0 compares the same as 0
|
||||
if (keyI === 0) {
|
||||
doCompare(-0);
|
||||
let req = store.add(i, -0);
|
||||
req.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
req.onsuccess = unexpectedSuccessHandler;
|
||||
yield;
|
||||
}
|
||||
else if (Array.isArray(keyI) && keyI.length === 1 && keyI[0] === 0) {
|
||||
doCompare([-0]);
|
||||
let req = store.add(i, [-0]);
|
||||
req.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
req.onsuccess = unexpectedSuccessHandler;
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
store.openCursor().onsuccess = grabEventAndContinueHandler;
|
||||
for (i = 0; i < keys.length; ++i) {
|
||||
event = yield;
|
||||
let cursor = event.target.result;
|
||||
is(mozIndexedDB.cmp(cursor.key, keys[i]), 0,
|
||||
"Read back key should cmp as equal");
|
||||
ok(compareKeys(cursor.key, keys[i]),
|
||||
"Read back key should actually be equal");
|
||||
is(cursor.value, i, "Stored with right value");
|
||||
|
||||
cursor.continue();
|
||||
}
|
||||
event = yield;
|
||||
is(event.target.result, undefined, "no more results expected");
|
||||
|
||||
var nan = 0/0;
|
||||
var invalidKeys = [
|
||||
nan,
|
||||
undefined,
|
||||
null,
|
||||
/x/,
|
||||
{},
|
||||
[nan],
|
||||
[undefined],
|
||||
[null],
|
||||
[/x/],
|
||||
[{}],
|
||||
[1, nan],
|
||||
[1, undefined],
|
||||
[1, null],
|
||||
[1, /x/],
|
||||
[1, {}],
|
||||
[1, [nan]],
|
||||
[1, [undefined]],
|
||||
[1, [null]],
|
||||
[1, [/x/]],
|
||||
[1, [{}]],
|
||||
];
|
||||
|
||||
for (i = 0; i < invalidKeys.length; ++i) {
|
||||
try {
|
||||
mozIndexedDB.cmp(invalidKeys[i], 1);
|
||||
ok(false, "didn't throw");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Threw IDBDatabaseException");
|
||||
is(ex.code, IDBDatabaseException.DATA_ERR, "Threw right IDBDatabaseException");
|
||||
}
|
||||
try {
|
||||
mozIndexedDB.cmp(1, invalidKeys[i]);
|
||||
ok(false, "didn't throw2");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Threw IDBDatabaseException2");
|
||||
is(ex.code, IDBDatabaseException.DATA_ERR, "Threw right IDBDatabaseException2");
|
||||
}
|
||||
try {
|
||||
store.put(1, invalidKeys[i]);
|
||||
ok(false, "didn't throw3");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Threw IDBDatabaseException3");
|
||||
is(ex.code, IDBDatabaseException.DATA_ERR, "Threw right IDBDatabaseException3");
|
||||
}
|
||||
}
|
||||
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_keys.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,219 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
// Test object stores
|
||||
|
||||
let openRequest = mozIndexedDB.open(window.location.pathname, 1);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
let tests =
|
||||
[{ add: { x: 1, id: 1 },
|
||||
indexes:[{ v: 1, k: 1 }] },
|
||||
{ add: { x: [2, 3], id: 2 },
|
||||
indexes:[{ v: 1, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 }] },
|
||||
{ put: { x: [2, 4], id: 1 },
|
||||
indexes:[{ v: 2, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 },
|
||||
{ v: 4, k: 1 }] },
|
||||
{ add: { x: [5, 6, 5, -2, 3], id: 3 },
|
||||
indexes:[{ v:-2, k: 3 },
|
||||
{ v: 2, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 },
|
||||
{ v: 3, k: 3 },
|
||||
{ v: 4, k: 1 },
|
||||
{ v: 5, k: 3 },
|
||||
{ v: 6, k: 3 }] },
|
||||
{ delete: IDBKeyRange.bound(1, 3),
|
||||
indexes:[] },
|
||||
{ put: { x: ["food", {}, false, undefined, /x/, [73, false]], id: 2 },
|
||||
indexes:[{ v: "food", k: 2 }] },
|
||||
{ add: { x: [{}, /x/, -12, "food", null, [false], undefined], id: 3 },
|
||||
indexes:[{ v: -12, k: 3 },
|
||||
{ v: "food", k: 2 },
|
||||
{ v: "food", k: 3 }] },
|
||||
{ put: { x: [], id: 2 },
|
||||
indexes:[{ v: -12, k: 3 },
|
||||
{ v: "food", k: 3 }] },
|
||||
{ put: { x: { y: 3 }, id: 3 },
|
||||
indexes:[] },
|
||||
{ add: { x: false, id: 7 },
|
||||
indexes:[] },
|
||||
{ delete: IDBKeyRange.lowerBound(0),
|
||||
indexes:[] },
|
||||
];
|
||||
|
||||
let store = db.createObjectStore("mystore", { keyPath: "id" });
|
||||
let index = store.createIndex("myindex", "x", { multiEntry: true });
|
||||
is(index.multiEntry, true, "index created with multiEntry");
|
||||
|
||||
let i;
|
||||
for (i = 0; i < tests.length; ++i) {
|
||||
let test = tests[i];
|
||||
let testName = " for " + JSON.stringify(test);
|
||||
let req;
|
||||
if (test.add) {
|
||||
req = store.add(test.add);
|
||||
}
|
||||
else if (test.put) {
|
||||
req = store.put(test.put);
|
||||
}
|
||||
else if (test.delete) {
|
||||
req = store.delete(test.delete);
|
||||
}
|
||||
else {
|
||||
ok(false, "borked test");
|
||||
}
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
let e = yield;
|
||||
|
||||
req = index.openKeyCursor();
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
for (let j = 0; j < test.indexes.length; ++j) {
|
||||
e = yield;
|
||||
is(req.result.key, test.indexes[j].v, "found expected index key at index " + j + testName);
|
||||
is(req.result.primaryKey, test.indexes[j].k, "found expected index primary key at index " + j + testName);
|
||||
req.result.continue();
|
||||
}
|
||||
e = yield;
|
||||
is(req.result, undefined, "exhausted indexes");
|
||||
|
||||
let tempIndex = store.createIndex("temp index", "x", { multiEntry: true });
|
||||
req = tempIndex.openKeyCursor();
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
for (let j = 0; j < test.indexes.length; ++j) {
|
||||
e = yield;
|
||||
is(req.result.key, test.indexes[j].v, "found expected temp index key at index " + j + testName);
|
||||
is(req.result.primaryKey, test.indexes[j].k, "found expected temp index primary key at index " + j + testName);
|
||||
req.result.continue();
|
||||
}
|
||||
e = yield;
|
||||
is(req.result, undefined, "exhausted temp index");
|
||||
store.deleteIndex("temp index");
|
||||
}
|
||||
|
||||
// Unique indexes
|
||||
tests =
|
||||
[{ add: { x: 1, id: 1 },
|
||||
indexes:[{ v: 1, k: 1 }] },
|
||||
{ add: { x: [2, 3], id: 2 },
|
||||
indexes:[{ v: 1, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 }] },
|
||||
{ put: { x: [2, 4], id: 3 },
|
||||
fail: true },
|
||||
{ put: { x: [1, 4], id: 1 },
|
||||
indexes:[{ v: 1, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 },
|
||||
{ v: 4, k: 1 }] },
|
||||
{ add: { x: [5, 0, 5, 5, 5], id: 3 },
|
||||
indexes:[{ v: 0, k: 3 },
|
||||
{ v: 1, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 },
|
||||
{ v: 4, k: 1 },
|
||||
{ v: 5, k: 3 }] },
|
||||
{ delete: IDBKeyRange.bound(1, 2),
|
||||
indexes:[{ v: 0, k: 3 },
|
||||
{ v: 5, k: 3 }] },
|
||||
{ add: { x: [0, 6], id: 8 },
|
||||
fail: true },
|
||||
{ add: { x: 5, id: 8 },
|
||||
fail: true },
|
||||
{ put: { x: 0, id: 8 },
|
||||
fail: true },
|
||||
];
|
||||
|
||||
store.deleteIndex("myindex");
|
||||
index = store.createIndex("myindex", "x", { multiEntry: true, unique: true });
|
||||
is(index.multiEntry, true, "index created with multiEntry");
|
||||
|
||||
let i;
|
||||
let indexes;
|
||||
for (i = 0; i < tests.length; ++i) {
|
||||
let test = tests[i];
|
||||
let testName = " for " + JSON.stringify(test);
|
||||
let req;
|
||||
if (test.add) {
|
||||
req = store.add(test.add);
|
||||
}
|
||||
else if (test.put) {
|
||||
req = store.put(test.put);
|
||||
}
|
||||
else if (test.delete) {
|
||||
req = store.delete(test.delete);
|
||||
}
|
||||
else {
|
||||
ok(false, "borked test");
|
||||
}
|
||||
|
||||
if (!test.fail) {
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
let e = yield;
|
||||
indexes = test.indexes;
|
||||
}
|
||||
else {
|
||||
req.onsuccess = unexpectedSuccessHandler;
|
||||
req.onerror = grabEventAndContinueHandler;
|
||||
ok(true, "waiting for error");
|
||||
let e = yield;
|
||||
ok(true, "got error: " + e.type);
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
let e;
|
||||
req = index.openKeyCursor();
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
for (let j = 0; j < indexes.length; ++j) {
|
||||
e = yield;
|
||||
is(req.result.key, indexes[j].v, "found expected index key at index " + j + testName);
|
||||
is(req.result.primaryKey, indexes[j].k, "found expected index primary key at index " + j + testName);
|
||||
req.result.continue();
|
||||
}
|
||||
e = yield;
|
||||
is(req.result, undefined, "exhausted indexes");
|
||||
|
||||
let tempIndex = store.createIndex("temp index", "x", { multiEntry: true, unique: true });
|
||||
req = tempIndex.openKeyCursor();
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
for (let j = 0; j < indexes.length; ++j) {
|
||||
e = yield;
|
||||
is(req.result.key, indexes[j].v, "found expected temp index key at index " + j + testName);
|
||||
is(req.result.primaryKey, indexes[j].k, "found expected temp index primary key at index " + j + testName);
|
||||
req.result.continue();
|
||||
}
|
||||
e = yield;
|
||||
is(req.result, undefined, "exhausted temp index");
|
||||
store.deleteIndex("temp index");
|
||||
}
|
||||
|
||||
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
let trans = db.transaction(["mystore"], IDBTransaction.READ_WRITE);
|
||||
store = trans.objectStore("mystore");
|
||||
index = store.index("myindex");
|
||||
is(index.multiEntry, true, "index still is multiEntry");
|
||||
trans.oncomplete = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_multientry.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,84 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
const objectStores = [
|
||||
{ name: "a", autoIncrement: false },
|
||||
{ name: "b", autoIncrement: true }
|
||||
];
|
||||
|
||||
const indexes = [
|
||||
{ name: "a", options: { } },
|
||||
{ name: "b", options: { unique: true } }
|
||||
];
|
||||
|
||||
var j = 0;
|
||||
for (let i in objectStores) {
|
||||
let request = mozIndexedDB.open(name, ++j, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore =
|
||||
db.createObjectStore(objectStores[i].name,
|
||||
{ keyPath: "id",
|
||||
autoIncrement: objectStores[i].autoIncrement });
|
||||
|
||||
for (let j in indexes) {
|
||||
objectStore.createIndex(indexes[j].name, "name", indexes[j].options);
|
||||
}
|
||||
|
||||
let data = { name: "Ben" };
|
||||
if (!objectStores[i].autoIncrement) {
|
||||
data.id = 1;
|
||||
}
|
||||
|
||||
request = objectStore.add(data);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.target.result == 1 || event.target.result == 2, "Good id");
|
||||
db.close();
|
||||
}
|
||||
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
|
||||
let request = mozIndexedDB.open(name, j, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
for (let i in objectStores) {
|
||||
for (let j in indexes) {
|
||||
let objectStore = db.transaction(objectStores[i].name)
|
||||
.objectStore(objectStores[i].name);
|
||||
let index = objectStore.index(indexes[j].name);
|
||||
|
||||
request = index.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
is(event.target.result.value.name, "Ben", "Good object");
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
}
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_objectCursors.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,56 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const IDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const IDBDatabaseException = Components.interfaces.nsIIDBDatabaseException;
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
var request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
var event = yield;
|
||||
|
||||
var db = event.target.result;
|
||||
|
||||
var test = {
|
||||
name: "inline key; key generator",
|
||||
autoIncrement: true,
|
||||
storedObject: {name: "Lincoln"},
|
||||
keyName: "id",
|
||||
};
|
||||
|
||||
let objectStore = db.createObjectStore(test.name,
|
||||
{ keyPath: test.keyName,
|
||||
autoIncrement: test.autoIncrement });
|
||||
|
||||
request = objectStore.add(test.storedObject);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let id = event.target.result;
|
||||
request = objectStore.get(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
// Sanity check!
|
||||
is(event.target.result.name, test.storedObject.name,
|
||||
"The correct object was stored.");
|
||||
|
||||
// Ensure that the id was also stored on the object.
|
||||
is(event.target.result.id, id, "The object had the id stored on it.");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_objectStore_inline_autoincrement_key_added_on_put.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,91 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const IDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const IDBDatabaseException = Components.interfaces.nsIIDBDatabaseException;
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
var data = [
|
||||
{ name: "inline key; key generator",
|
||||
autoIncrement: true,
|
||||
storedObject: {name: "Lincoln"},
|
||||
keyName: "id",
|
||||
keyValue: undefined,
|
||||
},
|
||||
{ name: "inline key; no key generator",
|
||||
autoIncrement: false,
|
||||
storedObject: {id: 1, name: "Lincoln"},
|
||||
keyName: "id",
|
||||
keyValue: undefined,
|
||||
},
|
||||
{ name: "out of line key; key generator",
|
||||
autoIncrement: true,
|
||||
storedObject: {name: "Lincoln"},
|
||||
keyName: undefined,
|
||||
keyValue: undefined,
|
||||
},
|
||||
{ name: "out of line key; no key generator",
|
||||
autoIncrement: false,
|
||||
storedObject: {name: "Lincoln"},
|
||||
keyName: null,
|
||||
keyValue: 1,
|
||||
}
|
||||
];
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let test = data[i];
|
||||
|
||||
let request = mozIndexedDB.open(name, i+1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(test.name,
|
||||
{ keyPath: test.keyName,
|
||||
autoIncrement: test.autoIncrement });
|
||||
|
||||
request = objectStore.add(test.storedObject, test.keyValue);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let id = event.target.result;
|
||||
request = objectStore.get(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
// Sanity check!
|
||||
is(test.storedObject.name, event.target.result.name,
|
||||
"The correct object was stored.");
|
||||
|
||||
request = objectStore.delete(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
// Make sure it was removed.
|
||||
request = objectStore.get(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.target.result === undefined, "Object was deleted");
|
||||
db.close();
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_objectStore_remove_values.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,48 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
let transaction = event.target.transaction;
|
||||
|
||||
let objectStore1 = db.createObjectStore("foo");
|
||||
let objectStore2 = transaction.objectStore("foo");
|
||||
ok(objectStore1 === objectStore2, "Got same objectStores");
|
||||
|
||||
let index1 = objectStore1.createIndex("bar", "key");
|
||||
let index2 = objectStore2.index("bar");
|
||||
ok(index1 === index2, "Got same indexes");
|
||||
|
||||
request.onsuccess = continueToNextStep;
|
||||
yield;
|
||||
|
||||
transaction = db.transaction(db.objectStoreNames);
|
||||
|
||||
let objectStore3 = transaction.objectStore("foo");
|
||||
let objectStore4 = transaction.objectStore("foo");
|
||||
ok(objectStore3 === objectStore4, "Got same objectStores");
|
||||
|
||||
ok(objectStore3 !== objectStore1, "Different objectStores");
|
||||
ok(objectStore4 !== objectStore2, "Different objectStores");
|
||||
|
||||
let index3 = objectStore3.index("bar");
|
||||
let index4 = objectStore4.index("bar");
|
||||
ok(index3 === index4, "Got same indexes");
|
||||
|
||||
ok(index3 !== index1, "Different indexes");
|
||||
ok(index4 !== index2, "Different indexes");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_object_identity.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,77 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const data = { key: 5, index: 10 };
|
||||
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
ok(db instanceof IDBDatabase, "Got a real database");
|
||||
|
||||
db.onerror = errorHandler;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "key",
|
||||
autoIncrement: true });
|
||||
let index = objectStore.createIndex("foo", "index");
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction("foo", IDBTransaction.READ_WRITE)
|
||||
.objectStore("foo");
|
||||
request = objectStore.add(data);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let key;
|
||||
setTimeout(function() {
|
||||
key = request.result;
|
||||
continueToNextStep();
|
||||
}, 0);
|
||||
yield;
|
||||
|
||||
is(key, data.key, "Got the right key");
|
||||
|
||||
objectStore = db.transaction("foo").objectStore("foo");
|
||||
objectStore.get(data.key).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let obj;
|
||||
setTimeout(function() {
|
||||
obj = event.target.result;
|
||||
continueToNextStep();
|
||||
}, 0);
|
||||
yield;
|
||||
|
||||
is(obj.key, data.key, "Got the right key");
|
||||
is(obj.index, data.index, "Got the right property value");
|
||||
|
||||
objectStore = db.transaction("foo", IDBTransaction.READ_WRITE)
|
||||
.objectStore("foo");
|
||||
request = objectStore.delete(data.key);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
key = undefined;
|
||||
setTimeout(function() {
|
||||
key = request.result;
|
||||
continueToNextStep();
|
||||
}, 0);
|
||||
yield;
|
||||
|
||||
ok(key === undefined, "Got the right value");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_odd_result_order.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,46 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const names = [
|
||||
"",
|
||||
null,
|
||||
undefined,
|
||||
window.location.pathname
|
||||
];
|
||||
|
||||
const version = 1;
|
||||
|
||||
for each (let name in names) {
|
||||
let request = mozIndexedDB.open(name, version);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
if (name === null) {
|
||||
name = "null";
|
||||
}
|
||||
else if (name === undefined) {
|
||||
name = "undefined";
|
||||
}
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.name, name, "Bad name");
|
||||
is(db.version, version, "Bad version");
|
||||
is(db.objectStoreNames.length, 0, "Bad objectStores list");
|
||||
|
||||
is(db.name, request.result.name, "Bad name");
|
||||
is(db.version, request.result.version, "Bad version");
|
||||
is(db.objectStoreNames.length, request.result.objectStoreNames.length,
|
||||
"Bad objectStores list");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_open_empty_db.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,41 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Bad objectStores list");
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName,
|
||||
{ keyPath: "foo" });
|
||||
|
||||
is(db.objectStoreNames.length, 1, "Bad objectStores list");
|
||||
is(db.objectStoreNames.item(0), objectStoreName, "Bad name");
|
||||
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction(objectStoreName).objectStore(objectStoreName);
|
||||
|
||||
is(objectStore.name, objectStoreName, "Bad name");
|
||||
is(objectStore.keyPath, "foo", "Bad keyPath");
|
||||
if(objectStore.indexNames.length, 0, "Bad indexNames");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_open_objectStore.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -9,91 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStores = [ "foo", "bar" ];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
event.target.onsuccess = grabEventAndContinueHandler;
|
||||
for (let i in objectStores) {
|
||||
db.createObjectStore(objectStores[i], { autoIncrement: true });
|
||||
}
|
||||
let event = yield;
|
||||
|
||||
is(db.objectStoreNames.length, objectStores.length,
|
||||
"Correct objectStoreNames list");
|
||||
|
||||
for (let i = 0; i < 50; i++) {
|
||||
let stepNumber = 0;
|
||||
|
||||
request = db.transaction(["foo"], READ_WRITE)
|
||||
.objectStore("foo")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 1, "This callback came first");
|
||||
stepNumber++;
|
||||
}
|
||||
|
||||
request = db.transaction(["foo"], READ_WRITE)
|
||||
.objectStore("foo")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 2, "This callback came second");
|
||||
stepNumber++;
|
||||
}
|
||||
|
||||
request = db.transaction(["foo", "bar"], READ_WRITE)
|
||||
.objectStore("bar")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 3, "This callback came third");
|
||||
stepNumber++;
|
||||
}
|
||||
|
||||
request = db.transaction(["foo", "bar"], READ_WRITE)
|
||||
.objectStore("bar")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 4, "This callback came fourth");
|
||||
stepNumber++;
|
||||
}
|
||||
|
||||
request = db.transaction(["bar"], READ_WRITE)
|
||||
.objectStore("bar")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 5, "This callback came fifth");
|
||||
stepNumber++;
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
}
|
||||
|
||||
stepNumber++;
|
||||
yield;
|
||||
|
||||
is(stepNumber, 6, "All callbacks received");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_overlapping_transactions.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,52 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
let testString = { key: 0, value: "testString" };
|
||||
let testInt = { key: 1, value: 1002 };
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName,
|
||||
{ autoIncrement: 0 });
|
||||
|
||||
request = objectStore.add(testString.value, testString.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testString.key, "Got the right key");
|
||||
request = objectStore.get(testString.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testString.value, "Got the right value");
|
||||
};
|
||||
};
|
||||
|
||||
request = objectStore.add(testInt.value, testInt.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testInt.key, "Got the right key");
|
||||
request = objectStore.get(testInt.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testInt.value, "Got the right value");
|
||||
finishTest();
|
||||
};
|
||||
}
|
||||
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_put_get_values.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,52 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
let testString = { value: "testString" };
|
||||
let testInt = { value: 1002 };
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName,
|
||||
{ autoIncrement: 1 });
|
||||
|
||||
request = objectStore.put(testString.value);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
testString.key = event.target.result;
|
||||
request = objectStore.get(testString.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testString.value, "Got the right value");
|
||||
};
|
||||
};
|
||||
|
||||
request = objectStore.put(testInt.value);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
testInt.key = event.target.result;
|
||||
request = objectStore.get(testInt.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testInt.value, "Got the right value");
|
||||
finishTest();
|
||||
};
|
||||
}
|
||||
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_put_get_values_autoIncrement.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,58 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const indexName = "My Test Index";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
let objectStore = db.createObjectStore("test store", { keyPath: "foo" });
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
|
||||
is(db.objectStoreNames.item(0), objectStore.name, "Correct name");
|
||||
|
||||
is(objectStore.indexNames.length, 0, "Correct indexNames list");
|
||||
|
||||
let index = objectStore.createIndex(indexName, "foo");
|
||||
|
||||
is(objectStore.indexNames.length, 1, "Correct indexNames list");
|
||||
is(objectStore.indexNames.item(0), indexName, "Correct name");
|
||||
is(objectStore.index(indexName), index, "Correct instance");
|
||||
|
||||
objectStore.deleteIndex(indexName);
|
||||
|
||||
is(objectStore.indexNames.length, 0, "Correct indexNames list");
|
||||
try {
|
||||
objectStore.index(indexName);
|
||||
ok(false, "should have thrown");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Got a IDBDatabaseException");
|
||||
is(ex.code, IDBDatabaseException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR");
|
||||
}
|
||||
|
||||
let index2 = objectStore.createIndex(indexName, "foo");
|
||||
isnot(index, index2, "New instance should be created");
|
||||
|
||||
is(objectStore.indexNames.length, 1, "Correct recreacted indexNames list");
|
||||
is(objectStore.indexNames.item(0), indexName, "Correct recreacted name");
|
||||
is(objectStore.index(indexName), index2, "Correct instance");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_remove_index.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,110 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const UNKNOWN_ERR =
|
||||
Components.interfaces.nsIIDBDatabaseException.UNKNOWN_ERR;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName,
|
||||
{ keyPath: "foo" });
|
||||
|
||||
let addedCount = 0;
|
||||
|
||||
for (let i = 0; i < 100; i++) {
|
||||
request = objectStore.add({foo: i});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedCount == 100) {
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
|
||||
is(db.objectStoreNames.item(0), objectStoreName, "Correct name");
|
||||
|
||||
db.close();
|
||||
|
||||
let request = mozIndexedDB.open(name, 2, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
let trans = event.target.transaction;
|
||||
|
||||
let oldObjectStore = trans.objectStore(objectStoreName);
|
||||
isnot(oldObjectStore, null, "Correct object store prior to deleting");
|
||||
db.deleteObjectStore(objectStoreName);
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStores list");
|
||||
try {
|
||||
trans.objectStore(objectStoreName);
|
||||
ok(false, "should have thrown");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Got a IDBDatabaseException");
|
||||
is(ex.code, IDBDatabaseException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR");
|
||||
}
|
||||
|
||||
objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
|
||||
is(db.objectStoreNames.item(0), objectStoreName, "Correct name");
|
||||
is(trans.objectStore(objectStoreName), objectStore, "Correct new objectStore");
|
||||
isnot(oldObjectStore, objectStore, "Old objectStore is not new objectStore");
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, undefined, "ObjectStore shouldn't have any items");
|
||||
testGenerator.send(event);
|
||||
}
|
||||
event = yield;
|
||||
|
||||
db.deleteObjectStore(objectStore.name);
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStores list");
|
||||
|
||||
continueToNextStep();
|
||||
yield;
|
||||
|
||||
db.close();
|
||||
|
||||
let request = mozIndexedDB.open(name, 3, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
|
||||
|
||||
request = objectStore.add({foo:"bar"});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
db.deleteObjectStore(objectStoreName);
|
||||
|
||||
event = yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_remove_objectStore.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,52 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
const LOADING = Components.interfaces.nsIIDBRequest.LOADING;
|
||||
const DONE = Components.interfaces.nsIIDBRequest.DONE;
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
is(request.readyState, LOADING, "Correct readyState");
|
||||
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
is(request.readyState, DONE, "Correct readyState");
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("foo");
|
||||
let key = 10;
|
||||
|
||||
request = objectStore.add({}, key);
|
||||
is(request.readyState, LOADING, "Correct readyState");
|
||||
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(request.readyState, DONE, "Correct readyState");
|
||||
is(event.target.result, key, "Correct key");
|
||||
|
||||
request = objectStore.get(key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
is(request.readyState, LOADING, "Correct readyState");
|
||||
event = yield;
|
||||
|
||||
ok(event.target.result, "Got something");
|
||||
is(request.readyState, DONE, "Correct readyState");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_request_readyState.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,55 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
const VERSION_CHANGE = Components.interfaces.nsIIDBTransaction.VERSION_CHANGE;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
// Check default state.
|
||||
is(db.version, 1, "Correct default version for a new database.");
|
||||
|
||||
const versions = [
|
||||
7,
|
||||
42,
|
||||
];
|
||||
|
||||
db.close();
|
||||
|
||||
for (let i = 0; i < versions.length; i++) {
|
||||
let version = versions[i];
|
||||
|
||||
let request = mozIndexedDB.open(name, version, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
is(db.version, version, "Database version number updated correctly");
|
||||
is(event.target.transaction.mode, VERSION_CHANGE, "Correct mode");
|
||||
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
db.close();
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_setVersion.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,66 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
const VERSION_CHANGE = Components.interfaces.nsIIDBTransaction.VERSION_CHANGE;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = grabEventAndContinueHandler;
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("foo");
|
||||
let index = objectStore.createIndex("bar", "baz");
|
||||
|
||||
is(db.version, 1, "Correct version");
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
|
||||
is(objectStore.indexNames.length, 1, "Correct indexNames length");
|
||||
|
||||
let transaction = event.target.transaction;
|
||||
transaction.oncomplete = unexpectedSuccessHandler;
|
||||
transaction.onabort = grabEventAndContinueHandler;
|
||||
transaction.abort();
|
||||
|
||||
event = yield;
|
||||
is(event.type, "abort", "Got transaction abort event");
|
||||
is(event.target, transaction, "Right target");
|
||||
|
||||
is(db.version, 1, "Correct version");
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
|
||||
|
||||
event = yield;
|
||||
is(event.type, "error", "Got request error event");
|
||||
is(event.target, request, "Right target");
|
||||
|
||||
request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = grabEventAndContinueHandler;
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db2 = event.target.result;
|
||||
|
||||
isnot(db, db2, "Should give a different db instance");
|
||||
is(db2.version, 1, "Correct version");
|
||||
is(db2.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
||||
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_setVersion_abort.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,149 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
// Open a datbase for the first time.
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
|
||||
// Sanity checks
|
||||
ok(request instanceof IDBRequest, "Request should be an IDBRequest");
|
||||
ok(request instanceof IDBOpenDBRequest, "Request should be an IDBOpenDBRequest");
|
||||
ok(request instanceof EventTarget, "Request should be an EventTarget");
|
||||
is(request.source, null, "Request should have no source");
|
||||
try {
|
||||
request.result;
|
||||
ok(false, "Getter should have thrown!");
|
||||
} catch (e if e.result == 0x80660006 /* NS_ERROR_DOM_INDEXEDDB_NOTALLOWED_ERR */) {
|
||||
ok(true, "Getter threw the right exception");
|
||||
}
|
||||
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let versionChangeEventCount = 0;
|
||||
let db1, db2, db3;
|
||||
|
||||
db1 = event.target.result;
|
||||
db1.addEventListener("versionchange", function(event) {
|
||||
ok(true, "Got version change event");
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
is(event.target.source, null, "Correct source");
|
||||
is(event.target, db1, "Correct target");
|
||||
is(event.target.version, 1, "Correct db version");
|
||||
is(event.oldVersion, 1, "Correct event oldVersion");
|
||||
is(event.newVersion, 2, "Correct event newVersion");
|
||||
is(versionChangeEventCount++, 0, "Correct count");
|
||||
db1.close();
|
||||
}, false);
|
||||
|
||||
// Open the database again and trigger an upgrade that should succeed
|
||||
request = mozIndexedDB.open(name, 2, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onblocked = errorHandler;
|
||||
event = yield;
|
||||
|
||||
// Test the upgradeneeded event.
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
ok(event.target.result instanceof IDBDatabase, "Good result");
|
||||
db2 = event.target.result;
|
||||
is(event.target.transaction.mode, IDBTransaction.VERSION_CHANGE,
|
||||
"Correct mode");
|
||||
is(db2.version, 2, "Correct db version");
|
||||
is(event.oldVersion, 1, "Correct event oldVersion");
|
||||
is(event.newVersion, 2, "Correct event newVersion");
|
||||
|
||||
request.onupgradeneeded = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
db2.addEventListener("versionchange", function(event) {
|
||||
ok(true, "Got version change event");
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
is(event.target.source, null, "Correct source");
|
||||
is(event.target, db2, "Correct target");
|
||||
is(event.target.version, 2, "Correct db version");
|
||||
is(event.oldVersion, 2, "Correct event oldVersion");
|
||||
is(event.newVersion, 3, "Correct event newVersion");
|
||||
is(versionChangeEventCount++, 1, "Correct count");
|
||||
}, false);
|
||||
|
||||
// Test opening the existing version again
|
||||
request = mozIndexedDB.open(name, 2, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
request.onblocked = errorHandler;
|
||||
event = yield;
|
||||
|
||||
db3 = event.target.result;
|
||||
|
||||
// Test an upgrade that should fail
|
||||
request = mozIndexedDB.open(name, 3, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = errorHandler;
|
||||
request.onupgradeneeded = errorHandler;
|
||||
request.onblocked = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
ok(true, "Got version change blocked event");
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
is(event.target.source, null, "Correct source");
|
||||
is(event.target.transaction, null, "Correct transaction");
|
||||
is(event.target, request, "Correct target");
|
||||
is(db3.version, 2, "Correct db version");
|
||||
is(event.oldVersion, 2, "Correct event oldVersion");
|
||||
is(event.newVersion, 3, "Correct event newVersion");
|
||||
versionChangeEventCount++;
|
||||
db2.close();
|
||||
db3.close();
|
||||
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
event = yield;
|
||||
|
||||
db3 = event.target.result;
|
||||
db3.close();
|
||||
|
||||
// Test another upgrade that should succeed.
|
||||
request = mozIndexedDB.open(name, 4);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onblocked = errorHandler;
|
||||
|
||||
event = yield;
|
||||
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
ok(event.target.result instanceof IDBDatabase, "Good result");
|
||||
is(event.target.transaction.mode, IDBTransaction.VERSION_CHANGE,
|
||||
"Correct mode");
|
||||
is(event.oldVersion, 3, "Correct event oldVersion");
|
||||
is(event.newVersion, 4, "Correct event newVersion");
|
||||
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
ok(event.target.result instanceof IDBDatabase, "Expect a database here");
|
||||
is(event.target.result.version, 4, "Right version");
|
||||
is(db3.version, 3, "After closing the version should not change!");
|
||||
is(db2.version, 2, "After closing the version should not change!");
|
||||
is(db1.version, 1, "After closing the version should not change!");
|
||||
|
||||
is(versionChangeEventCount, 3, "Saw all expected events");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_setVersion_events.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,81 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
|
||||
let request = mozIndexedDB.open(name, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
|
||||
let request2 = mozIndexedDB.open(name, 2);
|
||||
request2.onerror = errorHandler;
|
||||
request2.onupgradeneeded = unexpectedSuccessHandler;
|
||||
|
||||
let event = yield;
|
||||
is(event.type, "upgradeneeded", "Expect an upgradeneeded event");
|
||||
is(event.target, request, "Event should be fired on the request");
|
||||
ok(event.target.result instanceof IDBDatabase, "Expect a database here");
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.version, 1, "Database has correct version");
|
||||
|
||||
db.onupgradeneeded = function() {
|
||||
ok(false, "our ongoing VERSION_CHANGE transaction should exclude any others!");
|
||||
}
|
||||
|
||||
db.createObjectStore("foo");
|
||||
|
||||
try {
|
||||
db.transaction("foo");
|
||||
ok(false, "Transactions should be disallowed now!");
|
||||
} catch (e) {
|
||||
ok(e instanceof IDBDatabaseException, "Expect an IDBException");
|
||||
is(e.code, IDBDatabaseException.NOT_ALLOWED_ERR, "Expect a NOT_ALLOWED_ERR");
|
||||
}
|
||||
|
||||
request.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
|
||||
// The database is still not fully open here.
|
||||
try {
|
||||
db.transaction("foo");
|
||||
ok(false, "Transactions should be disallowed now!");
|
||||
} catch (e) {
|
||||
ok(e instanceof IDBDatabaseException, "Expect an IDBException");
|
||||
is(e.code, IDBDatabaseException.NOT_ALLOWED_ERR, "Expect a NOT_ALLOWED_ERR");
|
||||
}
|
||||
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
|
||||
db.onversionchange = function() {
|
||||
ok(true, "next setVersion was unblocked appropriately");
|
||||
db.close();
|
||||
}
|
||||
|
||||
try {
|
||||
db.transaction("foo");
|
||||
ok(true, "Transactions should be allowed now!");
|
||||
} catch (e) {
|
||||
ok(false, "Transactions should be allowed now!");
|
||||
}
|
||||
|
||||
request2.onupgradeneeded = null;
|
||||
request2.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_setVersion_exclusion.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,59 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("foo");
|
||||
objectStore.add({}, 1).onerror = errorHandler;
|
||||
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction("foo").objectStore("foo");
|
||||
|
||||
let transaction = objectStore.transaction;
|
||||
transaction.oncomplete = unexpectedSuccessHandler;
|
||||
transaction.onabort = grabEventAndContinueHandler;
|
||||
|
||||
let sawError = false;
|
||||
|
||||
request = objectStore.get(1);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onerror = function(event) {
|
||||
is(event.target.errorCode, IDBDatabaseException.ABORT_ERR, "Good code");
|
||||
sawError = true;
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
transaction.abort();
|
||||
|
||||
event = yield;
|
||||
|
||||
is(event.type, "abort", "Got abort event");
|
||||
is(sawError, true, "Saw get() error");
|
||||
|
||||
// Make sure the success event isn't queued somehow.
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var thread = Components.classes["@mozilla.org/thread-manager;1"]
|
||||
.getService(Components.interfaces.nsIThreadManager)
|
||||
.currentThread;
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(false);
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_success_events_after_abort.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,87 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const name = window.location.pathname;
|
||||
|
||||
let requests = [];
|
||||
function doOpen(version, errorCallback, upgradeNeededCallback, successCallback) {
|
||||
let request = mozIndexedDB.open(name, version);
|
||||
request.onerror = errorCallback;
|
||||
request.onupgradeneeded = upgradeNeededCallback;
|
||||
request.onsuccess = successCallback;
|
||||
requests.push(request);
|
||||
}
|
||||
|
||||
doOpen(1, errorHandler, grabEventAndContinueHandler, grabEventAndContinueHandler);
|
||||
doOpen(2, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
|
||||
|
||||
let event = yield;
|
||||
is(event.type, "upgradeneeded", "expect an upgradeneeded event");
|
||||
is(event.target, requests[0], "fired at the right request");
|
||||
|
||||
let db = event.target.result;
|
||||
db.createObjectStore("foo");
|
||||
|
||||
doOpen(3, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
|
||||
doOpen(2, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
|
||||
doOpen(3, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
|
||||
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "complete", "expect a complete event");
|
||||
is(event.target, requests[0].transaction, "expect it to be fired at the transaction");
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
is(event.target, requests[0], "fired at the right request");
|
||||
event.target.result.close();
|
||||
|
||||
requests[1].onupgradeneeded = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "upgradeneeded", "expect an upgradeneeded event");
|
||||
is(event.target, requests[1], "fired at the right request");
|
||||
|
||||
requests[1].onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
is(event.target, requests[1], "fired at the right request");
|
||||
event.target.result.close();
|
||||
|
||||
requests[2].onupgradeneeded = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "upgradeneeded", "expect an upgradeneeded event");
|
||||
is(event.target, requests[2], "fired at the right request");
|
||||
|
||||
requests[2].onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
is(event.target, requests[2], "fired at the right request");
|
||||
event.target.result.close();
|
||||
|
||||
requests[3].onerror = new ExpectError(IDBDatabaseException.VERSION_ERR);
|
||||
|
||||
event = yield;
|
||||
|
||||
requests[4].onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
is(event.target, requests[4], "fired at the right request");
|
||||
event.target.result.close();
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_traffic_jam.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,406 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
var abortFired = false;
|
||||
|
||||
function abortListener() { abortFired = true; }
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
const INITIAL = Ci.nsIIDBTransaction.INITIAL;
|
||||
const LOADING = Ci.nsIIDBTransaction.LOADING;
|
||||
const COMMITTING = Ci.nsIIDBTransaction.COMMITTING;
|
||||
const DONE = Ci.nsIIDBTransaction.DONE;
|
||||
const READ_ONLY = Ci.nsIIDBTransaction.READ_ONLY;
|
||||
const READ_WRITE = Ci.nsIIDBTransaction.READ_WRITE;
|
||||
const VERSION_CHANGE = Ci.nsIIDBTransaction.VERSION_CHANGE;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onabort = abortListener;
|
||||
|
||||
let transaction;
|
||||
let objectStore;
|
||||
let index;
|
||||
|
||||
transaction = event.target.transaction;
|
||||
objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
index = objectStore.createIndex("fooindex", "indexKey", { unique: true });
|
||||
|
||||
is(transaction.db, db, "Correct database");
|
||||
is(transaction.readyState, LOADING, "Correct readyState");
|
||||
is(transaction.mode, VERSION_CHANGE, "Correct mode");
|
||||
is(transaction.objectStoreNames.length, 1, "Correct names length");
|
||||
is(transaction.objectStoreNames.item(0), "foo", "Correct name");
|
||||
is(transaction.objectStore("foo"), objectStore, "Can get stores");
|
||||
is(transaction.oncomplete, null, "No complete listener");
|
||||
is(transaction.onabort, null, "No abort listener");
|
||||
|
||||
is(objectStore.name, "foo", "Correct name");
|
||||
is(objectStore.keyPath, null, "Correct keyPath");
|
||||
|
||||
is(objectStore.indexNames.length, 1, "Correct indexNames length");
|
||||
is(objectStore.indexNames[0], "fooindex", "Correct indexNames name");
|
||||
is(objectStore.index("fooindex"), index, "Can get index");
|
||||
|
||||
// Wait until it's complete!
|
||||
transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(transaction.db, db, "Correct database");
|
||||
is(transaction.readyState, DONE, "Correct readyState");
|
||||
is(transaction.mode, VERSION_CHANGE, "Correct mode");
|
||||
is(transaction.objectStoreNames.length, 1, "Correct names length");
|
||||
is(transaction.objectStoreNames.item(0), "foo", "Correct name");
|
||||
is(transaction.onabort, null, "No abort listener");
|
||||
|
||||
try {
|
||||
is(transaction.objectStore("foo").name, "foo", "Can't get stores");
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Out of scope transaction can't make stores");
|
||||
}
|
||||
|
||||
is(objectStore.name, "foo", "Correct name");
|
||||
is(objectStore.keyPath, null, "Correct keyPath");
|
||||
|
||||
is(objectStore.indexNames.length, 1, "Correct indexNames length");
|
||||
is(objectStore.indexNames[0], "fooindex", "Correct indexNames name");
|
||||
|
||||
try {
|
||||
objectStore.add({});
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Add threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({}, 1);
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Put threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({}, 1);
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Put threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete(1);
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Remove threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.get(1);
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Get threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.getAll(null);
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "GetAll threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.openCursor();
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "OpenCursor threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.createIndex("bar", "id");
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "CreateIndex threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.index("bar");
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Index threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.deleteIndex("bar");
|
||||
ok(false, "Should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "RemoveIndex threw");
|
||||
}
|
||||
|
||||
yield;
|
||||
|
||||
request = db.transaction("foo", READ_WRITE).objectStore("foo").add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
event.target.transaction.onabort = function(event) {
|
||||
ok(false, "Shouldn't see an abort event!");
|
||||
};
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.type, "complete", "Right kind of event");
|
||||
|
||||
let key;
|
||||
|
||||
request = db.transaction("foo", READ_WRITE).objectStore("foo").add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
key = event.target.result;
|
||||
|
||||
event.target.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.target.transaction.oncomplete = function(event) {
|
||||
ok(false, "Shouldn't see a complete event here!");
|
||||
};
|
||||
|
||||
is(event.target.transaction.readyState, LOADING, "Correct readyState");
|
||||
event.target.transaction.abort();
|
||||
is(event.target.transaction.readyState, DONE, "Correct readyState");
|
||||
|
||||
event = yield;
|
||||
|
||||
is(event.type, "abort", "Right kind of event");
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").get(key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, undefined, "Object was removed");
|
||||
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
|
||||
let keys = [];
|
||||
let abortEventCount = 0;
|
||||
function abortErrorHandler(event) {
|
||||
is(event.target.errorCode, IDBDatabaseException.ABORT_ERR,
|
||||
"Good code");
|
||||
abortEventCount++;
|
||||
event.preventDefault();
|
||||
};
|
||||
objectStore = db.transaction("foo", READ_WRITE).objectStore("foo");
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
request = objectStore.add({});
|
||||
request.onerror = abortErrorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
keys.push(event.target.result);
|
||||
if (keys.length == 5) {
|
||||
event.target.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.target.transaction.abort();
|
||||
}
|
||||
};
|
||||
}
|
||||
event = yield;
|
||||
|
||||
is(event.type, "abort", "Got abort event");
|
||||
is(keys.length, 5, "Added 5 items in this transaction");
|
||||
is(abortEventCount, 5, "Got 5 abort error events");
|
||||
|
||||
for (let i in keys) {
|
||||
request = db.transaction("foo").objectStore("foo").get(keys[i]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, undefined, "Object was removed by abort");
|
||||
}
|
||||
|
||||
// Set up some predictible data
|
||||
transaction = db.transaction("foo", READ_WRITE);
|
||||
objectStore = transaction.objectStore("foo");
|
||||
objectStore.clear();
|
||||
objectStore.add({}, 1);
|
||||
objectStore.add({}, 2);
|
||||
request = objectStore.add({}, 1);
|
||||
request.onsuccess = function() {
|
||||
ok(false, "inserting duplicate key should fail");
|
||||
}
|
||||
request.onerror = function(event) {
|
||||
ok(true, "inserting duplicate key should fail");
|
||||
event.preventDefault();
|
||||
}
|
||||
transaction.oncomplete = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
// Check when aborting is allowed
|
||||
abortEventCount = 0;
|
||||
let expectedAbortEventCount = 0;
|
||||
|
||||
// During INITIAL
|
||||
transaction = db.transaction("foo");
|
||||
is(transaction.readyState, INITIAL, "in INITIAL state");
|
||||
transaction.abort();
|
||||
is(transaction.readyState, DONE, "in DONE state after abort()");
|
||||
try {
|
||||
transaction.abort();
|
||||
ok(false, "second abort should throw an error");
|
||||
}
|
||||
catch (ex) {
|
||||
ok(true, "second abort should throw an error");
|
||||
}
|
||||
|
||||
// During LOADING
|
||||
transaction = db.transaction("foo");
|
||||
transaction.objectStore("foo").get(1).onerror = abortErrorHandler;
|
||||
expectedAbortEventCount++;
|
||||
is(transaction.readyState, LOADING, "in LOADING state");
|
||||
transaction.abort();
|
||||
is(transaction.readyState, DONE, "in DONE state after abort()");
|
||||
try {
|
||||
transaction.abort();
|
||||
ok(false, "second abort should throw an error");
|
||||
}
|
||||
catch (ex) {
|
||||
ok(true, "second abort should throw an error");
|
||||
}
|
||||
|
||||
// During LOADING from callback
|
||||
transaction = db.transaction("foo");
|
||||
transaction.objectStore("foo").get(1).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
transaction.objectStore("foo").get(1).onerror = abortErrorHandler;
|
||||
expectedAbortEventCount++
|
||||
is(transaction.readyState, LOADING, "in LOADING state");
|
||||
transaction.abort();
|
||||
is(transaction.readyState, DONE, "in DONE state after abort()");
|
||||
try {
|
||||
transaction.abort();
|
||||
ok(false, "second abort should throw an error");
|
||||
}
|
||||
catch (ex) {
|
||||
ok(true, "second abort should throw an error");
|
||||
}
|
||||
|
||||
// During LOADING from error callback
|
||||
transaction = db.transaction("foo", READ_WRITE);
|
||||
transaction.objectStore("foo").add({}, 1).onerror = function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
transaction.objectStore("foo").get(1).onerror = abortErrorHandler;
|
||||
expectedAbortEventCount++
|
||||
|
||||
is(transaction.readyState, LOADING, "in LOADING state");
|
||||
transaction.abort();
|
||||
is(transaction.readyState, DONE, "in DONE state after abort()");
|
||||
continueToNextStep();
|
||||
}
|
||||
yield;
|
||||
|
||||
// In between callbacks
|
||||
transaction = db.transaction("foo");
|
||||
function makeNewRequest() {
|
||||
let r = transaction.objectStore("foo").get(1);
|
||||
r.onsuccess = makeNewRequest;
|
||||
r.onerror = abortErrorHandler;
|
||||
}
|
||||
makeNewRequest();
|
||||
transaction.objectStore("foo").get(1).onsuccess = function(event) {
|
||||
SimpleTest.executeSoon(function() {
|
||||
is(transaction.readyState, LOADING, "in LOADING state");
|
||||
transaction.abort();
|
||||
expectedAbortEventCount++;
|
||||
is(transaction.readyState, DONE, "in DONE state after abort()");
|
||||
continueToNextStep();
|
||||
});
|
||||
};
|
||||
yield;
|
||||
|
||||
// During COMMITTING
|
||||
transaction = db.transaction("foo", READ_WRITE);
|
||||
transaction.objectStore("foo").put({hello: "world"}, 1).onsuccess = function(event) {
|
||||
continueToNextStep();
|
||||
};
|
||||
yield;
|
||||
is(transaction.readyState, COMMITTING, "in COMMITTING state");
|
||||
try {
|
||||
transaction.abort();
|
||||
ok(false, "second abort should throw an error");
|
||||
}
|
||||
catch (ex) {
|
||||
ok(true, "second abort should throw an error");
|
||||
}
|
||||
transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
is(transaction.readyState, DONE, "in DONE state");
|
||||
|
||||
// Since the previous transaction shouldn't have caused any error events,
|
||||
// we know that all events should have fired by now.
|
||||
is(abortEventCount, expectedAbortEventCount,
|
||||
"All abort errors fired");
|
||||
|
||||
// Abort both failing and succeeding requests
|
||||
transaction = db.transaction("foo", READ_WRITE);
|
||||
transaction.onabort = transaction.oncomplete = grabEventAndContinueHandler;
|
||||
transaction.objectStore("foo").add({indexKey: "key"}).onsuccess = function(event) {
|
||||
transaction.abort();
|
||||
};
|
||||
let request1 = transaction.objectStore("foo").add({indexKey: "key"});
|
||||
request1.onsuccess = grabEventAndContinueHandler;
|
||||
request1.onerror = grabEventAndContinueHandler;
|
||||
let request2 = transaction.objectStore("foo").get(1);
|
||||
request2.onsuccess = grabEventAndContinueHandler;
|
||||
request2.onerror = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "error", "abort() should make all requests fail");
|
||||
is(event.target, request1, "abort() should make all requests fail");
|
||||
is(event.target.errorCode, IDBDatabaseException.ABORT_ERR, "abort() should make all requests fail");
|
||||
event.preventDefault();
|
||||
|
||||
event = yield;
|
||||
is(event.type, "error", "abort() should make all requests fail");
|
||||
is(event.target, request2, "abort() should make all requests fail");
|
||||
is(event.target.errorCode, IDBDatabaseException.ABORT_ERR, "abort() should make all requests fail");
|
||||
event.preventDefault();
|
||||
|
||||
event = yield;
|
||||
is(event.type, "abort", "transaction should fail");
|
||||
is(event.target, transaction, "transaction should fail");
|
||||
|
||||
ok(abortFired, "Abort should have fired!");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_transaction_abort.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,39 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
db.createObjectStore("foo", { autoIncrement: true });
|
||||
yield;
|
||||
|
||||
let transaction = db.transaction("foo");
|
||||
continueToNextStep();
|
||||
yield;
|
||||
|
||||
try {
|
||||
transaction.objectStore("foo");
|
||||
ok(false, "Should have thrown!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(e instanceof IDBDatabaseException, "Got database exception.");
|
||||
is(e.code, IDBDatabaseException.NOT_ALLOWED_ERR, "Good error code.");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_transaction_lifetimes.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,63 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
db.createObjectStore("foo");
|
||||
yield;
|
||||
|
||||
let transaction1 = db.transaction("foo");
|
||||
is(transaction1.readyState, IDBTransaction.INITIAL, "Correct readyState");
|
||||
|
||||
let transaction2;
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
let thread = Components.classes["@mozilla.org/thread-manager;1"]
|
||||
.getService()
|
||||
.currentThread;
|
||||
|
||||
let eventHasRun;
|
||||
|
||||
thread.dispatch(function() {
|
||||
eventHasRun = true;
|
||||
|
||||
is(transaction1.readyState, IDBTransaction.INITIAL,
|
||||
"Correct readyState");
|
||||
|
||||
transaction2 = db.transaction("foo");
|
||||
is(transaction2.readyState, IDBTransaction.INITIAL,
|
||||
"Correct readyState");
|
||||
|
||||
}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
|
||||
|
||||
while (!eventHasRun) {
|
||||
thread.processNextEvent(false);
|
||||
}
|
||||
|
||||
is(transaction1.readyState, IDBTransaction.INITIAL, "Correct readyState");
|
||||
|
||||
ok(transaction2, "Non-null transaction2");
|
||||
is(transaction2.readyState, IDBTransaction.DONE, "Correct readyState");
|
||||
|
||||
continueToNextStep();
|
||||
yield;
|
||||
|
||||
is(transaction1.readyState, IDBTransaction.DONE, "Correct readyState");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_transaction_lifetimes_nested.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,49 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(window.location.pathname, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
request.onsuccess = continueToNextStep;
|
||||
|
||||
db.createObjectStore("foo");
|
||||
yield;
|
||||
|
||||
let trans1 = db.transaction("foo", IDBTransaction.READ_WRITE);
|
||||
let trans2 = db.transaction("foo", IDBTransaction.READ_WRITE);
|
||||
|
||||
let request1 = trans2.objectStore("foo").put("2", 42);
|
||||
let request2 = trans1.objectStore("foo").put("1", 42);
|
||||
|
||||
request1.onerror = errorHandler;
|
||||
request2.onerror = errorHandler;
|
||||
|
||||
trans1.oncomplete = grabEventAndContinueHandler;
|
||||
trans2.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
yield;
|
||||
|
||||
let trans3 = db.transaction("foo", IDBTransaction.READ);
|
||||
let request = trans3.objectStore("foo").get(42);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
request.onerror = errorHandler;
|
||||
|
||||
let event = yield;
|
||||
is(event.target.result, "2", "Transactions were ordered properly.");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_transaction_ordering.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -9,95 +9,7 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7">
|
||||
function testSteps()
|
||||
{
|
||||
const READ_ONLY = Components.interfaces.nsIIDBTransaction.READ_ONLY;
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
const VERSION_CHANGE =
|
||||
Components.interfaces.nsIIDBTransaction.VERSION_CHANGE;
|
||||
|
||||
const name = window.location.pathname;
|
||||
const description = "My Test Database";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
is(event.target.transaction.mode, VERSION_CHANGE, "Correct mode");
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
request = objectStore.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let key = event.target.result;
|
||||
ok(key, "Got a key");
|
||||
|
||||
yield;
|
||||
|
||||
let continueReading = true;
|
||||
let readerCount = 0;
|
||||
let callbackCount = 0;
|
||||
let finalCallbackCount = 0;
|
||||
|
||||
// Generate a bunch of reads right away without returning to the event
|
||||
// loop.
|
||||
for (let i = 0; i < 20; i++) {
|
||||
readerCount++;
|
||||
request = db.transaction("foo").objectStore("foo").get(key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
callbackCount++;
|
||||
};
|
||||
}
|
||||
|
||||
while (continueReading) {
|
||||
readerCount++;
|
||||
request = db.transaction("foo").objectStore("foo").get(key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.transaction.mode, READ_ONLY, "Correct mode");
|
||||
callbackCount++;
|
||||
if (callbackCount == 100) {
|
||||
request = db.transaction("foo", READ_WRITE)
|
||||
.objectStore("foo")
|
||||
.add({}, readerCount);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
continueReading = false;
|
||||
finalCallbackCount = callbackCount;
|
||||
is(event.target.result, callbackCount,
|
||||
"write callback came before later reads");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
}
|
||||
|
||||
while (callbackCount < readerCount) {
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
}
|
||||
|
||||
is(callbackCount, readerCount, "All requests accounted for");
|
||||
ok(callbackCount > finalCallbackCount, "More readers after writer");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
||||
SimpleTest.requestLongerTimeout(5); // see bug 580875
|
||||
|
||||
</script>
|
||||
<script type="text/javascript;version=1.7" src="unit/test_writer_starvation.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is Indexed Database Test Code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# The Mozilla Foundation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2010
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Shawn Wilsher <me@shawnwilsher.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
relativesrcdir = dom/indexedDB/test/unit
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
TEST_FILES = \
|
||||
test_add_put.js \
|
||||
test_add_twice_failure.js \
|
||||
test_advance.js \
|
||||
test_autoIncrement.js \
|
||||
test_autoIncrement_indexes.js \
|
||||
test_clear.js \
|
||||
test_count.js \
|
||||
test_create_index.js \
|
||||
test_create_index_with_integer_keys.js \
|
||||
test_create_objectStore.js \
|
||||
test_cursor_mutation.js \
|
||||
test_cursor_update_updates_indexes.js \
|
||||
test_cursors.js \
|
||||
test_event_source.js \
|
||||
test_getAll.js \
|
||||
test_global_data.js \
|
||||
test_index_empty_keyPath.js \
|
||||
test_index_getAll.js \
|
||||
test_index_getAllObjects.js \
|
||||
test_index_object_cursors.js \
|
||||
test_index_update_delete.js \
|
||||
test_indexes.js \
|
||||
test_indexes_bad_values.js \
|
||||
test_key_requirements.js \
|
||||
test_keys.js \
|
||||
test_multientry.js \
|
||||
test_object_identity.js \
|
||||
test_objectCursors.js \
|
||||
test_objectStore_inline_autoincrement_key_added_on_put.js \
|
||||
test_objectStore_remove_values.js \
|
||||
test_odd_result_order.js \
|
||||
test_open_empty_db.js \
|
||||
test_open_objectStore.js \
|
||||
test_optionalArguments.js \
|
||||
test_overlapping_transactions.js \
|
||||
test_put_get_values.js \
|
||||
test_put_get_values_autoIncrement.js \
|
||||
test_remove_index.js \
|
||||
test_remove_objectStore.js \
|
||||
test_request_readyState.js \
|
||||
test_setVersion.js \
|
||||
test_setVersion_abort.js \
|
||||
test_setVersion_events.js \
|
||||
test_setVersion_exclusion.js \
|
||||
test_success_events_after_abort.js \
|
||||
test_traffic_jam.js \
|
||||
test_transaction_abort.js \
|
||||
test_transaction_lifetimes.js \
|
||||
test_transaction_lifetimes_nested.js \
|
||||
test_transaction_ordering.js \
|
||||
test_writer_starvation.js \
|
||||
$(NULL)
|
||||
|
||||
|
||||
libs:: $(TEST_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const nsIIndexedDatabaseManager =
|
||||
Ci.nsIIndexedDatabaseManager;
|
||||
var idbManager = Components.classes["@mozilla.org/dom/indexeddb/manager;1"]
|
||||
.getService(nsIIndexedDatabaseManager);
|
||||
idbManager.initWindowless(this);
|
||||
// in xpcshell profile are not default
|
||||
do_get_profile();
|
||||
// oddly, if ProfD is requested from some worker thread first instead of the main thread it is crashing... so:
|
||||
var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
|
||||
var file = dirSvc.get("ProfD", Ci.nsIFile);
|
||||
|
||||
const IDBDatabaseException = Ci.nsIIDBDatabaseException;
|
||||
const IDBCursor = Ci.nsIIDBCursor;
|
||||
const IDBTransaction = Ci.nsIIDBTransaction;
|
||||
const IDBOpenDBRequest = Ci.nsIIDBOpenDBRequest;
|
||||
const IDBVersionChangeEvent = Ci.nsIIDBVersionChangeEvent
|
||||
const IDBDatabase = Ci.nsIIDBDatabase
|
||||
const IDBFactory = Ci.nsIIDBFactory
|
||||
const IDBIndex = Ci.nsIIDBIndex
|
||||
const IDBObjectStore = Ci.nsIIDBObjectStore
|
||||
const IDBRequest = Ci.nsIIDBRequest
|
||||
|
||||
|
||||
|
||||
function is(a, b, msg) {
|
||||
if(a != b)
|
||||
dump(msg);
|
||||
do_check_eq(a, b, Components.stack.caller);
|
||||
}
|
||||
|
||||
function ok(cond, msg) {
|
||||
if( !cond )
|
||||
dump(msg);
|
||||
do_check_true(!!cond, Components.stack.caller);
|
||||
}
|
||||
|
||||
function isnot(a, b, msg) {
|
||||
if( a == b )
|
||||
dump(msg);
|
||||
do_check_neq(a, b, Components.stack.caller);
|
||||
}
|
||||
|
||||
function executeSoon(fun) {
|
||||
do_execute_soon(fun);
|
||||
}
|
||||
|
||||
function todo(condition, name, diag) {
|
||||
dump("TODO: ", diag);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
runTest();
|
||||
};
|
||||
|
||||
function runTest()
|
||||
{
|
||||
do_test_pending();
|
||||
testGenerator.next();
|
||||
}
|
||||
|
||||
function finishTest()
|
||||
{
|
||||
do_execute_soon(function(){
|
||||
testGenerator.close();
|
||||
do_test_finished();
|
||||
})
|
||||
}
|
||||
|
||||
function grabEventAndContinueHandler(event)
|
||||
{
|
||||
testGenerator.send(event);
|
||||
}
|
||||
|
||||
function continueToNextStep()
|
||||
{
|
||||
do_execute_soon(function() {
|
||||
testGenerator.next();
|
||||
});
|
||||
}
|
||||
|
||||
function errorHandler(event)
|
||||
{
|
||||
dump("indexedDB error, code " + event.target.errorCode);
|
||||
do_check_true(false);
|
||||
finishTest();
|
||||
}
|
||||
|
||||
function unexpectedSuccessHandler()
|
||||
{
|
||||
do_check_true(false);
|
||||
finishTest();
|
||||
}
|
||||
|
||||
function ExpectError(code)
|
||||
{
|
||||
this._code = code;
|
||||
}
|
||||
ExpectError.prototype = {
|
||||
handleEvent: function(event)
|
||||
{
|
||||
do_check_eq(event.type, "error");
|
||||
do_check_eq(this._code, event.target.errorCode);
|
||||
event.preventDefault();
|
||||
grabEventAndContinueHandler(event);
|
||||
}
|
||||
};
|
||||
|
||||
function continueToNextStepSync()
|
||||
{
|
||||
testGenerator.next();
|
||||
}
|
||||
|
||||
function compareKeys(k1, k2) {
|
||||
let t = typeof k1;
|
||||
if (t != typeof k2)
|
||||
return false;
|
||||
|
||||
if (t !== "object")
|
||||
return k1 === k2;
|
||||
|
||||
if (k1 instanceof Date) {
|
||||
return (k2 instanceof Date) &&
|
||||
k1.getTime() === k2.getTime();
|
||||
}
|
||||
|
||||
if (k1 instanceof Array) {
|
||||
if (!(k2 instanceof Array) ||
|
||||
k1.length != k2.length)
|
||||
return false;
|
||||
|
||||
for (let i = 0; i < k1.length; ++i) {
|
||||
if (!compareKeys(k1[i], k2[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function addPermission(permission, url)
|
||||
{
|
||||
throw "addPermission";
|
||||
}
|
||||
|
||||
function removePermission(permission, url)
|
||||
{
|
||||
throw "removePermission";
|
||||
}
|
||||
|
||||
function setQuota(quota)
|
||||
{
|
||||
throw "setQuota";
|
||||
}
|
||||
|
||||
function allowIndexedDB(url)
|
||||
{
|
||||
throw "allowIndexedDB";
|
||||
}
|
||||
|
||||
function disallowIndexedDB(url)
|
||||
{
|
||||
throw "disallowIndexedDB";
|
||||
}
|
||||
|
||||
function allowUnlimitedQuota(url)
|
||||
{
|
||||
throw "allowUnlimitedQuota";
|
||||
}
|
||||
|
||||
function disallowUnlimitedQuota(url)
|
||||
{
|
||||
throw "disallowUnlimitedQuota";
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
let openRequest = mozIndexedDB.open(name, 1);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
let trans = event.target.transaction;
|
||||
|
||||
for each (let autoincrement in [true, false]) {
|
||||
for each (let keypath in [false, true, "missing", "invalid"]) {
|
||||
for each (let method in ["put", "add"]) {
|
||||
for each (let explicit in [true, false, undefined, "invalid"]) {
|
||||
for each (let existing in [true, false]) {
|
||||
let speccedNoKey = (keypath == false || keypath == "missing") &&
|
||||
!explicit;
|
||||
|
||||
// We can't do 'existing' checks if we use autogenerated key
|
||||
if (speccedNoKey && autoincrement && existing) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create store
|
||||
if (db.objectStoreNames.contains("mystore"))
|
||||
db.deleteObjectStore("mystore");
|
||||
let store = db.createObjectStore("mystore",
|
||||
{ autoIncrement: autoincrement,
|
||||
keyPath: (keypath ? "id" : null) });
|
||||
|
||||
test = " for test " + JSON.stringify({ autoincrement: autoincrement,
|
||||
keypath: keypath,
|
||||
method: method,
|
||||
explicit: explicit === undefined ? "undefined" : explicit,
|
||||
existing: existing });
|
||||
|
||||
// Insert "existing" data if needed
|
||||
if (existing) {
|
||||
if (keypath)
|
||||
store.add({ existing: "data", id: 5 }).onsuccess = grabEventAndContinueHandler;
|
||||
else
|
||||
store.add({ existing: "data" }, 5).onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
let e = yield;
|
||||
is(e.type, "success", "success inserting existing" + test);
|
||||
is(e.target.result, 5, "inserted correct key" + test);
|
||||
}
|
||||
|
||||
// Set up value to be inserted
|
||||
let value = { theObj: true };
|
||||
if (keypath === true) {
|
||||
value.id = 5;
|
||||
}
|
||||
else if (keypath === "invalid") {
|
||||
value.id = /x/;
|
||||
}
|
||||
|
||||
// Which arguments are passed to function
|
||||
args = [value];
|
||||
if (explicit === true) {
|
||||
args.push(5);
|
||||
}
|
||||
else if (explicit === undefined) {
|
||||
args.push(undefined);
|
||||
}
|
||||
else if (explicit === "invalid") {
|
||||
args.push(/x/);
|
||||
}
|
||||
|
||||
let expected = expectedResult(method, keypath, explicit, autoincrement, existing);
|
||||
|
||||
let valueJSON = JSON.stringify(value);
|
||||
|
||||
ok(true, "making call" + test);
|
||||
|
||||
// Make function call for throwing functions
|
||||
if (expected === "throw") {
|
||||
try {
|
||||
store[method].apply(store, args);
|
||||
ok(false, "should have thrown" + test);
|
||||
}
|
||||
catch (ex) {
|
||||
ok(true, "did throw" + test);
|
||||
ok(ex instanceof IDBDatabaseException, "Got a IDBDatabaseException" + test);
|
||||
is(ex.code, IDBDatabaseException.DATA_ERR, "expect a DATA_ERR" + test);
|
||||
is(JSON.stringify(value), valueJSON, "call didn't modify value" + test);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Make non-throwing function call
|
||||
let req = store[method].apply(store, args);
|
||||
is(JSON.stringify(value), valueJSON, "call didn't modify value" + test);
|
||||
|
||||
req.onsuccess = req.onerror = grabEventAndContinueHandler;
|
||||
let e = yield;
|
||||
|
||||
// Figure out what key we used
|
||||
let key = 5;
|
||||
if (autoincrement && speccedNoKey) {
|
||||
key = 1;
|
||||
}
|
||||
|
||||
// Adjust value if expected
|
||||
if (autoincrement && keypath && speccedNoKey) {
|
||||
value.id = key;
|
||||
}
|
||||
|
||||
// Check result
|
||||
if (expected === "error") {
|
||||
is(e.type, "error", "write should fail" + test);
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
continue;
|
||||
}
|
||||
|
||||
is(e.type, "success", "write should succeed" + test);
|
||||
is(e.target.result, key, "write should return correct key" + test);
|
||||
|
||||
store.get(key).onsuccess = grabEventAndContinueHandler;
|
||||
e = yield;
|
||||
is(e.type, "success", "read back should succeed" + test);
|
||||
is(JSON.stringify(e.target.result),
|
||||
JSON.stringify(value),
|
||||
"read back should return correct value" + test);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function expectedResult(method, keypath, explicit, autoincrement, existing) {
|
||||
if (keypath && explicit)
|
||||
return "throw";
|
||||
if (!keypath && !explicit && !autoincrement)
|
||||
return "throw";
|
||||
if (keypath == "invalid")
|
||||
return "throw";
|
||||
if (keypath == "missing" && !autoincrement)
|
||||
return "throw";
|
||||
if (explicit == "invalid")
|
||||
return "throw";
|
||||
|
||||
if (method == "add" && existing)
|
||||
return "error";
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = request.result;
|
||||
|
||||
ok(event.target === request, "Good event target");
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: null });
|
||||
let key = 10;
|
||||
|
||||
request = objectStore.add({}, key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(request.result, key, "Correct key");
|
||||
|
||||
request = objectStore.add({}, key);
|
||||
request.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,192 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const dataCount = 30;
|
||||
|
||||
let request = mozIndexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("", { keyPath: "key" });
|
||||
objectStore.createIndex("", "index");
|
||||
|
||||
for (let i = 0; i < dataCount; i++) {
|
||||
objectStore.add({ key: i, index: i });
|
||||
}
|
||||
yield;
|
||||
|
||||
function getObjectStore() {
|
||||
return db.transaction("").objectStore("");
|
||||
}
|
||||
|
||||
function getIndex() {
|
||||
return db.transaction("").objectStore("").index("");
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
|
||||
getObjectStore().openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
count++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount, "Saw all data");
|
||||
|
||||
count = 0;
|
||||
|
||||
getObjectStore().openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count) {
|
||||
count++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
count = 10;
|
||||
cursor.advance(10);
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount, "Saw all data");
|
||||
|
||||
count = 0;
|
||||
|
||||
getIndex().openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count) {
|
||||
count++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
count = 10;
|
||||
cursor.advance(10);
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount, "Saw all data");
|
||||
|
||||
count = 0;
|
||||
|
||||
getIndex().openKeyCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count) {
|
||||
count++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
count = 10;
|
||||
cursor.advance(10);
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount, "Saw all data");
|
||||
|
||||
count = 0;
|
||||
|
||||
getObjectStore().openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count == 0) {
|
||||
cursor.advance(dataCount + 1);
|
||||
}
|
||||
else {
|
||||
ok(false, "Should never get here!");
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, 0, "Saw all data");
|
||||
|
||||
count = dataCount - 1;
|
||||
|
||||
getObjectStore().openCursor(null, IDBCursor.PREV).onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
count--;
|
||||
if (count == dataCount - 2) {
|
||||
cursor.advance(10);
|
||||
count -= 9;
|
||||
}
|
||||
else {
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, -1, "Saw all data");
|
||||
|
||||
count = dataCount - 1;
|
||||
|
||||
getObjectStore().openCursor(null, IDBCursor.PREV).onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.primaryKey, count, "Got correct object");
|
||||
if (count == dataCount - 1) {
|
||||
cursor.advance(dataCount + 1);
|
||||
}
|
||||
else {
|
||||
ok(false, "Should never get here!");
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, dataCount - 1, "Saw all data");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,392 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function genCheck(key, value, test, options) {
|
||||
return function(event) {
|
||||
is(JSON.stringify(event.target.result), JSON.stringify(key),
|
||||
"correct returned key in " + test);
|
||||
if (options && options.store) {
|
||||
is(event.target.source, options.store, "correct store in " + test);
|
||||
}
|
||||
if (options && options.trans) {
|
||||
is(event.target.transaction, options.trans, "correct transaction in " + test);
|
||||
}
|
||||
|
||||
event.target.source.get(key).onsuccess = function(event) {
|
||||
is(JSON.stringify(event.target.result), JSON.stringify(value),
|
||||
"correct stored value in " + test);
|
||||
continueToNextStepSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const dbname = this.window ? window.location.pathname : "Splendid Test";
|
||||
const RW = IDBTransaction.READ_WRITE
|
||||
let c1 = 1;
|
||||
let c2 = 1;
|
||||
|
||||
let openRequest = mozIndexedDB.open(dbname, 1);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
let trans = event.target.transaction;
|
||||
|
||||
// Create test stores
|
||||
let store1 = db.createObjectStore("store1", { autoIncrement: true });
|
||||
let store2 = db.createObjectStore("store2", { autoIncrement: true, keyPath: "id" });
|
||||
let store3 = db.createObjectStore("store3", { autoIncrement: false });
|
||||
is(store1.autoIncrement, true, "store1 .autoIncrement");
|
||||
is(store2.autoIncrement, true, "store2 .autoIncrement");
|
||||
is(store3.autoIncrement, false, "store3 .autoIncrement");
|
||||
|
||||
store1.createIndex("unique1", "unique", { unique: true });
|
||||
store2.createIndex("unique1", "unique", { unique: true });
|
||||
|
||||
// Test simple inserts
|
||||
let test = " for test simple insert"
|
||||
store1.add({ foo: "value1" }).onsuccess =
|
||||
genCheck(c1++, { foo: "value1" }, "first" + test);
|
||||
store1.add({ foo: "value2" }).onsuccess =
|
||||
genCheck(c1++, { foo: "value2" }, "second" + test);
|
||||
|
||||
yield;
|
||||
yield;
|
||||
|
||||
store2.put({ bar: "value1" }).onsuccess =
|
||||
genCheck(c2, { bar: "value1", id: c2 }, "first in store2" + test,
|
||||
{ store: store2 });
|
||||
c2++;
|
||||
store1.put({ foo: "value3" }).onsuccess =
|
||||
genCheck(c1++, { foo: "value3" }, "third" + test,
|
||||
{ store: store1 });
|
||||
|
||||
yield;
|
||||
yield;
|
||||
|
||||
store2.get(IDBKeyRange.lowerBound(c2)).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
is(event.target.result, undefined, "no such value" + test);
|
||||
|
||||
// Close version_change transaction
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
is(event.target, openRequest, "succeeded to open" + test);
|
||||
is(event.type, "success", "succeeded to open" + test);
|
||||
|
||||
// Test inserting explicit keys
|
||||
test = " for test explicit keys";
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 1 }, 100).onsuccess =
|
||||
genCheck(100, { explicit: 1 }, "first" + test);
|
||||
c1 = 101;
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 2 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 2 }, "second" + test);
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 3 }, 200).onsuccess =
|
||||
genCheck(200, { explicit: 3 }, "third" + test);
|
||||
c1 = 201;
|
||||
trans.objectStore("store1").add({ explicit: 4 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 4 }, "fourth" + test);
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 5 }, 150).onsuccess =
|
||||
genCheck(150, { explicit: 5 }, "fifth" + test);
|
||||
yield;
|
||||
trans.objectStore("store1").add({ explicit: 6 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 6 }, "sixth" + test);
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 7 }, "key").onsuccess =
|
||||
genCheck("key", { explicit: 7 }, "seventh" + test);
|
||||
yield;
|
||||
trans.objectStore("store1").add({ explicit: 8 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 8 }, "eighth" + test);
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 7 }, [100000]).onsuccess =
|
||||
genCheck([100000], { explicit: 7 }, "seventh" + test);
|
||||
yield;
|
||||
trans.objectStore("store1").add({ explicit: 8 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 8 }, "eighth" + test);
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store1", RW);
|
||||
trans.objectStore("store1").add({ explicit: 9 }, -100000).onsuccess =
|
||||
genCheck(-100000, { explicit: 9 }, "ninth" + test);
|
||||
yield;
|
||||
trans.objectStore("store1").add({ explicit: 10 }).onsuccess =
|
||||
genCheck(c1++, { explicit: 10 }, "tenth" + test);
|
||||
yield;
|
||||
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit2: 1, id: 300 }).onsuccess =
|
||||
genCheck(300, { explicit2: 1, id: 300 }, "first store2" + test);
|
||||
c2 = 301;
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit2: 2 }).onsuccess =
|
||||
genCheck(c2, { explicit2: 2, id: c2 }, "second store2" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit2: 3, id: 400 }).onsuccess =
|
||||
genCheck(400, { explicit2: 3, id: 400 }, "third store2" + test);
|
||||
c2 = 401;
|
||||
trans.objectStore("store2").add({ explicit2: 4 }).onsuccess =
|
||||
genCheck(c2, { explicit2: 4, id: c2 }, "fourth store2" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit: 5, id: 150 }).onsuccess =
|
||||
genCheck(150, { explicit: 5, id: 150 }, "fifth store2" + test);
|
||||
yield;
|
||||
trans.objectStore("store2").add({ explicit: 6 }).onsuccess =
|
||||
genCheck(c2, { explicit: 6, id: c2 }, "sixth store2" + test);
|
||||
c2++;
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit: 7, id: "key" }).onsuccess =
|
||||
genCheck("key", { explicit: 7, id: "key" }, "seventh store2" + test);
|
||||
yield;
|
||||
trans.objectStore("store2").add({ explicit: 8 }).onsuccess =
|
||||
genCheck(c2, { explicit: 8, id: c2 }, "eighth store2" + test);
|
||||
c2++;
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit: 7, id: [100000] }).onsuccess =
|
||||
genCheck([100000], { explicit: 7, id: [100000] }, "seventh store2" + test);
|
||||
yield;
|
||||
trans.objectStore("store2").add({ explicit: 8 }).onsuccess =
|
||||
genCheck(c2, { explicit: 8, id: c2 }, "eighth store2" + test);
|
||||
c2++;
|
||||
yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans.objectStore("store2").add({ explicit: 9, id: -100000 }).onsuccess =
|
||||
genCheck(-100000, { explicit: 9, id: -100000 }, "ninth store2" + test);
|
||||
yield;
|
||||
trans.objectStore("store2").add({ explicit: 10 }).onsuccess =
|
||||
genCheck(c2, { explicit: 10, id: c2 }, "tenth store2" + test);
|
||||
c2++;
|
||||
yield;
|
||||
|
||||
|
||||
// Test separate transactions doesn't generate overlapping numbers
|
||||
test = " for test non-overlapping counts";
|
||||
trans = db.transaction("store1", RW);
|
||||
trans2 = db.transaction("store1", RW);
|
||||
trans2.objectStore("store1").put({ over: 2 }).onsuccess =
|
||||
genCheck(c1 + 1, { over: 2 }, "first" + test,
|
||||
{ trans: trans2 });
|
||||
trans.objectStore("store1").put({ over: 1 }).onsuccess =
|
||||
genCheck(c1, { over: 1 }, "second" + test,
|
||||
{ trans: trans });
|
||||
c1 += 2;
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction("store2", RW);
|
||||
trans2 = db.transaction("store2", RW);
|
||||
trans2.objectStore("store2").put({ over: 2 }).onsuccess =
|
||||
genCheck(c2 + 1, { over: 2, id: c2 + 1 }, "third" + test,
|
||||
{ trans: trans2 });
|
||||
trans.objectStore("store2").put({ over: 1 }).onsuccess =
|
||||
genCheck(c2, { over: 1, id: c2 }, "fourth" + test,
|
||||
{ trans: trans });
|
||||
c2 += 2;
|
||||
yield; yield;
|
||||
|
||||
// Test that error inserts doesn't increase generator
|
||||
test = " for test error inserts";
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ unique: 1 }, -1);
|
||||
trans.objectStore("store2").add({ unique: 1, id: "unique" });
|
||||
|
||||
trans.objectStore("store1").add({ error: 1, unique: 1 }).onerror =
|
||||
new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
trans.objectStore("store1").add({ error: 2 }).onsuccess =
|
||||
genCheck(c1++, { error: 2 }, "first" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store2").add({ error: 3, unique: 1 }).onerror =
|
||||
new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
trans.objectStore("store2").add({ error: 4 }).onsuccess =
|
||||
genCheck(c2, { error: 4, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ error: 5, unique: 1 }, 100000).onerror =
|
||||
new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
trans.objectStore("store1").add({ error: 6 }).onsuccess =
|
||||
genCheck(c1++, { error: 6 }, "third" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store2").add({ error: 7, unique: 1, id: 100000 }).onerror =
|
||||
new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
trans.objectStore("store2").add({ error: 8 }).onsuccess =
|
||||
genCheck(c2, { error: 8, id: c2 }, "fourth" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
// Test that aborts doesn't increase generator
|
||||
test = " for test aborted transaction";
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ abort: 1 }).onsuccess =
|
||||
genCheck(c1, { abort: 1 }, "first" + test);
|
||||
trans.objectStore("store2").put({ abort: 2 }).onsuccess =
|
||||
genCheck(c2, { abort: 2, id: c2 }, "second" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ abort: 3 }, 500).onsuccess =
|
||||
genCheck(500, { abort: 3 }, "third" + test);
|
||||
trans.objectStore("store2").put({ abort: 4, id: 600 }).onsuccess =
|
||||
genCheck(600, { abort: 4, id: 600 }, "fourth" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ abort: 5 }).onsuccess =
|
||||
genCheck(501, { abort: 5 }, "fifth" + test);
|
||||
trans.objectStore("store2").put({ abort: 6 }).onsuccess =
|
||||
genCheck(601, { abort: 6, id: 601 }, "sixth" + test);
|
||||
yield; yield;
|
||||
|
||||
trans.abort();
|
||||
trans.onabort = grabEventAndContinueHandler;
|
||||
event = yield
|
||||
is(event.type, "abort", "transaction aborted");
|
||||
is(event.target, trans, "correct transaction aborted");
|
||||
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ abort: 1 }).onsuccess =
|
||||
genCheck(c1++, { abort: 1 }, "re-first" + test);
|
||||
trans.objectStore("store2").put({ abort: 2 }).onsuccess =
|
||||
genCheck(c2, { abort: 2, id: c2 }, "re-second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
// Test that delete doesn't decrease generator
|
||||
test = " for test delete items"
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ delete: 1 }).onsuccess =
|
||||
genCheck(c1++, { delete: 1 }, "first" + test);
|
||||
trans.objectStore("store2").put({ delete: 2 }).onsuccess =
|
||||
genCheck(c2, { delete: 2, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").delete(c1 - 1).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").delete(c2 - 1).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ delete: 3 }).onsuccess =
|
||||
genCheck(c1++, { delete: 3 }, "first" + test);
|
||||
trans.objectStore("store2").put({ delete: 4 }).onsuccess =
|
||||
genCheck(c2, { delete: 4, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").delete(c1 - 1).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").delete(c2 - 1).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ delete: 5 }).onsuccess =
|
||||
genCheck(c1++, { delete: 5 }, "first" + test);
|
||||
trans.objectStore("store2").put({ delete: 6 }).onsuccess =
|
||||
genCheck(c2, { delete: 6, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
// Test that clears doesn't decrease generator
|
||||
test = " for test clear stores";
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ clear: 1 }).onsuccess =
|
||||
genCheck(c1++, { clear: 1 }, "first" + test);
|
||||
trans.objectStore("store2").put({ clear: 2 }).onsuccess =
|
||||
genCheck(c2, { clear: 2, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").add({ clear: 3 }).onsuccess =
|
||||
genCheck(c1++, { clear: 3 }, "third" + test);
|
||||
trans.objectStore("store2").put({ clear: 4 }).onsuccess =
|
||||
genCheck(c2, { clear: 4, id: c2 }, "forth" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
trans.objectStore("store1").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
dump("****************************************************************\n");
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").add({ clear: 5 }).onsuccess =
|
||||
genCheck(c1++, { clear: 5 }, "fifth" + test);
|
||||
trans.objectStore("store2").put({ clear: 6 }).onsuccess =
|
||||
genCheck(c2, { clear: 6, id: c2 }, "sixth" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
|
||||
dump("****************************************************************1\n");
|
||||
// Test that close/reopen doesn't decrease generator
|
||||
test = " for test clear stores";
|
||||
trans = db.transaction(["store1", "store2"], RW);
|
||||
trans.objectStore("store1").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
trans.objectStore("store2").clear().onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
yield; yield;
|
||||
db.close();
|
||||
dump("****************************************************************2\n");
|
||||
if (this.SpecialPowers) {
|
||||
SpecialPowers.gc();
|
||||
}
|
||||
dump("****************************************************************3\n");
|
||||
openRequest = mozIndexedDB.open(dbname, 2);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
event = yield;
|
||||
db = event.target.result;
|
||||
trans = event.target.transaction;
|
||||
dump("****************************************************************4\n");
|
||||
trans.objectStore("store1").add({ reopen: 1 }).onsuccess =
|
||||
genCheck(c1++, { reopen: 1 }, "first" + test);
|
||||
trans.objectStore("store2").put({ reopen: 2 }).onsuccess =
|
||||
genCheck(c2, { reopen: 2, id: c2 }, "second" + test);
|
||||
c2++;
|
||||
yield; yield;
|
||||
dump("****************************************************************5\n");
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = request.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "id",
|
||||
autoIncrement: true });
|
||||
objectStore.createIndex("first","first");
|
||||
objectStore.createIndex("second","second");
|
||||
objectStore.createIndex("third","third");
|
||||
|
||||
let data = { first: "foo", second: "foo", third: "foo" };
|
||||
|
||||
objectStore.add(data).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1, "Added entry");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
|
||||
let objectStore = db.transaction("foo").objectStore("foo");
|
||||
let first = objectStore.index("first");
|
||||
let second = objectStore.index("second");
|
||||
let third = objectStore.index("third");
|
||||
|
||||
first.get("foo").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is (event.target.result.id, 1, "Entry in first");
|
||||
|
||||
second.get("foo").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is (event.target.result.id, 1, "Entry in second");
|
||||
|
||||
third.get("foo").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is (event.target.result.id, 1, "Entry in third");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const entryCount = 1000;
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = request.result;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
let firstKey;
|
||||
for (let i = 0; i < entryCount; i++) {
|
||||
request = objectStore.add({});
|
||||
request.onerror = errorHandler;
|
||||
if (!i) {
|
||||
request.onsuccess = function(event) {
|
||||
firstKey = event.target.result;
|
||||
};
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
isnot(firstKey, undefined, "got first key");
|
||||
|
||||
let seenEntryCount = 0;
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
seenEntryCount++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(seenEntryCount, entryCount, "Correct entry count");
|
||||
|
||||
try {
|
||||
db.transaction("foo").objectStore("foo").clear();
|
||||
ok(false, "clear should throw on READ_ONLY transactions");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "clear should throw on READ_ONLY transactions");
|
||||
}
|
||||
|
||||
request = db.transaction("foo", READ_WRITE).objectStore("foo").clear();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.target.result === undefined, "Correct event.target.result");
|
||||
ok(request.result === undefined, "Correct request.result");
|
||||
ok(request === event.target, "Correct event.target");
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
let cursor = request.result;
|
||||
if (cursor) {
|
||||
ok(false, "Shouldn't have any entries");
|
||||
}
|
||||
continueToNextStep();
|
||||
}
|
||||
yield;
|
||||
|
||||
request = db.transaction("foo", READ_WRITE).objectStore("foo").add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
isnot(event.target.result, firstKey, "Got a different key");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,354 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const objectStoreName = "People";
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7738", value: { name: "Mel", height: 66, weight: {} } },
|
||||
{ key: "237-23-7739", value: { name: "Tom", height: 62, weight: 130 } }
|
||||
];
|
||||
|
||||
const indexData = {
|
||||
name: "weight",
|
||||
keyPath: "weight",
|
||||
options: { unique: false }
|
||||
};
|
||||
|
||||
const weightSort = [1, 0, 3, 7, 4, 2];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
is(event.type, "upgradeneeded", "Got correct event type");
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName, { });
|
||||
objectStore.createIndex(indexData.name, indexData.keyPath,
|
||||
indexData.options);
|
||||
|
||||
for each (let data in objectStoreData) {
|
||||
objectStore.add(data.value, data.key);
|
||||
}
|
||||
|
||||
event = yield;
|
||||
|
||||
is(event.type, "success", "Got correct event type");
|
||||
|
||||
objectStore = db.transaction(db.objectStoreNames)
|
||||
.objectStore(objectStoreName);
|
||||
|
||||
objectStore.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length,
|
||||
"Correct number of object store entries for all keys");
|
||||
|
||||
objectStore.count(null).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length,
|
||||
"Correct number of object store entries for null key");
|
||||
|
||||
objectStore.count(objectStoreData[2].key).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of object store entries for single existing key");
|
||||
|
||||
objectStore.count("foo").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of object store entries for single non-existing key");
|
||||
|
||||
let keyRange = IDBKeyRange.only(objectStoreData[2].key);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of object store entries for existing only keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.only("foo");
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of object store entries for non-existing only keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[2].key);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 2,
|
||||
"Correct number of object store entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[2].key, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 3,
|
||||
"Correct number of object store entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound("foo");
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of object store entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[2].key, false);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 3,
|
||||
"Correct number of object store entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[2].key, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 2,
|
||||
"Correct number of object store entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound("foo", true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length,
|
||||
"Correct number of object store entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[0].key,
|
||||
objectStoreData[objectStoreData.length - 1].key);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[0].key,
|
||||
objectStoreData[objectStoreData.length - 1].key,
|
||||
true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 1,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[0].key,
|
||||
objectStoreData[objectStoreData.length - 1].key,
|
||||
true, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 2,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound("foo", "foopy", true, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[0].key, "foo", true, true);
|
||||
objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreData.length - 1,
|
||||
"Correct number of object store entries for bound keyRange");
|
||||
|
||||
let index = objectStore.index(indexData.name);
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for no key");
|
||||
|
||||
index.count(objectStoreData[7].value.weight).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 2,
|
||||
"Correct number of index entries for duplicate key");
|
||||
|
||||
index.count(objectStoreData[0].value.weight).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of index entries for single key");
|
||||
|
||||
keyRange = IDBKeyRange.only(objectStoreData[0].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of index entries for only existing keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.only("foo");
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for only non-existing keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.only(objectStoreData[7].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 2,
|
||||
"Correct number of index entries for only duplicate keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[0]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[1]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[0]].value.weight - 1);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[0]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.lowerBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight + 1,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for lowerBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[0]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 1,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[0]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound(objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.upperBound("foo");
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for upperBound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound("foo", "foopy");
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, 0,
|
||||
"Correct number of index entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[weightSort[0]].value.weight,
|
||||
objectStoreData[weightSort[weightSort.length - 1]].value.weight);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length,
|
||||
"Correct number of index entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[weightSort[0]].value.weight,
|
||||
objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 1,
|
||||
"Correct number of index entries for bound keyRange");
|
||||
|
||||
keyRange = IDBKeyRange.bound(objectStoreData[weightSort[0]].value.weight,
|
||||
objectStoreData[weightSort[weightSort.length - 1]].value.weight,
|
||||
true, true);
|
||||
index.count(keyRange).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, weightSort.length - 2,
|
||||
"Correct number of index entries for bound keyRange");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const nsIIDBTransaction = Components.interfaces.nsIIDBTransaction;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStoreInfo = [
|
||||
{ name: "a", options: { keyPath: "id", autoIncrement: true } },
|
||||
{ name: "b", options: { keyPath: "id", autoIncrement: false } },
|
||||
];
|
||||
const indexInfo = [
|
||||
{ name: "1", keyPath: "unique_value", options: { unique: true } },
|
||||
{ name: "2", keyPath: "value", options: { unique: false } },
|
||||
{ name: "3", keyPath: "value", options: { unique: false } },
|
||||
{ name: "", keyPath: "value", options: { unique: false } },
|
||||
{ name: null, keyPath: "value", options: { unique: false } },
|
||||
{ name: undefined, keyPath: "value", options: { unique: false } },
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
|
||||
for (let i = 0; i < objectStoreInfo.length; i++) {
|
||||
let info = objectStoreInfo[i];
|
||||
let objectStore = info.hasOwnProperty("options") ?
|
||||
db.createObjectStore(info.name, info.options) :
|
||||
db.createObjectStore(info.name);
|
||||
|
||||
try {
|
||||
request = objectStore.createIndex("Hola");
|
||||
ok(false, "createIndex with no keyPath should throw");
|
||||
}
|
||||
catch(e) {
|
||||
ok(true, "createIndex with no keyPath should throw");
|
||||
}
|
||||
|
||||
try {
|
||||
request = objectStore.createIndex("Hola", ["foo"], { multiEntry: true });
|
||||
ok(false, "createIndex with array keyPath and multiEntry should throw");
|
||||
}
|
||||
catch(e) {
|
||||
ok(true, "createIndex with array keyPath and multiEntry should throw");
|
||||
}
|
||||
|
||||
try {
|
||||
request = objectStore.createIndex("Hola", []);
|
||||
ok(false, "createIndex with empty array keyPath should throw");
|
||||
}
|
||||
catch(e) {
|
||||
ok(true, "createIndex with empty array keyPath should throw");
|
||||
}
|
||||
|
||||
try {
|
||||
request = objectStore.createIndex("foo", "bar", 10);
|
||||
ok(false, "createIndex with bad options should throw");
|
||||
}
|
||||
catch(e) {
|
||||
ok(true, "createIndex with bad options threw");
|
||||
}
|
||||
|
||||
ok(objectStore.createIndex("foo", "bar", { foo: "" }),
|
||||
"createIndex with unknown options should not throw");
|
||||
objectStore.deleteIndex("foo");
|
||||
|
||||
// Test index creation, and that it ends up in indexNames.
|
||||
let objectStoreName = info.name;
|
||||
for (let j = 0; j < indexInfo.length; j++) {
|
||||
let info = indexInfo[j];
|
||||
let count = objectStore.indexNames.length;
|
||||
let index = info.hasOwnProperty("options") ?
|
||||
objectStore.createIndex(info.name, info.keyPath,
|
||||
info.options) :
|
||||
objectStore.createIndex(info.name, info.keyPath);
|
||||
|
||||
let name = info.name;
|
||||
if (name === null) {
|
||||
name = "null";
|
||||
}
|
||||
else if (name === undefined) {
|
||||
name = "undefined";
|
||||
}
|
||||
|
||||
is(index.name, name, "correct name");
|
||||
is(index.keyPath, info.keyPath, "correct keyPath");
|
||||
is(index.unique, info.options.unique, "correct uniqueness");
|
||||
|
||||
is(objectStore.indexNames.length, count + 1,
|
||||
"indexNames grew in size");
|
||||
let found = false;
|
||||
for (let k = 0; k < objectStore.indexNames.length; k++) {
|
||||
if (objectStore.indexNames.item(k) == name) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ok(found, "Name is on objectStore.indexNames");
|
||||
|
||||
ok(event.target.transaction, "event has a transaction");
|
||||
ok(event.target.transaction.db === db,
|
||||
"transaction has the right db");
|
||||
is(event.target.transaction.readyState, nsIIDBTransaction.LOADING,
|
||||
"transaction has the correct readyState");
|
||||
is(event.target.transaction.mode, nsIIDBTransaction.VERSION_CHANGE,
|
||||
"transaction has the correct mode");
|
||||
is(event.target.transaction.objectStoreNames.length, i + 1,
|
||||
"transaction only has one object store");
|
||||
is(event.target.transaction.objectStoreNames.item(0), objectStoreName,
|
||||
"transaction has the correct object store");
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const data = { id: new Date().getTime(),
|
||||
num: parseInt(Math.random() * 1000) };
|
||||
|
||||
let request = mozIndexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
// Make object store, add data.
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "id" });
|
||||
objectStore.add(data);
|
||||
yield;
|
||||
db.close();
|
||||
|
||||
let request = mozIndexedDB.open(this.window ? window.location.pathname : "Splendid Test", 2);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db2 = event.target.result;
|
||||
db2.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
// Create index.
|
||||
event.target.transaction.objectStore("foo").createIndex("foo", "num");
|
||||
yield;
|
||||
|
||||
// Make sure our object made it into the index.
|
||||
let seenCount = 0;
|
||||
|
||||
|
||||
db2.transaction("foo").objectStore("foo").index("foo")
|
||||
.openKeyCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, data.num, "Good key");
|
||||
is(cursor.primaryKey, data.id, "Good value");
|
||||
seenCount++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(seenCount, 1, "Saw our entry");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const nsIIDBTransaction = Components.interfaces.nsIIDBTransaction;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStoreInfo = [
|
||||
{ name: "1", options: { keyPath: null } },
|
||||
{ name: "2", options: { keyPath: null, autoIncrement: true } },
|
||||
{ name: "3", options: { keyPath: null, autoIncrement: false } },
|
||||
{ name: "4", options: { keyPath: null } },
|
||||
{ name: "5", options: { keyPath: "foo" } },
|
||||
{ name: "6" },
|
||||
{ name: "7", options: null },
|
||||
{ name: "8", options: { autoIncrement: true } },
|
||||
{ name: "9", options: { autoIncrement: false } },
|
||||
{ name: "10", options: { keyPath: "foo", autoIncrement: false } },
|
||||
{ name: "11", options: { keyPath: "foo", autoIncrement: true } },
|
||||
{ name: "" },
|
||||
{ name: null },
|
||||
{ name: undefined }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let count = db.objectStoreNames.length;
|
||||
is(count, 0, "correct objectStoreNames length");
|
||||
|
||||
try {
|
||||
db.createObjectStore("foo", "bar");
|
||||
ok(false, "createObjectStore with bad options should throw");
|
||||
}
|
||||
catch(e) {
|
||||
ok(true, "createObjectStore with bad options");
|
||||
}
|
||||
|
||||
ok(db.createObjectStore("foo", { foo: "" }),
|
||||
"createObjectStore with unknown options should not throw");
|
||||
db.deleteObjectStore("foo");
|
||||
|
||||
for (let index in objectStoreInfo) {
|
||||
index = parseInt(index);
|
||||
const info = objectStoreInfo[index];
|
||||
|
||||
let objectStore = info.hasOwnProperty("options") ?
|
||||
db.createObjectStore(info.name, info.options) :
|
||||
db.createObjectStore(info.name);
|
||||
|
||||
is(db.objectStoreNames.length, index + 1,
|
||||
"updated objectStoreNames list");
|
||||
|
||||
let name = info.name;
|
||||
if (name === null) {
|
||||
name = "null";
|
||||
}
|
||||
else if (name === undefined) {
|
||||
name = "undefined";
|
||||
}
|
||||
|
||||
let found = false;
|
||||
for (let i = 0; i <= index; i++) {
|
||||
if (db.objectStoreNames.item(i) == name) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
is(found, true, "objectStoreNames contains name");
|
||||
|
||||
is(objectStore.name, name, "Bad name");
|
||||
is(objectStore.keyPath, info.options && info.options.keyPath ?
|
||||
info.options.keyPath : null,
|
||||
"Bad keyPath");
|
||||
if(objectStore.indexNames.length, 0, "Bad indexNames");
|
||||
|
||||
ok(event.target.transaction, "event has a transaction");
|
||||
ok(event.target.transaction.db === db, "transaction has the right db");
|
||||
is(event.target.transaction.readyState, nsIIDBTransaction.LOADING,
|
||||
"transaction has the correct readyState");
|
||||
is(event.target.transaction.mode, nsIIDBTransaction.VERSION_CHANGE,
|
||||
"transaction has the correct mode");
|
||||
is(event.target.transaction.objectStoreNames.length, index + 1,
|
||||
"transaction has correct objectStoreNames list");
|
||||
found = false;
|
||||
for (let j = 0; j < event.target.transaction.objectStoreNames.length;
|
||||
j++) {
|
||||
if (event.target.transaction.objectStoreNames.item(j) == name) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
is(found, true, "transaction has correct objectStoreNames list");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const objectStoreData = [
|
||||
// This one will be removed.
|
||||
{ ss: "237-23-7732", name: "Bob" },
|
||||
|
||||
// These will always be included.
|
||||
{ ss: "237-23-7733", name: "Ann" },
|
||||
{ ss: "237-23-7734", name: "Ron" },
|
||||
{ ss: "237-23-7735", name: "Sue" },
|
||||
{ ss: "237-23-7736", name: "Joe" },
|
||||
|
||||
// This one will be added.
|
||||
{ ss: "237-23-7737", name: "Pat" }
|
||||
];
|
||||
|
||||
// Post-add and post-remove data ordered by name.
|
||||
const objectStoreDataNameSort = [ 1, 4, 5, 2, 3 ];
|
||||
|
||||
let request = mozIndexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "ss" });
|
||||
objectStore.createIndex("name", "name", { unique: true });
|
||||
|
||||
for (let i = 0; i < objectStoreData.length - 1; i++) {
|
||||
objectStore.add(objectStoreData[i]);
|
||||
}
|
||||
yield;
|
||||
|
||||
let count = 0;
|
||||
|
||||
let sawAdded = false;
|
||||
let sawRemoved = false;
|
||||
|
||||
db.transaction("foo").objectStore("foo").openCursor().onsuccess =
|
||||
function(event) {
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value.name == objectStoreData[0].name) {
|
||||
sawRemoved = true;
|
||||
}
|
||||
if (cursor.value.name ==
|
||||
objectStoreData[objectStoreData.length - 1].name) {
|
||||
sawAdded = true;
|
||||
}
|
||||
cursor.continue();
|
||||
count++;
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, objectStoreData.length - 1, "Good initial count");
|
||||
is(sawAdded, false, "Didn't see item that is about to be added");
|
||||
is(sawRemoved, true, "Saw item that is about to be removed");
|
||||
|
||||
count = 0;
|
||||
sawAdded = false;
|
||||
sawRemoved = false;
|
||||
|
||||
db.transaction("foo", IDBTransaction.READ_WRITE).objectStore("foo")
|
||||
.index("name").openCursor().onsuccess = function(event) {
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value.name == objectStoreData[0].name) {
|
||||
sawRemoved = true;
|
||||
}
|
||||
if (cursor.value.name ==
|
||||
objectStoreData[objectStoreData.length - 1].name) {
|
||||
sawAdded = true;
|
||||
}
|
||||
|
||||
is(cursor.value.name,
|
||||
objectStoreData[objectStoreDataNameSort[count++]].name,
|
||||
"Correct name");
|
||||
|
||||
if (count == 1) {
|
||||
let objectStore = event.target.transaction.objectStore("foo");
|
||||
objectStore.delete(objectStoreData[0].ss)
|
||||
.onsuccess = function(event) {
|
||||
objectStore.add(objectStoreData[objectStoreData.length - 1])
|
||||
.onsuccess =
|
||||
function(event) {
|
||||
cursor.continue();
|
||||
};
|
||||
};
|
||||
}
|
||||
else {
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(count, objectStoreData.length - 1, "Good final count");
|
||||
is(sawAdded, true, "Saw item that was added");
|
||||
is(sawRemoved, false, "Didn't see item that was removed");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const nsIIDBTransaction = Components.interfaces.nsIIDBTransaction;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const START_DATA = "hi";
|
||||
const END_DATA = "bye";
|
||||
const objectStoreInfo = [
|
||||
{ name: "1", options: { keyPath: null }, key: 1,
|
||||
entry: { data: START_DATA } },
|
||||
{ name: "2", options: { keyPath: "foo" },
|
||||
entry: { foo: 1, data: START_DATA } },
|
||||
{ name: "3", options: { keyPath: null, autoIncrement: true },
|
||||
entry: { data: START_DATA } },
|
||||
{ name: "4", options: { keyPath: "foo", autoIncrement: true },
|
||||
entry: { data: START_DATA } },
|
||||
];
|
||||
|
||||
for (let i = 0; i < objectStoreInfo.length; i++) {
|
||||
// Create our object stores.
|
||||
let info = objectStoreInfo[i];
|
||||
|
||||
ok(true, "1");
|
||||
request = mozIndexedDB.open(name, i + 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
ok(true, "2");
|
||||
let objectStore = info.hasOwnProperty("options") ?
|
||||
db.createObjectStore(info.name, info.options) :
|
||||
db.createObjectStore(info.name);
|
||||
|
||||
// Create the indexes on 'data' on the object store.
|
||||
let index = objectStore.createIndex("data_index", "data",
|
||||
{ unique: false });
|
||||
let uniqueIndex = objectStore.createIndex("unique_data_index", "data",
|
||||
{ unique: true });
|
||||
// Populate the object store with one entry of data.
|
||||
request = info.hasOwnProperty("key") ?
|
||||
objectStore.add(info.entry, info.key) :
|
||||
objectStore.add(info.entry);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "3");
|
||||
|
||||
// Use a cursor to update 'data' to END_DATA.
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "4");
|
||||
|
||||
let cursor = request.result;
|
||||
let obj = cursor.value;
|
||||
obj.data = END_DATA;
|
||||
request = cursor.update(obj);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "5");
|
||||
|
||||
// Check both indexes to make sure that they were updated.
|
||||
request = index.get(END_DATA);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "6");
|
||||
ok(obj.data, event.target.result.data,
|
||||
"Non-unique index was properly updated.");
|
||||
|
||||
request = uniqueIndex.get(END_DATA);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(true, "7");
|
||||
ok(obj.data, event.target.result.data,
|
||||
"Unique index was properly updated.");
|
||||
db.close();
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,361 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const keys = [1, -1, 0, 10, 2000, "q", "z", "two", "b", "a"];
|
||||
const sortedKeys = [-1, 0, 1, 10, 2000, "a", "b", "q", "two", "z"];
|
||||
|
||||
is(keys.length, sortedKeys.length, "Good key setup");
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("autoIncrement",
|
||||
{ autoIncrement: true });
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
||||
objectStore = db.createObjectStore("autoIncrementKeyPath",
|
||||
{ keyPath: "foo",
|
||||
autoIncrement: true });
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
||||
objectStore = db.createObjectStore("keyPath", { keyPath: "foo" });
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
||||
objectStore = db.createObjectStore("foo");
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
||||
let keyIndex = 0;
|
||||
|
||||
for (let i in keys) {
|
||||
request = objectStore.add("foo", keys[i]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++keyIndex == keys.length) {
|
||||
testGenerator.next();
|
||||
}
|
||||
};
|
||||
}
|
||||
yield;
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
cursor.continue();
|
||||
|
||||
try {
|
||||
cursor.continue();
|
||||
ok(false, "continue twice should throw");
|
||||
}
|
||||
catch (e) {
|
||||
ok(e instanceof IDBDatabaseException, "got a database exception");
|
||||
is(e.code, IDBDatabaseException.NOT_ALLOWED_ERR, "correct code");
|
||||
}
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex++;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all added items");
|
||||
|
||||
keyIndex = 4;
|
||||
|
||||
let range = IDBKeyRange.bound(2000, "q");
|
||||
request = objectStore.openCursor(range);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
cursor.continue();
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex++;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, 8, "Saw all the expected keys");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex) {
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
cursor.continue("b");
|
||||
}
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex += keyIndex ? 1: 6;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex) {
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
cursor.continue(10);
|
||||
}
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex += keyIndex ? 1: 3;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex) {
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
cursor.continue("c");
|
||||
}
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex += keyIndex ? 1 : 7;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex == 4) {
|
||||
request = cursor.update("bar");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
keyIndex++;
|
||||
cursor.continue();
|
||||
};
|
||||
}
|
||||
else {
|
||||
keyIndex++;
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
|
||||
request = objectStore.get(sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, "bar", "Update succeeded");
|
||||
|
||||
request = objectStore.put("foo", sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
let gotRemoveEvent = false;
|
||||
let retval = false;
|
||||
|
||||
request = objectStore.openCursor(null, IDBCursor.NEXT);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
if (keyIndex == 4) {
|
||||
request = cursor.delete();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
ok(event.target.result === undefined, "Should be undefined");
|
||||
is(keyIndex, 5, "Got result of remove before next continue");
|
||||
gotRemoveEvent = true;
|
||||
};
|
||||
}
|
||||
|
||||
keyIndex++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, keys.length, "Saw all the expected keys");
|
||||
is(gotRemoveEvent, true, "Saw the remove event");
|
||||
|
||||
request = objectStore.get(sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, undefined, "Entry was deleted");
|
||||
|
||||
request = objectStore.add("foo", sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
keyIndex = sortedKeys.length - 1;
|
||||
|
||||
request = objectStore.openCursor(null, IDBCursor.PREV);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
cursor.continue();
|
||||
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.primaryKey, sortedKeys[keyIndex], "Correct primary key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
||||
keyIndex--;
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, -1, "Saw all added items");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
var request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
var event = yield;
|
||||
|
||||
is(event.target.source, null, "correct event.target.source");
|
||||
|
||||
var db = event.target.result;
|
||||
var objectStore = db.createObjectStore(objectStoreName,
|
||||
{ autoIncrement: true });
|
||||
request = objectStore.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.target.source === objectStore, "correct event.source");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
const values = [ "a", "1", 1, "foo", 300, true, false, 4.5, null ];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
request = objectStore.getAll();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 0, "No elements");
|
||||
|
||||
let addedCount = 0;
|
||||
|
||||
for (let i in values) {
|
||||
request = objectStore.add(values[i]);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedCount == values.length) {
|
||||
executeSoon(function() { testGenerator.next(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
yield;
|
||||
yield;
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, values.length, "Same length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[i], "Same value");
|
||||
}
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(null, 5);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 5, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[i], "Same value");
|
||||
}
|
||||
|
||||
let keyRange = IDBKeyRange.bound(1, 9);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, values.length, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[i], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
// Get should take a key range also but it doesn't return an array.
|
||||
request = db.transaction("foo").objectStore("foo").get(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, false, "Not an array object");
|
||||
is(event.target.result, values[3], "Correct value");
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 50);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 0);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 0, "Correct length");
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7, true, true);
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 4], "Same value");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStore = { name: "Objects",
|
||||
options: { keyPath: "id", autoIncrement: true } };
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db1 = event.target.result;
|
||||
|
||||
is(db1.objectStoreNames.length, 0, "No objectStores in db1");
|
||||
|
||||
db1.createObjectStore(objectStore.name, objectStore.options);
|
||||
|
||||
continueToNextStep();
|
||||
yield;
|
||||
|
||||
request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let db2 = event.target.result;
|
||||
|
||||
ok(db1 !== db2, "Databases are not the same object");
|
||||
|
||||
is(db1.objectStoreNames.length, 1, "1 objectStore in db1");
|
||||
is(db1.objectStoreNames.item(0), objectStore.name, "Correct name");
|
||||
|
||||
is(db2.objectStoreNames.length, 1, "1 objectStore in db2");
|
||||
is(db2.objectStoreNames.item(0), objectStore.name, "Correct name");
|
||||
|
||||
let objectStore1 = db1.transaction(objectStore.name)
|
||||
.objectStore(objectStore.name);
|
||||
is(objectStore1.name, objectStore.name, "Same name");
|
||||
is(objectStore1.keyPath, objectStore.options.keyPath, "Same keyPath");
|
||||
|
||||
let objectStore2 = db2.transaction(objectStore.name)
|
||||
.objectStore(objectStore.name);
|
||||
|
||||
ok(objectStore1 !== objectStore2, "Different objectStores");
|
||||
is(objectStore1.name, objectStore2.name, "Same name");
|
||||
is(objectStore1.keyPath, objectStore2.keyPath, "Same keyPath");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "1", value: "foo" },
|
||||
{ key: "2", value: "bar" },
|
||||
{ key: "3", value: "baz" }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield; // upgradeneeded
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("data", { keyPath: null });
|
||||
|
||||
// First, add all our data to the object store.
|
||||
let addedData = 0;
|
||||
for (let i in objectStoreData) {
|
||||
request = objectStore.add(objectStoreData[i].value,
|
||||
objectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == objectStoreData.length) {
|
||||
testGenerator.send(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
event = yield; // testGenerator.send
|
||||
|
||||
// Now create the index.
|
||||
objectStore.createIndex("set", "", { unique: true });
|
||||
yield; // success
|
||||
|
||||
let trans = db.transaction("data", IDBTransaction.READ_WRITE);
|
||||
objectStore = trans.objectStore("data");
|
||||
index = objectStore.index("set");
|
||||
|
||||
let request = index.get("bar");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
let event = yield;
|
||||
|
||||
is(event.target.result, "bar", "Got correct result");
|
||||
|
||||
let request = objectStore.add("foopy", 4);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
|
||||
let request = index.get("foopy");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
let event = yield;
|
||||
|
||||
is(event.target.result, "foopy", "Got correct result");
|
||||
|
||||
let request = objectStore.add("foopy", 5);
|
||||
request.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
|
||||
trans.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "People";
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } }
|
||||
];
|
||||
|
||||
const indexData = [
|
||||
{ name: "name", keyPath: "name", options: { unique: true } },
|
||||
{ name: "height", keyPath: "height", options: { unique: false } },
|
||||
{ name: "weight", keyPath: "weight", options: { unique: false } }
|
||||
];
|
||||
|
||||
const objectStoreDataNameSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }
|
||||
];
|
||||
|
||||
const objectStoreDataWeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
const objectStoreDataHeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName);
|
||||
|
||||
// First, add all our data to the object store.
|
||||
let addedData = 0;
|
||||
for (let i in objectStoreData) {
|
||||
request = objectStore.add(objectStoreData[i].value,
|
||||
objectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == objectStoreData.length) {
|
||||
testGenerator.send(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
yield;
|
||||
ok(true, "1");
|
||||
|
||||
// Now create the indexes.
|
||||
for (let i in indexData) {
|
||||
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
|
||||
indexData[i].options);
|
||||
}
|
||||
|
||||
is(objectStore.indexNames.length, indexData.length, "Good index count");
|
||||
yield;
|
||||
|
||||
ok(true, "2");
|
||||
objectStore = db.transaction(objectStoreName)
|
||||
.objectStore(objectStoreName);
|
||||
|
||||
request = objectStore.index("height").getAllKeys(65);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "3");
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
||||
"Correct key");
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAllKeys();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "4");
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, objectStoreDataHeightSort.length,
|
||||
"Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAllKeys(null, 4);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(true, "5");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAllKeys(65, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(true, "6");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 1, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
||||
"Correct key");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "People";
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } }
|
||||
];
|
||||
|
||||
const indexData = [
|
||||
{ name: "name", keyPath: "name", options: { unique: true } },
|
||||
{ name: "height", keyPath: "height", options: { unique: false } },
|
||||
{ name: "weight", keyPath: "weight", options: { unique: false } }
|
||||
];
|
||||
|
||||
const objectStoreDataNameSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }
|
||||
];
|
||||
|
||||
const objectStoreDataWeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
const objectStoreDataHeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName, {});
|
||||
|
||||
// First, add all our data to the object store.
|
||||
let addedData = 0;
|
||||
for (let i in objectStoreData) {
|
||||
request = objectStore.add(objectStoreData[i].value,
|
||||
objectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == objectStoreData.length) {
|
||||
testGenerator.send(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
event = yield;
|
||||
|
||||
// Now create the indexes.
|
||||
for (let i in indexData) {
|
||||
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
|
||||
indexData[i].options);
|
||||
}
|
||||
|
||||
is(objectStore.indexNames.length, indexData.length, "Good index count");
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction(objectStoreName)
|
||||
.objectStore(objectStoreName);
|
||||
|
||||
request = objectStore.index("height").getAll(65);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
is(result.height, testObj.height, "Correct height");
|
||||
|
||||
if (testObj.hasOwnProperty("weight")) {
|
||||
is(result.weight, testObj.weight, "Correct weight");
|
||||
}
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAll();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, objectStoreDataHeightSort.length,
|
||||
"Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[i].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
is(result.height, testObj.height, "Correct height");
|
||||
|
||||
if (testObj.hasOwnProperty("weight")) {
|
||||
is(result.weight, testObj.weight, "Correct weight");
|
||||
}
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAll(null, 4);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[i].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
is(result.height, testObj.height, "Correct height");
|
||||
|
||||
if (testObj.hasOwnProperty("weight")) {
|
||||
is(result.weight, testObj.weight, "Correct weight");
|
||||
}
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAll(65, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 1, "Correct length");
|
||||
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
is(result.height, testObj.height, "Correct height");
|
||||
|
||||
if (testObj.hasOwnProperty("weight")) {
|
||||
is(result.weight, testObj.weight, "Correct weight");
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const objectStoreData = [
|
||||
{ name: "", options: { keyPath: "id", autoIncrement: true } },
|
||||
{ name: null, options: { keyPath: "ss" } },
|
||||
{ name: undefined, options: { } },
|
||||
{ name: "4", options: { autoIncrement: true } },
|
||||
];
|
||||
|
||||
const indexData = [
|
||||
{ name: "", keyPath: "name", options: { unique: true } },
|
||||
{ name: null, keyPath: "height", options: { } }
|
||||
];
|
||||
|
||||
const data = [
|
||||
{ ss: "237-23-7732", name: "Ann", height: 60 },
|
||||
{ ss: "237-23-7733", name: "Bob", height: 65 }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
for (let objectStoreIndex in objectStoreData) {
|
||||
const objectStoreInfo = objectStoreData[objectStoreIndex];
|
||||
let objectStore = db.createObjectStore(objectStoreInfo.name,
|
||||
objectStoreInfo.options);
|
||||
for (let indexIndex in indexData) {
|
||||
const indexInfo = indexData[indexIndex];
|
||||
let index = objectStore.createIndex(indexInfo.name,
|
||||
indexInfo.keyPath,
|
||||
indexInfo.options);
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
ok(true, "Initial setup");
|
||||
|
||||
for (let objectStoreIndex in objectStoreData) {
|
||||
const info = objectStoreData[objectStoreIndex];
|
||||
|
||||
for (let indexIndex in indexData) {
|
||||
const objectStoreName = objectStoreData[objectStoreIndex].name;
|
||||
const indexName = indexData[indexIndex].name;
|
||||
|
||||
let objectStore =
|
||||
db.transaction(objectStoreName, IDBTransaction.READ_WRITE)
|
||||
.objectStore(objectStoreName);
|
||||
ok(true, "Got objectStore " + objectStoreName);
|
||||
|
||||
for (let dataIndex in data) {
|
||||
const obj = data[dataIndex];
|
||||
let key;
|
||||
if (!info.options.keyPath && !info.options.autoIncrement) {
|
||||
key = obj.ss;
|
||||
}
|
||||
objectStore.add(obj, key);
|
||||
}
|
||||
|
||||
let index = objectStore.index(indexName);
|
||||
ok(true, "Got index " + indexName);
|
||||
|
||||
let keyIndex = 0;
|
||||
|
||||
index.openCursor().onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (!cursor) {
|
||||
continueToNextStep();
|
||||
return;
|
||||
}
|
||||
|
||||
is(cursor.key, data[keyIndex][indexData[indexIndex].keyPath],
|
||||
"Good key");
|
||||
is(cursor.value.ss, data[keyIndex].ss, "Correct ss");
|
||||
is(cursor.value.name, data[keyIndex].name, "Correct name");
|
||||
is(cursor.value.height, data[keyIndex].height, "Correct height");
|
||||
|
||||
if (!keyIndex) {
|
||||
let obj = cursor.value;
|
||||
obj.updated = true;
|
||||
|
||||
cursor.update(obj).onsuccess = function(event) {
|
||||
ok(true, "Object updated");
|
||||
cursor.continue();
|
||||
keyIndex++
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cursor.delete().onsuccess = function(event) {
|
||||
ok(true, "Object deleted");
|
||||
cursor.continue();
|
||||
keyIndex++
|
||||
}
|
||||
};
|
||||
yield;
|
||||
|
||||
is(keyIndex, 2, "Saw all the items");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
db.transaction(objectStoreName).objectStore(objectStoreName)
|
||||
.openCursor()
|
||||
.onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (!cursor) {
|
||||
continueToNextStep();
|
||||
return;
|
||||
}
|
||||
|
||||
is(cursor.value.ss, data[keyIndex].ss, "Correct ss");
|
||||
is(cursor.value.name, data[keyIndex].name, "Correct name");
|
||||
is(cursor.value.height, data[keyIndex].height, "Correct height");
|
||||
is(cursor.value.updated, true, "Correct updated flag");
|
||||
|
||||
cursor.continue();
|
||||
keyIndex++;
|
||||
};
|
||||
yield;
|
||||
|
||||
is(keyIndex, 1, "Saw all the items");
|
||||
|
||||
db.transaction(objectStoreName, IDBTransaction.READ_WRITE)
|
||||
.objectStore(objectStoreName).clear()
|
||||
.onsuccess = continueToNextStep;
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
let name = this.window ? window.location.pathname : "Splendid Test";
|
||||
let request = mozIndexedDB.open(name, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
for each (let autoIncrement in [false, true]) {
|
||||
let objectStore =
|
||||
db.createObjectStore(autoIncrement, { keyPath: "id",
|
||||
autoIncrement: autoIncrement });
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
objectStore.add({ id: i, index: i });
|
||||
}
|
||||
|
||||
for each (let unique in [false, true]) {
|
||||
objectStore.createIndex(unique, "index", { unique: unique });
|
||||
}
|
||||
|
||||
for (let i = 10; i < 20; i++) {
|
||||
objectStore.add({ id: i, index: i });
|
||||
}
|
||||
}
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
|
||||
for each (let autoIncrement in [false, true]) {
|
||||
let objectStore = db.transaction(autoIncrement)
|
||||
.objectStore(autoIncrement);
|
||||
|
||||
objectStore.count().onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
is(event.target.result, 20, "Correct number of entries in objectStore");
|
||||
|
||||
let objectStoreCount = event.target.result;
|
||||
let indexCount = event.target.result;
|
||||
|
||||
for each (let unique in [false, true]) {
|
||||
let index = db.transaction(autoIncrement, IDBTransaction.READ_WRITE)
|
||||
.objectStore(autoIncrement)
|
||||
.index(unique);
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
is(event.target.result, indexCount,
|
||||
"Correct number of entries in index");
|
||||
|
||||
let modifiedEntry = unique ? 5 : 10;
|
||||
let keyRange = IDBKeyRange.only(modifiedEntry);
|
||||
|
||||
let sawEntry = false;
|
||||
index.openCursor(keyRange).onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
sawEntry = true;
|
||||
is(cursor.key, modifiedEntry, "Correct key");
|
||||
|
||||
cursor.value.index = unique ? 30 : 35;
|
||||
cursor.update(cursor.value).onsuccess = function(event) {
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(sawEntry, true, "Saw entry for key value " + modifiedEntry);
|
||||
|
||||
// Recount index. Shouldn't change.
|
||||
index = db.transaction(autoIncrement, IDBTransaction.READ_WRITE)
|
||||
.objectStore(autoIncrement)
|
||||
.index(unique);
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, indexCount,
|
||||
"Correct number of entries in index");
|
||||
|
||||
modifiedEntry = unique ? 30 : 35;
|
||||
keyRange = IDBKeyRange.only(modifiedEntry);
|
||||
|
||||
sawEntry = false;
|
||||
index.openCursor(keyRange).onsuccess = function(event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
sawEntry = true;
|
||||
is(cursor.key, modifiedEntry, "Correct key");
|
||||
|
||||
delete cursor.value.index;
|
||||
cursor.update(cursor.value).onsuccess = function(event) {
|
||||
indexCount--;
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
continueToNextStep();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(sawEntry, true, "Saw entry for key value " + modifiedEntry);
|
||||
|
||||
// Recount objectStore. Should be unchanged.
|
||||
objectStore = db.transaction(autoIncrement, IDBTransaction.READ_WRITE)
|
||||
.objectStore(autoIncrement);
|
||||
|
||||
objectStore.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreCount,
|
||||
"Correct number of entries in objectStore");
|
||||
|
||||
// Recount index. Should be one item less.
|
||||
index = objectStore.index(unique);
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, indexCount,
|
||||
"Correct number of entries in index");
|
||||
|
||||
modifiedEntry = objectStoreCount - 1;
|
||||
|
||||
objectStore.delete(modifiedEntry).onsuccess =
|
||||
grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
objectStoreCount--;
|
||||
indexCount--;
|
||||
|
||||
objectStore.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, objectStoreCount,
|
||||
"Correct number of entries in objectStore");
|
||||
|
||||
index.count().onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, indexCount,
|
||||
"Correct number of entries in index");
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,135 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const CONSTRAINT_ERR =
|
||||
Components.interfaces.nsIIDBDatabaseException.CONSTRAINT_ERR;
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
const objectStoreName = "People";
|
||||
|
||||
const objectStoreData = [
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
|
||||
{ key: "237-23-7738", value: { name: "Mel", height: 66, weight: {} } }
|
||||
];
|
||||
|
||||
const badObjectStoreData = [
|
||||
{ key: "237-23-7739", value: { name: "Rob", height: 65 } },
|
||||
{ key: "237-23-7740", value: { name: "Jen", height: 66, weight: {} } }
|
||||
];
|
||||
|
||||
const indexData = [
|
||||
{ name: "weight", keyPath: "weight", options: { unique: false } }
|
||||
];
|
||||
|
||||
const objectStoreDataWeightSort = [
|
||||
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
|
||||
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
|
||||
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
|
||||
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
|
||||
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
|
||||
];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName, { } );
|
||||
|
||||
let addedData = 0;
|
||||
for (let i in objectStoreData) {
|
||||
request = objectStore.add(objectStoreData[i].value,
|
||||
objectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == objectStoreData.length) {
|
||||
testGenerator.send(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
event = yield;
|
||||
|
||||
for (let i in indexData) {
|
||||
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
|
||||
indexData[i].options);
|
||||
}
|
||||
|
||||
addedData = 0;
|
||||
for (let i in badObjectStoreData) {
|
||||
request = objectStore.add(badObjectStoreData[i].value,
|
||||
badObjectStoreData[i].key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedData == badObjectStoreData.length) {
|
||||
executeSoon(function() { testGenerator.next() });
|
||||
}
|
||||
}
|
||||
}
|
||||
yield;
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction(objectStoreName)
|
||||
.objectStore(objectStoreName);
|
||||
|
||||
let keyIndex = 0;
|
||||
|
||||
request = objectStore.index("weight").openKeyCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
|
||||
"Correct key");
|
||||
is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key,
|
||||
"Correct value");
|
||||
keyIndex++;
|
||||
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, objectStoreDataWeightSort.length, "Saw all weights");
|
||||
|
||||
keyIndex = 0;
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
keyIndex++;
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
testGenerator.next();
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(keyIndex, objectStoreData.length + badObjectStoreData.length,
|
||||
"Saw all people");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,282 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
db.addEventListener("error", function(event) {
|
||||
event.preventDefault();
|
||||
}, false);
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
request = objectStore.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let key1 = event.target.result;
|
||||
|
||||
request = objectStore.put({}, key1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "put gave the same key back");
|
||||
|
||||
let key2 = 10;
|
||||
|
||||
request = objectStore.put({}, key2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key2, "put gave the same key back");
|
||||
|
||||
key2 = 100;
|
||||
|
||||
request = objectStore.add({}, key2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key2, "put gave the same key back");
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(true, "put with no key should not throw with autoIncrement!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(false, "put with no key threw with autoIncrement");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(true, "put with no key should not throw with autoIncrement!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(false, "put with no key threw with autoIncrement");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete();
|
||||
ok(false, "remove with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with no key threw");
|
||||
}
|
||||
|
||||
objectStore = db.createObjectStore("bar");
|
||||
|
||||
try {
|
||||
objectStore.add({});
|
||||
ok(false, "add with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(false, "put with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(false, "put with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete();
|
||||
ok(false, "remove with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with no key threw");
|
||||
}
|
||||
|
||||
objectStore = db.createObjectStore("baz", { keyPath: "id" });
|
||||
|
||||
try {
|
||||
objectStore.add({});
|
||||
ok(false, "add with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.add({id:5}, 5);
|
||||
ok(false, "add with inline key and passed key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with inline key and passed key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(false, "put with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(false, "put with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete();
|
||||
ok(false, "remove with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with no key threw");
|
||||
}
|
||||
|
||||
key1 = 10;
|
||||
|
||||
request = objectStore.add({id:key1});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "add gave back the same key");
|
||||
|
||||
request = objectStore.put({id:10});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "put gave back the same key");
|
||||
|
||||
request = objectStore.put({id:10});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "put gave back the same key");
|
||||
|
||||
request = objectStore.add({id:10});
|
||||
request.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
event = yield;
|
||||
|
||||
try {
|
||||
objectStore.add({}, null);
|
||||
ok(false, "add with null key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with null key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({}, null);
|
||||
ok(false, "put with null key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with null key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({}, null);
|
||||
ok(false, "put with null key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "put with null key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete({}, null);
|
||||
ok(false, "remove with null key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with null key threw");
|
||||
}
|
||||
|
||||
objectStore = db.createObjectStore("bazing", { keyPath: "id",
|
||||
autoIncrement: true });
|
||||
|
||||
request = objectStore.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
key1 = event.target.result;
|
||||
|
||||
request = objectStore.put({id:key1});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key1, "put gave the same key back");
|
||||
|
||||
key2 = 10;
|
||||
|
||||
request = objectStore.put({id:key2});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.target.result, key2, "put gave the same key back");
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(true, "put with no key should not throw with autoIncrement!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(false, "put with no key threw with autoIncrement");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
ok(true, "put with no key should not throw with autoIncrement!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(false, "put with no key threw with autoIncrement");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.delete();
|
||||
ok(false, "remove with no key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "remove with no key threw");
|
||||
}
|
||||
|
||||
try {
|
||||
objectStore.add({id:5}, 5);
|
||||
ok(false, "add with inline key and passed key should throw!");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "add with inline key and passed key threw");
|
||||
}
|
||||
|
||||
request = objectStore.delete(key2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,263 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const dbname = this.window ? window.location.pathname : "Splendid Test";
|
||||
const RW = IDBTransaction.READ_WRITE
|
||||
let c1 = 1;
|
||||
let c2 = 1;
|
||||
|
||||
let openRequest = mozIndexedDB.open(dbname, 1);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
let trans = event.target.transaction;
|
||||
|
||||
// Create test stores
|
||||
let store = db.createObjectStore("store");
|
||||
|
||||
// Test simple inserts
|
||||
var keys = [
|
||||
-1/0,
|
||||
-1.7e308,
|
||||
-10000,
|
||||
-2,
|
||||
-1.5,
|
||||
-1,
|
||||
-1.00001e-200,
|
||||
-1e-200,
|
||||
0,
|
||||
1e-200,
|
||||
1.00001e-200,
|
||||
1,
|
||||
2,
|
||||
10000,
|
||||
1.7e308,
|
||||
1/0,
|
||||
new Date("1750-01-02"),
|
||||
new Date("1800-12-31T12:34:56.001"),
|
||||
new Date(-1000),
|
||||
new Date(-10),
|
||||
new Date(-1),
|
||||
new Date(0),
|
||||
new Date(1),
|
||||
new Date(2),
|
||||
new Date(1000),
|
||||
new Date("1971-01-01"),
|
||||
new Date("1971-01-01T01:01:01"),
|
||||
new Date("1971-01-01T01:01:01.001"),
|
||||
new Date("1971-01-01T01:01:01.01"),
|
||||
new Date("1971-01-01T01:01:01.1"),
|
||||
new Date("1980-02-02"),
|
||||
new Date("3333-03-19T03:33:33.333"),
|
||||
"",
|
||||
"\x00",
|
||||
"\x00\x00",
|
||||
"\x00\x01",
|
||||
"\x01",
|
||||
"\x02",
|
||||
"\x03",
|
||||
"\x04",
|
||||
"\x07",
|
||||
"\x08",
|
||||
"\x0F",
|
||||
"\x10",
|
||||
"\x1F",
|
||||
"\x20",
|
||||
"01234",
|
||||
"\x3F",
|
||||
"\x40",
|
||||
"A",
|
||||
"A\x00",
|
||||
"A1",
|
||||
"ZZZZ",
|
||||
"a",
|
||||
"a\x00",
|
||||
"aa",
|
||||
"azz",
|
||||
"}",
|
||||
"\x7E",
|
||||
"\x7F",
|
||||
"\x80",
|
||||
"\xFF",
|
||||
"\u0100",
|
||||
"\u01FF",
|
||||
"\u0200",
|
||||
"\u03FF",
|
||||
"\u0400",
|
||||
"\u07FF",
|
||||
"\u0800",
|
||||
"\u0FFF",
|
||||
"\u1000",
|
||||
"\u1FFF",
|
||||
"\u2000",
|
||||
"\u3FFF",
|
||||
"\u4000",
|
||||
"\u7FFF",
|
||||
"\u8000",
|
||||
"\uD800",
|
||||
"\uD800a",
|
||||
"\uD800\uDC01",
|
||||
"\uDBFF",
|
||||
"\uDC00",
|
||||
"\uDFFF\uD800",
|
||||
"\uFFFE",
|
||||
"\uFFFF",
|
||||
"\uFFFF\x00",
|
||||
"\uFFFFZZZ",
|
||||
[],
|
||||
[-1/0],
|
||||
[-1],
|
||||
[0],
|
||||
[1],
|
||||
[1, "a"],
|
||||
[1, []],
|
||||
[1, [""]],
|
||||
[2, 3],
|
||||
[2, 3.0000000000001],
|
||||
[12, [[]]],
|
||||
[12, [[[]]]],
|
||||
[12, [[[""]]]],
|
||||
[12, [[["foo"]]]],
|
||||
[12, [[[[[3]]]]]],
|
||||
[12, [[[[[[3]]]]]]],
|
||||
[new Date(-1)],
|
||||
[new Date(1)],
|
||||
[""],
|
||||
["", [[]]],
|
||||
["", [[[]]]],
|
||||
["abc"],
|
||||
["abc", "def"],
|
||||
["abc\x00"],
|
||||
["abc\x00", "\x00\x01"],
|
||||
["abc\x00", "\x00def"],
|
||||
["abc\x00\x00def"],
|
||||
["x", [[]]],
|
||||
["x", [[[]]]],
|
||||
[[]],
|
||||
[[],"foo"],
|
||||
[[],[]],
|
||||
[[[]]],
|
||||
[[[]], []],
|
||||
[[[]], [[]]],
|
||||
[[[]], [[1]]],
|
||||
[[[]], [[[]]]],
|
||||
[[[1]]],
|
||||
[[[[]], []]],
|
||||
];
|
||||
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
let keyI = keys[i];
|
||||
is(mozIndexedDB.cmp(keyI, keyI), 0, i + " compared to self");
|
||||
|
||||
function doCompare(keyI) {
|
||||
for (var j = i-1; j >= i-10 && j >= 0; --j) {
|
||||
is(mozIndexedDB.cmp(keyI, keys[j]), 1, i + " compared to " + j);
|
||||
is(mozIndexedDB.cmp(keys[j], keyI), -1, j + " compared to " + i);
|
||||
}
|
||||
}
|
||||
|
||||
doCompare(keyI);
|
||||
store.add(i, keyI).onsuccess = function(e) {
|
||||
is(mozIndexedDB.cmp(e.target.result, keyI), 0,
|
||||
"Returned key should cmp as equal");
|
||||
ok(compareKeys(e.target.result, keyI),
|
||||
"Returned key should actually be equal");
|
||||
};
|
||||
|
||||
// Test that -0 compares the same as 0
|
||||
if (keyI === 0) {
|
||||
doCompare(-0);
|
||||
let req = store.add(i, -0);
|
||||
req.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
req.onsuccess = unexpectedSuccessHandler;
|
||||
yield;
|
||||
}
|
||||
else if (Array.isArray(keyI) && keyI.length === 1 && keyI[0] === 0) {
|
||||
doCompare([-0]);
|
||||
let req = store.add(i, [-0]);
|
||||
req.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
req.onsuccess = unexpectedSuccessHandler;
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
store.openCursor().onsuccess = grabEventAndContinueHandler;
|
||||
for (i = 0; i < keys.length; ++i) {
|
||||
event = yield;
|
||||
let cursor = event.target.result;
|
||||
is(mozIndexedDB.cmp(cursor.key, keys[i]), 0,
|
||||
"Read back key should cmp as equal");
|
||||
ok(compareKeys(cursor.key, keys[i]),
|
||||
"Read back key should actually be equal");
|
||||
is(cursor.value, i, "Stored with right value");
|
||||
|
||||
cursor.continue();
|
||||
}
|
||||
event = yield;
|
||||
is(event.target.result, undefined, "no more results expected");
|
||||
|
||||
var nan = 0/0;
|
||||
var invalidKeys = [
|
||||
nan,
|
||||
undefined,
|
||||
null,
|
||||
/x/,
|
||||
{},
|
||||
[nan],
|
||||
[undefined],
|
||||
[null],
|
||||
[/x/],
|
||||
[{}],
|
||||
[1, nan],
|
||||
[1, undefined],
|
||||
[1, null],
|
||||
[1, /x/],
|
||||
[1, {}],
|
||||
[1, [nan]],
|
||||
[1, [undefined]],
|
||||
[1, [null]],
|
||||
[1, [/x/]],
|
||||
[1, [{}]],
|
||||
];
|
||||
|
||||
for (i = 0; i < invalidKeys.length; ++i) {
|
||||
try {
|
||||
mozIndexedDB.cmp(invalidKeys[i], 1);
|
||||
ok(false, "didn't throw");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Threw IDBDatabaseException");
|
||||
is(ex.code, IDBDatabaseException.DATA_ERR, "Threw right IDBDatabaseException");
|
||||
}
|
||||
try {
|
||||
mozIndexedDB.cmp(1, invalidKeys[i]);
|
||||
ok(false, "didn't throw2");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Threw IDBDatabaseException2");
|
||||
is(ex.code, IDBDatabaseException.DATA_ERR, "Threw right IDBDatabaseException2");
|
||||
}
|
||||
try {
|
||||
store.put(1, invalidKeys[i]);
|
||||
ok(false, "didn't throw3");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Threw IDBDatabaseException3");
|
||||
is(ex.code, IDBDatabaseException.DATA_ERR, "Threw right IDBDatabaseException3");
|
||||
}
|
||||
}
|
||||
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,219 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
// Test object stores
|
||||
|
||||
let name = this.window ? window.location.pathname : "Splendid Test";
|
||||
let openRequest = mozIndexedDB.open(name, 1);
|
||||
openRequest.onerror = errorHandler;
|
||||
openRequest.onupgradeneeded = grabEventAndContinueHandler;
|
||||
openRequest.onsuccess = unexpectedSuccessHandler;
|
||||
let event = yield;
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
let tests =
|
||||
[{ add: { x: 1, id: 1 },
|
||||
indexes:[{ v: 1, k: 1 }] },
|
||||
{ add: { x: [2, 3], id: 2 },
|
||||
indexes:[{ v: 1, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 }] },
|
||||
{ put: { x: [2, 4], id: 1 },
|
||||
indexes:[{ v: 2, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 },
|
||||
{ v: 4, k: 1 }] },
|
||||
{ add: { x: [5, 6, 5, -2, 3], id: 3 },
|
||||
indexes:[{ v:-2, k: 3 },
|
||||
{ v: 2, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 },
|
||||
{ v: 3, k: 3 },
|
||||
{ v: 4, k: 1 },
|
||||
{ v: 5, k: 3 },
|
||||
{ v: 6, k: 3 }] },
|
||||
{ delete: IDBKeyRange.bound(1, 3),
|
||||
indexes:[] },
|
||||
{ put: { x: ["food", {}, false, undefined, /x/, [73, false]], id: 2 },
|
||||
indexes:[{ v: "food", k: 2 }] },
|
||||
{ add: { x: [{}, /x/, -12, "food", null, [false], undefined], id: 3 },
|
||||
indexes:[{ v: -12, k: 3 },
|
||||
{ v: "food", k: 2 },
|
||||
{ v: "food", k: 3 }] },
|
||||
{ put: { x: [], id: 2 },
|
||||
indexes:[{ v: -12, k: 3 },
|
||||
{ v: "food", k: 3 }] },
|
||||
{ put: { x: { y: 3 }, id: 3 },
|
||||
indexes:[] },
|
||||
{ add: { x: false, id: 7 },
|
||||
indexes:[] },
|
||||
{ delete: IDBKeyRange.lowerBound(0),
|
||||
indexes:[] },
|
||||
];
|
||||
|
||||
let store = db.createObjectStore("mystore", { keyPath: "id" });
|
||||
let index = store.createIndex("myindex", "x", { multiEntry: true });
|
||||
is(index.multiEntry, true, "index created with multiEntry");
|
||||
|
||||
let i;
|
||||
for (i = 0; i < tests.length; ++i) {
|
||||
let test = tests[i];
|
||||
let testName = " for " + JSON.stringify(test);
|
||||
let req;
|
||||
if (test.add) {
|
||||
req = store.add(test.add);
|
||||
}
|
||||
else if (test.put) {
|
||||
req = store.put(test.put);
|
||||
}
|
||||
else if (test.delete) {
|
||||
req = store.delete(test.delete);
|
||||
}
|
||||
else {
|
||||
ok(false, "borked test");
|
||||
}
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
let e = yield;
|
||||
|
||||
req = index.openKeyCursor();
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
for (let j = 0; j < test.indexes.length; ++j) {
|
||||
e = yield;
|
||||
is(req.result.key, test.indexes[j].v, "found expected index key at index " + j + testName);
|
||||
is(req.result.primaryKey, test.indexes[j].k, "found expected index primary key at index " + j + testName);
|
||||
req.result.continue();
|
||||
}
|
||||
e = yield;
|
||||
is(req.result, undefined, "exhausted indexes");
|
||||
|
||||
let tempIndex = store.createIndex("temp index", "x", { multiEntry: true });
|
||||
req = tempIndex.openKeyCursor();
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
for (let j = 0; j < test.indexes.length; ++j) {
|
||||
e = yield;
|
||||
is(req.result.key, test.indexes[j].v, "found expected temp index key at index " + j + testName);
|
||||
is(req.result.primaryKey, test.indexes[j].k, "found expected temp index primary key at index " + j + testName);
|
||||
req.result.continue();
|
||||
}
|
||||
e = yield;
|
||||
is(req.result, undefined, "exhausted temp index");
|
||||
store.deleteIndex("temp index");
|
||||
}
|
||||
|
||||
// Unique indexes
|
||||
tests =
|
||||
[{ add: { x: 1, id: 1 },
|
||||
indexes:[{ v: 1, k: 1 }] },
|
||||
{ add: { x: [2, 3], id: 2 },
|
||||
indexes:[{ v: 1, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 }] },
|
||||
{ put: { x: [2, 4], id: 3 },
|
||||
fail: true },
|
||||
{ put: { x: [1, 4], id: 1 },
|
||||
indexes:[{ v: 1, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 },
|
||||
{ v: 4, k: 1 }] },
|
||||
{ add: { x: [5, 0, 5, 5, 5], id: 3 },
|
||||
indexes:[{ v: 0, k: 3 },
|
||||
{ v: 1, k: 1 },
|
||||
{ v: 2, k: 2 },
|
||||
{ v: 3, k: 2 },
|
||||
{ v: 4, k: 1 },
|
||||
{ v: 5, k: 3 }] },
|
||||
{ delete: IDBKeyRange.bound(1, 2),
|
||||
indexes:[{ v: 0, k: 3 },
|
||||
{ v: 5, k: 3 }] },
|
||||
{ add: { x: [0, 6], id: 8 },
|
||||
fail: true },
|
||||
{ add: { x: 5, id: 8 },
|
||||
fail: true },
|
||||
{ put: { x: 0, id: 8 },
|
||||
fail: true },
|
||||
];
|
||||
|
||||
store.deleteIndex("myindex");
|
||||
index = store.createIndex("myindex", "x", { multiEntry: true, unique: true });
|
||||
is(index.multiEntry, true, "index created with multiEntry");
|
||||
|
||||
let i;
|
||||
let indexes;
|
||||
for (i = 0; i < tests.length; ++i) {
|
||||
let test = tests[i];
|
||||
let testName = " for " + JSON.stringify(test);
|
||||
let req;
|
||||
if (test.add) {
|
||||
req = store.add(test.add);
|
||||
}
|
||||
else if (test.put) {
|
||||
req = store.put(test.put);
|
||||
}
|
||||
else if (test.delete) {
|
||||
req = store.delete(test.delete);
|
||||
}
|
||||
else {
|
||||
ok(false, "borked test");
|
||||
}
|
||||
|
||||
if (!test.fail) {
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
let e = yield;
|
||||
indexes = test.indexes;
|
||||
}
|
||||
else {
|
||||
req.onsuccess = unexpectedSuccessHandler;
|
||||
req.onerror = grabEventAndContinueHandler;
|
||||
ok(true, "waiting for error");
|
||||
let e = yield;
|
||||
ok(true, "got error: " + e.type);
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
let e;
|
||||
req = index.openKeyCursor();
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
for (let j = 0; j < indexes.length; ++j) {
|
||||
e = yield;
|
||||
is(req.result.key, indexes[j].v, "found expected index key at index " + j + testName);
|
||||
is(req.result.primaryKey, indexes[j].k, "found expected index primary key at index " + j + testName);
|
||||
req.result.continue();
|
||||
}
|
||||
e = yield;
|
||||
is(req.result, undefined, "exhausted indexes");
|
||||
|
||||
let tempIndex = store.createIndex("temp index", "x", { multiEntry: true, unique: true });
|
||||
req = tempIndex.openKeyCursor();
|
||||
req.onsuccess = grabEventAndContinueHandler;
|
||||
for (let j = 0; j < indexes.length; ++j) {
|
||||
e = yield;
|
||||
is(req.result.key, indexes[j].v, "found expected temp index key at index " + j + testName);
|
||||
is(req.result.primaryKey, indexes[j].k, "found expected temp index primary key at index " + j + testName);
|
||||
req.result.continue();
|
||||
}
|
||||
e = yield;
|
||||
is(req.result, undefined, "exhausted temp index");
|
||||
store.deleteIndex("temp index");
|
||||
}
|
||||
|
||||
|
||||
openRequest.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
let trans = db.transaction(["mystore"], IDBTransaction.READ_WRITE);
|
||||
store = trans.objectStore("mystore");
|
||||
index = store.index("myindex");
|
||||
is(index.multiEntry, true, "index still is multiEntry");
|
||||
trans.oncomplete = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
const objectStores = [
|
||||
{ name: "a", autoIncrement: false },
|
||||
{ name: "b", autoIncrement: true }
|
||||
];
|
||||
|
||||
const indexes = [
|
||||
{ name: "a", options: { } },
|
||||
{ name: "b", options: { unique: true } }
|
||||
];
|
||||
|
||||
var j = 0;
|
||||
for (let i in objectStores) {
|
||||
let request = mozIndexedDB.open(name, ++j, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore =
|
||||
db.createObjectStore(objectStores[i].name,
|
||||
{ keyPath: "id",
|
||||
autoIncrement: objectStores[i].autoIncrement });
|
||||
|
||||
for (let j in indexes) {
|
||||
objectStore.createIndex(indexes[j].name, "name", indexes[j].options);
|
||||
}
|
||||
|
||||
let data = { name: "Ben" };
|
||||
if (!objectStores[i].autoIncrement) {
|
||||
data.id = 1;
|
||||
}
|
||||
|
||||
request = objectStore.add(data);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.target.result == 1 || event.target.result == 2, "Good id");
|
||||
db.close();
|
||||
}
|
||||
|
||||
executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
|
||||
let request = mozIndexedDB.open(name, j, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
for (let i in objectStores) {
|
||||
for (let j in indexes) {
|
||||
let objectStore = db.transaction(objectStores[i].name)
|
||||
.objectStore(objectStores[i].name);
|
||||
let index = objectStore.index(indexes[j].name);
|
||||
|
||||
request = index.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
is(event.target.result.value.name, "Ben", "Good object");
|
||||
executeSoon(function() { testGenerator.next(); });
|
||||
}
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const IDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const IDBDatabaseException = Components.interfaces.nsIIDBDatabaseException;
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
var request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
var event = yield;
|
||||
|
||||
var db = event.target.result;
|
||||
|
||||
var test = {
|
||||
name: "inline key; key generator",
|
||||
autoIncrement: true,
|
||||
storedObject: {name: "Lincoln"},
|
||||
keyName: "id",
|
||||
};
|
||||
|
||||
let objectStore = db.createObjectStore(test.name,
|
||||
{ keyPath: test.keyName,
|
||||
autoIncrement: test.autoIncrement });
|
||||
|
||||
request = objectStore.add(test.storedObject);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let id = event.target.result;
|
||||
request = objectStore.get(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
// Sanity check!
|
||||
is(event.target.result.name, test.storedObject.name,
|
||||
"The correct object was stored.");
|
||||
|
||||
// Ensure that the id was also stored on the object.
|
||||
is(event.target.result.id, id, "The object had the id stored on it.");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const IDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const IDBDatabaseException = Components.interfaces.nsIIDBDatabaseException;
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
var data = [
|
||||
{ name: "inline key; key generator",
|
||||
autoIncrement: true,
|
||||
storedObject: {name: "Lincoln"},
|
||||
keyName: "id",
|
||||
keyValue: undefined,
|
||||
},
|
||||
{ name: "inline key; no key generator",
|
||||
autoIncrement: false,
|
||||
storedObject: {id: 1, name: "Lincoln"},
|
||||
keyName: "id",
|
||||
keyValue: undefined,
|
||||
},
|
||||
{ name: "out of line key; key generator",
|
||||
autoIncrement: true,
|
||||
storedObject: {name: "Lincoln"},
|
||||
keyName: undefined,
|
||||
keyValue: undefined,
|
||||
},
|
||||
{ name: "out of line key; no key generator",
|
||||
autoIncrement: false,
|
||||
storedObject: {name: "Lincoln"},
|
||||
keyName: null,
|
||||
keyValue: 1,
|
||||
}
|
||||
];
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let test = data[i];
|
||||
|
||||
let request = mozIndexedDB.open(name, i+1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(test.name,
|
||||
{ keyPath: test.keyName,
|
||||
autoIncrement: test.autoIncrement });
|
||||
|
||||
request = objectStore.add(test.storedObject, test.keyValue);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let id = event.target.result;
|
||||
request = objectStore.get(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
// Sanity check!
|
||||
is(test.storedObject.name, event.target.result.name,
|
||||
"The correct object was stored.");
|
||||
|
||||
request = objectStore.delete(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
// Make sure it was removed.
|
||||
request = objectStore.get(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.target.result === undefined, "Object was deleted");
|
||||
db.close();
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
let transaction = event.target.transaction;
|
||||
|
||||
let objectStore1 = db.createObjectStore("foo");
|
||||
let objectStore2 = transaction.objectStore("foo");
|
||||
ok(objectStore1 === objectStore2, "Got same objectStores");
|
||||
|
||||
let index1 = objectStore1.createIndex("bar", "key");
|
||||
let index2 = objectStore2.index("bar");
|
||||
ok(index1 === index2, "Got same indexes");
|
||||
|
||||
request.onsuccess = continueToNextStep;
|
||||
yield;
|
||||
|
||||
transaction = db.transaction(db.objectStoreNames);
|
||||
|
||||
let objectStore3 = transaction.objectStore("foo");
|
||||
let objectStore4 = transaction.objectStore("foo");
|
||||
ok(objectStore3 === objectStore4, "Got same objectStores");
|
||||
|
||||
ok(objectStore3 !== objectStore1, "Different objectStores");
|
||||
ok(objectStore4 !== objectStore2, "Different objectStores");
|
||||
|
||||
let index3 = objectStore3.index("bar");
|
||||
let index4 = objectStore4.index("bar");
|
||||
ok(index3 === index4, "Got same indexes");
|
||||
|
||||
ok(index3 !== index1, "Different indexes");
|
||||
ok(index4 !== index2, "Different indexes");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const data = { key: 5, index: 10 };
|
||||
|
||||
let request = mozIndexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
ok(db instanceof IDBDatabase, "Got a real database");
|
||||
|
||||
db.onerror = errorHandler;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "key",
|
||||
autoIncrement: true });
|
||||
let index = objectStore.createIndex("foo", "index");
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction("foo", IDBTransaction.READ_WRITE)
|
||||
.objectStore("foo");
|
||||
request = objectStore.add(data);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let key;
|
||||
executeSoon(function() {
|
||||
key = request.result;
|
||||
continueToNextStep();
|
||||
});
|
||||
yield;
|
||||
|
||||
is(key, data.key, "Got the right key");
|
||||
|
||||
objectStore = db.transaction("foo").objectStore("foo");
|
||||
objectStore.get(data.key).onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let obj;
|
||||
executeSoon(function() {
|
||||
obj = event.target.result;
|
||||
continueToNextStep();
|
||||
});
|
||||
yield;
|
||||
|
||||
is(obj.key, data.key, "Got the right key");
|
||||
is(obj.index, data.index, "Got the right property value");
|
||||
|
||||
objectStore = db.transaction("foo", IDBTransaction.READ_WRITE)
|
||||
.objectStore("foo");
|
||||
request = objectStore.delete(data.key);
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
key = undefined;
|
||||
executeSoon(function() {
|
||||
key = request.result;
|
||||
continueToNextStep();
|
||||
}, 0);
|
||||
yield;
|
||||
|
||||
ok(key === undefined, "Got the right value");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const names = [
|
||||
//"",
|
||||
null,
|
||||
undefined,
|
||||
this.window ? window.location.pathname : "Splendid Test"
|
||||
];
|
||||
|
||||
const version = 1;
|
||||
|
||||
for each (let name in names) {
|
||||
let request = mozIndexedDB.open(name, version);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
if (name === null) {
|
||||
name = "null";
|
||||
}
|
||||
else if (name === undefined) {
|
||||
name = "undefined";
|
||||
}
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.name, name, "Bad name");
|
||||
is(db.version, version, "Bad version");
|
||||
is(db.objectStoreNames.length, 0, "Bad objectStores list");
|
||||
|
||||
is(db.name, request.result.name, "Bad name");
|
||||
is(db.version, request.result.version, "Bad version");
|
||||
is(db.objectStoreNames.length, request.result.objectStoreNames.length,
|
||||
"Bad objectStores list");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Bad objectStores list");
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName,
|
||||
{ keyPath: "foo" });
|
||||
|
||||
is(db.objectStoreNames.length, 1, "Bad objectStores list");
|
||||
is(db.objectStoreNames.item(0), objectStoreName, "Bad name");
|
||||
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction(objectStoreName).objectStore(objectStoreName);
|
||||
|
||||
is(objectStore.name, objectStoreName, "Bad name");
|
||||
is(objectStore.keyPath, "foo", "Bad keyPath");
|
||||
if(objectStore.indexNames.length, 0, "Bad indexNames");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStores = [ "foo", "bar" ];
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
event.target.onsuccess = grabEventAndContinueHandler;
|
||||
for (let i in objectStores) {
|
||||
db.createObjectStore(objectStores[i], { autoIncrement: true });
|
||||
}
|
||||
let event = yield;
|
||||
|
||||
is(db.objectStoreNames.length, objectStores.length,
|
||||
"Correct objectStoreNames list");
|
||||
|
||||
for (let i = 0; i < 50; i++) {
|
||||
let stepNumber = 0;
|
||||
|
||||
request = db.transaction(["foo"], READ_WRITE)
|
||||
.objectStore("foo")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 1, "This callback came first");
|
||||
stepNumber++;
|
||||
}
|
||||
|
||||
request = db.transaction(["foo"], READ_WRITE)
|
||||
.objectStore("foo")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 2, "This callback came second");
|
||||
stepNumber++;
|
||||
}
|
||||
|
||||
request = db.transaction(["foo", "bar"], READ_WRITE)
|
||||
.objectStore("bar")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 3, "This callback came third");
|
||||
stepNumber++;
|
||||
}
|
||||
|
||||
request = db.transaction(["foo", "bar"], READ_WRITE)
|
||||
.objectStore("bar")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 4, "This callback came fourth");
|
||||
stepNumber++;
|
||||
}
|
||||
|
||||
request = db.transaction(["bar"], READ_WRITE)
|
||||
.objectStore("bar")
|
||||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 5, "This callback came fifth");
|
||||
stepNumber++;
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
}
|
||||
|
||||
stepNumber++;
|
||||
yield;
|
||||
|
||||
is(stepNumber, 6, "All callbacks received");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
let testString = { key: 0, value: "testString" };
|
||||
let testInt = { key: 1, value: 1002 };
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName,
|
||||
{ autoIncrement: 0 });
|
||||
|
||||
request = objectStore.add(testString.value, testString.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testString.key, "Got the right key");
|
||||
request = objectStore.get(testString.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testString.value, "Got the right value");
|
||||
};
|
||||
};
|
||||
|
||||
request = objectStore.add(testInt.value, testInt.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testInt.key, "Got the right key");
|
||||
request = objectStore.get(testInt.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testInt.value, "Got the right value");
|
||||
finishTest();
|
||||
};
|
||||
}
|
||||
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
let testString = { value: "testString" };
|
||||
let testInt = { value: 1002 };
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName,
|
||||
{ autoIncrement: 1 });
|
||||
|
||||
request = objectStore.put(testString.value);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
testString.key = event.target.result;
|
||||
request = objectStore.get(testString.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testString.value, "Got the right value");
|
||||
};
|
||||
};
|
||||
|
||||
request = objectStore.put(testInt.value);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
testInt.key = event.target.result;
|
||||
request = objectStore.get(testInt.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, testInt.value, "Got the right value");
|
||||
finishTest();
|
||||
};
|
||||
}
|
||||
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const indexName = "My Test Index";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
let objectStore = db.createObjectStore("test store", { keyPath: "foo" });
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
|
||||
is(db.objectStoreNames.item(0), objectStore.name, "Correct name");
|
||||
|
||||
is(objectStore.indexNames.length, 0, "Correct indexNames list");
|
||||
|
||||
let index = objectStore.createIndex(indexName, "foo");
|
||||
|
||||
is(objectStore.indexNames.length, 1, "Correct indexNames list");
|
||||
is(objectStore.indexNames.item(0), indexName, "Correct name");
|
||||
is(objectStore.index(indexName), index, "Correct instance");
|
||||
|
||||
objectStore.deleteIndex(indexName);
|
||||
|
||||
is(objectStore.indexNames.length, 0, "Correct indexNames list");
|
||||
try {
|
||||
objectStore.index(indexName);
|
||||
ok(false, "should have thrown");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Got a IDBDatabaseException");
|
||||
is(ex.code, IDBDatabaseException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR");
|
||||
}
|
||||
|
||||
let index2 = objectStore.createIndex(indexName, "foo");
|
||||
isnot(index, index2, "New instance should be created");
|
||||
|
||||
is(objectStore.indexNames.length, 1, "Correct recreacted indexNames list");
|
||||
is(objectStore.indexNames.item(0), indexName, "Correct recreacted name");
|
||||
is(objectStore.index(indexName), index2, "Correct instance");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
||||
const UNKNOWN_ERR =
|
||||
Components.interfaces.nsIIDBDatabaseException.UNKNOWN_ERR;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
const objectStoreName = "Objects";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
let objectStore = db.createObjectStore(objectStoreName,
|
||||
{ keyPath: "foo" });
|
||||
|
||||
let addedCount = 0;
|
||||
|
||||
for (let i = 0; i < 100; i++) {
|
||||
request = objectStore.add({foo: i});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
if (++addedCount == 100) {
|
||||
executeSoon(function() { testGenerator.next(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
yield;
|
||||
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
|
||||
is(db.objectStoreNames.item(0), objectStoreName, "Correct name");
|
||||
|
||||
db.close();
|
||||
|
||||
let request = mozIndexedDB.open(name, 2, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
let trans = event.target.transaction;
|
||||
|
||||
let oldObjectStore = trans.objectStore(objectStoreName);
|
||||
isnot(oldObjectStore, null, "Correct object store prior to deleting");
|
||||
db.deleteObjectStore(objectStoreName);
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStores list");
|
||||
try {
|
||||
trans.objectStore(objectStoreName);
|
||||
ok(false, "should have thrown");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(ex instanceof IDBDatabaseException, "Got a IDBDatabaseException");
|
||||
is(ex.code, IDBDatabaseException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR");
|
||||
}
|
||||
|
||||
objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
|
||||
is(db.objectStoreNames.item(0), objectStoreName, "Correct name");
|
||||
is(trans.objectStore(objectStoreName), objectStore, "Correct new objectStore");
|
||||
isnot(oldObjectStore, objectStore, "Old objectStore is not new objectStore");
|
||||
|
||||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.target.result, undefined, "ObjectStore shouldn't have any items");
|
||||
testGenerator.send(event);
|
||||
}
|
||||
event = yield;
|
||||
|
||||
db.deleteObjectStore(objectStore.name);
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStores list");
|
||||
|
||||
continueToNextStep();
|
||||
yield;
|
||||
|
||||
db.close();
|
||||
|
||||
let request = mozIndexedDB.open(name, 3, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
|
||||
|
||||
request = objectStore.add({foo:"bar"});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
db.deleteObjectStore(objectStoreName);
|
||||
|
||||
event = yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
const LOADING = Components.interfaces.nsIIDBRequest.LOADING;
|
||||
const DONE = Components.interfaces.nsIIDBRequest.DONE;
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
is(request.readyState, LOADING, "Correct readyState");
|
||||
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
is(request.readyState, DONE, "Correct readyState");
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("foo");
|
||||
let key = 10;
|
||||
|
||||
request = objectStore.add({}, key);
|
||||
is(request.readyState, LOADING, "Correct readyState");
|
||||
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(request.readyState, DONE, "Correct readyState");
|
||||
is(event.target.result, key, "Correct key");
|
||||
|
||||
request = objectStore.get(key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
is(request.readyState, LOADING, "Correct readyState");
|
||||
event = yield;
|
||||
|
||||
ok(event.target.result, "Got something");
|
||||
is(request.readyState, DONE, "Correct readyState");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
const VERSION_CHANGE = Components.interfaces.nsIIDBTransaction.VERSION_CHANGE;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
// Check default state.
|
||||
is(db.version, 1, "Correct default version for a new database.");
|
||||
|
||||
const versions = [
|
||||
7,
|
||||
42,
|
||||
];
|
||||
|
||||
db.close();
|
||||
|
||||
for (let i = 0; i < versions.length; i++) {
|
||||
let version = versions[i];
|
||||
|
||||
let request = mozIndexedDB.open(name, version, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
is(db.version, version, "Database version number updated correctly");
|
||||
is(event.target.transaction.mode, VERSION_CHANGE, "Correct mode");
|
||||
|
||||
executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
db.close();
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||||
const VERSION_CHANGE = Components.interfaces.nsIIDBTransaction.VERSION_CHANGE;
|
||||
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = grabEventAndContinueHandler;
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
let objectStore = db.createObjectStore("foo");
|
||||
let index = objectStore.createIndex("bar", "baz");
|
||||
|
||||
is(db.version, 1, "Correct version");
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
|
||||
is(objectStore.indexNames.length, 1, "Correct indexNames length");
|
||||
|
||||
let transaction = event.target.transaction;
|
||||
transaction.oncomplete = unexpectedSuccessHandler;
|
||||
transaction.onabort = grabEventAndContinueHandler;
|
||||
transaction.abort();
|
||||
|
||||
event = yield;
|
||||
is(event.type, "abort", "Got transaction abort event");
|
||||
is(event.target, transaction, "Right target");
|
||||
|
||||
is(db.version, 1, "Correct version");
|
||||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
|
||||
|
||||
event = yield;
|
||||
is(event.type, "error", "Got request error event");
|
||||
is(event.target, request, "Right target");
|
||||
|
||||
request = mozIndexedDB.open(name, 1, description);
|
||||
request.onerror = grabEventAndContinueHandler;
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db2 = event.target.result;
|
||||
|
||||
isnot(db, db2, "Should give a different db instance");
|
||||
is(db2.version, 1, "Correct version");
|
||||
is(db2.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
||||
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
const description = "My Test Database";
|
||||
|
||||
// Open a datbase for the first time.
|
||||
let request = mozIndexedDB.open(name, 1, description);
|
||||
|
||||
// Sanity checks
|
||||
ok(request instanceof IDBRequest, "Request should be an IDBRequest");
|
||||
ok(request instanceof IDBOpenDBRequest, "Request should be an IDBOpenDBRequest");
|
||||
//ok(request instanceof EventTarget, "Request should be an EventTarget");
|
||||
is(request.source, null, "Request should have no source");
|
||||
try {
|
||||
request.result;
|
||||
ok(false, "Getter should have thrown!");
|
||||
} catch (e if e.result == 0x80660006 /* NS_ERROR_DOM_INDEXEDDB_NOTALLOWED_ERR */) {
|
||||
ok(true, "Getter threw the right exception");
|
||||
}
|
||||
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let versionChangeEventCount = 0;
|
||||
let db1, db2, db3;
|
||||
|
||||
db1 = event.target.result;
|
||||
db1.addEventListener("versionchange", function(event) {
|
||||
ok(true, "Got version change event");
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
is(event.target.source, null, "Correct source");
|
||||
is(event.target, db1, "Correct target");
|
||||
is(event.target.version, 1, "Correct db version");
|
||||
is(event.oldVersion, 1, "Correct event oldVersion");
|
||||
is(event.newVersion, 2, "Correct event newVersion");
|
||||
is(versionChangeEventCount++, 0, "Correct count");
|
||||
db1.close();
|
||||
}, false);
|
||||
|
||||
// Open the database again and trigger an upgrade that should succeed
|
||||
request = mozIndexedDB.open(name, 2, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onblocked = errorHandler;
|
||||
event = yield;
|
||||
|
||||
// Test the upgradeneeded event.
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
ok(event.target.result instanceof IDBDatabase, "Good result");
|
||||
db2 = event.target.result;
|
||||
is(event.target.transaction.mode, IDBTransaction.VERSION_CHANGE,
|
||||
"Correct mode");
|
||||
is(db2.version, 2, "Correct db version");
|
||||
is(event.oldVersion, 1, "Correct event oldVersion");
|
||||
is(event.newVersion, 2, "Correct event newVersion");
|
||||
|
||||
request.onupgradeneeded = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
db2.addEventListener("versionchange", function(event) {
|
||||
ok(true, "Got version change event");
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
is(event.target.source, null, "Correct source");
|
||||
is(event.target, db2, "Correct target");
|
||||
is(event.target.version, 2, "Correct db version");
|
||||
is(event.oldVersion, 2, "Correct event oldVersion");
|
||||
is(event.newVersion, 3, "Correct event newVersion");
|
||||
is(versionChangeEventCount++, 1, "Correct count");
|
||||
}, false);
|
||||
|
||||
// Test opening the existing version again
|
||||
request = mozIndexedDB.open(name, 2, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
request.onblocked = errorHandler;
|
||||
event = yield;
|
||||
|
||||
db3 = event.target.result;
|
||||
|
||||
// Test an upgrade that should fail
|
||||
request = mozIndexedDB.open(name, 3, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = errorHandler;
|
||||
request.onupgradeneeded = errorHandler;
|
||||
request.onblocked = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
ok(true, "Got version change blocked event");
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
is(event.target.source, null, "Correct source");
|
||||
is(event.target.transaction, null, "Correct transaction");
|
||||
is(event.target, request, "Correct target");
|
||||
is(db3.version, 2, "Correct db version");
|
||||
is(event.oldVersion, 2, "Correct event oldVersion");
|
||||
is(event.newVersion, 3, "Correct event newVersion");
|
||||
versionChangeEventCount++;
|
||||
db2.close();
|
||||
db3.close();
|
||||
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
event = yield;
|
||||
|
||||
db3 = event.target.result;
|
||||
db3.close();
|
||||
|
||||
// Test another upgrade that should succeed.
|
||||
request = mozIndexedDB.open(name, 4);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onblocked = errorHandler;
|
||||
|
||||
event = yield;
|
||||
|
||||
ok(event instanceof IDBVersionChangeEvent, "Event is of the right type");
|
||||
ok(event.target.result instanceof IDBDatabase, "Good result");
|
||||
is(event.target.transaction.mode, IDBTransaction.VERSION_CHANGE,
|
||||
"Correct mode");
|
||||
is(event.oldVersion, 3, "Correct event oldVersion");
|
||||
is(event.newVersion, 4, "Correct event newVersion");
|
||||
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
ok(event.target.result instanceof IDBDatabase, "Expect a database here");
|
||||
is(event.target.result.version, 4, "Right version");
|
||||
is(db3.version, 3, "After closing the version should not change!");
|
||||
is(db2.version, 2, "After closing the version should not change!");
|
||||
is(db1.version, 1, "After closing the version should not change!");
|
||||
|
||||
is(versionChangeEventCount, 3, "Saw all expected events");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
|
||||
let request = mozIndexedDB.open(name, 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
|
||||
let request2 = mozIndexedDB.open(name, 2);
|
||||
request2.onerror = errorHandler;
|
||||
request2.onupgradeneeded = unexpectedSuccessHandler;
|
||||
|
||||
let event = yield;
|
||||
is(event.type, "upgradeneeded", "Expect an upgradeneeded event");
|
||||
is(event.target, request, "Event should be fired on the request");
|
||||
ok(event.target.result instanceof IDBDatabase, "Expect a database here");
|
||||
|
||||
let db = event.target.result;
|
||||
is(db.version, 1, "Database has correct version");
|
||||
|
||||
db.onupgradeneeded = function() {
|
||||
ok(false, "our ongoing VERSION_CHANGE transaction should exclude any others!");
|
||||
}
|
||||
|
||||
db.createObjectStore("foo");
|
||||
|
||||
try {
|
||||
db.transaction("foo");
|
||||
ok(false, "Transactions should be disallowed now!");
|
||||
} catch (e) {
|
||||
ok(e instanceof IDBDatabaseException, "Expect an IDBException");
|
||||
is(e.code, IDBDatabaseException.NOT_ALLOWED_ERR, "Expect a NOT_ALLOWED_ERR");
|
||||
}
|
||||
|
||||
request.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
|
||||
// The database is still not fully open here.
|
||||
try {
|
||||
db.transaction("foo");
|
||||
ok(false, "Transactions should be disallowed now!");
|
||||
} catch (e) {
|
||||
ok(e instanceof IDBDatabaseException, "Expect an IDBException");
|
||||
is(e.code, IDBDatabaseException.NOT_ALLOWED_ERR, "Expect a NOT_ALLOWED_ERR");
|
||||
}
|
||||
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
|
||||
db.onversionchange = function() {
|
||||
ok(true, "next setVersion was unblocked appropriately");
|
||||
db.close();
|
||||
}
|
||||
|
||||
try {
|
||||
db.transaction("foo");
|
||||
ok(true, "Transactions should be allowed now!");
|
||||
} catch (e) {
|
||||
ok(false, "Transactions should be allowed now!");
|
||||
}
|
||||
|
||||
request2.onupgradeneeded = null;
|
||||
request2.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
yield;
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
let request = mozIndexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.target.result;
|
||||
|
||||
event.target.onsuccess = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("foo");
|
||||
objectStore.add({}, 1).onerror = errorHandler;
|
||||
|
||||
yield;
|
||||
|
||||
objectStore = db.transaction("foo").objectStore("foo");
|
||||
|
||||
let transaction = objectStore.transaction;
|
||||
transaction.oncomplete = unexpectedSuccessHandler;
|
||||
transaction.onabort = grabEventAndContinueHandler;
|
||||
|
||||
let sawError = false;
|
||||
|
||||
request = objectStore.get(1);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onerror = function(event) {
|
||||
is(event.target.errorCode, IDBDatabaseException.ABORT_ERR, "Good code");
|
||||
sawError = true;
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
transaction.abort();
|
||||
|
||||
event = yield;
|
||||
|
||||
is(event.type, "abort", "Got abort event");
|
||||
is(sawError, true, "Saw get() error");
|
||||
if (this.window) {
|
||||
// Make sure the success event isn't queued somehow.
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var thread = Components.classes["@mozilla.org/thread-manager;1"]
|
||||
.getService(Components.interfaces.nsIThreadManager)
|
||||
.currentThread;
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(false);
|
||||
}
|
||||
}
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function testSteps()
|
||||
{
|
||||
const name = this.window ? window.location.pathname : "Splendid Test";
|
||||
|
||||
let requests = [];
|
||||
function doOpen(version, errorCallback, upgradeNeededCallback, successCallback) {
|
||||
let request = mozIndexedDB.open(name, version);
|
||||
request.onerror = errorCallback;
|
||||
request.onupgradeneeded = upgradeNeededCallback;
|
||||
request.onsuccess = successCallback;
|
||||
requests.push(request);
|
||||
}
|
||||
|
||||
doOpen(1, errorHandler, grabEventAndContinueHandler, grabEventAndContinueHandler);
|
||||
doOpen(2, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
|
||||
|
||||
let event = yield;
|
||||
is(event.type, "upgradeneeded", "expect an upgradeneeded event");
|
||||
is(event.target, requests[0], "fired at the right request");
|
||||
|
||||
let db = event.target.result;
|
||||
db.createObjectStore("foo");
|
||||
|
||||
doOpen(3, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
|
||||
doOpen(2, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
|
||||
doOpen(3, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
|
||||
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "complete", "expect a complete event");
|
||||
is(event.target, requests[0].transaction, "expect it to be fired at the transaction");
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
is(event.target, requests[0], "fired at the right request");
|
||||
event.target.result.close();
|
||||
|
||||
requests[1].onupgradeneeded = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "upgradeneeded", "expect an upgradeneeded event");
|
||||
is(event.target, requests[1], "fired at the right request");
|
||||
|
||||
requests[1].onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
is(event.target, requests[1], "fired at the right request");
|
||||
event.target.result.close();
|
||||
|
||||
requests[2].onupgradeneeded = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "upgradeneeded", "expect an upgradeneeded event");
|
||||
is(event.target, requests[2], "fired at the right request");
|
||||
|
||||
requests[2].onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
is(event.target, requests[2], "fired at the right request");
|
||||
event.target.result.close();
|
||||
|
||||
requests[3].onerror = new ExpectError(IDBDatabaseException.VERSION_ERR);
|
||||
|
||||
event = yield;
|
||||
|
||||
requests[4].onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield;
|
||||
is(event.type, "success", "expect a success event");
|
||||
is(event.target, requests[4], "fired at the right request");
|
||||
event.target.result.close();
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче