Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2046)

Unified Diff: content/test/data/indexeddb/empty_blob.html

Issue 942633004: IndexedDB: Fixed support for empty blobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test cleanup & added blob delete to test. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/browser/indexed_db_context.h ('k') | storage/browser/blob/blob_data_builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3e10e0829b6cab75a5a6c5c3d4d0ff30216ae773
--- /dev/null
+++ b/content/test/data/indexeddb/empty_blob.html
@@ -0,0 +1,99 @@
+<!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.");
+
+ put_blob = new Blob();
+
+ var put_tx = db.transaction(store_name, 'readwrite');
+ put_tx.onabort = unexpectedAbortCallback;
+ var put_request = put_tx.objectStore(store_name).put(put_blob, blob_key);
+ put_request.onerror = unexpectedErrorCallback;
+ put_tx.oncomplete = function () {
+ var get_tx = db.transaction(store_name);
+ get_tx.onabort = unexpectedAbortCallback;
+ get_tx.oncomplete = writeFile;
jsbell 2015/03/03 23:37:57 Maybe move this to the end of the block as well.
cmumford 2015/03/06 18:02:09 Done.
+
+ var get_request = get_tx.objectStore(store_name).get(blob_key);
+ get_request.onerror = unexpectedErrorCallback;
+ get_request.onsuccess = function(evt) {
+ get_blob = evt.target.result;
+ resultType = typeof get_blob;
+ shouldBe('resultType', '"object"');
+ shouldBe('get_blob.size', '0');
+ };
+ };
+}
+
+function writeFile() {
+ put_file = new File([''], 'somefile', {
+ type: 'application/x-special-snowflake',
+ lastModified: new Date('1999-12-31T23:59:59Z')
+ });
+ var put_tx = db.transaction(store_name, 'readwrite');
+ put_tx.objectStore(store_name).put(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;
jsbell 2015/03/03 23:37:57 Ditto.
cmumford 2015/03/06 18:02:10 Done.
+ get_tx.objectStore(store_name).get(file_key).onsuccess = function(e) {
+ get_file = e.target.result;
+
+ shouldBe('get_file.name', 'put_file.name');
+ shouldBe('get_file.size', 'put_file.size');
+ shouldBe('get_file.type', 'put_file.type');
+ shouldBe('get_file.lastModified', 'put_file.lastModified');
+ shouldBe('String(get_file.lastModifiedDate)', 'String(put_file.lastModifiedDate)');
+ };
+ };
+}
+
+function deleteBlob() {
jsbell 2015/03/03 23:37:57 Maybe move this below deleteFile(), to follow exec
cmumford 2015/03/06 18:02:09 Done.
+ var tx = db.transaction(store_name, 'readwrite');
+ tx.objectStore(store_name).delete(blob_key);
+ tx.onabort = unexpectedAbortCallback;
+ tx.oncomplete = done;
+}
+
+function deleteFile() {
+ var tx = db.transaction(store_name, 'readwrite');
+ tx.objectStore(store_name).delete(file_key);
+ tx.onabort = unexpectedAbortCallback;
+ tx.oncomplete = deleteBlob;
+}
+
+</script>
+</head>
+<body onLoad="test()">
+ <div id="status">Starting...</div>
+</body>
+</html>
« no previous file with comments | « content/public/browser/indexed_db_context.h ('k') | storage/browser/blob/blob_data_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698