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_NAVIGATION_MESSAGE: 'DEVICE_NAVIGATION',
29 REMOVABLE_DEVICE_NAVIGATION_BUTTON_LABEL: '',
30 DEVICE_UNKNOWN_MESSAGE: 'DEVICE_UNKNOWN: $1',
31 DEVICE_UNSUPPORTED_MESSAGE: 'DEVICE_UNSUPPORTED: $1',
32 DEVICE_HARD_UNPLUGGED_TITLE: 'DEVICE_HARD_UNPLUGGED_TITLE',
33 DEVICE_HARD_UNPLUGGED_MESSAGE: 'DEVICE_HARD_UNPLUGGED_MESSAGE',
34 MULTIPART_DEVICE_UNSUPPORTED_MESSAGE: 'MULTIPART_DEVICE_UNSUPPORTED: $1',
35 EXTERNAL_STORAGE_DISABLED_MESSAGE: 'EXTERNAL_STORAGE_DISABLED',
36 FORMATTING_OF_DEVICE_PENDING_TITLE: 'FORMATTING_OF_DEVICE_PENDING_TITLE',
37 FORMATTING_OF_DEVICE_PENDING_MESSAGE: 'FORMATTING_OF_DEVICE_PENDING',
38 FORMATTING_OF_DEVICE_FINISHED_TITLE: 'FORMATTING_OF_DEVICE_FINISHED_TITLE',
39 FORMATTING_FINISHED_SUCCESS_MESSAGE: 'FORMATTING_FINISHED_SUCCESS',
40 FORMATTING_OF_DEVICE_FAILED_TITLE: 'FORMATTING_OF_DEVICE_FAILED_TITLE',
41 FORMATTING_FINISHED_FAILURE_MESSAGE: 'FORMATTING_FINISHED_FAILURE'
48 addListener: function(listener) {
49 this.dispatch = listener;
53 addListener: function(listener) {
54 this.dispatch = listener;
59 create: function(id, params, callback) {
60 this.items[id] = params;
63 clear: function(id, callback) { delete this.items[id]; callback(); },
66 addListener: function(listener) {
67 this.dispatch = listener;
72 getURL: function(path) { return path; },
74 addListener: function() {}
79 // Make a device handler.
80 handler = new DeviceHandler();
83 function testGoodDevice() {
84 chrome.fileManagerPrivate.onMountCompleted.dispatch({
90 devicePath: '/device/path',
95 assertEquals(1, Object.keys(chrome.notifications.items).length);
98 chrome.notifications.items['deviceNavigation:/device/path'].message);
101 function testGoodDeviceNotNavigated() {
102 chrome.fileManagerPrivate.onMountCompleted.dispatch({
106 isParentDevice: true,
108 devicePath: '/device/path',
113 assertEquals(0, Object.keys(chrome.notifications.items).length);
116 function testGoodDeviceWithBadParent() {
117 chrome.fileManagerPrivate.onMountCompleted.dispatch({
119 status: 'error_internal',
121 isParentDevice: true,
123 devicePath: '/device/path',
128 assertFalse(!!chrome.notifications.items['device:/device/path']);
130 'DEVICE_UNKNOWN: label',
131 chrome.notifications.items['deviceFail:/device/path'].message);
133 chrome.fileManagerPrivate.onMountCompleted.dispatch({
137 isParentDevice: false,
139 devicePath: '/device/path',
144 assertEquals(1, Object.keys(chrome.notifications.items).length);
147 chrome.notifications.items['deviceNavigation:/device/path'].message);
149 chrome.fileManagerPrivate.onMountCompleted.dispatch({
153 isParentDevice: false,
155 devicePath: '/device/path',
160 // Should do nothing this time.
161 assertEquals(1, Object.keys(chrome.notifications.items).length);
164 chrome.notifications.items['deviceNavigation:/device/path'].message);
167 function testUnsupportedDevice() {
168 chrome.fileManagerPrivate.onMountCompleted.dispatch({
170 status: 'error_unsupported_filesystem',
172 isParentDevice: false,
174 devicePath: '/device/path',
179 assertFalse(!!chrome.notifications.items['device:/device/path']);
181 'DEVICE_UNSUPPORTED: label',
182 chrome.notifications.items['deviceFail:/device/path'].message);
185 function testUnsupportedWithUnknownParent() {
186 chrome.fileManagerPrivate.onMountCompleted.dispatch({
188 status: 'error_internal',
190 isParentDevice: true,
192 devicePath: '/device/path',
198 'DEVICE_UNKNOWN: label',
199 chrome.notifications.items['deviceFail:/device/path'].message);
201 chrome.fileManagerPrivate.onMountCompleted.dispatch({
203 status: 'error_unsupported_filesystem',
205 isParentDevice: false,
207 devicePath: '/device/path',
212 assertEquals(1, Object.keys(chrome.notifications.items).length);
214 'DEVICE_UNSUPPORTED: label',
215 chrome.notifications.items['deviceFail:/device/path'].message);
218 function testMountPartialSuccess() {
219 chrome.fileManagerPrivate.onMountCompleted.dispatch({
223 isParentDevice: false,
225 devicePath: '/device/path',
230 assertEquals(1, Object.keys(chrome.notifications.items).length);
233 chrome.notifications.items['deviceNavigation:/device/path'].message);
235 chrome.fileManagerPrivate.onMountCompleted.dispatch({
237 status: 'error_unsupported_filesystem',
239 isParentDevice: false,
241 devicePath: '/device/path',
246 assertEquals(2, Object.keys(chrome.notifications.items).length);
248 'MULTIPART_DEVICE_UNSUPPORTED: label',
249 chrome.notifications.items['deviceFail:/device/path'].message);
252 function testUnknown() {
253 chrome.fileManagerPrivate.onMountCompleted.dispatch({
255 status: 'error_unknown',
257 isParentDevice: false,
259 devicePath: '/device/path',
264 assertEquals(1, Object.keys(chrome.notifications.items).length);
266 'DEVICE_UNKNOWN: label',
267 chrome.notifications.items['deviceFail:/device/path'].message);
270 function testNonASCIILabel() {
271 chrome.fileManagerPrivate.onMountCompleted.dispatch({
273 status: 'error_internal',
275 isParentDevice: false,
277 devicePath: '/device/path',
278 // "RA (U+30E9) BE (U+30D9) RU (U+30EB)" in Katakana letters.
279 deviceLabel: '\u30E9\u30D9\u30EB'
283 assertEquals(1, Object.keys(chrome.notifications.items).length);
285 'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB',
286 chrome.notifications.items['deviceFail:/device/path'].message);
289 function testMulitpleFail() {
290 // The first parent error.
291 chrome.fileManagerPrivate.onMountCompleted.dispatch({
293 status: 'error_internal',
295 isParentDevice: true,
297 devicePath: '/device/path',
302 assertEquals(1, Object.keys(chrome.notifications.items).length);
304 'DEVICE_UNKNOWN: label',
305 chrome.notifications.items['deviceFail:/device/path'].message);
307 // The first child error that replaces the parent error.
308 chrome.fileManagerPrivate.onMountCompleted.dispatch({
310 status: 'error_internal',
312 isParentDevice: false,
314 devicePath: '/device/path',
319 assertEquals(1, Object.keys(chrome.notifications.items).length);
321 'DEVICE_UNKNOWN: label',
322 chrome.notifications.items['deviceFail:/device/path'].message);
324 // The second child error that turns to a multi-partition error.
325 chrome.fileManagerPrivate.onMountCompleted.dispatch({
327 status: 'error_internal',
329 isParentDevice: false,
331 devicePath: '/device/path',
336 assertEquals(1, Object.keys(chrome.notifications.items).length);
338 'MULTIPART_DEVICE_UNSUPPORTED: label',
339 chrome.notifications.items['deviceFail:/device/path'].message);
341 // The third child error that should be ignored because the error message does
343 chrome.fileManagerPrivate.onMountCompleted.dispatch({
345 status: 'error_internal',
347 isParentDevice: false,
349 devicePath: '/device/path',
354 assertEquals(1, Object.keys(chrome.notifications.items).length);
356 'MULTIPART_DEVICE_UNSUPPORTED: label',
357 chrome.notifications.items['deviceFail:/device/path'].message);
360 function testDisabledDevice() {
361 chrome.fileManagerPrivate.onDeviceChanged.dispatch({
363 devicePath: '/device/path'
365 assertEquals(1, Object.keys(chrome.notifications.items).length);
366 assertEquals('EXTERNAL_STORAGE_DISABLED',
367 chrome.notifications.items['deviceFail:/device/path'].message);
369 chrome.fileManagerPrivate.onDeviceChanged.dispatch({
371 devicePath: '/device/path'
373 assertEquals(0, Object.keys(chrome.notifications.items).length);
376 function testFormatSucceeded() {
377 chrome.fileManagerPrivate.onDeviceChanged.dispatch({
378 type: 'format_start',
379 devicePath: '/device/path'
381 assertEquals(1, Object.keys(chrome.notifications.items).length);
382 assertEquals('FORMATTING_OF_DEVICE_PENDING',
383 chrome.notifications.items['formatStart:/device/path'].message);
385 chrome.fileManagerPrivate.onDeviceChanged.dispatch({
386 type: 'format_success',
387 devicePath: '/device/path'
389 assertEquals(1, Object.keys(chrome.notifications.items).length);
390 assertEquals('FORMATTING_FINISHED_SUCCESS',
391 chrome.notifications.items[
392 'formatSuccess:/device/path'].message);
395 function testFormatFailed() {
396 chrome.fileManagerPrivate.onDeviceChanged.dispatch({
397 type: 'format_start',
398 devicePath: '/device/path'
400 assertEquals(1, Object.keys(chrome.notifications.items).length);
401 assertEquals('FORMATTING_OF_DEVICE_PENDING',
402 chrome.notifications.items['formatStart:/device/path'].message);
404 chrome.fileManagerPrivate.onDeviceChanged.dispatch({
406 devicePath: '/device/path'
408 assertEquals(1, Object.keys(chrome.notifications.items).length);
409 assertEquals('FORMATTING_FINISHED_FAILURE',
410 chrome.notifications.items['formatFail:/device/path'].message);
413 function testDeviceHardUnplugged() {
414 chrome.fileManagerPrivate.onDeviceChanged.dispatch({
415 type: 'hard_unplugged',
416 devicePath: '/device/path'
418 assertEquals(1, Object.keys(chrome.notifications.items).length);
419 assertEquals('DEVICE_HARD_UNPLUGGED_MESSAGE',
420 chrome.notifications.items[
421 'hardUnplugged:/device/path'].message);