Bug 1598164 - Fix structured-clone-transaction-state.any.js test case. r=dom-workers-and-storage-reviewers,janv

Also removed obsolete dom/indexedDB/test/test_clone_before_key_evaluation.html test case,
which tested for the opposite behaviour.

Differential Revision: https://phabricator.services.mozilla.com/D54267

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Simon Giesecke 2019-11-26 13:18:09 +00:00
parent 0d6f5cd8de
commit f7864022f8
7 changed files with 36 additions and 184 deletions

View File

@ -1513,7 +1513,11 @@ already_AddRefed<IDBRequest> IDBObjectStore::AddOrPut(
StructuredCloneWriteInfo cloneWriteInfo(mTransaction->Database());
nsTArray<IndexUpdateInfo> updateInfo;
GetAddInfo(aCx, aValueWrapper, aKey, cloneWriteInfo, key, updateInfo, aRv);
{
const auto autoStateRestore = mTransaction->TemporarilyProceedToInactive();
GetAddInfo(aCx, aValueWrapper, aKey, cloneWriteInfo, key, updateInfo, aRv);
}
if (aRv.Failed()) {
return nullptr;
}

View File

@ -59,7 +59,7 @@ class IDBTransaction final : public DOMEventTargetHelper, public nsIRunnable {
MODE_INVALID
};
enum ReadyState { INITIAL = 0, LOADING, COMMITTING, DONE };
enum ReadyState { INITIAL = 0, LOADING, INACTIVE, COMMITTING, DONE };
private:
// TODO: Only non-const because of Bug 1575173.
@ -188,6 +188,36 @@ class IDBTransaction final : public DOMEventTargetHelper, public nsIRunnable {
return NS_FAILED(mAbortCode);
}
auto TemporarilyProceedToInactive() {
AssertIsOnOwningThread();
MOZ_ASSERT(mReadyState == INITIAL || mReadyState == LOADING);
const auto savedReadyState = mReadyState;
mReadyState = INACTIVE;
struct AutoRestoreState {
IDBTransaction& mOwner;
ReadyState mSavedReadyState;
#ifdef DEBUG
uint32_t mSavedPendingRequestCount;
#endif
~AutoRestoreState() {
mOwner.AssertIsOnOwningThread();
MOZ_ASSERT(mOwner.mReadyState == INACTIVE);
MOZ_ASSERT(mOwner.mPendingRequestCount == mSavedPendingRequestCount);
mOwner.mReadyState = mSavedReadyState;
}
};
return AutoRestoreState{*this, savedReadyState
#ifdef DEBUG
,
mPendingRequestCount
#endif
};
}
nsresult AbortCode() const {
AssertIsOnOwningThread();
return mAbortCode;

View File

@ -26,7 +26,6 @@ support-files =
unit/test_blob_file_backed.js
unit/test_blocked_order.js
unit/test_clear.js
unit/test_clone_before_key_evaluation.js
unit/test_complex_keyPaths.js
unit/test_constraint_error_messages.js
unit/test_count.js
@ -137,7 +136,6 @@ skip-if = e10s && os == 'win' && os_version == '6.1' # Bug 1342415
[test_blocked_order.html]
[test_bug937006.html]
[test_clear.html]
[test_clone_before_key_evaluation.html]
[test_complex_keyPaths.html]
[test_constraint_error_messages.html]
[test_count.html]

View File

@ -1,18 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Test</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript" src="unit/test_clone_before_key_evaluation.js"></script>
<script type="text/javascript" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>

View File

@ -1,140 +0,0 @@
/**
* 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
: "test_clone_before_key_evaluation.js";
const objectStoreInfo = {
name: "customers",
options: { keyPath: "ssn" },
};
const indexInfo = {
name: "customerIndex",
keyPath: ["id", "email", "name"],
options: { unique: false },
};
for (let test of [1, 2]) {
info("Opening database");
let request = indexedDB.open(name);
request.onerror = errorHandler;
request.onupgradeneeded = continueToNextStepSync;
request.onsuccess = unexpectedSuccessHandler;
yield undefined;
// upgradeneeded
request.onupgradeneeded = unexpectedSuccessHandler;
request.onsuccess = continueToNextStepSync;
let db = request.result;
db.onerror = errorHandler;
info("Creating objectStore");
let objectStore = db.createObjectStore(
objectStoreInfo.name,
objectStoreInfo.options
);
info("Creating index");
objectStore.createIndex(
indexInfo.name,
indexInfo.keyPath,
indexInfo.options
);
switch (test) {
case 1: {
info("Adding data with a getter");
let idCount = 0;
const customerData = {
ssn: "444-44-4444",
name: "Bill",
age: 25,
email: "bill@company.com",
get id() {
idCount++;
objectStore.deleteIndex(indexInfo.name);
return "ID_001";
},
};
objectStore.add(customerData);
ok(idCount == 1, "Getter was called only once");
ok(objectStore.indexNames.length == 0, "Index was removed");
break;
}
case 2: {
info("Adding data with a prototype getter");
let idCount = 0;
const customerData = {
ssn: "555-55-5555",
name: "Joe",
age: 52,
email: "joe@company.com",
};
Object.defineProperty(Object.prototype, "id", {
get() {
idCount++;
objectStore.deleteIndex(indexInfo.name);
return "ID_002";
},
enumerable: false,
configurable: true,
});
objectStore.add(customerData);
ok(idCount == 0, "Prototype getter was not called");
// Paranoid checks, just to be sure that the protype getter is called
// in standard JS.
let id = customerData.id;
ok(id == "ID_002", "Prototype getter returned correct value");
ok(idCount == 1, "Prototype getter was called only once");
delete Object.prototype.id;
id = customerData.id;
ok(id == undefined, "Prototype getter was removed");
ok(objectStore.indexNames.length == 0, "Index was removed");
break;
}
}
yield undefined;
// success
db.close();
request = indexedDB.deleteDatabase(name);
request.onerror = errorHandler;
request.onsuccess = continueToNextStepSync;
yield undefined;
}
finishTest();
}

View File

@ -11,7 +11,6 @@
[test_autoIncrement_indexes.js]
[test_blocked_order.js]
[test_clear.js]
[test_clone_before_key_evaluation.js]
[test_complex_keyPaths.js]
[test_count.js]
[test_create_index.js]

View File

@ -1,21 +0,0 @@
[structured-clone-transaction-state.any.html]
[Transaction inactive during structured clone in IDBObjectStore.add()]
expected: FAIL
[Transaction inactive during structured clone in IDBCursor.update()]
expected: FAIL
[Transaction inactive during structured clone in IDBObjectStore.put()]
expected: FAIL
[structured-clone-transaction-state.any.worker.html]
[Transaction inactive during structured clone in IDBObjectStore.add()]
expected: FAIL
[Transaction inactive during structured clone in IDBCursor.update()]
expected: FAIL
[Transaction inactive during structured clone in IDBObjectStore.put()]
expected: FAIL