зеркало из https://github.com/mozilla/gecko-dev.git
Bug 929274 - 'InvalidStateError when accessing transaction.error after aborted transaction'. Patch by bent & Shihua Zheng <szheng@mozilla.com>, r=janv, r=khuey.
This commit is contained in:
Родитель
edf297ebce
Коммит
ad46289006
|
@ -660,15 +660,10 @@ IDBTransaction::GetMode(ErrorResult& aRv) const
|
|||
}
|
||||
|
||||
DOMError*
|
||||
IDBTransaction::GetError(ErrorResult& aRv)
|
||||
IDBTransaction::GetError() const
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (IsOpen()) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return mError;
|
||||
}
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ public:
|
|||
}
|
||||
|
||||
DOMError*
|
||||
GetError(ErrorResult& aRv);
|
||||
GetError() const;
|
||||
|
||||
already_AddRefed<IDBObjectStore>
|
||||
ObjectStore(const nsAString& aName, ErrorResult& aRv);
|
||||
|
|
|
@ -58,6 +58,7 @@ tail =
|
|||
[test_success_events_after_abort.js]
|
||||
[test_traffic_jam.js]
|
||||
[test_transaction_abort.js]
|
||||
[test_transaction_error.js]
|
||||
[test_transaction_lifetimes.js]
|
||||
[test_transaction_lifetimes_nested.js]
|
||||
[test_transaction_ordering.js]
|
||||
|
|
|
@ -192,6 +192,8 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop spec
|
|||
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
|
||||
[test_transaction_abort_hang.html]
|
||||
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
|
||||
[test_transaction_error.html]
|
||||
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
|
||||
[test_transaction_lifetimes.html]
|
||||
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
|
||||
[test_transaction_lifetimes_nested.html]
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Indexed Database Test</title>
|
||||
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript;version=1.7" src="unit/test_transaction_error.js"></script>
|
||||
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||||
</head>
|
||||
|
||||
<body onload="runTest();"></body>
|
||||
|
||||
</html>
|
|
@ -64,6 +64,7 @@
|
|||
[test_traffic_jam.js]
|
||||
[test_transaction_abort.js]
|
||||
[test_transaction_abort_hang.js]
|
||||
[test_transaction_error.js]
|
||||
[test_transaction_lifetimes.js]
|
||||
[test_transaction_lifetimes_nested.js]
|
||||
[test_transaction_ordering.js]
|
||||
|
|
|
@ -34,13 +34,7 @@ function testSteps()
|
|||
|
||||
transaction = event.target.transaction;
|
||||
|
||||
try {
|
||||
let error = transaction.error;
|
||||
ok(false, "Expect an exception");
|
||||
} catch(e) {
|
||||
ok(true, "Got an exception.");
|
||||
is(e.name, "InvalidStateError", "Got the right exception");
|
||||
}
|
||||
is(transaction.error, null, "Expect a null error");
|
||||
|
||||
objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
index = objectStore.createIndex("fooindex", "indexKey", { unique: true });
|
||||
|
@ -334,7 +328,7 @@ function testSteps()
|
|||
});
|
||||
};
|
||||
yield undefined;
|
||||
|
||||
|
||||
// During COMMITTING
|
||||
transaction = db.transaction("foo", "readwrite");
|
||||
transaction.objectStore("foo").put({hello: "world"}, 1).onsuccess = function(event) {
|
||||
|
@ -389,4 +383,4 @@ function testSteps()
|
|||
|
||||
finishTest();
|
||||
yield undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
let testGenerator = testSteps();
|
||||
|
||||
function testSteps() {
|
||||
const dbName = this.window ?
|
||||
window.location.pathname :
|
||||
"test_transaction_error";
|
||||
const dbVersion = 1;
|
||||
const objectStoreName = "foo";
|
||||
const data = { };
|
||||
const dataKey = 1;
|
||||
const expectedError = "ConstraintError";
|
||||
|
||||
let request = indexedDB.open(dbName, dbVersion);
|
||||
request.onerror = errorHandler;
|
||||
request.onupgradeneeded = grabEventAndContinueHandler;
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
|
||||
let event = yield undefined;
|
||||
|
||||
info("Creating database");
|
||||
|
||||
let db = event.target.result;
|
||||
let objectStore = db.createObjectStore(objectStoreName);
|
||||
objectStore.add(data, dataKey);
|
||||
|
||||
request.onupgradeneeded = unexpectedSuccessHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
|
||||
event = yield undefined;
|
||||
|
||||
db = event.target.result;
|
||||
|
||||
let transaction = db.transaction(objectStoreName, "readwrite");
|
||||
transaction.onerror = grabEventAndContinueHandler;
|
||||
transaction.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
objectStore = transaction.objectStore(objectStoreName);
|
||||
|
||||
info("Adding duplicate entry with preventDefault()");
|
||||
|
||||
let request = objectStore.add(data, dataKey);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onerror = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
is(event.type, "error", "Got an error event");
|
||||
is(event.target, request, "Error event targeted request");
|
||||
is(event.currentTarget, request, "Got request error first");
|
||||
is(event.currentTarget.error.name, expectedError,
|
||||
"Request has correct error");
|
||||
event.preventDefault();
|
||||
|
||||
event = yield undefined;
|
||||
|
||||
is(event.type, "error", "Got an error event");
|
||||
is(event.target, request, "Error event targeted request");
|
||||
is(event.currentTarget, transaction, "Got transaction error second");
|
||||
is(event.currentTarget.error, null, "Transaction has null error");
|
||||
|
||||
event = yield undefined;
|
||||
|
||||
is(event.type, "complete", "Got a complete event");
|
||||
is(event.target, transaction, "Complete event targeted transaction");
|
||||
is(event.currentTarget, transaction,
|
||||
"Complete event only targeted transaction");
|
||||
is(event.currentTarget.error, null, "Transaction has null error");
|
||||
|
||||
// Try again without preventDefault().
|
||||
|
||||
transaction = db.transaction(objectStoreName, "readwrite");
|
||||
transaction.onerror = grabEventAndContinueHandler;
|
||||
transaction.onabort = grabEventAndContinueHandler;
|
||||
|
||||
objectStore = transaction.objectStore(objectStoreName);
|
||||
|
||||
info("Adding duplicate entry without preventDefault()");
|
||||
|
||||
if ("SimpleTest" in this) {
|
||||
SimpleTest.expectUncaughtException();
|
||||
}
|
||||
|
||||
request = objectStore.add(data, dataKey);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onerror = grabEventAndContinueHandler;
|
||||
event = yield undefined;
|
||||
|
||||
is(event.type, "error", "Got an error event");
|
||||
is(event.target, request, "Error event targeted request");
|
||||
is(event.currentTarget, request, "Got request error first");
|
||||
is(event.currentTarget.error.name, expectedError,
|
||||
"Request has correct error");
|
||||
|
||||
event = yield undefined;
|
||||
|
||||
is(event.type, "error", "Got an error event");
|
||||
is(event.target, request, "Error event targeted request");
|
||||
is(event.currentTarget, transaction, "Got transaction error second");
|
||||
is(event.currentTarget.error, null, "Transaction has null error");
|
||||
|
||||
event = yield undefined;
|
||||
|
||||
is(event.type, "abort", "Got an abort event");
|
||||
is(event.target, transaction, "Abort event targeted transaction");
|
||||
is(event.currentTarget, transaction,
|
||||
"Abort event only targeted transaction");
|
||||
is(event.currentTarget.error.name, expectedError,
|
||||
"Transaction has correct error");
|
||||
|
||||
finishTest();
|
||||
yield undefined;
|
||||
}
|
|
@ -79,6 +79,7 @@ skip-if = os == "android" && processor == "x86"
|
|||
[test_traffic_jam.js]
|
||||
[test_transaction_abort.js]
|
||||
[test_transaction_abort_hang.js]
|
||||
[test_transaction_error.js]
|
||||
[test_transaction_lifetimes.js]
|
||||
[test_transaction_lifetimes_nested.js]
|
||||
[test_transaction_ordering.js]
|
||||
|
|
|
@ -19,7 +19,6 @@ interface IDBTransaction : EventTarget {
|
|||
readonly attribute IDBTransactionMode mode;
|
||||
readonly attribute IDBDatabase db;
|
||||
|
||||
[Throws]
|
||||
readonly attribute DOMError? error;
|
||||
|
||||
[Throws]
|
||||
|
|
Загрузка…
Ссылка в новой задаче