From 72c8e580039b733311cb25f1bf71c9bedb7300b2 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Wed, 11 May 2016 16:36:52 +0800 Subject: [PATCH] Bug 823371 - Fire "blocked" event if deleteDatabase is blocked by other open connection. r=khuey --- dom/indexedDB/ActorsParent.cpp | 2 +- dom/indexedDB/test/mochitest.ini | 6 ++ .../test/test_deleteDatabase_onblocked.html | 19 +++++ ...atabase_onblocked_duringVersionChange.html | 19 +++++ .../unit/test_deleteDatabase_onblocked.js | 83 ++++++++++++++++++ ...eDatabase_onblocked_duringVersionChange.js | 84 +++++++++++++++++++ dom/indexedDB/test/unit/xpcshell-shared.ini | 2 + 7 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 dom/indexedDB/test/test_deleteDatabase_onblocked.html create mode 100644 dom/indexedDB/test/test_deleteDatabase_onblocked_duringVersionChange.html create mode 100644 dom/indexedDB/test/unit/test_deleteDatabase_onblocked.js create mode 100644 dom/indexedDB/test/unit/test_deleteDatabase_onblocked_duringVersionChange.js diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 10cf7b70ae22..bee85dc131cb 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -22228,7 +22228,7 @@ DeleteDatabaseOp::SendBlockedNotification() MOZ_ASSERT(mState == State::WaitingForOtherDatabasesToClose); if (!IsActorDestroyed()) { - Unused << SendBlocked(0); + Unused << SendBlocked(mPreviousVersion); } } diff --git a/dom/indexedDB/test/mochitest.ini b/dom/indexedDB/test/mochitest.ini index 226b800480c9..8a2bdb1e8292 100644 --- a/dom/indexedDB/test/mochitest.ini +++ b/dom/indexedDB/test/mochitest.ini @@ -38,6 +38,8 @@ support-files = unit/test_cursors.js unit/test_deleteDatabase.js unit/test_deleteDatabase_interactions.js + unit/test_deleteDatabase_onblocked.js + unit/test_deleteDatabase_onblocked_duringVersionChange.js unit/test_event_source.js unit/test_filehandle_append_read_data.js unit/test_getAll.js @@ -171,6 +173,10 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116 skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116 [test_deleteDatabase_interactions.html] skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116 +[test_deleteDatabase_onblocked.html] +skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116 +[test_deleteDatabase_onblocked_duringVersionChange.html] +skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116 [test_error_events_abort_transactions.html] skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116 [test_event_propagation.html] diff --git a/dom/indexedDB/test/test_deleteDatabase_onblocked.html b/dom/indexedDB/test/test_deleteDatabase_onblocked.html new file mode 100644 index 000000000000..817182c30eb9 --- /dev/null +++ b/dom/indexedDB/test/test_deleteDatabase_onblocked.html @@ -0,0 +1,19 @@ + + + + Indexed Database Onblocked Test During Deleting Database + + + + + + + + + + + + diff --git a/dom/indexedDB/test/test_deleteDatabase_onblocked_duringVersionChange.html b/dom/indexedDB/test/test_deleteDatabase_onblocked_duringVersionChange.html new file mode 100644 index 000000000000..dd6a00217516 --- /dev/null +++ b/dom/indexedDB/test/test_deleteDatabase_onblocked_duringVersionChange.html @@ -0,0 +1,19 @@ + + + + Indexed Database Onblocked Test During Version Change Transaction + + + + + + + + + + + + diff --git a/dom/indexedDB/test/unit/test_deleteDatabase_onblocked.js b/dom/indexedDB/test/unit/test_deleteDatabase_onblocked.js new file mode 100644 index 000000000000..51390612d7c0 --- /dev/null +++ b/dom/indexedDB/test/unit/test_deleteDatabase_onblocked.js @@ -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 dbVersion = 10; + + let openRequest = indexedDB.open(name, dbVersion); + openRequest.onerror = errorHandler; + openRequest.onblocked = errorHandler; + openRequest.onsuccess = unexpectedSuccessHandler; + openRequest.onupgradeneeded = grabEventAndContinueHandler; + + let event = yield undefined; + + is(event.type, "upgradeneeded", "Expect an upgradeneeded event"); + ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event"); + + let db = event.target.result; + db.onversionchange = errorHandler; + db.createObjectStore("stuff"); + + openRequest.onsuccess = grabEventAndContinueHandler; + + event = yield undefined; + + is(event.type, "success", "Expect a success event"); + is(event.target, openRequest, "Event has right target"); + ok(event.target.result instanceof IDBDatabase, "Result should be a database"); + is(db.objectStoreNames.length, 1, "Expect an objectStore here"); + + db.onversionchange = grabEventAndContinueHandler; + let deletingRequest = indexedDB.deleteDatabase(name); + deletingRequest.onerror = errorHandler; + deletingRequest.onsuccess = errorHandler; + deletingRequest.onblocked = errorHandler; + + event = yield undefined; + + is(event.type, "versionchange", "Expect an versionchange event"); + is(event.target, db, "Event has right target"); + ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event"); + is(event.oldVersion, dbVersion, "Correct old version"); + is(event.newVersion, null, "Correct new version"); + + deletingRequest.onblocked = grabEventAndContinueHandler; + + event = yield undefined; + + is(event.type, "blocked", "Expect an blocked event"); + is(event.target, deletingRequest, "Event has right target"); + ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event"); + is(event.oldVersion, dbVersion, "Correct old version"); + is(event.newVersion, null, "Correct new version"); + + deletingRequest.onsuccess = grabEventAndContinueHandler; + db.close(); + + event = yield undefined; + + is(event.type, "success", "expect a success event"); + is(event.target, deletingRequest, "event has right target"); + is(event.target.result, undefined, "event should have no result"); + + openRequest = indexedDB.open(name, 1); + openRequest.onerror = errorHandler; + openRequest.onsuccess = grabEventAndContinueHandler; + + event = yield undefined; + db = event.target.result; + is(db.version, 1, "DB has proper version"); + is(db.objectStoreNames.length, 0, "DB should have no object stores"); + + db.close(); + + finishTest(); + yield undefined; +} diff --git a/dom/indexedDB/test/unit/test_deleteDatabase_onblocked_duringVersionChange.js b/dom/indexedDB/test/unit/test_deleteDatabase_onblocked_duringVersionChange.js new file mode 100644 index 000000000000..40ece64c0da0 --- /dev/null +++ b/dom/indexedDB/test/unit/test_deleteDatabase_onblocked_duringVersionChange.js @@ -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 dbVersion = 10; + + let openRequest = indexedDB.open(name, dbVersion); + openRequest.onerror = errorHandler; + openRequest.onblocked = errorHandler; + openRequest.onsuccess = unexpectedSuccessHandler; + openRequest.onupgradeneeded = grabEventAndContinueHandler; + + let event = yield undefined; + + is(event.type, "upgradeneeded", "Expect an upgradeneeded event"); + ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event"); + + let db = event.target.result; + db.onversionchange = errorHandler; + db.createObjectStore("stuff"); + + let deletingRequest = indexedDB.deleteDatabase(name); + deletingRequest.onerror = errorHandler; + deletingRequest.onsuccess = errorHandler; + deletingRequest.onblocked = errorHandler; + + openRequest.onsuccess = grabEventAndContinueHandler; + + event = yield undefined; + + is(event.type, "success", "Expect a success event"); + is(event.target, openRequest, "Event has right target"); + ok(event.target.result instanceof IDBDatabase, "Result should be a database"); + is(db.objectStoreNames.length, 1, "Expect an objectStore here"); + + db.onversionchange = grabEventAndContinueHandler; + + event = yield undefined; + + is(event.type, "versionchange", "Expect an versionchange event"); + is(event.target, db, "Event has right target"); + ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event"); + is(event.oldVersion, dbVersion, "Correct old version"); + is(event.newVersion, null, "Correct new version"); + + deletingRequest.onblocked = grabEventAndContinueHandler; + + event = yield undefined; + + is(event.type, "blocked", "Expect an blocked event"); + is(event.target, deletingRequest, "Event has right target"); + ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event"); + is(event.oldVersion, dbVersion, "Correct old version"); + is(event.newVersion, null, "Correct new version"); + + deletingRequest.onsuccess = grabEventAndContinueHandler; + db.close(); + + event = yield undefined; + + is(event.type, "success", "expect a success event"); + is(event.target, deletingRequest, "event has right target"); + is(event.target.result, undefined, "event should have no result"); + + openRequest = indexedDB.open(name, 1); + openRequest.onerror = errorHandler; + openRequest.onsuccess = grabEventAndContinueHandler; + + event = yield undefined; + db = event.target.result; + is(db.version, 1, "DB has proper version"); + is(db.objectStoreNames.length, 0, "DB should have no object stores"); + + db.close(); + + finishTest(); + yield undefined; +} diff --git a/dom/indexedDB/test/unit/xpcshell-shared.ini b/dom/indexedDB/test/unit/xpcshell-shared.ini index e613916a156e..1f02645669a2 100644 --- a/dom/indexedDB/test/unit/xpcshell-shared.ini +++ b/dom/indexedDB/test/unit/xpcshell-shared.ini @@ -22,6 +22,8 @@ skip-if = toolkit == 'android' # bug 864843 [test_cursors.js] [test_deleteDatabase.js] [test_deleteDatabase_interactions.js] +[test_deleteDatabase_onblocked.js] +[test_deleteDatabase_onblocked_duringVersionChange.js] [test_event_source.js] [test_getAll.js] [test_globalObjects_other.js]