OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 'use strict'; | 4 'use strict'; |
5 | 5 |
6 /** | 6 /** |
7 * Test target. | 7 * Test target. |
8 * @type {DeviceHandler} | 8 * @type {DeviceHandler} |
9 */ | 9 */ |
10 var handler; | 10 var handler; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 * Call all pending timeout functions. | 94 * Call all pending timeout functions. |
95 */ | 95 */ |
96 function callTimeoutCallbacks() { | 96 function callTimeoutCallbacks() { |
97 while (timeoutCallbacks.length) { | 97 while (timeoutCallbacks.length) { |
98 timeoutCallbacks.shift()(); | 98 timeoutCallbacks.shift()(); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 function registerTypicalDevice() { | 102 function registerTypicalDevice() { |
103 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ | 103 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ |
104 type: 'added', | 104 type: 'scan_started', |
105 devicePath: '/device/path' | 105 devicePath: '/device/path' |
106 }); | 106 }); |
107 assertFalse('device:/device/path' in chrome.notifications.items); | 107 assertTrue('device:/device/path' in chrome.notifications.items); |
108 callTimeoutCallbacks(); | |
109 assertEquals('Scanning...', | 108 assertEquals('Scanning...', |
110 chrome.notifications.items['device:/device/path'].message); | 109 chrome.notifications.items['device:/device/path'].message); |
111 } | 110 } |
112 | 111 |
113 function testGoodDevice() { | 112 function testGoodDevice() { |
114 registerTypicalDevice(); | 113 registerTypicalDevice(); |
115 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 114 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
116 status: 'success', | 115 status: 'success', |
117 volumeMetadata: { | 116 volumeMetadata: { |
118 isParentDevice: true, | 117 isParentDevice: true, |
119 deviceType: 'usb', | 118 deviceType: 'usb', |
120 devicePath: '/device/path', | 119 devicePath: '/device/path', |
121 deviceLabel: 'label' | 120 deviceLabel: 'label' |
122 } | 121 }, |
122 shouldNotify: true | |
123 }); | 123 }); |
124 assertEquals(0, Object.keys(chrome.notifications.items).length); | 124 assertEquals(0, Object.keys(chrome.notifications.items).length); |
125 } | 125 } |
126 | 126 |
127 function testGoodDeviceWithBadParent() { | 127 function testGoodDeviceWithBadParent() { |
128 registerTypicalDevice(); | 128 registerTypicalDevice(); |
129 | 129 |
130 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 130 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
131 status: 'error_internal', | 131 status: 'error_internal', |
132 volumeMetadata: { | 132 volumeMetadata: { |
133 isParentDevice: true, | 133 isParentDevice: true, |
134 deviceType: 'usb', | 134 deviceType: 'usb', |
135 devicePath: '/device/path', | 135 devicePath: '/device/path', |
136 deviceLabel: 'label' | 136 deviceLabel: 'label' |
137 } | 137 }, |
138 shouldNotify: true | |
138 }); | 139 }); |
139 assertFalse(!!chrome.notifications.items['device:/device/path']); | 140 assertFalse(!!chrome.notifications.items['device:/device/path']); |
140 assertEquals( | 141 assertEquals( |
141 'DEVICE_UNKNOWN: label', | 142 'DEVICE_UNKNOWN: label', |
142 chrome.notifications.items['deviceFail:/device/path'].message); | 143 chrome.notifications.items['deviceFail:/device/path'].message); |
143 | 144 |
144 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 145 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
145 status: 'success', | 146 status: 'success', |
146 volumeMetadata: { | 147 volumeMetadata: { |
147 isParentDevice: false, | 148 isParentDevice: false, |
148 deviceType: 'usb', | 149 deviceType: 'usb', |
149 devicePath: '/device/path', | 150 devicePath: '/device/path', |
150 deviceLabel: 'label' | 151 deviceLabel: 'label' |
151 } | 152 }, |
153 shouldNotify: true | |
152 }); | 154 }); |
153 assertEquals(0, Object.keys(chrome.notifications.items).length); | 155 assertEquals(0, Object.keys(chrome.notifications.items).length); |
154 | 156 |
155 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 157 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
156 status: 'success', | 158 status: 'success', |
157 volumeMetadata: { | 159 volumeMetadata: { |
158 isParentDevice: false, | 160 isParentDevice: false, |
159 deviceType: 'usb', | 161 deviceType: 'usb', |
160 devicePath: '/device/path', | 162 devicePath: '/device/path', |
161 deviceLabel: 'label' | 163 deviceLabel: 'label' |
162 } | 164 }, |
165 shouldNotify: true | |
163 }); | 166 }); |
164 // Should do nothing this time. | 167 // Should do nothing this time. |
165 assertEquals(0, Object.keys(chrome.notifications.items).length); | 168 assertEquals(0, Object.keys(chrome.notifications.items).length); |
166 } | 169 } |
167 | 170 |
168 function testUnsupportedDevice() { | 171 function testUnsupportedDevice() { |
169 registerTypicalDevice(); | 172 registerTypicalDevice(); |
170 | 173 |
171 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 174 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
172 status: 'error_unsupported_filesystem', | 175 status: 'error_unsupported_filesystem', |
173 volumeMetadata: { | 176 volumeMetadata: { |
174 isParentDevice: false, | 177 isParentDevice: false, |
175 deviceType: 'usb', | 178 deviceType: 'usb', |
176 devicePath: '/device/path', | 179 devicePath: '/device/path', |
177 deviceLabel: 'label' | 180 deviceLabel: 'label' |
178 } | 181 }, |
182 shouldNotify: true | |
179 }); | 183 }); |
180 assertFalse(!!chrome.notifications.items['device:/device/path']); | 184 assertFalse(!!chrome.notifications.items['device:/device/path']); |
181 assertEquals( | 185 assertEquals( |
182 'DEVICE_UNSUPPORTED: label', | 186 'DEVICE_UNSUPPORTED: label', |
183 chrome.notifications.items['deviceFail:/device/path'].message); | 187 chrome.notifications.items['deviceFail:/device/path'].message); |
184 } | 188 } |
185 | 189 |
186 function testUnsupportedWithUnknownParent() { | 190 function testUnsupportedWithUnknownParent() { |
187 registerTypicalDevice(); | 191 registerTypicalDevice(); |
188 | 192 |
189 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 193 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
190 status: 'error_internal', | 194 status: 'error_internal', |
191 volumeMetadata: { | 195 volumeMetadata: { |
192 isParentDevice: true, | 196 isParentDevice: true, |
193 deviceType: 'usb', | 197 deviceType: 'usb', |
194 devicePath: '/device/path', | 198 devicePath: '/device/path', |
195 deviceLabel: 'label' | 199 deviceLabel: 'label' |
196 } | 200 }, |
201 shouldNotify: true | |
197 }); | 202 }); |
198 assertEquals( | 203 assertEquals( |
199 'DEVICE_UNKNOWN: label', | 204 'DEVICE_UNKNOWN: label', |
200 chrome.notifications.items['deviceFail:/device/path'].message); | 205 chrome.notifications.items['deviceFail:/device/path'].message); |
201 | 206 |
202 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 207 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
203 status: 'error_unsupported_filesystem', | 208 status: 'error_unsupported_filesystem', |
204 volumeMetadata: { | 209 volumeMetadata: { |
205 isParentDevice: false, | 210 isParentDevice: false, |
206 deviceType: 'usb', | 211 deviceType: 'usb', |
207 devicePath: '/device/path', | 212 devicePath: '/device/path', |
208 deviceLabel: 'label' | 213 deviceLabel: 'label' |
209 } | 214 }, |
215 shouldNotify: true | |
210 }); | 216 }); |
211 assertEquals(1, Object.keys(chrome.notifications.items).length); | 217 assertEquals(1, Object.keys(chrome.notifications.items).length); |
212 assertEquals( | 218 assertEquals( |
213 'DEVICE_UNSUPPORTED: label', | 219 'DEVICE_UNSUPPORTED: label', |
214 chrome.notifications.items['deviceFail:/device/path'].message); | 220 chrome.notifications.items['deviceFail:/device/path'].message); |
215 } | 221 } |
216 | 222 |
217 function testMountPartialSuccess() { | 223 function testMountPartialSuccess() { |
218 registerTypicalDevice(); | 224 registerTypicalDevice(); |
219 | 225 |
220 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 226 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
221 status: 'success', | 227 status: 'success', |
222 volumeMetadata: { | 228 volumeMetadata: { |
223 isParentDevice: false, | 229 isParentDevice: false, |
224 deviceType: 'usb', | 230 deviceType: 'usb', |
225 devicePath: '/device/path', | 231 devicePath: '/device/path', |
226 deviceLabel: 'label' | 232 deviceLabel: 'label' |
227 } | 233 }, |
234 shouldNotify: true | |
228 }); | 235 }); |
229 assertEquals(0, Object.keys(chrome.notifications.items).length); | 236 assertEquals(0, Object.keys(chrome.notifications.items).length); |
230 | 237 |
231 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 238 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
232 status: 'error_unsupported_filesystem', | 239 status: 'error_unsupported_filesystem', |
233 volumeMetadata: { | 240 volumeMetadata: { |
234 isParentDevice: false, | 241 isParentDevice: false, |
235 deviceType: 'usb', | 242 deviceType: 'usb', |
236 devicePath: '/device/path', | 243 devicePath: '/device/path', |
237 deviceLabel: 'label' | 244 deviceLabel: 'label' |
238 } | 245 }, |
246 shouldNotify: true | |
239 }); | 247 }); |
240 assertEquals(1, Object.keys(chrome.notifications.items).length); | 248 assertEquals(1, Object.keys(chrome.notifications.items).length); |
241 assertEquals( | 249 assertEquals( |
242 'MULTIPART_DEVICE_UNSUPPORTED: label', | 250 'MULTIPART_DEVICE_UNSUPPORTED: label', |
243 chrome.notifications.items['deviceFail:/device/path'].message); | 251 chrome.notifications.items['deviceFail:/device/path'].message); |
244 } | 252 } |
245 | 253 |
246 function testUnknown() { | 254 function testUnknown() { |
247 registerTypicalDevice(); | 255 registerTypicalDevice(); |
248 | 256 |
249 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 257 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
250 status: 'error_unknown', | 258 status: 'error_unknown', |
251 volumeMetadata: { | 259 volumeMetadata: { |
252 isParentDevice: false, | 260 isParentDevice: false, |
253 deviceType: 'usb', | 261 deviceType: 'usb', |
254 devicePath: '/device/path', | 262 devicePath: '/device/path', |
255 deviceLabel: 'label' | 263 deviceLabel: 'label' |
256 } | 264 }, |
265 shouldNotify: true | |
257 }); | 266 }); |
258 assertEquals(1, Object.keys(chrome.notifications.items).length); | 267 assertEquals(1, Object.keys(chrome.notifications.items).length); |
259 assertEquals( | 268 assertEquals( |
260 'DEVICE_UNKNOWN: label', | 269 'DEVICE_UNKNOWN: label', |
261 chrome.notifications.items['deviceFail:/device/path'].message); | 270 chrome.notifications.items['deviceFail:/device/path'].message); |
262 } | 271 } |
263 | 272 |
264 function testNonASCIILabel() { | 273 function testNonASCIILabel() { |
265 registerTypicalDevice(); | 274 registerTypicalDevice(); |
266 | 275 |
267 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 276 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
268 status: 'error_internal', | 277 status: 'error_internal', |
269 volumeMetadata: { | 278 volumeMetadata: { |
270 isParentDevice: false, | 279 isParentDevice: false, |
271 deviceType: 'usb', | 280 deviceType: 'usb', |
272 devicePath: '/device/path', | 281 devicePath: '/device/path', |
273 // "RA (U+30E9) BE (U+30D9) RU (U+30EB)" in Katakana letters. | 282 // "RA (U+30E9) BE (U+30D9) RU (U+30EB)" in Katakana letters. |
274 deviceLabel: '\u30E9\u30D9\u30EB' | 283 deviceLabel: '\u30E9\u30D9\u30EB' |
275 } | 284 }, |
285 shouldNotify: true | |
276 }); | 286 }); |
277 assertEquals(1, Object.keys(chrome.notifications.items).length); | 287 assertEquals(1, Object.keys(chrome.notifications.items).length); |
278 assertEquals( | 288 assertEquals( |
279 'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB', | 289 'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB', |
280 chrome.notifications.items['deviceFail:/device/path'].message); | 290 chrome.notifications.items['deviceFail:/device/path'].message); |
281 } | 291 } |
282 | 292 |
283 function testMulitpleFail() { | 293 function testMulitpleFail() { |
284 registerTypicalDevice(); | 294 registerTypicalDevice(); |
285 | 295 |
286 // The first parent error. | 296 // The first parent error. |
287 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 297 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
288 status: 'error_internal', | 298 status: 'error_internal', |
289 volumeMetadata: { | 299 volumeMetadata: { |
290 isParentDevice: true, | 300 isParentDevice: true, |
291 deviceType: 'usb', | 301 deviceType: 'usb', |
292 devicePath: '/device/path', | 302 devicePath: '/device/path', |
293 deviceLabel: 'label' | 303 deviceLabel: 'label' |
294 } | 304 }, |
305 shouldNotify: true | |
295 }); | 306 }); |
296 assertEquals(1, Object.keys(chrome.notifications.items).length); | 307 assertEquals(1, Object.keys(chrome.notifications.items).length); |
297 assertEquals( | 308 assertEquals( |
298 'DEVICE_UNKNOWN: label', | 309 'DEVICE_UNKNOWN: label', |
299 chrome.notifications.items['deviceFail:/device/path'].message); | 310 chrome.notifications.items['deviceFail:/device/path'].message); |
300 | 311 |
301 // The first child error that replaces the parent error. | 312 // The first child error that replaces the parent error. |
302 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 313 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
303 status: 'error_internal', | 314 status: 'error_internal', |
304 volumeMetadata: { | 315 volumeMetadata: { |
305 isParentDevice: false, | 316 isParentDevice: false, |
306 deviceType: 'usb', | 317 deviceType: 'usb', |
307 devicePath: '/device/path', | 318 devicePath: '/device/path', |
308 deviceLabel: 'label' | 319 deviceLabel: 'label' |
309 } | 320 }, |
321 shouldNotify: true | |
310 }); | 322 }); |
311 assertEquals(1, Object.keys(chrome.notifications.items).length); | 323 assertEquals(1, Object.keys(chrome.notifications.items).length); |
312 assertEquals( | 324 assertEquals( |
313 'DEVICE_UNKNOWN: label', | 325 'DEVICE_UNKNOWN: label', |
314 chrome.notifications.items['deviceFail:/device/path'].message); | 326 chrome.notifications.items['deviceFail:/device/path'].message); |
315 | 327 |
316 // The second child error that turns to a multi-partition error. | 328 // The second child error that turns to a multi-partition error. |
317 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 329 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
318 status: 'error_internal', | 330 status: 'error_internal', |
319 volumeMetadata: { | 331 volumeMetadata: { |
320 isParentDevice: false, | 332 isParentDevice: false, |
321 deviceType: 'usb', | 333 deviceType: 'usb', |
322 devicePath: '/device/path', | 334 devicePath: '/device/path', |
323 deviceLabel: 'label' | 335 deviceLabel: 'label' |
324 } | 336 }, |
337 shouldNotify: true | |
325 }); | 338 }); |
326 assertEquals(1, Object.keys(chrome.notifications.items).length); | 339 assertEquals(1, Object.keys(chrome.notifications.items).length); |
327 assertEquals( | 340 assertEquals( |
328 'MULTIPART_DEVICE_UNSUPPORTED: label', | 341 'MULTIPART_DEVICE_UNSUPPORTED: label', |
329 chrome.notifications.items['deviceFail:/device/path'].message); | 342 chrome.notifications.items['deviceFail:/device/path'].message); |
330 | 343 |
331 // The third child error that should be ignored because the error message does | 344 // The third child error that should be ignored because the error message does |
332 // not changed. | 345 // not changed. |
333 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ | 346 chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
334 status: 'error_internal', | 347 status: 'error_internal', |
335 volumeMetadata: { | 348 volumeMetadata: { |
336 isParentDevice: false, | 349 isParentDevice: false, |
337 deviceType: 'usb', | 350 deviceType: 'usb', |
338 devicePath: '/device/path', | 351 devicePath: '/device/path', |
339 deviceLabel: 'label' | 352 deviceLabel: 'label' |
340 } | 353 }, |
354 shouldNotify: true | |
mtomasz
2014/08/26 02:49:43
nit: Do we have any unit test with shouldNotify =
hirono
2014/08/26 03:48:26
Done.
| |
341 }); | 355 }); |
342 assertEquals(1, Object.keys(chrome.notifications.items).length); | 356 assertEquals(1, Object.keys(chrome.notifications.items).length); |
343 assertEquals( | 357 assertEquals( |
344 'MULTIPART_DEVICE_UNSUPPORTED: label', | 358 'MULTIPART_DEVICE_UNSUPPORTED: label', |
345 chrome.notifications.items['deviceFail:/device/path'].message); | 359 chrome.notifications.items['deviceFail:/device/path'].message); |
346 } | 360 } |
347 | 361 |
348 function testScanCanceled() { | 362 function testScanCanceled() { |
349 registerTypicalDevice(); | 363 registerTypicalDevice(); |
350 | 364 |
351 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ | 365 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ |
352 type: 'scan_canceled', | 366 type: 'scan_cancelled', |
353 devicePath: '/device/path' | 367 devicePath: '/device/path' |
354 }); | 368 }); |
355 assertEquals(0, Object.keys(chrome.notifications.items).length); | 369 assertEquals(0, Object.keys(chrome.notifications.items).length); |
356 | 370 |
357 // Nothing happened. | 371 // Nothing happened. |
358 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ | 372 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ |
359 type: 'removed', | 373 type: 'removed', |
360 devicePath: '/device/path' | 374 devicePath: '/device/path' |
361 }); | 375 }); |
362 assertEquals(0, Object.keys(chrome.notifications.items).length); | 376 assertEquals(0, Object.keys(chrome.notifications.items).length); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 function testDeviceHardUnplugged() { | 432 function testDeviceHardUnplugged() { |
419 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ | 433 chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ |
420 type: 'hard_unplugged', | 434 type: 'hard_unplugged', |
421 devicePath: '/device/path' | 435 devicePath: '/device/path' |
422 }); | 436 }); |
423 assertEquals(1, Object.keys(chrome.notifications.items).length); | 437 assertEquals(1, Object.keys(chrome.notifications.items).length); |
424 assertEquals('DEVICE_HARD_UNPLUGGED_MESSAGE', | 438 assertEquals('DEVICE_HARD_UNPLUGGED_MESSAGE', |
425 chrome.notifications.items[ | 439 chrome.notifications.items[ |
426 'hardUnplugged:/device/path'].message); | 440 'hardUnplugged:/device/path'].message); |
427 } | 441 } |
OLD | NEW |