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

Unified Diff: LayoutTests/storage/indexeddb/empty-blob-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: Updated test expectations to match ToT. Created 5 years, 9 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-blob-file.html
diff --git a/LayoutTests/storage/indexeddb/empty-blob-file.html b/LayoutTests/storage/indexeddb/empty-blob-file.html
new file mode 100644
index 0000000000000000000000000000000000000000..599250dd640e9385fbe40090406a71dd1467a142
--- /dev/null
+++ b/LayoutTests/storage/indexeddb/empty-blob-file.html
@@ -0,0 +1,124 @@
+<!DOCTYPE html>
+<script src="../../resources/js-test.js"></script>
+<script src="resources/shared.js"></script>
+<input type="file" id="emptyFileInput"></input>
+<input type="file" id="emptyFileListInput" multiple></input>
+<script>
+
+description("Confirm that IndexedDB can store an empty Blob/File/FileList");
+
+var emptyFileInput = document.getElementById("emptyFileInput");
+var emptyFileListInput = document.getElementById("emptyFileListInput");
+if (window.eventSender) {
+ var fileRect = emptyFileInput.getClientRects()[0];
+ var targetX = fileRect.left + fileRect.width / 2;
+ var targetY = fileRect.top + fileRect.height / 2;
+ eventSender.beginDragWithFiles(['resources/empty.txt']);
+ eventSender.mouseMoveTo(targetX, targetY);
+ eventSender.mouseUp();
+}
+
+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 blobValidation = ".size == 0";
+function testEmptyBlob()
+{
+ preamble();
+ evalAndLog("blob = new Blob([])");
+ validateResult("blob", blobValidation, testEmptyDataBlob);
+}
+function testEmptyDataBlob()
+{
+ preamble();
+ evalAndLog("blob = new Blob(['', '', ''])");
+ validateResult("blob", blobValidation, testEmptyNestedBlob);
+}
+function testEmptyNestedBlob()
+{
+ preamble();
+ evalAndLog("blob = new Blob(['', new Blob([]), ''])");
+ validateResult("blob", blobValidation, testEmptyNestedDataBlob);
+}
+function testEmptyNestedDataBlob()
+{
+ preamble();
+ evalAndLog("blob = new Blob(['', new Blob(['']), ''])");
+ validateResult("blob", blobValidation, testEmptyFileInsideBlob);
+}
+function testEmptyFileInsideBlob()
+{
+ preamble();
+ evalAndLog("file = emptyFileInput.files[0]");
+ evalAndLog("blob = new Blob(['', file, ''])");
+ validateResult("blob", blobValidation, testEmptyFileInsideNestedBlob);
+}
+function testEmptyFileInsideNestedBlob()
+{
+ preamble();
+ evalAndLog("file = emptyFileInput.files[0]");
+ evalAndLog("blob = new Blob(['', new Blob([file]), ''])");
+ validateResult("blob", blobValidation, testEmptyFile);
+}
+
+var fileValidation = ".size == 0";
+function testEmptyFile()
+{
+ preamble();
+ evalAndLog("file = emptyFileInput.files[0]");
+ validateResult("file", fileValidation, testEmptyFileList);
+}
+
+var fileListValidation = ".length == 0";
+function testEmptyFileList()
+{
+ preamble();
+ evalAndLog("fileList = emptyFileListInput.files");
+ validateResult("fileList",
+ fileListValidation, finishJSTest);
+}
+
+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;
+}
+
+if (window.eventSender) {
+ indexedDBTest(prepareDatabase, testEmptyBlob);
+} else {
+ alert("Select an empty file using the left input control above to initiate the test");
+ document.getElementById("emptyFileInput").onchange = function() { indexedDBTest(prepareDatabase, testEmptyBlob); };
+}
+</script>

Powered by Google App Engine
This is Rietveld 408576698