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

Side by Side Diff: ui/file_manager/file_manager/background/js/mock_media_scanner.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 /** 5 /**
6 * importer.MediaScanner and importer.ScanResult test double. 6 * importer.MediaScanner and importer.ScanResult test double.
7 * 7 *
8 * @constructor 8 * @constructor
9 * @struct 9 * @struct
10 * @implements {importer.MediaScanner} 10 * @implements {importer.MediaScanner}
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 }; 96 };
97 97
98 /** 98 /**
99 * @param {number} expected 99 * @param {number} expected
100 */ 100 */
101 TestMediaScanner.prototype.assertScanCount = function(expected) { 101 TestMediaScanner.prototype.assertScanCount = function(expected) {
102 assertEquals(expected, this.scans_.length); 102 assertEquals(expected, this.scans_.length);
103 }; 103 };
104 104
105 /** 105 /**
106 * @param {number} expected
mtomasz 2015/04/01 02:28:45 There is no "expected" in the argument list.
Steve McKay 2015/04/01 03:52:52 Done.
107 */
108 TestMediaScanner.prototype.assertLastScanCanceled = function() {
109 assertTrue(this.scans_.length > 0);
110 assertTrue(this.scans_[this.scans_.length - 1].canceled());
111 };
112
113 /**
106 * importer.MediaScanner and importer.ScanResult test double. 114 * importer.MediaScanner and importer.ScanResult test double.
107 * 115 *
108 * @constructor 116 * @constructor
109 * @struct 117 * @struct
110 * @implements {importer.ScanResult} 118 * @implements {importer.ScanResult}
111 * 119 *
112 * @param {!Array.<!FileEntry>} fileEntries 120 * @param {!Array.<!FileEntry>} fileEntries
113 */ 121 */
114 function TestScanResult(fileEntries) { 122 function TestScanResult(fileEntries) {
123
124 this.scanId_ = ++TestScanResult.lastId_;
115 /** 125 /**
116 * List of file entries found while scanning. 126 * List of file entries found while scanning.
117 * @type {!Array.<!FileEntry>} 127 * @type {!Array.<!FileEntry>}
118 */ 128 */
119 this.fileEntries = fileEntries.slice(); 129 this.fileEntries = fileEntries.slice();
120 130
121 /** @type {number} */ 131 /** @type {number} */
122 this.totalBytes = 100; 132 this.totalBytes = 100;
123 133
124 /** @type {number} */ 134 /** @type {number} */
125 this.scanDuration = 100; 135 this.scanDuration = 100;
126 136
127 /** @type {function} */ 137 /** @type {function} */
128 this.resolveResult_; 138 this.resolveResult_;
129 139
130 /** @type {function} */ 140 /** @type {function} */
131 this.rejectResult_; 141 this.rejectResult_;
132 142
133 /** @type {boolean} */ 143 /** @type {boolean} */
134 this.settled_ = false; 144 this.settled_ = false;
135 145
146 /** @private {boolean} */
147 this.canceled_ = false;
148
136 /** @type {!Promise.<!importer.ScanResult>} */ 149 /** @type {!Promise.<!importer.ScanResult>} */
137 this.whenFinal_ = new Promise( 150 this.whenFinal_ = new Promise(
138 function(resolve, reject) { 151 function(resolve, reject) {
139 this.resolveResult_ = function(result) { 152 this.resolveResult_ = function(result) {
140 this.settled_ = true; 153 this.settled_ = true;
141 resolve(result); 154 resolve(result);
142 }.bind(this); 155 }.bind(this);
143 this.rejectResult_ = function() { 156 this.rejectResult_ = function() {
144 this.settled_ = true; 157 this.settled_ = true;
145 reject(); 158 reject();
146 }.bind(this); 159 }.bind(this);
147 }.bind(this)); 160 }.bind(this));
148 } 161 }
149 162
163 /** @private {number} */
164 TestScanResult.lastId_ = 0;
165
166 /** @struct */
167 TestScanResult.prototype = {
168 /** @return {string} */
169 get name() { return 'TestScanResult(' + this.scanId_ + ')' }
170 };
171
150 /** @override */ 172 /** @override */
151 TestScanResult.prototype.getFileEntries = function() { 173 TestScanResult.prototype.getFileEntries = function() {
152 return this.fileEntries; 174 return this.fileEntries;
153 }; 175 };
154 176
155 /** @override */ 177 /** @override */
156 TestScanResult.prototype.finalize = function() { 178 TestScanResult.prototype.finalize = function() {
157 return this.resolveResult_(this); 179 return this.resolveResult_(this);
158 }; 180 };
159 181
160 /** @override */ 182 /** @override */
161 TestScanResult.prototype.whenFinal = function() { 183 TestScanResult.prototype.whenFinal = function() {
162 return this.whenFinal_; 184 return this.whenFinal_;
163 }; 185 };
164 186
165 /** @override */ 187 /** @override */
166 TestScanResult.prototype.isFinal = function() { 188 TestScanResult.prototype.isFinal = function() {
167 return this.settled_; 189 return this.settled_;
168 }; 190 };
169 191
170 /** @override */ 192 /** @override */
171 TestScanResult.prototype.isInvalidated = function() { 193 TestScanResult.prototype.cancel = function() {
172 return false; 194 this.canceled_ = true;
173 }; 195 };
174 196
175 /** @override */ 197 /** @override */
198 TestScanResult.prototype.canceled = function() {
199 return this.canceled_;
200 };
201
202 /** @override */
176 TestScanResult.prototype.getStatistics = function() { 203 TestScanResult.prototype.getStatistics = function() {
177 return { 204 return {
178 scanDuration: this.scanDuration, 205 scanDuration: this.scanDuration,
179 newFileCount: this.fileEntries.length, 206 newFileCount: this.fileEntries.length,
180 duplicates: {}, 207 duplicates: {},
181 sizeBytes: this.totalBytes 208 sizeBytes: this.totalBytes
182 }; 209 };
183 }; 210 };
184 211
185 /** 212 /**
(...skipping 11 matching lines...) Expand all
197 * @public {boolean} 224 * @public {boolean}
198 */ 225 */
199 this.triggered = false; 226 this.triggered = false;
200 }; 227 };
201 228
202 /** 229 /**
203 * @override 230 * @override
204 */ 231 */
205 TestDirectoryWatcher.prototype.addDirectory = function() { 232 TestDirectoryWatcher.prototype.addDirectory = function() {
206 }; 233 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698