Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: ui/file_manager/file_manager/foreground/js/import_controller_unittest.js

Issue 1045663002: Cancel scans when directory changed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also, cancel scans when window closes...and add test coverage. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 4
5 /** @const {!Event} */ 5 /** @const {!Event} */
6 var EMPTY_EVENT = new Event('directory-changed'); 6 var EMPTY_EVENT = new Event('directory-changed');
7 7
8 /** @type {!MockVolumeManager} */ 8 /** @type {!MockVolumeManager} */
9 var volumeManager; 9 var volumeManager;
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 '/DCIM/', 88 '/DCIM/',
89 '/DCIM/photos0/', 89 '/DCIM/photos0/',
90 '/DCIM/photos0/IMG00001.jpg', 90 '/DCIM/photos0/IMG00001.jpg',
91 '/DCIM/photos0/IMG00002.jpg', 91 '/DCIM/photos0/IMG00002.jpg',
92 '/DCIM/photos1/', 92 '/DCIM/photos1/',
93 '/DCIM/photos1/IMG00001.jpg', 93 '/DCIM/photos1/IMG00001.jpg',
94 '/DCIM/photos1/IMG00003.jpg' 94 '/DCIM/photos1/IMG00003.jpg'
95 ], 95 ],
96 '/DCIM'); 96 '/DCIM');
97 97
98 environment.directoryChangedListener_(EMPTY_EVENT); 98 var dcim = environment.getCurrentDirectory();
99 var notDcim = new MockDirectoryEntry(
100 new MockFileSystem('testFs'),
mtomasz 2015/04/01 02:28:45 nit: indent
Steve McKay 2015/04/01 03:52:53 Done.
101 '/jellybeans/');
102
103 environment.directoryChangedListener(EMPTY_EVENT);
99 var promise = widget.updateResolver.promise.then( 104 var promise = widget.updateResolver.promise.then(
100 function() { 105 function() {
101 // Reset the promise so we can wait on a second widget update. 106 // Reset the promise so we can wait on a second widget update.
102 widget.resetPromises(); 107 widget.resetPromises();
103 108 environment.setCurrentDirectory(notDcim);
104 // Faux unmount the volume, then request an update again.
105 // A fresh new scan should be started.
106 environment.simulateUnmount(); 109 environment.simulateUnmount();
107 110
108 environment.directoryChangedListener_(EMPTY_EVENT); 111 environment.setCurrentDirectory(dcim);
112 environment.directoryChangedListener(EMPTY_EVENT);
109 // Return the new promise, so subsequent "thens" only 113 // Return the new promise, so subsequent "thens" only
110 // fire once the widget has been updated again. 114 // fire once the widget has been updated again.
111 return widget.updateResolver.promise; 115 return widget.updateResolver.promise;
112 }).then( 116 }).then(
113 function() { 117 function() {
114 mediaScanner.assertScanCount(2); 118 mediaScanner.assertScanCount(2);
115 }); 119 });
116 120
117 reportPromise(promise, callback); 121 reportPromise(promise, callback);
118 } 122 }
119 123
120 function testDirectoryChange_TriggersUpdate(callback) { 124 function testDirectoryChange_TriggersUpdate(callback) {
121 var controller = createController( 125 var controller = createController(
122 VolumeManagerCommon.VolumeType.MTP, 126 VolumeManagerCommon.VolumeType.MTP,
123 'mtp-volume', 127 'mtp-volume',
124 [ 128 [
125 '/DCIM/', 129 '/DCIM/',
126 '/DCIM/photos0/', 130 '/DCIM/photos0/',
127 '/DCIM/photos0/IMG00001.jpg', 131 '/DCIM/photos0/IMG00001.jpg',
128 ], 132 ],
129 '/DCIM'); 133 '/DCIM');
130 134
131 environment.directoryChangedListener_(EMPTY_EVENT); 135 environment.directoryChangedListener(EMPTY_EVENT);
132 reportPromise(widget.updateResolver.promise, callback); 136 reportPromise(widget.updateResolver.promise, callback);
133 } 137 }
134 138
139 function testDirectoryChange_CancelsScan(callback) {
140 var controller = createController(
141 VolumeManagerCommon.VolumeType.MTP,
142 'mtp-volume',
143 [
144 '/DCIM/',
145 '/DCIM/photos0/',
146 '/DCIM/photos0/IMG00001.jpg',
147 '/DCIM/photos0/IMG00002.jpg',
148 '/DCIM/photos1/',
149 '/DCIM/photos1/IMG00001.jpg',
150 '/DCIM/photos1/IMG00003.jpg'
151 ],
152 '/DCIM');
153
154 var notDcim = new MockDirectoryEntry(
155 new MockFileSystem('testFs'),
mtomasz 2015/04/01 03:19:47 nit: indent
Steve McKay 2015/04/01 03:52:53 Done.
156 '/jellybeans/');
157
158 environment.directoryChangedListener(EMPTY_EVENT);
159 var promise = widget.updateResolver.promise.then(
160 function() {
mtomasz 2015/04/01 03:19:47 nit: indent
Steve McKay 2015/04/01 03:52:53 Done.
161 // Reset the promise so we can wait on a second widget update.
162 widget.resetPromises();
163 environment.setCurrentDirectory(notDcim);
164 environment.directoryChangedListener(EMPTY_EVENT);
165 }).then(
166 function() {
mtomasz 2015/04/01 03:19:47 nit: indent
Steve McKay 2015/04/01 03:52:53 Done.
167 mediaScanner.assertScanCount(1);
168 mediaScanner.assertLastScanCanceled();
169 });
170
171 reportPromise(promise, callback);
172 }
173
174 function testWindowClose_CancelsScan(callback) {
175 var controller = createController(
176 VolumeManagerCommon.VolumeType.MTP,
177 'mtp-volume',
178 [
179 '/DCIM/',
180 '/DCIM/photos0/',
181 '/DCIM/photos0/IMG00001.jpg',
182 '/DCIM/photos0/IMG00002.jpg',
183 '/DCIM/photos1/',
184 '/DCIM/photos1/IMG00001.jpg',
185 '/DCIM/photos1/IMG00003.jpg'
186 ],
187 '/DCIM');
188
189 environment.directoryChangedListener(EMPTY_EVENT);
190 var promise = widget.updateResolver.promise.then(
191 function() {
mtomasz 2015/04/01 02:28:45 nit: 4 spaces indent
Steve McKay 2015/04/01 03:52:53 Done.
192 // Reset the promise so we can wait on a second widget update.
193 widget.resetPromises();
194 environment.windowCloseListener();
195 }).then(
196 function() {
mtomasz 2015/04/01 02:28:45 nit: 4 spaces indent.
Steve McKay 2015/04/01 03:52:53 Done.
197 mediaScanner.assertScanCount(1);
198 mediaScanner.assertLastScanCanceled();
199 });
200
201 reportPromise(promise, callback);
202 }
203
135 function testDirectoryChange_DetailsPanelVisibility_InitialChangeDir() { 204 function testDirectoryChange_DetailsPanelVisibility_InitialChangeDir() {
136 var controller = createController( 205 var controller = createController(
137 VolumeManagerCommon.VolumeType.MTP, 206 VolumeManagerCommon.VolumeType.MTP,
138 'mtp-volume', 207 'mtp-volume',
139 [ 208 [
140 '/DCIM/', 209 '/DCIM/',
141 '/DCIM/photos0/', 210 '/DCIM/photos0/',
142 '/DCIM/photos0/IMG00001.jpg', 211 '/DCIM/photos0/IMG00001.jpg',
143 ], 212 ],
144 '/DCIM'); 213 '/DCIM');
145 214
146 var event = new Event('directory-changed'); 215 var event = new Event('directory-changed');
147 event.newDirEntry = new MockDirectoryEntry( 216 event.newDirEntry = new MockDirectoryEntry(
148 new MockFileSystem('testFs'), 217 new MockFileSystem('testFs'),
149 '/DCIM/'); 218 '/DCIM/');
150 219
151 environment.directoryChangedListener_(event); 220 environment.directoryChangedListener(event);
152 assertTrue(widget.detailsVisible); 221 assertTrue(widget.detailsVisible);
153 } 222 }
154 223
155 function testDirectoryChange_DetailsPanelVisibility_SubsequentChangeDir() { 224 function testDirectoryChange_DetailsPanelVisibility_SubsequentChangeDir() {
156 var controller = createController( 225 var controller = createController(
157 VolumeManagerCommon.VolumeType.MTP, 226 VolumeManagerCommon.VolumeType.MTP,
158 'mtp-volume', 227 'mtp-volume',
159 [ 228 [
160 '/DCIM/', 229 '/DCIM/',
161 '/DCIM/photos0/', 230 '/DCIM/photos0/',
162 '/DCIM/photos0/IMG00001.jpg', 231 '/DCIM/photos0/IMG00001.jpg',
163 ], 232 ],
164 '/DCIM'); 233 '/DCIM');
165 234
166 var event = new Event('directory-changed'); 235 var event = new Event('directory-changed');
167 event.newDirEntry = new MockDirectoryEntry( 236 event.newDirEntry = new MockDirectoryEntry(
168 new MockFileSystem('testFs'), 237 new MockFileSystem('testFs'),
169 '/DCIM/'); 238 '/DCIM/');
170 // Any previous dir at all will skip the new window logic. 239 // Any previous dir at all will skip the new window logic.
171 event.previousDirEntry = event.newDirEntry; 240 event.previousDirEntry = event.newDirEntry;
172 241
173 environment.directoryChangedListener_(event); 242 environment.directoryChangedListener(event);
174 assertFalse(widget.detailsVisible); 243 assertFalse(widget.detailsVisible);
175 } 244 }
176 245
177 function testSelectionChange_TriggersUpdate(callback) { 246 function testSelectionChange_TriggersUpdate(callback) {
178 var controller = createController( 247 var controller = createController(
179 VolumeManagerCommon.VolumeType.MTP, 248 VolumeManagerCommon.VolumeType.MTP,
180 'mtp-volume', 249 'mtp-volume',
181 [ 250 [
182 '/DCIM/', 251 '/DCIM/',
183 '/DCIM/photos0/', 252 '/DCIM/photos0/',
184 '/DCIM/photos0/IMG00001.jpg', 253 '/DCIM/photos0/IMG00001.jpg',
185 ], 254 ],
186 '/DCIM'); 255 '/DCIM');
187 256
188 environment.selectionChangedListener_(); 257 var fileSystem = new MockFileSystem('testFs');
258 // ensure there is some content in the scan so the code that depends
259 // on this state doesn't croak which it finds it missing.
260 environment.selection.push(
261 new MockFileEntry(fileSystem, '/DCIM/photos0/IMG00001.jpg', {size: 0}));
262
263 environment.selectionChangedListener();
264 mediaScanner.finalizeScans();
189 reportPromise(widget.updateResolver.promise, callback); 265 reportPromise(widget.updateResolver.promise, callback);
190 } 266 }
191 267
192 function testFinalizeScans_TriggersUpdate(callback) { 268 function testFinalizeScans_TriggersUpdate(callback) {
193 var controller = createController( 269 var controller = createController(
194 VolumeManagerCommon.VolumeType.MTP, 270 VolumeManagerCommon.VolumeType.MTP,
195 'mtp-volume', 271 'mtp-volume',
196 [ 272 [
197 '/DCIM/', 273 '/DCIM/',
198 '/DCIM/photos0/', 274 '/DCIM/photos0/',
199 '/DCIM/photos0/IMG00001.jpg', 275 '/DCIM/photos0/IMG00001.jpg',
200 ], 276 ],
201 '/DCIM'); 277 '/DCIM');
202 278
203 var fileSystem = new MockFileSystem('testFs'); 279 var fileSystem = new MockFileSystem('testFs');
204 // ensure there is some content in the scan so the code that depends 280 // ensure there is some content in the scan so the code that depends
205 // on this state doesn't croak which it finds it missing. 281 // on this state doesn't croak which it finds it missing.
206 mediaScanner.fileEntries.push( 282 mediaScanner.fileEntries.push(
207 new MockFileEntry(fileSystem, '/DCIM/photos0/IMG00001.jpg', {size: 0})); 283 new MockFileEntry(fileSystem, '/DCIM/photos0/IMG00001.jpg', {size: 0}));
208 284
209 environment.directoryChangedListener_(EMPTY_EVENT); // initiates a scan. 285 environment.directoryChangedListener(EMPTY_EVENT); // initiates a scan.
210 widget.resetPromises(); 286 widget.resetPromises();
211 mediaScanner.finalizeScans(); 287 mediaScanner.finalizeScans();
212 288
213 reportPromise(widget.updateResolver.promise, callback); 289 reportPromise(widget.updateResolver.promise, callback);
214 } 290 }
215 291
216 function testClickDestination_ShowsRootPriorToImport(callback) { 292 function testClickDestination_ShowsRootPriorToImport(callback) {
217 var controller = createController( 293 var controller = createController(
218 VolumeManagerCommon.VolumeType.MTP, 294 VolumeManagerCommon.VolumeType.MTP,
219 'mtp-volume', 295 'mtp-volume',
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 ], 332 ],
257 '/DCIM'); 333 '/DCIM');
258 334
259 var fileSystem = new MockFileSystem('testFs'); 335 var fileSystem = new MockFileSystem('testFs');
260 // ensure there is some content in the scan so the code that depends 336 // ensure there is some content in the scan so the code that depends
261 // on this state doesn't croak which it finds it missing. 337 // on this state doesn't croak which it finds it missing.
262 mediaScanner.fileEntries.push( 338 mediaScanner.fileEntries.push(
263 new MockFileEntry(fileSystem, '/DCIM/photos0/IMG00001.jpg', {size: 0})); 339 new MockFileEntry(fileSystem, '/DCIM/photos0/IMG00001.jpg', {size: 0}));
264 340
265 // First we need to force the controller into a scanning state. 341 // First we need to force the controller into a scanning state.
266 environment.directoryChangedListener_(EMPTY_EVENT); 342 environment.directoryChangedListener(EMPTY_EVENT);
267 343
268 return widget.updateResolver.promise.then( 344 return widget.updateResolver.promise.then(
269 function() { 345 function() {
270 widget.resetPromises(); 346 widget.resetPromises();
271 mediaScanner.finalizeScans(); 347 mediaScanner.finalizeScans();
272 return widget.updateResolver.promise.then( 348 return widget.updateResolver.promise.then(
273 function() { 349 function() {
274 widget.resetPromises(); 350 widget.resetPromises();
275 widget.click(clickSource); 351 widget.click(clickSource);
276 return mediaImporter.importResolver.promise; 352 return mediaImporter.importResolver.promise;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 * @param {!VolumeInfo} volumeInfo 463 * @param {!VolumeInfo} volumeInfo
388 * @param {!DirectoryEntry} directory 464 * @param {!DirectoryEntry} directory
389 */ 465 */
390 TestControllerEnvironment = function(volumeInfo, directory) { 466 TestControllerEnvironment = function(volumeInfo, directory) {
391 /** @private {!VolumeInfo} */ 467 /** @private {!VolumeInfo} */
392 this.volumeInfo_ = volumeInfo; 468 this.volumeInfo_ = volumeInfo;
393 469
394 /** @private {!DirectoryEntry} */ 470 /** @private {!DirectoryEntry} */
395 this.directory_ = directory; 471 this.directory_ = directory;
396 472
397 /** @private {function(string)} */ 473 /** @public {function()} */
398 this.volumeUnmountListener_; 474 this.windowCloseListener;
399 475
400 /** @private {function()} */ 476 /** @public {function(string)} */
401 this.directoryChangedListener_; 477 this.volumeUnmountListener;
402 478
403 /** @private {function()} */ 479 /** @public {function()} */
404 this.selectionChangedListener_; 480 this.directoryChangedListener;
481
482 /** @public {function()} */
483 this.selectionChangedListener;
405 484
406 /** @public {!Entry} */ 485 /** @public {!Entry} */
407 this.selection = []; 486 this.selection = [];
408 487
409 /** @public {boolean} */ 488 /** @public {boolean} */
410 this.isDriveMounted = true; 489 this.isDriveMounted = true;
411 490
412 /** @public {number} */ 491 /** @public {number} */
413 this.freeStorageSpace = 123456789; // bytes 492 this.freeStorageSpace = 123456789; // bytes
414 493
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 return this.isDriveMounted; 527 return this.isDriveMounted;
449 }; 528 };
450 529
451 /** @override */ 530 /** @override */
452 TestControllerEnvironment.prototype.getFreeStorageSpace = 531 TestControllerEnvironment.prototype.getFreeStorageSpace =
453 function() { 532 function() {
454 return Promise.resolve(this.freeStorageSpace); 533 return Promise.resolve(this.freeStorageSpace);
455 }; 534 };
456 535
457 /** @override */ 536 /** @override */
537 TestControllerEnvironment.prototype.addWindowCloseListener =
538 function(listener) {
539 this.windowCloseListener = listener;
540 };
541
542 /** @override */
458 TestControllerEnvironment.prototype.addVolumeUnmountListener = 543 TestControllerEnvironment.prototype.addVolumeUnmountListener =
459 function(listener) { 544 function(listener) {
460 this.volumeUnmountListener_ = listener; 545 this.volumeUnmountListener = listener;
461 }; 546 };
462 547
463 /** @override */ 548 /** @override */
464 TestControllerEnvironment.prototype.addDirectoryChangedListener = 549 TestControllerEnvironment.prototype.addDirectoryChangedListener =
465 function(listener) { 550 function(listener) {
466 this.directoryChangedListener_ = listener; 551 this.directoryChangedListener = listener;
467 }; 552 };
468 553
469 /** @override */ 554 /** @override */
470 TestControllerEnvironment.prototype.addSelectionChangedListener = 555 TestControllerEnvironment.prototype.addSelectionChangedListener =
471 function(listener) { 556 function(listener) {
472 this.selectionChangedListener_ = listener; 557 this.selectionChangedListener = listener;
473 }; 558 };
474 559
475 /** @override */ 560 /** @override */
476 TestControllerEnvironment.prototype.getImportDestination = 561 TestControllerEnvironment.prototype.getImportDestination =
477 function(date) { 562 function(date) {
478 var fileSystem = new MockFileSystem('testFs'); 563 var fileSystem = new MockFileSystem('testFs');
479 return new MockDirectoryEntry(fileSystem, '/abc/123'); 564 return new MockDirectoryEntry(fileSystem, '/abc/123');
480 }; 565 };
481 566
482 /** @override */ 567 /** @override */
483 TestControllerEnvironment.prototype.showImportDestination = function() { 568 TestControllerEnvironment.prototype.showImportDestination = function() {
484 this.showImportDestinationResolver.resolve(); 569 this.showImportDestinationResolver.resolve();
485 }; 570 };
486 571
487 /** @override */ 572 /** @override */
488 TestControllerEnvironment.prototype.showImportRoot = function() { 573 TestControllerEnvironment.prototype.showImportRoot = function() {
489 this.showImportRootResolver.resolve(); 574 this.showImportRootResolver.resolve();
490 }; 575 };
491 576
492 /** 577 /**
493 * Simulates an unmount event. 578 * Simulates an unmount event.
494 */ 579 */
495 TestControllerEnvironment.prototype.simulateUnmount = function() { 580 TestControllerEnvironment.prototype.simulateUnmount = function() {
496 this.volumeUnmountListener_(this.volumeInfo_.volumeId); 581 this.volumeUnmountListener(this.volumeInfo_.volumeId);
497 }; 582 };
498 583
499 /** 584 /**
500 * Test implementation of importer.CommandWidget. 585 * Test implementation of importer.CommandWidget.
501 * 586 *
502 * @constructor 587 * @constructor
503 * @implements {importer.CommandWidget} 588 * @implements {importer.CommandWidget}
504 * @struct 589 * @struct
505 */ 590 */
506 importer.TestCommandWidget = function() { 591 importer.TestCommandWidget = function() {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 * @param {!Array.<string>} fileNames 686 * @param {!Array.<string>} fileNames
602 * @return {!VolumeInfo} 687 * @return {!VolumeInfo}
603 */ 688 */
604 function setupFileSystem(volumeType, volumeId, fileNames) { 689 function setupFileSystem(volumeType, volumeId, fileNames) {
605 var volumeInfo = volumeManager.createVolumeInfo( 690 var volumeInfo = volumeManager.createVolumeInfo(
606 volumeType, volumeId, 'A volume known as ' + volumeId); 691 volumeType, volumeId, 'A volume known as ' + volumeId);
607 assertTrue(volumeInfo != null); 692 assertTrue(volumeInfo != null);
608 volumeInfo.fileSystem.populate(fileNames); 693 volumeInfo.fileSystem.populate(fileNames);
609 return volumeInfo; 694 return volumeInfo;
610 } 695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698