OLD | NEW |
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, testNewFile); | 45 validateResult("file", fileValidation, testNewFile); |
51 } | 46 } |
52 | 47 |
53 var newFileValidation = ".name == newFile.name"; | 48 var newFileValidation = ".name == newFile.name"; |
54 function testNewFile() | 49 function testNewFile() |
55 { | 50 { |
56 debug(""); | 51 debug(""); |
57 debug("testNewFile():"); | 52 debug("testNewFile():"); |
58 evalAndLog("newFile = new File([test_content], 'filename', {type:'text/plain
'})"); | 53 evalAndLog("newFile = new File([test_content], 'filename', {type:'text/plain
'})"); |
59 validateResult("newFile", newFileValidation, testFileList); | 54 validateResult("newFile", newFileValidation, testFileList); |
60 } | 55 } |
61 | 56 |
62 var fileListValidation = "[1].name == fileInput.files[1].name"; | 57 var fileListValidation = "[1].name == fileInput.files[1].name"; |
63 function testFileList() | 58 function testFileList() |
64 { | 59 { |
65 debug(""); | 60 preamble(); |
66 debug("testFileList():"); | |
67 evalAndLog("filelist = fileInput.files"); | 61 evalAndLog("filelist = fileInput.files"); |
68 validateResult("filelist", | 62 validateResult("filelist", |
69 fileListValidation, testCursor); | 63 fileListValidation, testCursor); |
70 } | 64 } |
71 | 65 |
72 function testCursor() | 66 function testCursor() |
73 { | 67 { |
74 debug(""); | 68 preamble(); |
75 debug("testCursor():"); | |
76 evalAndLog("transaction = db.transaction('storeName', 'readonly')"); | 69 evalAndLog("transaction = db.transaction('storeName', 'readonly')"); |
77 transaction.onerror = unexpectedErrorCallback; | 70 transaction.onerror = unexpectedErrorCallback; |
78 transaction.onabort = unexpectedAbortCallback; | 71 transaction.onabort = unexpectedAbortCallback; |
79 evalAndLog("store = transaction.objectStore('storeName')"); | 72 evalAndLog("store = transaction.objectStore('storeName')"); |
80 evalAndLog("request = store.openCursor()"); | 73 evalAndLog("request = store.openCursor()"); |
81 | 74 |
82 var count = 0; | 75 var count = 0; |
83 request.onsuccess = continueToTest; | 76 request.onsuccess = continueToTest; |
84 | 77 |
85 function continueToTest(event) | 78 function continueToTest(event) |
(...skipping 19 matching lines...) Expand all Loading... |
105 shouldBeNull("cursor"); | 98 shouldBeNull("cursor"); |
106 finishJSTest(); | 99 finishJSTest(); |
107 return; | 100 return; |
108 default: | 101 default: |
109 testFailed("count was unexpectedly " + count); | 102 testFailed("count was unexpectedly " + count); |
110 } | 103 } |
111 evalAndLog("cursor.continue();"); | 104 evalAndLog("cursor.continue();"); |
112 } | 105 } |
113 } | 106 } |
114 | 107 |
115 function validateResult(variable, validation, onComplete) | 108 function validateResult(variable, validation, onSuccess) |
116 { | 109 { |
117 var keyName = variable + "key"; | 110 var keyName = variable + "key"; |
118 debug(""); | 111 debug(""); |
119 debug("validateResult(" + variable + "):"); | 112 debug("validateResult(" + variable + "):"); |
| 113 shouldBeTrue(variable + validation); |
120 evalAndLog("transaction = db.transaction('storeName', 'readwrite')"); | 114 evalAndLog("transaction = db.transaction('storeName', 'readwrite')"); |
121 evalAndLog("store = transaction.objectStore('storeName')"); | 115 evalAndLog("store = transaction.objectStore('storeName')"); |
122 evalAndLog("store.put(" + variable + ", '" + keyName + "')"); | 116 evalAndLog("store.put(" + variable + ", '" + keyName + "')"); |
123 transaction.onerror = unexpectedErrorCallback; | 117 transaction.onerror = unexpectedErrorCallback; |
124 transaction.onabort = unexpectedAbortCallback; | 118 transaction.onabort = unexpectedAbortCallback; |
125 var readTransactionOnComplete = function (e) { | 119 var onGetSuccess = function (e) { |
126 shouldBeTrue("event.target.result" + validation); | 120 shouldBeTrue("event.target.result" + validation); |
127 onComplete(); | 121 onSuccess(); |
128 } | 122 } |
129 transaction.oncomplete = function () { | 123 transaction.oncomplete = function () { |
130 doRead(keyName, readTransactionOnComplete); | 124 doRead(keyName, onGetSuccess); |
131 } | 125 } |
132 } | 126 } |
133 | 127 |
134 function doRead(keyName, onComplete) | 128 function doRead(keyName, onSuccess) |
135 { | 129 { |
136 evalAndLog("transaction = db.transaction('storeName', 'readwrite')"); | 130 evalAndLog("transaction = db.transaction('storeName', 'readwrite')"); |
137 evalAndLog("store = transaction.objectStore('storeName')"); | 131 evalAndLog("store = transaction.objectStore('storeName')"); |
138 evalAndLog("request = store.get('" + keyName + "')"); | 132 evalAndLog("request = store.get('" + keyName + "')"); |
139 request.onsuccess = onComplete; | 133 request.onsuccess = onSuccess; |
140 transaction.onerror = unexpectedErrorCallback; | 134 transaction.onerror = unexpectedErrorCallback; |
141 transaction.onabort = unexpectedAbortCallback; | 135 transaction.onabort = unexpectedAbortCallback; |
142 } | 136 } |
143 | 137 |
144 if (window.eventSender) { | 138 if (window.eventSender) { |
145 indexedDBTest(prepareDatabase, testBlob); | 139 indexedDBTest(prepareDatabase, testBlob); |
146 } else { | 140 } else { |
147 alert("Select at least 2 files using the input control above to initiate the
test"); | 141 alert("Select at least 2 files using the input control above to initiate the
test"); |
148 document.getElementById("fileInput").onchange = function() { indexedDBTest(p
repareDatabase, testBlob); }; | 142 document.getElementById("fileInput").onchange = function() { indexedDBTest(p
repareDatabase, testBlob); }; |
149 } | 143 } |
150 | 144 |
151 </script> | 145 </script> |
152 </body> | |
153 </html> | |
OLD | NEW |