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

Unified Diff: LayoutTests/storage/indexeddb/empty-filesystem-file.html

Issue 433983002: LayoutTests for writing empty Blob/File/FileList to IndexedDB. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed feedback. Created 6 years, 5 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
Index: LayoutTests/storage/indexeddb/empty-filesystem-file.html
diff --git a/LayoutTests/storage/indexeddb/empty-filesystem-file.html b/LayoutTests/storage/indexeddb/empty-filesystem-file.html
new file mode 100644
index 0000000000000000000000000000000000000000..a3aa6850a52ef7e8eff31e06c958dd3201cdba4a
--- /dev/null
+++ b/LayoutTests/storage/indexeddb/empty-filesystem-file.html
@@ -0,0 +1,90 @@
+<!DOCTYPE html>
+<script src="../../resources/js-test.js"></script>
+<script src="resources/shared.js"></script>
+<script>
+
+description("Confirm that IndexedDB can store an empty File from the Filesystem API");
+
+function prepareDatabase()
+{
+ db = event.target.result;
+ var trans = event.target.transaction;
+ evalAndLog("store = db.createObjectStore('storeName')");
+ evalAndLog("store.put('value', 'key')");
+ trans.onerror = unexpectedErrorCallback;
+ trans.onabort = unexpectedAbortCallback;
+}
+
+var fileValidation = ".size == 0";
+function testEmptyFilesystemFile()
+{
+ preamble();
+ evalAndLog("file = window.emptyFile");
+ validateResult("file", fileValidation, cleanupFs);
+}
+
+function validateResult(variable, validation, onSuccess)
+{
+ var keyName = variable + "key";
+ debug("");
+ debug("validateResult(" + variable + "):");
+ shouldBeTrue(variable + validation);
+ evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
+ evalAndLog("store = transaction.objectStore('storeName')");
+ evalAndLog("store.put(" + variable + ", '" + keyName + "')");
+ transaction.onerror = unexpectedErrorCallback;
+ transaction.onabort = unexpectedAbortCallback;
+ var onGetSuccess = function (e) {
+ shouldBeTrue("event.target.result" + validation);
+ onSuccess();
+ }
+ transaction.oncomplete = function () {
+ doRead(keyName, onGetSuccess);
+ }
+}
+
+function doRead(keyName, onSuccess)
+{
+ evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
+ evalAndLog("store = transaction.objectStore('storeName')");
+ evalAndLog("request = store.get('" + keyName + "')");
+ request.onsuccess = onSuccess;
+ transaction.onerror = unexpectedErrorCallback;
+ transaction.onabort = unexpectedAbortCallback;
+}
+
+function fsError(error)
+{
+ debug("Filesystem error:" + error.name);
+ cleanupFs();
+}
+function fsCreated(fs)
+{
+ debug("Got FileSystem:" + fs.name);
+ window.fileSystem = fs;
+
+ fs.root.getFile("empty.txt", {create: true}, function(entry) {
+ entry.file(function(file) {
+ window.emptyFile = file;
+ indexedDBTest(prepareDatabase, testEmptyFilesystemFile);
+ });
+ }, fsError);
+}
+
+if (window.webkitRequestFileSystem)
+ window.webkitRequestFileSystem(TEMPORARY, 100, fsCreated, fsError);
+else
+ alert("This test requires the FileSystem API");
+
+function cleanupFs()
+{
+ if (window.fileSystem) {
+ var fs = window.fileSystem;
+ // cleanupFs shouldn't get called again if an error occurs below.
+ window.fileSystem = null;
+ fs.root.getFile("empty.txt", {create: false}, function (entry) {
+ entry.remove(finishJSTest, fsError);
+ }, fsError);
+ }
+}
+</script>

Powered by Google App Engine
This is Rietveld 408576698