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

Side by Side Diff: LayoutTests/storage/indexeddb/blob-basics-metadata.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
1 <html> 1 <!DOCTYPE html>
2 <head>
3 <script src="../../resources/js-test.js"></script> 2 <script src="../../resources/js-test.js"></script>
4 <script src="resources/shared.js"></script> 3 <script src="resources/shared.js"></script>
5 </head>
6 <body>
7 <input type="file" id="fileInput" multiple></input> 4 <input type="file" id="fileInput" multiple></input>
8 <script> 5 <script>
9 6
10 description("Confirm basic Blob/File/FileList functionality."); 7 description("Confirm basic Blob/File/FileList functionality.");
11 8
12 fileInput = document.getElementById("fileInput"); 9 fileInput = document.getElementById("fileInput");
13 if (window.eventSender) { 10 if (window.eventSender) {
14 var fileRect = fileInput.getClientRects()[0]; 11 var fileRect = fileInput.getClientRects()[0];
15 var targetX = fileRect.left + fileRect.width / 2; 12 var targetX = fileRect.left + fileRect.width / 2;
16 var targetY = fileRect.top + fileRect.height / 2; 13 var targetY = fileRect.top + fileRect.height / 2;
17 eventSender.beginDragWithFiles(['resources/test-data.html', 'resources/test- data.txt']); 14 eventSender.beginDragWithFiles(['resources/test-data.html', 'resources/test- data.txt']);
18 eventSender.mouseMoveTo(targetX, targetY); 15 eventSender.mouseMoveTo(targetX, targetY);
19 eventSender.mouseUp(); 16 eventSender.mouseUp();
20 } 17 }
21 18
22 function prepareDatabase() 19 function prepareDatabase()
23 { 20 {
24 db = event.target.result; 21 db = event.target.result;
25 var trans = event.target.transaction; 22 var trans = event.target.transaction;
26 evalAndLog("store = db.createObjectStore('storeName')"); 23 evalAndLog("store = db.createObjectStore('storeName')");
27 evalAndLog("store.put('value', 'key')"); 24 evalAndLog("store.put('value', 'key')");
28 trans.onerror = unexpectedErrorCallback; 25 trans.onerror = unexpectedErrorCallback;
29 trans.onabort = unexpectedAbortCallback; 26 trans.onabort = unexpectedAbortCallback;
30 } 27 }
31 28
32 var blobValidation = ".size == test_content.length"; 29 var blobValidation = ".size == test_content.length";
33 function testBlob() 30 function testBlob()
34 { 31 {
35 debug(""); 32 preamble();
36 debug("testBlob():");
37 33
38 shouldBeTrue("FileReader != null"); 34 shouldBeTrue("FileReader != null");
39 evalAndLog("test_content = 'This is a test. This is only a test.'"); 35 evalAndLog("test_content = 'This is a test. This is only a test.'");
40 evalAndLog("blob = new Blob([test_content])"); 36 evalAndLog("blob = new Blob([test_content])");
41 validateResult("blob", blobValidation, testFile); 37 validateResult("blob", blobValidation, testFile);
42 } 38 }
43 39
44 var fileValidation = ".name == fileInput.files[0].name"; 40 var fileValidation = ".name == fileInput.files[0].name";
45 function testFile() 41 function testFile()
46 { 42 {
47 debug(""); 43 preamble();
48 debug("testFile():");
49 evalAndLog("file = fileInput.files[0]"); 44 evalAndLog("file = fileInput.files[0]");
50 validateResult("file", fileValidation, testFileList); 45 validateResult("file", fileValidation, testFileList);
51 } 46 }
52 47
53 var fileListValidation = "[1].name == fileInput.files[1].name"; 48 var fileListValidation = "[1].name == fileInput.files[1].name";
54 function testFileList() 49 function testFileList()
55 { 50 {
56 debug(""); 51 preamble();
57 debug("testFileList():");
58 evalAndLog("filelist = fileInput.files"); 52 evalAndLog("filelist = fileInput.files");
59 validateResult("filelist", 53 validateResult("filelist",
60 fileListValidation, testCursor); 54 fileListValidation, testCursor);
61 } 55 }
62 56
63 function testCursor() 57 function testCursor()
64 { 58 {
65 debug(""); 59 preamble();
66 debug("testCursor():");
67 evalAndLog("transaction = db.transaction('storeName', 'readonly')"); 60 evalAndLog("transaction = db.transaction('storeName', 'readonly')");
68 transaction.onerror = unexpectedErrorCallback; 61 transaction.onerror = unexpectedErrorCallback;
69 transaction.onabort = unexpectedAbortCallback; 62 transaction.onabort = unexpectedAbortCallback;
70 evalAndLog("store = transaction.objectStore('storeName')"); 63 evalAndLog("store = transaction.objectStore('storeName')");
71 evalAndLog("request = store.openCursor()"); 64 evalAndLog("request = store.openCursor()");
72 65
73 var count = 0; 66 var count = 0;
74 request.onsuccess = continueToTest; 67 request.onsuccess = continueToTest;
75 68
76 function continueToTest(event) 69 function continueToTest(event)
(...skipping 16 matching lines...) Expand all
93 shouldBeNull("cursor"); 86 shouldBeNull("cursor");
94 finishJSTest(); 87 finishJSTest();
95 return; 88 return;
96 default: 89 default:
97 testFailed("count was unexpectedly " + count); 90 testFailed("count was unexpectedly " + count);
98 } 91 }
99 evalAndLog("cursor.continue();"); 92 evalAndLog("cursor.continue();");
100 } 93 }
101 } 94 }
102 95
103 function validateResult(variable, validation, onComplete) 96 function validateResult(variable, validation, onSuccess)
104 { 97 {
105 var keyName = variable + "key"; 98 var keyName = variable + "key";
106 debug(""); 99 debug("");
107 debug("validateResult(" + variable + "):"); 100 debug("validateResult(" + variable + "):");
101 shouldBeTrue(variable + validation);
108 evalAndLog("transaction = db.transaction('storeName', 'readwrite')"); 102 evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
109 evalAndLog("store = transaction.objectStore('storeName')"); 103 evalAndLog("store = transaction.objectStore('storeName')");
110 evalAndLog("store.put(" + variable + ", '" + keyName + "')"); 104 evalAndLog("store.put(" + variable + ", '" + keyName + "')");
111 transaction.onerror = unexpectedErrorCallback; 105 transaction.onerror = unexpectedErrorCallback;
112 transaction.onabort = unexpectedAbortCallback; 106 transaction.onabort = unexpectedAbortCallback;
113 var readTransactionOnComplete = function (e) { 107 var onGetSuccess = function (e) {
114 shouldBeTrue("event.target.result" + validation); 108 shouldBeTrue("event.target.result" + validation);
115 onComplete(); 109 onSuccess();
116 } 110 }
117 transaction.oncomplete = function () { 111 transaction.oncomplete = function () {
118 doRead(keyName, readTransactionOnComplete); 112 doRead(keyName, onGetSuccess);
119 } 113 }
120 } 114 }
121 115
122 function doRead(keyName, onComplete) 116 function doRead(keyName, onSuccess)
123 { 117 {
124 evalAndLog("transaction = db.transaction('storeName', 'readwrite')"); 118 evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
125 evalAndLog("store = transaction.objectStore('storeName')"); 119 evalAndLog("store = transaction.objectStore('storeName')");
126 evalAndLog("request = store.get('" + keyName + "')"); 120 evalAndLog("request = store.get('" + keyName + "')");
127 request.onsuccess = onComplete; 121 request.onsuccess = onSuccess;
128 transaction.onerror = unexpectedErrorCallback; 122 transaction.onerror = unexpectedErrorCallback;
129 transaction.onabort = unexpectedAbortCallback; 123 transaction.onabort = unexpectedAbortCallback;
130 } 124 }
131 125
132 if (window.eventSender) { 126 if (window.eventSender) {
133 indexedDBTest(prepareDatabase, testBlob); 127 indexedDBTest(prepareDatabase, testBlob);
134 } else { 128 } else {
135 alert("Select at least 2 files using the input control above to initiate the test"); 129 alert("Select at least 2 files using the input control above to initiate the test");
136 document.getElementById("fileInput").onchange = function() { indexedDBTest(p repareDatabase, testBlob); }; 130 document.getElementById("fileInput").onchange = function() { indexedDBTest(p repareDatabase, testBlob); };
137 } 131 }
138 132
139 </script> 133 </script>
140 </body>
141 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698