Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / empty-blob-file.html
blob599250dd640e9385fbe40090406a71dd1467a142
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>
8 description("Confirm that IndexedDB can store an empty Blob/File/FileList");
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();
21 function prepareDatabase()
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;
31 var blobValidation = ".size == 0";
32 function testEmptyBlob()
34 preamble();
35 evalAndLog("blob = new Blob([])");
36 validateResult("blob", blobValidation, testEmptyDataBlob);
38 function testEmptyDataBlob()
40 preamble();
41 evalAndLog("blob = new Blob(['', '', ''])");
42 validateResult("blob", blobValidation, testEmptyNestedBlob);
44 function testEmptyNestedBlob()
46 preamble();
47 evalAndLog("blob = new Blob(['', new Blob([]), ''])");
48 validateResult("blob", blobValidation, testEmptyNestedDataBlob);
50 function testEmptyNestedDataBlob()
52 preamble();
53 evalAndLog("blob = new Blob(['', new Blob(['']), ''])");
54 validateResult("blob", blobValidation, testEmptyFileInsideBlob);
56 function testEmptyFileInsideBlob()
58 preamble();
59 evalAndLog("file = emptyFileInput.files[0]");
60 evalAndLog("blob = new Blob(['', file, ''])");
61 validateResult("blob", blobValidation, testEmptyFileInsideNestedBlob);
63 function testEmptyFileInsideNestedBlob()
65 preamble();
66 evalAndLog("file = emptyFileInput.files[0]");
67 evalAndLog("blob = new Blob(['', new Blob([file]), ''])");
68 validateResult("blob", blobValidation, testEmptyFile);
71 var fileValidation = ".size == 0";
72 function testEmptyFile()
74 preamble();
75 evalAndLog("file = emptyFileInput.files[0]");
76 validateResult("file", fileValidation, testEmptyFileList);
79 var fileListValidation = ".length == 0";
80 function testEmptyFileList()
82 preamble();
83 evalAndLog("fileList = emptyFileListInput.files");
84 validateResult("fileList",
85 fileListValidation, finishJSTest);
88 function validateResult(variable, validation, onSuccess)
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();
103 transaction.oncomplete = function () {
104 doRead(keyName, onGetSuccess);
108 function doRead(keyName, onSuccess)
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;
118 if (window.eventSender) {
119 indexedDBTest(prepareDatabase, testEmptyBlob);
120 } else {
121 alert("Select an empty file using the left input control above to initiate the test");
122 document.getElementById("emptyFileInput").onchange = function() { indexedDBTest(prepareDatabase, testEmptyBlob); };
124 </script>