Bug 1273833 - Always return AbortError of the Open DB Request if the Upgrade Transaction is aborted. r=khuey

This commit is contained in:
Bevis Tseng 2016-05-19 15:05:31 +08:00
Родитель 63933a9276
Коммит 66870c070f
5 изменённых файлов: 59 добавлений и 20 удалений

Просмотреть файл

@ -15515,7 +15515,11 @@ VersionChangeTransaction::SendCompleteNotification(nsresult aResult)
}
if (NS_FAILED(aResult) && NS_SUCCEEDED(openDatabaseOp->mResultCode)) {
openDatabaseOp->mResultCode = aResult;
// 3.3.1 Opening a database:
// "If the upgrade transaction was aborted, run the steps for closing a
// database connection with connection, create and return a new AbortError
// exception and abort these steps."
openDatabaseOp->mResultCode = NS_ERROR_DOM_INDEXEDDB_ABORT_ERR;
}
openDatabaseOp->mState = OpenDatabaseOp::State::SendingResults;

Просмотреть файл

@ -84,7 +84,7 @@
request = objectStore.add({}, 1);
request.onsuccess = unexpectedSuccessHandler;
request.onerror = function(event) {
// Don't do anything! We want this error.
// Don't do anything! ConstraintError is expected in window.onerror.
}
event = yield undefined;
@ -98,8 +98,10 @@
event = yield undefined;
is(event.type, "error", "Got request error event");
is(event.target, originalRequest, "error event has right target");
is(event.target.error.name, "ConstraintError", "Right error");
is(event.target.error.name, "AbortError", "Right error");
is(originalRequest.transaction, null, "request.transaction should now be null");
// Skip the verification of ConstraintError in window.onerror.
event.preventDefault();
request = indexedDB.open(window.location.pathname, 1);
request.onerror = errorHandler;
@ -198,6 +200,7 @@
ok(objectStore.indexNames.contains("dontDeleteMe"), "Has correct index");
ok(objectStore.indexNames.contains("newIndex"), "Has correct index");
// ConstraintError is expected in window.onerror.
objectStore.add({}, 1);
trans.onabort = grabEventAndContinueHandler;
@ -221,6 +224,10 @@
request.onerror = grabEventAndContinueHandler;
event = yield undefined;
is(event.type, "error", "Got request error event");
is(event.target.error.name, "AbortError", "Right error");
// Skip the verification of ConstraintError in window.onerror.
event.preventDefault();
finishTest();
yield undefined;

Просмотреть файл

@ -164,7 +164,7 @@ function testSteps()
setLowDiskMode(true);
let request = indexedDB.open(dbName, dbVersion + 2);
request.onerror = expectedErrorHandler("QuotaExceededError");
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = unexpectedSuccessHandler;
@ -175,12 +175,20 @@ function testSteps()
let db = event.target.result;
db.onerror = errorHandler;
let txn = event.target.transaction;
txn.onerror = expectedErrorHandler("AbortError");
txn.onabort = grabEventAndContinueHandler;
let objectStore = db.createObjectStore(objectStoreName, objectStoreOptions);
request.onupgradeneeded = unexpectedSuccessHandler;
event = yield undefined;
is(event.type, "error", "Failed database upgrade");
is(event.type, "abort", "Got correct event type");
is(event.target.error.name, "QuotaExceededError", "Got correct error type");
request.onerror = expectedErrorHandler("AbortError");
event = yield undefined;
}
{ // Make sure creating indexes in low disk mode fails.
@ -214,7 +222,7 @@ function testSteps()
setLowDiskMode(true);
request = indexedDB.open(dbName, dbVersion + 3);
request.onerror = expectedErrorHandler("QuotaExceededError");
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = unexpectedSuccessHandler;
event = yield undefined;
@ -223,6 +231,9 @@ function testSteps()
db = event.target.result;
db.onerror = errorHandler;
let txn = event.target.transaction;
txn.onerror = expectedErrorHandler("AbortError");
txn.onabort = grabEventAndContinueHandler;
objectStore = event.target.transaction.objectStore(objectStoreName);
let index = objectStore.createIndex(indexName, indexName, indexOptions);
@ -230,7 +241,11 @@ function testSteps()
request.onupgradeneeded = unexpectedSuccessHandler;
event = yield undefined;
is(event.type, "error", "Failed database upgrade");
is(event.type, "abort", "Got correct event type");
is(event.target.error.name, "QuotaExceededError", "Got correct error type");
request.onerror = expectedErrorHandler("AbortError");
event = yield undefined;
}
{ // Make sure deleting indexes in low disk mode succeeds.

Просмотреть файл

@ -40,17 +40,26 @@ function testSteps()
info("Opening database for " + spec + " with version " + options.version);
let gotUpgradeNeeded = false;
let gotUpgradeIncomplete = false;
let gotUpgradeComplete = false;
let request =
indexedDB.openForPrincipal(getPrincipal(spec), name, options);
request.onerror = function(event) {
is(request.error.name, "QuotaExceededError", "Reached quota limit");
is(request.error.name,
gotUpgradeIncomplete ? "AbortError" : "QuotaExceededError",
"Reached quota limit");
event.preventDefault();
testGenerator.send(false);
}
request.onupgradeneeded = function(event) {
gotUpgradeNeeded = true;
event.target.transaction.onabort = function(e) {
gotUpgradeIncomplete = true;
is(e.target.error.name, "QuotaExceededError", "Reached quota limit");
}
event.target.transaction.oncomplete = function() {
gotUpgradeComplete = true;
}
}
request.onsuccess = function(event) {
let db = event.target.result;
@ -61,7 +70,7 @@ function testSteps()
let shouldContinue = yield undefined;
if (shouldContinue) {
is(gotUpgradeNeeded, true, "Got upgradeneeded event");
is(gotUpgradeComplete, true, "Got upgradeneeded event");
ok(true, "Got success event");
} else {
break;
@ -78,17 +87,26 @@ function testSteps()
info("Opening database for " + spec + " with version " + options.version);
let gotUpgradeNeeded = false;
let gotUpgradeIncomplete = false;
let gotUpgradeComplete = false;
let request =
indexedDB.openForPrincipal(getPrincipal(spec), name, options);
request.onerror = function(event) {
is(request.error.name, "QuotaExceededError", "Reached quota limit");
is(request.error.name,
gotUpgradeIncomplete ? "AbortError" : "QuotaExceededError",
"Reached quota limit");
event.preventDefault();
testGenerator.send(false);
}
request.onupgradeneeded = function(event) {
gotUpgradeNeeded = true;
event.target.transaction.onabort = function(e) {
gotUpgradeIncomplete = true;
is(e.target.error.name, "QuotaExceededError", "Reached quota limit");
}
event.target.transaction.oncomplete = function() {
gotUpgradeComplete = true;
}
}
request.onsuccess = function(event) {
let db = event.target.result;
@ -99,7 +117,7 @@ function testSteps()
let shouldContinue = yield undefined;
if (shouldContinue) {
is(gotUpgradeNeeded, true, "Got upgradeneeded event");
is(gotUpgradeComplete, true, "Got upgradeneeded event");
ok(true, "Got success event");
} else {
break;

Просмотреть файл

@ -1,5 +0,0 @@
[idbobjectstore_createIndex7-event_order.htm]
type: testharness
[IDBObjectStore.createIndex() - Event ordering for ConstraintError on request]
expected: FAIL