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

Side by Side Diff: LayoutTests/storage/indexeddb/blob-basics-metadata.html

Issue 18590006: Blob support for IDB [Blink] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebasing issue? Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 <html>
2 <head>
3 <script src="../../resources/js-test.js"></script>
4 <script src="resources/shared.js"></script>
5 </head>
6 <body>
7 <input type="file" id="fileInput" multiple></input>
8 <script>
9
10 description("Confirm basic Blob/File/FileList functionality.");
11
12 fileInput = document.getElementById("fileInput");
13 if (window.eventSender) {
14 var fileRect = fileInput.getClientRects()[0];
15 var targetX = fileRect.left + fileRect.width / 2;
16 var targetY = fileRect.top + fileRect.height / 2;
17 eventSender.beginDragWithFiles(['resources/test-data.html', 'resources/test- data.txt']);
18 eventSender.mouseMoveTo(targetX, targetY);
19 eventSender.mouseUp();
20 }
21
22 function prepareDatabase()
23 {
24 db = event.target.result;
25 var trans = event.target.transaction;
26 evalAndLog("store = db.createObjectStore('storeName')");
27 evalAndLog("store.put('value', 'key')");
28 trans.onerror = unexpectedErrorCallback;
29 trans.onabort = unexpectedAbortCallback;
30 }
31
32 var blobValidation = ".size == test_content.length";
33 function testBlob()
34 {
35 debug("");
36 debug("testBlob():");
37
38 shouldBeTrue("FileReader != null");
39 evalAndLog("test_content = 'This is a test. This is only a test.'");
40 evalAndLog("blob = new Blob([test_content])");
41 validateResult("blob", blobValidation, testFile);
42 }
43
44 var fileValidation = ".name == fileInput.files[0].name";
45 function testFile()
46 {
47 debug("");
48 debug("testFile():");
49 evalAndLog("file = fileInput.files[0]");
50 validateResult("file", fileValidation, testFileList);
51 }
52
53 var fileListValidation = "[1].name == fileInput.files[1].name";
54 function testFileList()
55 {
56 debug("");
57 debug("testFileList():");
58 evalAndLog("filelist = fileInput.files");
59 validateResult("filelist",
60 fileListValidation, testCursor);
61 }
62
63 function testCursor()
64 {
65 debug("");
66 debug("testCursor():");
67 evalAndLog("transaction = db.transaction('storeName', 'readonly')");
68 transaction.onerror = unexpectedErrorCallback;
69 evalAndLog("store = transaction.objectStore('storeName')");
70 evalAndLog("request = store.openCursor()");
71
72 var count = 0;
73 request.onsuccess = continueToTest;
74
75 function continueToTest(event)
76 {
77 cursor = event.target.result;
78 switch (count++) {
79 case 0:
80 shouldBeTrue("cursor.value" + blobValidation);
81 break;
82 case 1:
83 shouldBeTrue("cursor.value" + fileValidation);
84 break;
85 case 2:
86 shouldBeTrue("cursor.value" + fileListValidation);
87 break;
88 case 3:
89 shouldBeTrue("cursor.value == 'value'");
90 break;
91 case 4:
92 shouldBeNull(cursor);
jsbell 2014/05/29 00:40:06 should be: shouldBeNull("cursor")
ericu 2014/06/02 22:18:47 Done.
93 finishJSTest();
94 return;
95 default:
96 testFailed("count was unexpectedly " + count);
97 }
98 evalAndLog("cursor.continue();");
99 }
100 }
101
102 function validateResult(variable, validation, onComplete)
103 {
104 var keyName = variable + "key";
105 debug("");
106 debug("validateResult(" + variable + "):");
107 evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
108 evalAndLog("store = transaction.objectStore('storeName')");
109 evalAndLog("store.put(" + variable + ", '" + keyName + "')");
110 var readTransactionOnComplete = getValidator(validation, onComplete);
111 transaction.oncomplete = function () {
112 doRead(keyName, readTransactionOnComplete);
jsbell 2014/05/29 00:40:06 Personally, I find the use of getValidator here ma
ericu 2014/06/02 22:18:47 Done; I suspect that was left over from more compl
113 }
114 }
115
116 function getValidator(validation, onComplete)
117 {
118 return function (e) {
119 shouldBeTrue("event.target.result" + validation);
120 onComplete();
121 }
122 }
123
124 function doRead(keyName, onComplete)
125 {
126 evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
127 evalAndLog("store = transaction.objectStore('storeName')");
128 evalAndLog("request = store.get('" + keyName + "')");
129 request.onsuccess = onComplete;
130 transaction.onerror = unexpectedErrorCallback;
131 }
132
133 if (window.eventSender) {
134 indexedDBTest(prepareDatabase, testBlob);
135 } else {
136 alert("Select at least 2 files using the input control above to initiate the test");
137 document.getElementById("fileInput").onchange = function() { indexedDBTest(p repareDatabase, testBlob); };
138 }
139
140 </script>
141 </body>
142 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698