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 DEVICE_HARD_UNPLUGGED_MESSAGE: 'DEVICE_HARD_UNPLUGGED_MESSAGE',
32 MULTIPART_DEVICE_UNSUPPORTED_MESSAGE: 'MULTIPART_DEVICE_UNSUPPORTED: $1',
33 EXTERNAL_STORAGE_DISABLED_MESSAGE: 'EXTERNAL_STORAGE_DISABLED',
34 FORMATTING_OF_DEVICE_PENDING_TITLE: 'FORMATTING_OF_DEVICE_PENDING_TITLE',
35 FORMATTING_OF_DEVICE_PENDING_MESSAGE: 'FORMATTING_OF_DEVICE_PENDING',
36 FORMATTING_OF_DEVICE_FINISHED_TITLE: 'FORMATTING_OF_DEVICE_FINISHED_TITLE',
37 FORMATTING_FINISHED_SUCCESS_MESSAGE: 'FORMATTING_FINISHED_SUCCESS',
38 FORMATTING_OF_DEVICE_FAILED_TITLE: 'FORMATTING_OF_DEVICE_FAILED_TITLE',
39 FORMATTING_FINISHED_FAILURE_MESSAGE: 'FORMATTING_FINISHED_FAILURE'
46 addListener: function(listener) {
47 this.dispatch = listener;
51 addListener: function(listener) {
52 this.dispatch = listener;
57 create: function(id, params, callback) {
58 assertFalse(!!this.items[id]);
59 this.items[id] = params;
62 clear: function(id, callback) { delete this.items[id]; callback(); },
65 addListener: function(listener) {
66 this.dispatch = listener;
71 getURL: function(path) { return path; }
75 // Reset timeout callbacks.
76 timeoutCallbacks = [];
78 // Make a device handler.
79 handler = new DeviceHandler();
83 * Overrided setTimoeut funciton.
85 window.setTimeout = function(func) {
86 timeoutCallbacks.push(func);
90 * Call all pending timeout functions.
92 function callTimeoutCallbacks() {
93 while (timeoutCallbacks.length) {
94 timeoutCallbacks.shift()();
98 function registerTypicalDevice() {
99 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
101 devicePath: '/device/path'
103 assertFalse('device:/device/path' in chrome.notifications.items);
104 callTimeoutCallbacks();
105 assertEquals('Scanning...',
106 chrome.notifications.items['device:/device/path'].message);
109 function testGoodDevice() {
110 registerTypicalDevice();
111 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
114 isParentDevice: true,
116 devicePath: '/device/path',
120 assertEquals(0, Object.keys(chrome.notifications.items).length);
123 function testGoodDeviceWithBadParent() {
124 registerTypicalDevice();
126 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
127 status: 'error_internal',
129 isParentDevice: true,
131 devicePath: '/device/path',
135 assertFalse(!!chrome.notifications.items['device:/device/path']);
137 'DEVICE_UNKNOWN: label',
138 chrome.notifications.items['deviceFail:/device/path'].message);
140 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
143 isParentDevice: false,
145 devicePath: '/device/path',
149 assertEquals(0, Object.keys(chrome.notifications.items).length);
151 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
154 isParentDevice: false,
156 devicePath: '/device/path',
160 // Should do nothing this time.
161 assertEquals(0, Object.keys(chrome.notifications.items).length);
164 function testUnsupportedDevice() {
165 registerTypicalDevice();
167 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
168 status: 'error_unsuported_filesystem',
170 isParentDevice: false,
172 devicePath: '/device/path',
176 assertFalse(!!chrome.notifications.items['device:/device/path']);
178 'DEVICE_UNSUPPORTED: label',
179 chrome.notifications.items['deviceFail:/device/path'].message);
182 function testUnsupportedWithUnknownParent() {
183 registerTypicalDevice();
185 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
186 status: 'error_internal',
188 isParentDevice: true,
190 devicePath: '/device/path',
195 'DEVICE_UNKNOWN: label',
196 chrome.notifications.items['deviceFail:/device/path'].message);
198 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
199 status: 'error_unsuported_filesystem',
201 isParentDevice: false,
203 devicePath: '/device/path',
207 assertEquals(1, Object.keys(chrome.notifications.items).length);
209 'DEVICE_UNSUPPORTED: label',
210 chrome.notifications.items['deviceFail:/device/path'].message);
213 function testMountPartialSuccess() {
214 registerTypicalDevice();
216 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
219 isParentDevice: false,
221 devicePath: '/device/path',
225 assertEquals(0, Object.keys(chrome.notifications.items).length);
227 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
228 status: 'error_unsuported_filesystem',
230 isParentDevice: false,
232 devicePath: '/device/path',
236 assertEquals(1, Object.keys(chrome.notifications.items).length);
238 'MULTIPART_DEVICE_UNSUPPORTED: label',
239 chrome.notifications.items['deviceFail:/device/path'].message);
242 function testUnknown() {
243 registerTypicalDevice();
245 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
246 status: 'error_unknown',
248 isParentDevice: false,
250 devicePath: '/device/path',
254 assertEquals(1, Object.keys(chrome.notifications.items).length);
256 'DEVICE_UNKNOWN: label',
257 chrome.notifications.items['deviceFail:/device/path'].message);
260 function testNonASCIILabel() {
261 registerTypicalDevice();
263 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
264 status: 'error_internal',
266 isParentDevice: false,
268 devicePath: '/device/path',
269 // "RA (U+30E9) BE (U+30D9) RU (U+30EB)" in Katakana letters.
270 deviceLabel: '\u30E9\u30D9\u30EB'
273 assertEquals(1, Object.keys(chrome.notifications.items).length);
275 'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB',
276 chrome.notifications.items['deviceFail:/device/path'].message);
279 function testMulitpleFail() {
280 registerTypicalDevice();
282 // The first parent error.
283 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
284 status: 'error_internal',
286 isParentDevice: true,
288 devicePath: '/device/path',
292 assertEquals(1, Object.keys(chrome.notifications.items).length);
294 'DEVICE_UNKNOWN: label',
295 chrome.notifications.items['deviceFail:/device/path'].message);
297 // The first child error that replaces the parent error.
298 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
299 status: 'error_internal',
301 isParentDevice: false,
303 devicePath: '/device/path',
307 assertEquals(1, Object.keys(chrome.notifications.items).length);
309 'DEVICE_UNKNOWN: label',
310 chrome.notifications.items['deviceFail:/device/path'].message);
312 // The second child error that turns to a multi-partition error.
313 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
314 status: 'error_internal',
316 isParentDevice: false,
318 devicePath: '/device/path',
322 assertEquals(1, Object.keys(chrome.notifications.items).length);
324 'MULTIPART_DEVICE_UNSUPPORTED: label',
325 chrome.notifications.items['deviceFail:/device/path'].message);
327 // The third child error that should be ignored because the error message does
329 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
330 status: 'error_internal',
332 isParentDevice: false,
334 devicePath: '/device/path',
338 assertEquals(1, Object.keys(chrome.notifications.items).length);
340 'MULTIPART_DEVICE_UNSUPPORTED: label',
341 chrome.notifications.items['deviceFail:/device/path'].message);
344 function testScanCanceled() {
345 registerTypicalDevice();
347 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
348 type: 'scan_canceled',
349 devicePath: '/device/path'
351 assertEquals(0, Object.keys(chrome.notifications.items).length);
354 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
356 devicePath: '/device/path'
358 assertEquals(0, Object.keys(chrome.notifications.items).length);
361 function testDisabledDevice() {
362 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
364 devicePath: '/device/path'
366 assertEquals(1, Object.keys(chrome.notifications.items).length);
367 assertEquals('EXTERNAL_STORAGE_DISABLED',
368 chrome.notifications.items['deviceFail:/device/path'].message);
370 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
372 devicePath: '/device/path'
374 assertEquals(0, Object.keys(chrome.notifications.items).length);
377 function testFormatSucceeded() {
378 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
379 type: 'format_start',
380 devicePath: '/device/path'
382 assertEquals(1, Object.keys(chrome.notifications.items).length);
383 assertEquals('FORMATTING_OF_DEVICE_PENDING',
384 chrome.notifications.items['formatStart:/device/path'].message);
386 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
387 type: 'format_success',
388 devicePath: '/device/path'
390 assertEquals(1, Object.keys(chrome.notifications.items).length);
391 assertEquals('FORMATTING_FINISHED_SUCCESS',
392 chrome.notifications.items[
393 'formatSuccess:/device/path'].message);
396 function testFormatFailed() {
397 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
398 type: 'format_start',
399 devicePath: '/device/path'
401 assertEquals(1, Object.keys(chrome.notifications.items).length);
402 assertEquals('FORMATTING_OF_DEVICE_PENDING',
403 chrome.notifications.items['formatStart:/device/path'].message);
405 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
407 devicePath: '/device/path'
409 assertEquals(1, Object.keys(chrome.notifications.items).length);
410 assertEquals('FORMATTING_FINISHED_FAILURE',
411 chrome.notifications.items['formatFail:/device/path'].message);
414 function testDeviceHardUnplugged() {
415 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
416 type: 'hard_unplugged',
417 devicePath: '/device/path'
419 assertEquals(1, Object.keys(chrome.notifications.items).length);
420 assertEquals('DEVICE_HARD_UNPLUGGED_MESSAGE',
421 chrome.notifications.items['deviceFail:/device/path'].message);