Bug 809727 - Wait for the write transaction to finish so that the blobs are expired. r=janv

This commit is contained in:
Philipp von Weitershausen 2012-11-09 20:32:10 -05:00
parent 27caf16bf3
commit e1bfa6aa62
3 changed files with 72 additions and 4 deletions

View File

@ -216,6 +216,19 @@ public:
mFile->GetLeafName(mName);
}
nsDOMFileFile(nsIFile *aFile, FileInfo *aFileInfo)
: nsDOMFile(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX),
mFile(aFile), mWholeFile(true), mStoredFile(true)
{
NS_ASSERTION(mFile, "must have file");
NS_ASSERTION(aFileInfo, "must have file info");
// Lazily get the content type and size
mContentType.SetIsVoid(true);
mFile->GetLeafName(mName);
mFileInfos.AppendElement(aFileInfo);
}
// Create as a file
nsDOMFileFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile *aFile)

View File

@ -1507,7 +1507,7 @@ IDBObjectStore::ConvertBlobsToActors(
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(nativeFile);
nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(nativeFile, file.mFileInfo);
BlobParent* actor =
aContentParent->GetOrCreateActorForBlob(blob);

View File

@ -12,8 +12,7 @@
<script type="text/javascript;version=1.7">
function testSteps()
{
const BLOB_DATA = ["fun ", "times ", "all ", "around!"];
const INDEX_KEY = 5;
info("Setting up test fixtures: create an IndexedDB database and object store.");
let request = indexedDB.open(window.location.pathname, 1);
request.onerror = errorHandler;
@ -30,6 +29,11 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
info("Let's create a blob and store it in IndexedDB twice.");
const BLOB_DATA = ["fun ", "times ", "all ", "around!"];
const INDEX_KEY = 5;
let blob = new Blob(BLOB_DATA, { type: "text/plain" });
let data = { blob: blob, index: INDEX_KEY };
@ -42,6 +46,9 @@
objectStore.add(data).onsuccess = grabEventAndContinueHandler;
event = yield;
info("Let's retrieve the blob again and verify the contents is the same.");
objectStore = db.transaction("foo").objectStore("foo");
objectStore.get(key).onsuccess = grabEventAndContinueHandler;
event = yield;
@ -53,7 +60,9 @@
is(event.target.result, BLOB_DATA.join(""), "Correct text");
info("Trying blob url");
info("Let's retrieve it again, create an object URL for the blob, load" +
"it via an XMLHttpRequest, and verify the contents is the same.");
objectStore = db.transaction("foo").objectStore("foo");
objectStore.get(key).onsuccess = grabEventAndContinueHandler;
@ -71,6 +80,9 @@
is(xhr.responseText, BLOB_DATA.join(""), "Correct responseText");
info("Retrieve both blob entries from the database and verify contents.");
objectStore = db.transaction("foo").objectStore("foo");
objectStore.mozGetAll().onsuccess = grabEventAndContinueHandler;
event = yield;
@ -108,6 +120,9 @@
is(event.target.result, BLOB_DATA.join(""), "Correct text");
info("Retrieve blobs from database via index and verify contents.");
let index = db.transaction("foo").objectStore("foo").index("foo");
index.get(INDEX_KEY).onsuccess = grabEventAndContinueHandler;
event = yield;
@ -163,6 +178,9 @@
is(event.target.result, BLOB_DATA.join(""), "Correct text");
info("Slice the the retrieved blob and verify its contents.");
let slice = cursorResults[1].blob.slice(0, BLOB_DATA[0].length);
fileReader = new FileReader();
@ -172,6 +190,9 @@
is(event.target.result, BLOB_DATA[0], "Correct text");
info("Send blob to a worker, read its contents there, and verify results.");
function workerScript() {
onmessage = function(event) {
var reader = new FileReaderSync();
@ -196,6 +217,40 @@
is(event.data, BLOB_DATA[0][1], "Correct text");
info("Store a blob back in the database, and keep holding on to the " +
"blob, verifying that it still can be read.");
objectStore = db.transaction("foo").objectStore("foo");
objectStore.get(key).onsuccess = grabEventAndContinueHandler;
event = yield;
let blobFromDB = event.target.result.blob;
let txn = db.transaction("foo", "readwrite");
txn.objectStore("foo").put(event.target.result, key);
txn.oncomplete = grabEventAndContinueHandler;
event = yield;
let fileReader = new FileReader();
fileReader.onload = grabEventAndContinueHandler;
fileReader.readAsText(blobFromDB);
event = yield;
is(event.target.result, BLOB_DATA.join(""), "Correct text");
let blobURL = URL.createObjectURL(blobFromDB);
let xhr = new XMLHttpRequest();
xhr.open("GET", blobURL);
xhr.onload = grabEventAndContinueHandler;
xhr.send();
yield;
URL.revokeObjectURL(blobURL);
is(xhr.responseText, BLOB_DATA.join(""), "Correct responseText");
finishTest();
yield;
}