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

Side by Side 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: Addressed feedback. Created 6 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../../resources/js-test.js"></script>
3 <script src="resources/shared.js"></script>
4 <input type="file" id="emptyFileInput"></input>
5 <input type="file" id="emptyFileListInput" multiple></input>
6 <script>
7
8 description("Confirm that IndexedDB can store an empty Blob/File/FileList");
9
10 var emptyFileInput = document.getElementById("emptyFileInput");
11 var emptyFileListInput = document.getElementById("emptyFileListInput");
12 if (window.eventSender) {
13 var fileRect = emptyFileInput.getClientRects()[0];
14 var targetX = fileRect.left + fileRect.width / 2;
15 var targetY = fileRect.top + fileRect.height / 2;
16 eventSender.beginDragWithFiles(['resources/empty.txt']);
17 eventSender.mouseMoveTo(targetX, targetY);
18 eventSender.mouseUp();
19 }
20
21 function prepareDatabase()
22 {
23 db = event.target.result;
24 var trans = event.target.transaction;
25 evalAndLog("store = db.createObjectStore('storeName')");
26 evalAndLog("store.put('value', 'key')");
27 trans.onerror = unexpectedErrorCallback;
28 trans.onabort = unexpectedAbortCallback;
29 }
30
31 var blobValidation = ".size == 0";
32 function testEmptyBlob()
33 {
34 preamble();
35 evalAndLog("blob = new Blob([])");
36 validateResult("blob", blobValidation, testEmptyDataBlob);
37 }
38 function testEmptyDataBlob()
39 {
40 preamble();
41 evalAndLog("blob = new Blob(['', '', ''])");
42 validateResult("blob", blobValidation, testEmptyNestedBlob);
43 }
44 function testEmptyNestedBlob()
45 {
46 preamble();
47 evalAndLog("blob = new Blob(['', new Blob([]), ''])");
48 validateResult("blob", blobValidation, testEmptyNestedDataBlob);
49 }
50 function testEmptyNestedDataBlob()
51 {
52 preamble();
53 evalAndLog("blob = new Blob(['', new Blob(['']), ''])");
54 validateResult("blob", blobValidation, testEmptyFileInsideBlob);
55 }
56 function testEmptyFileInsideBlob()
57 {
58 preamble();
59 evalAndLog("file = emptyFileInput.files[0]");
60 evalAndLog("blob = new Blob(['', file, ''])");
61 validateResult("blob", blobValidation, testEmptyFileInsideNestedBlob);
62 }
63 function testEmptyFileInsideNestedBlob()
64 {
65 preamble();
66 evalAndLog("file = emptyFileInput.files[0]");
67 evalAndLog("blob = new Blob(['', new Blob([file]), ''])");
68 validateResult("blob", blobValidation, testEmptyFile);
69 }
70
71 var fileValidation = ".size == 0";
72 function testEmptyFile()
73 {
74 preamble();
75 evalAndLog("file = emptyFileInput.files[0]");
76 validateResult("file", fileValidation, testEmptyFileList);
77 }
78
79 var fileListValidation = ".length == 0";
80 function testEmptyFileList()
81 {
82 preamble();
83 evalAndLog("fileList = emptyFileListInput.files");
84 validateResult("fileList",
85 fileListValidation, finishJSTest);
86 }
87
88 function validateResult(variable, validation, onSuccess)
89 {
90 var keyName = variable + "key";
91 debug("");
92 debug("validateResult(" + variable + "):");
93 shouldBeTrue(variable + validation);
94 evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
95 evalAndLog("store = transaction.objectStore('storeName')");
96 evalAndLog("store.put(" + variable + ", '" + keyName + "')");
97 transaction.onerror = unexpectedErrorCallback;
98 transaction.onabort = unexpectedAbortCallback;
99 var onGetSuccess = function (e) {
100 shouldBeTrue("event.target.result" + validation);
101 onSuccess();
102 }
103 transaction.oncomplete = function () {
104 doRead(keyName, onGetSuccess);
105 }
106 }
107
108 function doRead(keyName, onSuccess)
109 {
110 evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
111 evalAndLog("store = transaction.objectStore('storeName')");
112 evalAndLog("request = store.get('" + keyName + "')");
113 request.onsuccess = onSuccess;
114 transaction.onerror = unexpectedErrorCallback;
115 transaction.onabort = unexpectedAbortCallback;
116 }
117
118 if (window.eventSender) {
119 indexedDBTest(prepareDatabase, testEmptyBlob);
120 } else {
121 alert("Select an empty file using the left input control above to initiate t he test");
122 document.getElementById("emptyFileInput").onchange = function() { indexedDBT est(prepareDatabase, testEmptyBlob); };
123 }
124 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698