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}
17 // Set up the test components.
19 // Set up string assets.
21 REMOVABLE_DEVICE_DETECTION_TITLE: 'Device detected',
22 REMOVABLE_DEVICE_SCANNING_MESSAGE: 'Scanning...',
23 DEVICE_UNKNOWN_MESSAGE: 'DEVICE_UNKNOWN: $1',
24 DEVICE_UNSUPPORTED_MESSAGE: 'DEVICE_UNSUPPORTED: $1',
25 MULTIPART_DEVICE_UNSUPPORTED_MESSAGE: 'MULTIPART_DEVICE_UNSUPPORTED: $1',
26 EXTERNAL_STORAGE_DISABLED_MESSAGE: 'EXTERNAL_STORAGE_DISABLED',
27 FORMATTING_OF_DEVICE_PENDING_TITLE: 'FORMATTING_OF_DEVICE_PENDING_TITLE',
28 FORMATTING_OF_DEVICE_PENDING_MESSAGE: 'FORMATTING_OF_DEVICE_PENDING',
29 FORMATTING_OF_DEVICE_FINISHED_TITLE: 'FORMATTING_OF_DEVICE_FINISHED_TITLE',
30 FORMATTING_FINISHED_SUCCESS_MESSAGE: 'FORMATTING_FINISHED_SUCCESS',
31 FORMATTING_OF_DEVICE_FAILED_TITLE: 'FORMATTING_OF_DEVICE_FAILED_TITLE',
32 FORMATTING_FINISHED_FAILURE_MESSAGE: 'FORMATTING_FINISHED_FAILURE'
39 addListener: function(listener) {
40 this.dispatch = listener;
44 addListener: function(listener) {
45 this.dispatch = listener;
50 create: function(id, params, callback) {
51 assertFalse(!!this.items[id]);
52 this.items[id] = params;
54 clear: function(id) { delete this.items[id]; },
58 getURL: function(path) { return path; }
62 // Make a device handler.
63 handler = new DeviceHandler();
66 function registerTypicalDevice() {
67 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
69 devicePath: '/device/path'
71 assertEquals('Scanning...',
72 chrome.notifications.items['device:/device/path'].message);
75 function testGoodDevice() {
76 registerTypicalDevice();
77 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
82 devicePath: '/device/path',
86 assertEquals(0, Object.keys(chrome.notifications.items).length);
89 function testGoodDeviceWithBadParent() {
90 registerTypicalDevice();
92 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
93 status: 'error_internal',
97 devicePath: '/device/path',
101 assertFalse(!!chrome.notifications.items['device:/device/path']);
103 'DEVICE_UNKNOWN: label',
104 chrome.notifications.items['deviceFail:/device/path'].message);
106 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
109 isParentDevice: false,
111 devicePath: '/device/path',
115 assertEquals(0, Object.keys(chrome.notifications.items).length);
117 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
120 isParentDevice: false,
122 devicePath: '/device/path',
126 // Should do nothing this time.
127 assertEquals(0, Object.keys(chrome.notifications.items).length);
130 function testUnsupportedDevice() {
131 registerTypicalDevice();
133 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
134 status: 'error_unsuported_filesystem',
136 isParentDevice: false,
138 devicePath: '/device/path',
142 assertFalse(!!chrome.notifications.items['device:/device/path']);
144 'DEVICE_UNSUPPORTED: label',
145 chrome.notifications.items['deviceFail:/device/path'].message);
148 function testUnsupportedWithUnknownParent() {
149 registerTypicalDevice();
151 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
152 status: 'error_internal',
154 isParentDevice: true,
156 devicePath: '/device/path',
161 'DEVICE_UNKNOWN: label',
162 chrome.notifications.items['deviceFail:/device/path'].message);
164 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
165 status: 'error_unsuported_filesystem',
167 isParentDevice: false,
169 devicePath: '/device/path',
173 assertEquals(1, Object.keys(chrome.notifications.items).length);
175 'DEVICE_UNSUPPORTED: label',
176 chrome.notifications.items['deviceFail:/device/path'].message);
179 function testMountPartialSuccess() {
180 registerTypicalDevice();
182 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
185 isParentDevice: false,
187 devicePath: '/device/path',
191 assertEquals(0, Object.keys(chrome.notifications.items).length);
193 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
194 status: 'error_unsuported_filesystem',
196 isParentDevice: false,
198 devicePath: '/device/path',
202 assertEquals(1, Object.keys(chrome.notifications.items).length);
204 'MULTIPART_DEVICE_UNSUPPORTED: label',
205 chrome.notifications.items['deviceFail:/device/path'].message);
208 function testUnknown() {
209 registerTypicalDevice();
211 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
212 status: 'error_unknown',
214 isParentDevice: false,
216 devicePath: '/device/path',
220 assertEquals(1, Object.keys(chrome.notifications.items).length);
222 'DEVICE_UNKNOWN: label',
223 chrome.notifications.items['deviceFail:/device/path'].message);
226 function testNonASCIILabel() {
227 registerTypicalDevice();
229 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
230 status: 'error_internal',
232 isParentDevice: false,
234 devicePath: '/device/path',
235 // "RA (U+30E9) BE (U+30D9) RU (U+30EB)" in Katakana letters.
236 deviceLabel: '\u30E9\u30D9\u30EB'
239 assertEquals(1, Object.keys(chrome.notifications.items).length);
241 'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB',
242 chrome.notifications.items['deviceFail:/device/path'].message);
245 function testMulitpleFail() {
246 registerTypicalDevice();
248 // The first parent error.
249 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
250 status: 'error_internal',
252 isParentDevice: true,
254 devicePath: '/device/path',
258 assertEquals(1, Object.keys(chrome.notifications.items).length);
260 'DEVICE_UNKNOWN: label',
261 chrome.notifications.items['deviceFail:/device/path'].message);
263 // The first child error that replaces the parent error.
264 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
265 status: 'error_internal',
267 isParentDevice: false,
269 devicePath: '/device/path',
273 assertEquals(1, Object.keys(chrome.notifications.items).length);
275 'DEVICE_UNKNOWN: label',
276 chrome.notifications.items['deviceFail:/device/path'].message);
278 // The second child error that turns to a multi-partition error.
279 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
280 status: 'error_internal',
282 isParentDevice: false,
284 devicePath: '/device/path',
288 assertEquals(1, Object.keys(chrome.notifications.items).length);
290 'MULTIPART_DEVICE_UNSUPPORTED: label',
291 chrome.notifications.items['deviceFail:/device/path'].message);
293 // The third child error that should be ignored because the error message does
295 chrome.fileBrowserPrivate.onMountCompleted.dispatch({
296 status: 'error_internal',
298 isParentDevice: false,
300 devicePath: '/device/path',
304 assertEquals(1, Object.keys(chrome.notifications.items).length);
306 'MULTIPART_DEVICE_UNSUPPORTED: label',
307 chrome.notifications.items['deviceFail:/device/path'].message);
310 function testScanCanceled() {
311 registerTypicalDevice();
313 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
314 type: 'scan_canceled',
315 devicePath: '/device/path'
317 assertEquals(0, Object.keys(chrome.notifications.items).length);
320 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
322 devicePath: '/device/path'
324 assertEquals(0, Object.keys(chrome.notifications.items).length);
327 function testDisabledDevice() {
328 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
330 devicePath: '/device/path'
332 assertEquals(1, Object.keys(chrome.notifications.items).length);
333 assertEquals('EXTERNAL_STORAGE_DISABLED',
334 chrome.notifications.items['deviceFail:/device/path'].message);
336 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
338 devicePath: '/device/path'
340 assertEquals(0, Object.keys(chrome.notifications.items).length);
343 function testFormatSucceeded() {
344 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
345 type: 'format_start',
346 devicePath: '/device/path'
348 assertEquals(1, Object.keys(chrome.notifications.items).length);
349 assertEquals('FORMATTING_OF_DEVICE_PENDING',
350 chrome.notifications.items['formatStart:/device/path'].message);
352 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
353 type: 'format_success',
354 devicePath: '/device/path'
356 assertEquals(1, Object.keys(chrome.notifications.items).length);
357 assertEquals('FORMATTING_FINISHED_SUCCESS',
358 chrome.notifications.items[
359 'formatSuccess:/device/path'].message);
362 function testFormatFailed() {
363 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
364 type: 'format_start',
365 devicePath: '/device/path'
367 assertEquals(1, Object.keys(chrome.notifications.items).length);
368 assertEquals('FORMATTING_OF_DEVICE_PENDING',
369 chrome.notifications.items['formatStart:/device/path'].message);
371 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({
373 devicePath: '/device/path'
375 assertEquals(1, Object.keys(chrome.notifications.items).length);
376 assertEquals('FORMATTING_FINISHED_FAILURE',
377 chrome.notifications.items['formatFail:/device/path'].message);