Chromium Code Reviews| Index: content/test/data/indexeddb/empty_blob.html |
| diff --git a/content/test/data/indexeddb/empty_blob.html b/content/test/data/indexeddb/empty_blob.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6c6d652cf184b103e96aa72ad0031ae549a5d97d |
| --- /dev/null |
| +++ b/content/test/data/indexeddb/empty_blob.html |
| @@ -0,0 +1,95 @@ |
| +<!DOCTYPE html> |
| +<html> |
| +<!-- |
| + Copyright 2015 The Chromium Authors. All rights reserved. |
| + Use of this source code is governed by a BSD-style license that can be |
| + found in the LICENSE file. |
| +--> |
| +<head> |
| +<title>IDB Test that we can store and retrieve an empty blob</title> |
| +<script src="common.js"></script> |
| +<script> |
| + |
| +// Constants. |
| +var store_name = 'empty_blob'; |
| +var blob_key = 'blob_key'; |
| +var file_key = 'file_key'; |
| + |
| +// Shared variables. |
| +var db; |
| +var emptyFileInput; |
| + |
| +function test() { |
| + indexedDBTest(prepareDatabase, writeBlob); |
| +} |
| + |
| +function prepareDatabase() { |
| + db = event.target.result; |
| + db.createObjectStore(store_name); |
| +} |
| + |
| +function writeBlob() { |
| + debug("Writing blob."); |
| + |
| + var trans = db.transaction(store_name, 'readwrite'); |
|
jsbell
2015/03/03 22:38:07
It's probably personal preference, but WDYT about
cmumford
2015/03/03 23:01:35
I think I see what you're talking about. Let me kn
|
| + trans.onabort = unexpectedAbortCallback; |
| + trans.oncomplete = function () { |
| + var trans = db.transaction(store_name); |
| + trans.onabort = unexpectedAbortCallback; |
| + trans.oncomplete = writeFile; |
| + |
| + var request = trans.objectStore(store_name).get(blob_key); |
| + request.onerror = unexpectedErrorCallback; |
| + request.onsuccess = function(evt) { |
| + get_blob = evt.target.result; |
| + resultType = typeof get_blob; |
| + shouldBe('resultType', '"object"'); |
| + shouldBe('get_blob.size', '0'); |
| + }; |
| + }; |
| + |
| + put_blob = new Blob(); |
| + var request = trans.objectStore(store_name).put(put_blob, blob_key); |
| + request.onerror = unexpectedErrorCallback; |
| +} |
| + |
| +function writeFile() { |
| + file = new File([''], 'somefile', { |
| + type: 'application/x-special-snowflake', |
| + lastModified: new Date('1999-12-31T23:59:59Z') |
|
jsbell
2015/03/03 22:38:07
Party like it's...
cmumford
2015/03/03 23:01:35
1999
|
| + }); |
| + var put_tx = db.transaction(store_name, 'readwrite'); |
| + put_tx.objectStore(store_name).put(file, file_key); |
| + put_tx.onabort = unexpectedAbortCallback; |
| + put_tx.oncomplete = function() { |
| + var get_tx = db.transaction(store_name); |
| + get_tx.onabort = unexpectedAbortCallback; |
| + get_tx.oncomplete = deleteFile; |
| + get_tx.objectStore(store_name).get(file_key).onsuccess = function(e) { |
| + result = e.target.result; |
|
jsbell
2015/03/03 22:38:07
Just a consistency nit: in the blob case you have
cmumford
2015/03/03 23:01:35
Done.
|
| + |
| + shouldBe('result.name', 'file.name'); |
| + shouldBe('result.size', 'file.size'); |
| + shouldBe('result.type', 'file.type'); |
| + shouldBe('result.lastModified', 'file.lastModified'); |
| + shouldBe('String(result.lastModifiedDate)', 'String(file.lastModifiedDate)'); |
| + }; |
| + }; |
| +} |
| + |
| +function deleteFile() { |
|
jsbell
2015/03/03 22:38:07
Should we have a case for deleting blob as well?
cmumford
2015/03/03 23:01:35
Done.
|
| + var put_tx = db.transaction(store_name, 'readwrite'); |
| + put_tx.objectStore(store_name).delete(file_key); |
| + put_tx.onabort = unexpectedAbortCallback; |
| + put_tx.oncomplete = function() { |
|
jsbell
2015/03/03 22:38:07
could just say: oncomplete = done;
cmumford
2015/03/03 23:01:35
Done.
|
| + done(); |
| + }; |
| +} |
| + |
| +</script> |
| +</head> |
| +<body onLoad="test()"> |
| + <input type="file" id="emptyFileInput"></input> |
| + <div id="status">Starting...</div> |
| +</body> |
| +</html> |