-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IDB: idbobjectstore_delete WPT extended to workers in addition to window
web_tests/external/wpt/IndexedDB/Tests currently only verify in window environment. Extend tests to cover dedicated, shared and service workers. Tests related to idbobjectstore_delete.htm have been extended. 7 idbobjectstore_delete.htm files have been consolidated into one file: idbobjectstore_delete.any.js along with idbobjectstore_deleteindex.any.js idbobjectstore_deleted.htm has been extended to idbdatabase_deleteObjectStore.any.js. The other existing files like idbdatabase_deleteObjectStore.htm (3-4) have also been consolidated to idbdatabase_deleteObjectStore.any.js. Bug: 41455766 Change-Id: Ied919a90027f30a86f8679dc463a0f7a2930d6bd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5371125 Commit-Queue: Sneha Agarwal <[email protected]> Reviewed-by: Ayu Ishii <[email protected]> Reviewed-by: Evan Stade <[email protected]> Reviewed-by: Rahul Singh <[email protected]> Cr-Commit-Position: refs/heads/main@{#1276500}
- Loading branch information
1 parent
a885671
commit 8814952
Showing
15 changed files
with
338 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// META: global=window,worker | ||
// META: title=IDBDatabase.deleteObjectStore() | ||
// META: script=resources/support.js | ||
// @author Microsoft <https://www.microsoft.com> | ||
// @author Odin Hørthe Omdal <mailto:[email protected]> | ||
|
||
'use_strict'; | ||
|
||
async_test(t => { | ||
let db; | ||
let add_success = false; | ||
|
||
const open_rq = createdb(t); | ||
open_rq.onupgradeneeded = function(e) { | ||
db = e.target.result; | ||
|
||
const objStore = db.createObjectStore("store", { autoIncrement: true }); | ||
assert_equals(db.objectStoreNames[0], "store", "objectStoreNames"); | ||
|
||
const rq_add = objStore.add(1); | ||
rq_add.onsuccess = function() { add_success = true; }; | ||
rq_add.onerror = fail(t, 'rq_add.error'); | ||
|
||
objStore.createIndex("idx", "a"); | ||
db.deleteObjectStore("store"); | ||
assert_equals(db.objectStoreNames.length, 0, "objectStoreNames.length after delete"); | ||
assert_false(db.objectStoreNames.contains("store")); | ||
|
||
const exc = "InvalidStateError"; | ||
assert_throws_dom(exc, function() { objStore.add(2); }); | ||
assert_throws_dom(exc, function() { objStore.put(3); }); | ||
assert_throws_dom(exc, function() { objStore.get(1); }); | ||
assert_throws_dom(exc, function() { objStore.clear(); }); | ||
assert_throws_dom(exc, function() { objStore.count(); }); | ||
assert_throws_dom(exc, function() { objStore.delete(1); }); | ||
assert_throws_dom(exc, function() { objStore.openCursor(); }); | ||
assert_throws_dom(exc, function() { objStore.index("idx"); }); | ||
assert_throws_dom(exc, function() { objStore.deleteIndex("idx"); }); | ||
assert_throws_dom(exc, function() { objStore.createIndex("idx2", "a"); | ||
}); | ||
}; | ||
|
||
open_rq.onsuccess = function() { | ||
assert_true(add_success, "First add was successful"); | ||
t.done(); | ||
} | ||
}, 'Deleted object store\'s name should be removed from database\'s list. Attempting to use a \ | ||
deleted IDBObjectStore should throw an InvalidStateError'); | ||
|
||
async_test(t => { | ||
const open_rq = createdb(t); | ||
|
||
open_rq.onupgradeneeded = function(e) { | ||
const db = e.target.result; | ||
assert_throws_dom('NotFoundError', function() { db.deleteObjectStore('whatever'); }); | ||
t.done(); | ||
}; | ||
}, 'Attempting to remove an object store that does not exist should throw a NotFoundError'); | ||
|
||
async_test(t => { | ||
const keys = []; | ||
const open_rq = createdb(t); | ||
|
||
open_rq.onupgradeneeded = function(e) { | ||
const db = e.target.result; | ||
|
||
const objStore = db.createObjectStore("resurrected", { autoIncrement: true, keyPath: "k" }); | ||
objStore.add({ k: 5 }).onsuccess = function(e) { keys.push(e.target.result); }; | ||
objStore.add({}).onsuccess = function(e) { keys.push(e.target.result); }; | ||
objStore.createIndex("idx", "i"); | ||
assert_true(objStore.indexNames.contains("idx")); | ||
assert_equals(objStore.keyPath, "k", "keyPath"); | ||
|
||
db.deleteObjectStore("resurrected"); | ||
|
||
const objStore2 = db.createObjectStore("resurrected", { autoIncrement: true }); | ||
objStore2.add("Unicorns'R'us").onsuccess = function(e) { keys.push(e.target.result); }; | ||
assert_false(objStore2.indexNames.contains("idx"), "index exist on new objstore"); | ||
assert_equals(objStore2.keyPath, null, "keyPath"); | ||
|
||
assert_throws_dom("NotFoundError", function() { objStore2.index("idx"); }); | ||
}; | ||
|
||
open_rq.onsuccess = function(e) { | ||
assert_array_equals(keys, [5, 6, 1], "keys"); | ||
t.done(); | ||
}; | ||
}, 'Attempting to access an index that was deleted as part of object store deletion and then \ | ||
recreated using the same object store name should throw a NotFoundError'); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
// META: global=window,worker | ||
// META: title=IDBObjectStore.delete() | ||
// META: script=resources/support.js | ||
// @author Microsoft <https://www.microsoft.com> | ||
|
||
'use_strict'; | ||
|
||
async_test(t => { | ||
let db; | ||
const record = { key: 1, property: "data" }; | ||
|
||
const open_rq = createdb(t); | ||
open_rq.onupgradeneeded = function(e) { | ||
db = e.target.result; | ||
|
||
const objStore = db.createObjectStore("test", { keyPath: "key" }); | ||
objStore.add(record); | ||
}; | ||
|
||
open_rq.onsuccess = function(e) { | ||
const delete_rq = db.transaction("test", "readwrite", | ||
{ durability: 'relaxed' }) | ||
.objectStore("test") | ||
.delete(record.key); | ||
|
||
delete_rq.onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result, undefined); | ||
|
||
e.target.transaction.oncomplete = t.step_func(VerifyRecordRemoved); | ||
}); | ||
}; | ||
|
||
function VerifyRecordRemoved() { | ||
const rq = db.transaction("test", "readonly", | ||
{ durability: 'relaxed' }) | ||
.objectStore("test") | ||
.get(record.key); | ||
|
||
rq.onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result, undefined); | ||
t.done(); | ||
}); | ||
} | ||
}, 'delete() removes record (inline keys)'); | ||
|
||
async_test(t => { | ||
const open_rq = createdb(t); | ||
open_rq.onupgradeneeded = function(e) { | ||
const db = e.target.result; | ||
|
||
const delete_rq = db.createObjectStore("test") | ||
.delete(1); | ||
|
||
delete_rq.onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result, undefined); | ||
t.done(); | ||
}); | ||
}; | ||
}, 'delete() key doesn\'t match any records'); | ||
|
||
async_test(t => { | ||
let db; | ||
const record = { test: { obj: { key: 1 } }, property: "data" }; | ||
|
||
const open_rq = createdb(t); | ||
open_rq.onupgradeneeded = function(e) { | ||
db = e.target.result; | ||
|
||
const objStore = db.createObjectStore("test", | ||
{ keyPath: "test.obj.key" }); | ||
objStore.add(record); | ||
}; | ||
|
||
open_rq.onsuccess = function(e) { | ||
const delete_rq = db.transaction("test", "readwrite", | ||
{ durability: 'relaxed' }) | ||
.objectStore("test") | ||
.delete(record.test.obj.key); | ||
|
||
delete_rq.onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result, undefined); | ||
|
||
e.target.transaction.oncomplete = t.step_func(VerifyRecordRemoved); | ||
}); | ||
}; | ||
|
||
function VerifyRecordRemoved() { | ||
const rq = db.transaction("test", "readonly", | ||
{ durability: 'relaxed' }) | ||
.objectStore("test") | ||
.get(record.test.obj.key); | ||
|
||
rq.onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result, undefined); | ||
t.done(); | ||
}); | ||
} | ||
}, 'Object store\'s key path is an object attribute'); | ||
|
||
async_test(t => { | ||
let db; | ||
const key = 1; | ||
const record = { property: "data" }; | ||
|
||
const open_rq = createdb(t); | ||
open_rq.onupgradeneeded = function(e) { | ||
db = e.target.result; | ||
|
||
const objStore = db.createObjectStore("test"); | ||
objStore.add(record, key); | ||
}; | ||
|
||
open_rq.onsuccess = function(e) { | ||
const delete_rq = db.transaction("test", "readwrite", | ||
{ durability: 'relaxed' }) | ||
.objectStore("test") | ||
.delete(key); | ||
|
||
delete_rq.onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result, undefined); | ||
|
||
e.target.transaction.oncomplete = t.step_func(VerifyRecordRemoved); | ||
}); | ||
}; | ||
|
||
function VerifyRecordRemoved() { | ||
const rq = db.transaction("test", "readonly", | ||
{ durability: 'relaxed' }) | ||
.objectStore("test") | ||
.get(key); | ||
|
||
rq.onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result, undefined); | ||
t.done(); | ||
}); | ||
} | ||
}, 'delete() removes record (out-of-line keys)'); | ||
|
||
async_test(t => { | ||
let db; | ||
const open_rq = createdb(t); | ||
|
||
open_rq.onupgradeneeded = function(e) { | ||
db = e.target.result; | ||
const os = db.createObjectStore("store"); | ||
|
||
for(let i = 0; i < 10; i++) | ||
os.add("data" + i, i); | ||
}; | ||
|
||
open_rq.onsuccess = function (e) { | ||
const os = db.transaction("store", "readwrite", | ||
{ durability: 'relaxed' }) | ||
.objectStore("store"); | ||
|
||
os.delete(IDBKeyRange.bound(3, 6)); | ||
os.count().onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result, 6, "Count after deleting \ | ||
3-6 from 10"); | ||
t.done(); | ||
}); | ||
}; | ||
}, 'delete() removes all of the records in the range'); | ||
|
||
async_test(function(t) { | ||
let db; | ||
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; | ||
|
||
const open_rq = createdb(t); | ||
open_rq.onupgradeneeded = function(event) { | ||
db = event.target.result; | ||
const objStore = db.createObjectStore("store", { keyPath: "pKey" }); | ||
for (let i = 0; i < records.length; i++) { | ||
objStore.add(records[i]); | ||
} | ||
}; | ||
|
||
open_rq.onsuccess = function(event) { | ||
const txn = db.transaction("store", "readonly", | ||
{ durability: 'relaxed' }); | ||
const ostore = txn.objectStore("store"); | ||
t.step(function() { | ||
assert_throws_dom("ReadOnlyError", function() { | ||
ostore.delete("primaryKey_0"); | ||
}); | ||
}); | ||
t.done(); | ||
}; | ||
}, 'If the transaction this IDBObjectStore belongs to has its mode set to \ | ||
readonly, throw ReadOnlyError'); | ||
|
||
async_test(t => { | ||
let ostore; | ||
const records = [{ pKey: "primaryKey_0" }, { pKey: "primaryKey_1" }]; | ||
|
||
const open_rq = createdb(t); | ||
open_rq.onupgradeneeded = function(event) { | ||
const db = event.target.result; | ||
ostore = db.createObjectStore("store", { keyPath: "pKey" }); | ||
db.deleteObjectStore("store"); | ||
assert_throws_dom("InvalidStateError", function() { | ||
ostore.delete("primaryKey_0"); | ||
}); | ||
t.done(); | ||
}; | ||
}, 'If the object store has been deleted, the implementation must throw a \ | ||
DOMException of type InvalidStateError'); |
Oops, something went wrong.