Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: third_party/WebKit/LayoutTests/storage/indexeddb/rename-object-store.html

Issue 2276593002: Support renaming of IndexedDB indexes and object stores. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename-object-store covers all happy paths (no errors yet). Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/indexeddb/IDBIndex.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/storage/indexeddb/rename-object-store.html
diff --git a/third_party/WebKit/LayoutTests/storage/indexeddb/rename-object-store.html b/third_party/WebKit/LayoutTests/storage/indexeddb/rename-object-store.html
new file mode 100644
index 0000000000000000000000000000000000000000..786c87e056ec897b617e0902c263b961d98d4270
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/storage/indexeddb/rename-object-store.html
@@ -0,0 +1,327 @@
+<!DOCTYPE html>
+<title>IndexedDB v2: object store renaming support</title>
+<script src='../../resources/testharness.js'></script>
+<link rel="help"
+ href="https://w3c.github.io/IndexedDB/#dom-idbobjectstore-name">
+<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
+<script src='../../resources/testharnessreport.js'></script>
+<script>
+
+// Returns an IndexedDB database name likely to be unique to the test case.
+const databaseName = function(testCase) {
+ return 'db' + self.location.pathname + '-' + testCase.name;
+};
+
+// Creates an EventWatcher covering all the events that can be issued by
+// IndexedDB requests and transactions.
+const requestWatcher = function(testCase, request) {
+ return new EventWatcher(testCase, request,
+ ['abort', 'complete', 'error', 'success', 'upgradeneeded']);
+};
+
+// Creates an IndexedDB database whose name is unique for the test case.
+//
+// setupCallback will be called during a versionchange transaction, and will be
+// given the created database and the versionchange transaction.
+//
+// Returns a promise that yields an IndexedDB open success event.
+const createDatabase = function(testCase, setupCallback) {
+ const dbName = databaseName(testCase);
+ const request = indexedDB.deleteDatabase(dbName);
+ const eventWatcher = requestWatcher(testCase, request);
+
+ return eventWatcher.wait_for('success').then((event) => {
+ // We cannot use eventWatcher.wait_for('upgradeneeded') here, because
+ // the versionchange transaction auto-commits before the Promise's then
+ // callback gets called.
+ return new Promise((resolve, reject) => {
+ const request = indexedDB.open(dbName, 1);
+ request.onupgradeneeded = (event) => {
+ const eventWatcher = requestWatcher(testCase, request);
+ const database = event.target.result;
+ const transaction = event.target.transaction;
+ setupCallback(database, transaction);
+ resolve(eventWatcher.wait_for('success'));
+ };
+ request.onerror =
+ testCase.unreached_func('indexedDB.open issued an error event');
+ });
+ });
+};
+
+// Creates a 'books' object store whose contents closely resembles the first
+// example in the IndexedDB specification.
+const createBooksStore = function(testCase, database) {
+ const store = database.createObjectStore('books',
+ { keyPath: 'isbn', autoIncrement: true });
+ const index = store.createIndex('by_author', 'author');
+ store.put({title: 'Quarry Memories', author: 'Fred', isbn: 123456});
+ store.put({title: 'Water Buffaloes', author: 'Fred', isbn: 234567});
+ store.put({title: 'Bedrock Nights', author: 'Barney', isbn: 345678});
+ return store;
+};
+
+// Creates a 'not_books' object store used to test renaming into existing or
+// deleted store names.
+const createNotBooksStore = function(testCase, database) {
cmumford 2016/08/26 21:23:52 You need to call this somewhere too right? Also, c
pwnall 2016/08/26 22:23:17 Done. I wrote createNotBooksStore to test the ren
+ const store = database.createObjectStore('not_books');
+ return store;
+};
+
+// Renames the 'books' store into a 'not books' store.
+//
+// Returns a Promise that yields an IndexedDB open success event.
+const renameBooksStore = function(testCase) {
+ return new Promise((resolve, reject) => {
+ const request = indexedDB.open(databaseName(testCase), 2);
+ request.onupgradeneeded = (event) => {
+ const eventWatcher = requestWatcher(testCase, request);
+ const database = event.target.result;
+ const transaction = event.target.transaction;
+ const store = transaction.objectStore('books');
+ store.name = 'renamed_books';
+ resolve(eventWatcher.wait_for('success'));
+ };
+ request.onerror =
+ testCase.unreached_func('indexedDB.open issued an error event');
+ });
+};
+
+// Verifies that an object store's contents matches the contents used to create
+// the books store in the test database's version 1.
+const checkStoreContents = function(testCase, store) {
+ let request = store.get(123456);
+ let eventWatcher = requestWatcher(testCase, request);
+ return eventWatcher.wait_for('success').then(() => {
+ let result = request.result;
+ testCase.step(() => {
+ assert_equals(result.isbn, 123456);
+ assert_equals(result.author, 'Fred');
+ assert_equals(result.title, 'Quarry Memories');
+ });
+ });
+};
+
+// Verifies that an object store's index matches the index used to create the
+// books store in the test database's version 1.
+const checkStoreIndex = function(testCase, store) {
+ let index = store.index('by_author');
+ let request = index.get('Barney');
+ let eventWatcher = requestWatcher(testCase, request);
+ return eventWatcher.wait_for('success').then(() => {
+ let result = request.result;
+ testCase.step(() => {
+ assert_equals(result.isbn, 345678);
+ assert_equals(result.title, 'Bedrock Nights');
+ });
+ });
+};
+
+// Verifies that an object store's key generator is in the same state as the
+// key generator created for the books store in the test database's version 1.
+const checkStoreGenerator = function(testCase, store, expectedKey) {
+ let request = store.put({title: 'Bedrock Nights II', author: 'Barney'});
+ let eventWatcher = requestWatcher(testCase, request);
+ return eventWatcher.wait_for('success').then(() => {
+ let result = request.result;
+ testCase.step(() => {
+ assert_equals(result, expectedKey);
+ });
+ });
+};
+
+promise_test(testCase => {
+ let bookStore = null, bookStore2 = null;
+ let renamedBookStore = null, renamedBookStore2 = null;
+ return createDatabase(testCase, (database, transaction) => {
+ bookStore = createBooksStore(testCase, database);
+ }).then((event) => {
+ const database = event.target.result;
+ testCase.step(() => {
+ assert_array_equals(database.objectStoreNames, ['books']);
+ });
+ const transaction = database.transaction('books', 'readonly');
+ bookStore2 = transaction.objectStore('books');
+ // If checkStoreContents fails here, its implementation is incorrect.
+ return checkStoreContents(testCase, bookStore2).then(() => {
+ database.close();
+ });
+ }).then(() => {
+ return new Promise((resolve, reject) => {
+ const request = indexedDB.open(databaseName(testCase), 2);
+ request.onupgradeneeded = (event) => {
+ const eventWatcher = requestWatcher(testCase, request);
+ const database = event.target.result;
+ const transaction = event.target.transaction;
+ renamedBookStore = transaction.objectStore('books');
+ renamedBookStore.name = 'renamed_books';
+ testCase.step(() => {
+ assert_equals(renamedBookStore.name, 'renamed_books');
+ });
+ resolve(eventWatcher.wait_for('success'));
+ };
+ request.onerror =
+ testCase.unreached_func('indexedDB.open issued an error event');
+ });
+ }).then((event) => {
+ const database = event.target.result;
+ testCase.step(() => {
+ assert_array_equals(database.objectStoreNames, ['renamed_books']);
+ });
+ const transaction = database.transaction('renamed_books', 'readonly');
+ renamedBookStore2 = transaction.objectStore('renamed_books');
+ return checkStoreContents(testCase, renamedBookStore2).then(() => {
+ database.close();
+ });
+ }).then(() => {
+ testCase.step(() => {
+ assert_equals(bookStore.name, 'books');
+ assert_equals(bookStore2.name, 'books');
+ assert_equals(renamedBookStore.name, 'renamed_books');
+ assert_equals(renamedBookStore2.name, 'renamed_books');
+ });
+ });
+}, 'IndexedDB object store rename in new transaction', {
+ assert: 'An object store can be renamed in a new version change transaction',
+});
+
+promise_test(testCase => {
+ let renamedBookStore = null, renamedBookStore2 = null;
+ return createDatabase(testCase, (database, transaction) => {
+ renamedBookStore = createBooksStore(testCase, database);
+ renamedBookStore.name = 'renamed_books';
+ testCase.step(() => {
+ assert_equals(renamedBookStore.name, 'renamed_books');
+ });
+ }).then((event) => {
+ const database = event.target.result;
+ testCase.step(() => {
+ assert_array_equals(database.objectStoreNames, ['renamed_books']);
+ });
+ const transaction = database.transaction('renamed_books', 'readonly');
+ renamedBookStore2 = transaction.objectStore('renamed_books');
+ return checkStoreContents(testCase, renamedBookStore2).then(() => {
+ database.close();
+ });
+ }).then(() => {
+ testCase.step(() => {
+ assert_equals(renamedBookStore.name, 'renamed_books');
+ assert_equals(renamedBookStore2.name, 'renamed_books');
+ });
+ });
+}, 'IndexedDB object store rename in the transaction where it is created', {
+ assert:
+ 'An object store can be renamed in the transaction where it is created',
+});
+
+promise_test(testCase => {
+ return createDatabase(testCase, (database, transaction) => {
+ createBooksStore(testCase, database);
+ }).then((event) => {
+ const database = event.target.result;
+ const transaction = database.transaction('books', 'readonly');
+ const store = transaction.objectStore('books');
+ // If checkStoreIndex fails here, its implementation is incorrect.
+ return checkStoreIndex(testCase, store).then(() => {
+ database.close();
+ });
+ }).then(() => {
+ return renameBooksStore(testCase);
+ }).then((event) => {
+ const database = event.target.result;
+ const transaction = database.transaction('renamed_books', 'readonly');
+ const store = transaction.objectStore('renamed_books');
+ return checkStoreIndex(testCase, store).then(() => {
+ database.close();
+ });
+ });
+}, 'IndexedDB object store rename covers index', {
+ assert: 'Renaming an object store maintains its indexes',
+});
+
+promise_test(testCase => {
+ return createDatabase(testCase, (database, transaction) => {
+ createBooksStore(testCase, database);
+ }).then((event) => {
+ const database = event.target.result;
+ const transaction = database.transaction('books', 'readwrite');
+ // If checkStoreGenerator fails here, its implementation is incorrect.
+ const store = transaction.objectStore('books');
+ return checkStoreGenerator(testCase, store, 345679).then(() => {
+ database.close();
+ });
+ }).then(() => {
+ return renameBooksStore(testCase);
+ }).then((event) => {
+ const database = event.target.result;
+ const transaction = database.transaction('renamed_books', 'readwrite');
+ const store = transaction.objectStore('renamed_books');
+ return checkStoreGenerator(testCase, store, 345680).then(() => {
+ database.close();
+ });
+ });
+}, 'IndexedDB object store rename covers key generator', {
+ assert: 'Renaming an object store maintains its key generator',
+});
+
+promise_test(testCase => {
+ const dbName = databaseName(testCase);
+ let bookStore = null, bookStore2 = null, bookStore3 = null;
+ return createDatabase(testCase, (database, transaction) => {
+ bookStore = createBooksStore(testCase, database);
+ }).then((event) => {
+ const database = event.target.result;
+ database.close();
+ }).then((event) => {
+ return new Promise((resolve, reject) => {
+ const request = indexedDB.open(dbName, 2);
+ request.onupgradeneeded = (event) => {
+ const database = event.target.result;
+ const transaction = event.target.transaction;
+ bookStore2 = transaction.objectStore('books');
+ bookStore2.name = 'renamed_books';
+ testCase.step(() => {
+ assert_equals(bookStore.name, 'books');
+ assert_equals(bookStore2.name, 'renamed_books');
+ });
+ request.onerror = (event) => {
+ event.preventDefault();
+ resolve(event);
+ }
+ transaction.onabort = () => null;
+ transaction.onerror = () => null;
+ transaction.abort();
+ };
+ request.onerror =
+ testCase.unreached_func('indexedDB.open issued an error event');
+ request.onsuccess = testCase.unreached_func(
+ 'indexedDB.open was not supposed to succeed');
+ });
+ }).then((event) => {
+ testCase.step(() => {
+ assert_equals(bookStore.name, 'books',
+ 'object store rename not reverted after transaction abort');
+ });
+
+ const request = indexedDB.open(dbName, 1);
+ const eventWatcher = requestWatcher(testCase, request);
+ return eventWatcher.wait_for('success');
+ }).then((event) => {
+ const database = event.target.result;
+ const transaction = database.transaction('books', 'readonly');
+ bookStore3 = transaction.objectStore('books');
+ return checkStoreContents(testCase, bookStore3).then(() => {
+ database.close();
+ });
+ }).then(() => {
+ testCase.step(() => {
+ assert_equals(bookStore.name, 'books');
+ assert_equals(bookStore2.name, 'books');
+ assert_equals(bookStore3.name, 'books');
+ });
+ });
+}, 'IndexedDB object store rename in aborted transaction', {
+ assert: 'An object store rename is correctly reverted',
+});
+
+</script>
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/indexeddb/IDBIndex.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698