Chromium Code Reviews| 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 | 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 Loading... | |
| 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 * Asserts that the last scan was canceled. Fails if no | |
| 107 * scan exists. | |
| 108 */ | |
| 109 TestMediaScanner.prototype.assertLastScanCanceled = function() { | |
| 110 assertTrue(this.scans_.length > 0); | |
| 111 assertTrue(this.scans_[this.scans_.length - 1].canceled()); | |
| 112 }; | |
| 113 | |
| 114 /** | |
| 106 * importer.MediaScanner and importer.ScanResult test double. | 115 * importer.MediaScanner and importer.ScanResult test double. |
| 107 * | 116 * |
| 108 * @constructor | 117 * @constructor |
| 109 * @struct | 118 * @struct |
| 110 * @implements {importer.ScanResult} | 119 * @implements {importer.ScanResult} |
| 111 * | 120 * |
| 112 * @param {!Array.<!FileEntry>} fileEntries | 121 * @param {!Array.<!FileEntry>} fileEntries |
| 113 */ | 122 */ |
| 114 function TestScanResult(fileEntries) { | 123 function TestScanResult(fileEntries) { |
| 124 | |
|
mtomasz
2015/04/01 03:55:40
nit: Remove \n
Steve McKay
2015/04/01 04:00:13
Done.
| |
| 125 this.scanId_ = ++TestScanResult.lastId_; | |
| 115 /** | 126 /** |
|
mtomasz
2015/04/01 03:55:40
nit: Add \n
Steve McKay
2015/04/01 04:00:13
Done.
| |
| 116 * List of file entries found while scanning. | 127 * List of file entries found while scanning. |
| 117 * @type {!Array.<!FileEntry>} | 128 * @type {!Array.<!FileEntry>} |
| 118 */ | 129 */ |
| 119 this.fileEntries = fileEntries.slice(); | 130 this.fileEntries = fileEntries.slice(); |
| 120 | 131 |
| 121 /** @type {number} */ | 132 /** @type {number} */ |
| 122 this.totalBytes = 100; | 133 this.totalBytes = 100; |
| 123 | 134 |
| 124 /** @type {number} */ | 135 /** @type {number} */ |
| 125 this.scanDuration = 100; | 136 this.scanDuration = 100; |
| 126 | 137 |
| 127 /** @type {function} */ | 138 /** @type {function} */ |
| 128 this.resolveResult_; | 139 this.resolveResult_; |
| 129 | 140 |
| 130 /** @type {function} */ | 141 /** @type {function} */ |
| 131 this.rejectResult_; | 142 this.rejectResult_; |
| 132 | 143 |
| 133 /** @type {boolean} */ | 144 /** @type {boolean} */ |
| 134 this.settled_ = false; | 145 this.settled_ = false; |
| 135 | 146 |
| 147 /** @private {boolean} */ | |
| 148 this.canceled_ = false; | |
| 149 | |
| 136 /** @type {!Promise.<!importer.ScanResult>} */ | 150 /** @type {!Promise.<!importer.ScanResult>} */ |
| 137 this.whenFinal_ = new Promise( | 151 this.whenFinal_ = new Promise( |
| 138 function(resolve, reject) { | 152 function(resolve, reject) { |
| 139 this.resolveResult_ = function(result) { | 153 this.resolveResult_ = function(result) { |
| 140 this.settled_ = true; | 154 this.settled_ = true; |
| 141 resolve(result); | 155 resolve(result); |
| 142 }.bind(this); | 156 }.bind(this); |
| 143 this.rejectResult_ = function() { | 157 this.rejectResult_ = function() { |
| 144 this.settled_ = true; | 158 this.settled_ = true; |
| 145 reject(); | 159 reject(); |
| 146 }.bind(this); | 160 }.bind(this); |
| 147 }.bind(this)); | 161 }.bind(this)); |
| 148 } | 162 } |
| 149 | 163 |
| 164 /** @private {number} */ | |
| 165 TestScanResult.lastId_ = 0; | |
| 166 | |
| 167 /** @struct */ | |
| 168 TestScanResult.prototype = { | |
| 169 /** @return {string} */ | |
| 170 get name() { return 'TestScanResult(' + this.scanId_ + ')' } | |
| 171 }; | |
| 172 | |
| 150 /** @override */ | 173 /** @override */ |
| 151 TestScanResult.prototype.getFileEntries = function() { | 174 TestScanResult.prototype.getFileEntries = function() { |
| 152 return this.fileEntries; | 175 return this.fileEntries; |
| 153 }; | 176 }; |
| 154 | 177 |
| 155 /** @override */ | 178 /** @override */ |
| 156 TestScanResult.prototype.finalize = function() { | 179 TestScanResult.prototype.finalize = function() { |
| 157 return this.resolveResult_(this); | 180 return this.resolveResult_(this); |
| 158 }; | 181 }; |
| 159 | 182 |
| 160 /** @override */ | 183 /** @override */ |
| 161 TestScanResult.prototype.whenFinal = function() { | 184 TestScanResult.prototype.whenFinal = function() { |
| 162 return this.whenFinal_; | 185 return this.whenFinal_; |
| 163 }; | 186 }; |
| 164 | 187 |
| 165 /** @override */ | 188 /** @override */ |
| 166 TestScanResult.prototype.isFinal = function() { | 189 TestScanResult.prototype.isFinal = function() { |
| 167 return this.settled_; | 190 return this.settled_; |
| 168 }; | 191 }; |
| 169 | 192 |
| 170 /** @override */ | 193 /** @override */ |
| 171 TestScanResult.prototype.isInvalidated = function() { | 194 TestScanResult.prototype.cancel = function() { |
| 172 return false; | 195 this.canceled_ = true; |
| 173 }; | 196 }; |
| 174 | 197 |
| 175 /** @override */ | 198 /** @override */ |
| 199 TestScanResult.prototype.canceled = function() { | |
| 200 return this.canceled_; | |
| 201 }; | |
| 202 | |
| 203 /** @override */ | |
| 176 TestScanResult.prototype.getStatistics = function() { | 204 TestScanResult.prototype.getStatistics = function() { |
| 177 return { | 205 return { |
| 178 scanDuration: this.scanDuration, | 206 scanDuration: this.scanDuration, |
| 179 newFileCount: this.fileEntries.length, | 207 newFileCount: this.fileEntries.length, |
| 180 duplicates: {}, | 208 duplicates: {}, |
| 181 sizeBytes: this.totalBytes | 209 sizeBytes: this.totalBytes |
| 182 }; | 210 }; |
| 183 }; | 211 }; |
| 184 | 212 |
| 185 /** | 213 /** |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 197 * @public {boolean} | 225 * @public {boolean} |
| 198 */ | 226 */ |
| 199 this.triggered = false; | 227 this.triggered = false; |
| 200 }; | 228 }; |
| 201 | 229 |
| 202 /** | 230 /** |
| 203 * @override | 231 * @override |
| 204 */ | 232 */ |
| 205 TestDirectoryWatcher.prototype.addDirectory = function() { | 233 TestDirectoryWatcher.prototype.addDirectory = function() { |
| 206 }; | 234 }; |
| OLD | NEW |