1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * @type {DeviceHandler}
18 * Callbacks registered by setTimeout.
19 * @type {Array.<function>}
23 // Set up the test components.
25 // Set up string assets.
27 REMOVABLE_DEVICE_DETECTION_TITLE: 'Device detected',
28 REMOVABLE_DEVICE_SCANNING_MESSAGE: 'Scanning...',
29 DEVICE_UNKNOWN_MESSAGE: 'DEVICE_UNKNOWN: $1',
30 DEVICE_UNSUPPORTED_MESSAGE: 'DEVICE_UNSUPPORTED: $1',
31 MULTIPART_DEVICE_UNSUPPORTED_MESSAGE: 'MULTIPART_DEVICE_UNSUPPORTED: $1',
32 EXTERNAL_STORAGE_DISABLED_MESSAGE: 'EXTERNAL_STORAGE_DISABLED',
33 FORMATTING_OF_DEVICE_PENDING_TITLE: 'FORMATTING_OF_DEVICE_PENDING_TITLE',
34 FORMATTING_OF_DEVICE_PENDING_MESSAGE: 'FORMATTING_OF_DEVICE_PENDING',
35 FORMATTING_OF_DEVICE_FINISHED_TITLE: 'FORMATTING_OF_DEVICE_FINISHED_TITLE',
36 FORMATTING_FINISHED_SUCCESS_MESSAGE: 'FORMATTING_FINISHED_SUCCESS',
37 FORMATTING_OF_DEVICE_FAILED_TITLE: 'FORMATTING_OF_DEVICE_FAILED_TITLE',
38 FORMATTING_FINISHED_FAILURE_MESSAGE: 'FORMATTING_FINISHED_FAILURE'
45 addListener: function(listener) {
46 this.dispatch = listener;
50 addListener: function(listener) {
51 this.dispatch = listener;
56 create: function(id, params, callback) {
57 assertFalse(!!this.items[id]);
58 this.items[id] = params;
61 clear: function(id, callback) { delete this.items[id]; callback(); },
65 getURL: function(path) { return path; }
69 // Reset timeout callbacks.
70 timeoutCallbacks = [];
72 // Make a device handler.
73 handler = new DeviceHandler();
77 * Overrided setTimoeut funciton.
79 window.setTimeout = function(func) {
80 timeoutCallbacks.push(func);
84 * Call all pending timeout functions.
86 function callTimeoutCallbacks() {
87 while (timeoutCallbacks.length) {
88 timeoutCallbacks.shift()();
92 function registerTypicalDevice() {
93 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
95 devicePath: '/device/path'
97 assertFalse('device:/device/path' in chrome.notifications.items);
98 callTimeoutCallbacks();
99 assertEquals('Scanning...',
100 chrome.notifications.items['device:/device/path'].message);
103 function testGoodDevice() {
104 registerTypicalDevice();
105 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
108 isParentDevice: true,
110 devicePath: '/device/path',
114 assertEquals(0, Object.keys(chrome.notifications.items).length);
117 function testGoodDeviceWithBadParent() {
118 registerTypicalDevice();
120 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
121 status: 'error_internal',
123 isParentDevice: true,
125 devicePath: '/device/path',
129 assertFalse(!!chrome.notifications.items['device:/device/path']);
131 'DEVICE_UNKNOWN: label',
132 chrome.notifications.items['deviceFail:/device/path'].message);
134 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
137 isParentDevice: false,
139 devicePath: '/device/path',
143 assertEquals(0, Object.keys(chrome.notifications.items).length);
145 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
148 isParentDevice: false,
150 devicePath: '/device/path',
154 // Should do nothing this time.
155 assertEquals(0, Object.keys(chrome.notifications.items).length);
158 function testUnsupportedDevice() {
159 registerTypicalDevice();
161 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
162 status: 'error_unsuported_filesystem',
164 isParentDevice: false,
166 devicePath: '/device/path',
170 assertFalse(!!chrome.notifications.items['device:/device/path']);
172 'DEVICE_UNSUPPORTED: label',
173 chrome.notifications.items['deviceFail:/device/path'].message);
176 function testUnsupportedWithUnknownParent() {
177 registerTypicalDevice();
179 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
180 status: 'error_internal',
182 isParentDevice: true,
184 devicePath: '/device/path',
189 'DEVICE_UNKNOWN: label',
190 chrome.notifications.items['deviceFail:/device/path'].message);
192 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
193 status: 'error_unsuported_filesystem',
195 isParentDevice: false,
197 devicePath: '/device/path',
201 assertEquals(1, Object.keys(chrome.notifications.items).length);
203 'DEVICE_UNSUPPORTED: label',
204 chrome.notifications.items['deviceFail:/device/path'].message);
207 function testMountPartialSuccess() {
208 registerTypicalDevice();
210 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
213 isParentDevice: false,
215 devicePath: '/device/path',
219 assertEquals(0, Object.keys(chrome.notifications.items).length);
221 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
222 status: 'error_unsuported_filesystem',
224 isParentDevice: false,
226 devicePath: '/device/path',
230 assertEquals(1, Object.keys(chrome.notifications.items).length);
232 'MULTIPART_DEVICE_UNSUPPORTED: label',
233 chrome.notifications.items['deviceFail:/device/path'].message);
236 function testUnknown() {
237 registerTypicalDevice();
239 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
240 status: 'error_unknown',
242 isParentDevice: false,
244 devicePath: '/device/path',
248 assertEquals(1, Object.keys(chrome.notifications.items).length);
250 'DEVICE_UNKNOWN: label',
251 chrome.notifications.items['deviceFail:/device/path'].message);
254 function testNonASCIILabel() {
255 registerTypicalDevice();
257 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
258 status: 'error_internal',
260 isParentDevice: false,
262 devicePath: '/device/path',
263 // "RA (U+30E9) BE (U+30D9) RU (U+30EB)" in Katakana letters.
264 deviceLabel: '\u30E9\u30D9\u30EB'
267 assertEquals(1, Object.keys(chrome.notifications.items).length);
269 'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB',
270 chrome.notifications.items['deviceFail:/device/path'].message);
273 function testMulitpleFail() {
274 registerTypicalDevice();
276 // The first parent error.
277 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
278 status: 'error_internal',
280 isParentDevice: true,
282 devicePath: '/device/path',
286 assertEquals(1, Object.keys(chrome.notifications.items).length);
288 'DEVICE_UNKNOWN: label',
289 chrome.notifications.items['deviceFail:/device/path'].message);
291 // The first child error that replaces the parent error.
292 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
293 status: 'error_internal',
295 isParentDevice: false,
297 devicePath: '/device/path',
301 assertEquals(1, Object.keys(chrome.notifications.items).length);
303 'DEVICE_UNKNOWN: label',
304 chrome.notifications.items['deviceFail:/device/path'].message);
306 // The second child error that turns to a multi-partition error.
307 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
308 status: 'error_internal',
310 isParentDevice: false,
312 devicePath: '/device/path',
316 assertEquals(1, Object.keys(chrome.notifications.items).length);
318 'MULTIPART_DEVICE_UNSUPPORTED: label',
319 chrome.notifications.items['deviceFail:/device/path'].message);
321 // The third child error that should be ignored because the error message does
323 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
324 status: 'error_internal',
326 isParentDevice: false,
328 devicePath: '/device/path',
332 assertEquals(1, Object.keys(chrome.notifications.items).length);
334 'MULTIPART_DEVICE_UNSUPPORTED: label',
335 chrome.notifications.items['deviceFail:/device/path'].message);
338 function testScanCanceled() {
339 registerTypicalDevice();
341 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
342 type: 'scan_canceled',
343 devicePath: '/device/path'
345 assertEquals(0, Object.keys(chrome.notifications.items).length);
348 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
350 devicePath: '/device/path'
352 assertEquals(0, Object.keys(chrome.notifications.items).length);
355 function testDisabledDevice() {
356 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
358 devicePath: '/device/path'
360 assertEquals(1, Object.keys(chrome.notifications.items).length);
361 assertEquals('EXTERNAL_STORAGE_DISABLED',
362 chrome.notifications.items['deviceFail:/device/path'].message);
364 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
366 devicePath: '/device/path'
368 assertEquals(0, Object.keys(chrome.notifications.items).length);
371 function testFormatSucceeded() {
372 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
373 type: 'format_start',
374 devicePath: '/device/path'
376 assertEquals(1, Object.keys(chrome.notifications.items).length);
377 assertEquals('FORMATTING_OF_DEVICE_PENDING',
378 chrome.notifications.items['formatStart:/device/path'].message);
380 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
381 type: 'format_success',
382 devicePath: '/device/path'
384 assertEquals(1, Object.keys(chrome.notifications.items).length);
385 assertEquals('FORMATTING_FINISHED_SUCCESS',
386 chrome.notifications.items[
387 'formatSuccess:/device/path'].message);
390 function testFormatFailed() {
391 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
392 type: 'format_start',
393 devicePath: '/device/path'
395 assertEquals(1, Object.keys(chrome.notifications.items).length);
396 assertEquals('FORMATTING_OF_DEVICE_PENDING',
397 chrome.notifications.items['formatStart:/device/path'].message);
399 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
401 devicePath: '/device/path'
403 assertEquals(1, Object.keys(chrome.notifications.items).length);
404 assertEquals('FORMATTING_FINISHED_FAILURE',
405 chrome.notifications.items['formatFail:/device/path'].message);