blob: 5d29f3b50708704bae4a0abff57672937ca6e37d [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="resources/utilities.js"></script>
<script>
function test()
{
let suite = InspectorTest.createAsyncSuite("IndexedDB.clearObjectStore");
suite.addTestCase({
name: "ClearDatabases",
description: "Remove any existing IndexedDB databases.",
test(resolve, reject) {
// FIXME: Remove any existing IndexedDB databases that might exist to workaround:
// <https://webkit.org/b/148006> Each test should run with its own clean data store
IndexedDBAgent.requestDatabaseNames(WI.networkManager.mainFrame.securityOrigin, (error, names) => {
InspectorTest.evaluateInPage("deleteDatabaseNames(" + JSON.stringify(names) + ")", resolve);
});
}
});
suite.addTestCase({
name: "CreateDatabaseAndClearObjectStore",
description: "Ensure that clearing an object store clears entries in that object store.",
test(resolve, reject) {
InspectorTest.evaluateInPage("createDatabaseWithStores('CompleteDatabase', 1)");
IndexedDBAgent.requestDatabase(WI.networkManager.mainFrame.securityOrigin, "CompleteDatabase", (error, database) => {
InspectorTest.expectNoError(error);
function expectObjectStoreEntryCount(objectStore, expectedCount, message) {
const securityOrigin = WI.networkManager.mainFrame.securityOrigin;
const indexName = "";
const skipCount = 0;
const pageSize = 10;
IndexedDBAgent.requestData(securityOrigin, database.name, objectStore.name, indexName, skipCount, pageSize, (error, entries, hasMore) => {
InspectorTest.expectNoError(error);
InspectorTest.expectThat(entries.length === expectedCount, message);
});
}
let securityOrigin = WI.networkManager.mainFrame.securityOrigin;
let [emptyObjectStore, reviewersObjectStore, statsObjectStore] = database.objectStores;
expectObjectStoreEntryCount(emptyObjectStore, 0, "'Empty' object store should always be empty.");
expectObjectStoreEntryCount(reviewersObjectStore, 4, "'Reviewers' object store should start with 4 entries.");
expectObjectStoreEntryCount(statsObjectStore, 4, "'Stats' object store should start with 4 entries.");
IndexedDBAgent.clearObjectStore(securityOrigin, database.name, reviewersObjectStore.name, (error) => {
InspectorTest.expectNoError(error);
});
expectObjectStoreEntryCount(emptyObjectStore, 0, "'Empty' object store should always be empty.");
expectObjectStoreEntryCount(reviewersObjectStore, 0, "'Reviewers' object store should have been cleared.");
expectObjectStoreEntryCount(statsObjectStore, 4, "'Stats' object store remain unchanged with 4 entries.");
IndexedDBAgent.clearObjectStore(securityOrigin, database.name, statsObjectStore.name, (error) => {
InspectorTest.expectNoError(error);
});
expectObjectStoreEntryCount(emptyObjectStore, 0, "'Empty' object store should always be empty.");
expectObjectStoreEntryCount(reviewersObjectStore, 0, "'Reviewers' object store should have been cleared.");
expectObjectStoreEntryCount(statsObjectStore, 0, "'Stats' object store should have been cleared.");
InspectorBackend.runAfterPendingDispatches(resolve);
});
}
});
suite.addTestCase({
name: "NoSuchObjectStore",
test(resolve, reject) {
InspectorTest.awaitEvent("DatabaseCreated")
.then((event) => {
IndexedDBAgent.requestDatabase(WI.networkManager.mainFrame.securityOrigin, "EmptyDatabase", (error, database) => {
IndexedDBAgent.clearObjectStore(WI.networkManager.mainFrame.securityOrigin, database.name, "NoSuchObjectStore", (error) => {
InspectorTest.expectThat(error, "Should be an error attempting to clear an object store that does not exist.");
resolve();
});
});
});
InspectorTest.evaluateInPage("createEmptyDatabase('EmptyDatabase', 1)");
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
</body>
</html>