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

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/IndexedDB/support-promises.js

Issue 2763813002: Ensure correctness for interleaved IndexedDB cursor iteration. (Closed)
Patch Set: Added comment showing the interleaving sequence used in this test. Created 3 years, 9 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 | « third_party/WebKit/LayoutTests/external/wpt/IndexedDB/interleaved-cursors.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/external/wpt/IndexedDB/support-promises.js
diff --git a/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/support-promises.js b/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/support-promises.js
index 2db051281cf7c13207902286a56437ce44467afd..0762a8d7e9c1a664d68b79e96b20fbafad883944 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/support-promises.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/support-promises.js
@@ -21,7 +21,7 @@ function requestWatcher(testCase, request) {
// open request.
//
// Returns a promise. If the versionchange transaction goes through, the promise
-// resolves to an IndexedDB database that must be closed by the caller. If the
+// resolves to an IndexedDB database that should be closed by the caller. If the
// versionchange transaction is aborted, the promise resolves to an error.
function migrateDatabase(testCase, newVersion, migrationCallback) {
return migrateNamedDatabase(
@@ -37,7 +37,7 @@ function migrateDatabase(testCase, newVersion, migrationCallback) {
// open request.
//
// Returns a promise. If the versionchange transaction goes through, the promise
-// resolves to an IndexedDB database that must be closed by the caller. If the
+// resolves to an IndexedDB database that should be closed by the caller. If the
// versionchange transaction is aborted, the promise resolves to an error.
function migrateNamedDatabase(
testCase, databaseName, newVersion, migrationCallback) {
@@ -88,10 +88,20 @@ function migrateNamedDatabase(
resolve(Promise.resolve(callbackResult).then(() => requestEventPromise));
});
request.onerror = event => reject(event.target.error);
- request.onsuccess = () => reject(new Error(
- 'indexedDB.open should not succeed without creating a ' +
- 'versionchange transaction'));
- }).then(event => event.target.result || event.target.error);
+ request.onsuccess = () => {
+ const database = request.result;
+ testCase.add_cleanup(() => { database.close(); });
+ reject(new Error(
+ 'indexedDB.open should not succeed without creating a ' +
+ 'versionchange transaction'));
+ };
+ }).then(event => {
+ const database = event.target.result;
+ if (database) {
+ testCase.add_cleanup(() => { database.close(); });
+ }
+ return database || event.target.error;
+ });
}
// Creates an IndexedDB database whose name is unique for the test case.
@@ -100,7 +110,7 @@ function migrateNamedDatabase(
// given the created database, the versionchange transaction, and the database
// open request.
//
-// Returns a promise that resolves to an IndexedDB database. The caller must
+// Returns a promise that resolves to an IndexedDB database. The caller should
// close the database.
function createDatabase(testCase, setupCallback) {
return createNamedDatabase(testCase, databaseName(testCase), setupCallback);
@@ -112,21 +122,23 @@ function createDatabase(testCase, setupCallback) {
// given the created database, the versionchange transaction, and the database
// open request.
//
-// Returns a promise that resolves to an IndexedDB database. The caller must
+// Returns a promise that resolves to an IndexedDB database. The caller should
// close the database.
function createNamedDatabase(testCase, databaseName, setupCallback) {
const request = indexedDB.deleteDatabase(databaseName);
const eventWatcher = requestWatcher(testCase, request);
- return eventWatcher.wait_for('success').then(event =>
- migrateNamedDatabase(testCase, databaseName, 1, setupCallback));
+ return eventWatcher.wait_for('success').then(event => {
+ testCase.add_cleanup(() => { indexedDB.deleteDatabase(databaseName); });
+ return migrateNamedDatabase(testCase, databaseName, 1, setupCallback)
+ });
}
// Opens an IndexedDB database without performing schema changes.
//
// The given version number must match the database's current version.
//
-// Returns a promise that resolves to an IndexedDB database. The caller must
+// Returns a promise that resolves to an IndexedDB database. The caller should
// close the database.
function openDatabase(testCase, version) {
return openNamedDatabase(testCase, databaseName(testCase), version);
@@ -136,12 +148,16 @@ function openDatabase(testCase, version) {
//
// The given version number must match the database's current version.
//
-// Returns a promise that resolves to an IndexedDB database. The caller must
+// Returns a promise that resolves to an IndexedDB database. The caller should
// close the database.
function openNamedDatabase(testCase, databaseName, version) {
const request = indexedDB.open(databaseName, version);
const eventWatcher = requestWatcher(testCase, request);
- return eventWatcher.wait_for('success').then(event => event.target.result);
+ return eventWatcher.wait_for('success').then(() => {
+ const database = request.result;
+ testCase.add_cleanup(() => { database.close(); });
+ return database;
+ });
}
// The data in the 'books' object store records in the first example of the
« no previous file with comments | « third_party/WebKit/LayoutTests/external/wpt/IndexedDB/interleaved-cursors.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698