Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** @type {!importer.DuplicateFinder} */ | 5 /** @type {!importer.DuplicateFinder} */ |
| 6 var duplicateFinder; | 6 var duplicateFinder; |
| 7 | 7 |
| 8 /** @type {!VolumeInfo} */ | 8 /** @type {!VolumeInfo} */ |
| 9 var drive; | 9 var drive; |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Map of file URL to hash code. | 12 * Map of file URL to hash code. |
| 13 * @type {!Object<string, string>} | 13 * @type {!Object<string, string>} |
| 14 */ | 14 */ |
| 15 var hashes = {}; | 15 var hashes = {}; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Map of hash code to file URL. | 18 * Map of hash code to file URL. |
| 19 * @type {!Object<string, string>} | 19 * @type {!Object<string, string>} |
| 20 */ | 20 */ |
| 21 var fileUrls = {}; | 21 var fileUrls = {}; |
| 22 | 22 |
| 23 /** @type {!MockFileSystem} */ | 23 /** @type {!MockFileSystem} */ |
| 24 var fileSystem; | 24 var fileSystem; |
| 25 | 25 |
| 26 /** @type {!importer.TestImportHistory} */ | |
| 27 var testHistory; | |
| 28 | |
| 29 /** @type {function(!FileEntry, !importer.Destination): | |
| 30 !importer.Disposition} */ | |
| 31 var getDisposition; | |
| 32 | |
| 26 // Set up string assets. | 33 // Set up string assets. |
| 27 loadTimeData.data = { | 34 loadTimeData.data = { |
| 28 CLOUD_IMPORT_ITEMS_REMAINING: '', | 35 CLOUD_IMPORT_ITEMS_REMAINING: '', |
| 29 DRIVE_DIRECTORY_LABEL: 'My Drive', | 36 DRIVE_DIRECTORY_LABEL: 'My Drive', |
| 30 DOWNLOADS_DIRECTORY_LABEL: 'Downloads' | 37 DOWNLOADS_DIRECTORY_LABEL: 'Downloads' |
| 31 }; | 38 }; |
| 32 | 39 |
| 33 function setUp() { | 40 function setUp() { |
| 34 // importer.setupTestLogger(); | 41 // importer.setupTestLogger(); |
| 35 fileSystem = new MockFileSystem('fake-filesystem'); | 42 fileSystem = new MockFileSystem('fake-filesystem'); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 61 result[hash] = fileUrls[hash] || []; | 68 result[hash] = fileUrls[hash] || []; |
| 62 }); | 69 }); |
| 63 callback(result); | 70 callback(result); |
| 64 } | 71 } |
| 65 }, | 72 }, |
| 66 runtime: { | 73 runtime: { |
| 67 lastError: null | 74 lastError: null |
| 68 } | 75 } |
| 69 }; | 76 }; |
| 70 | 77 |
| 71 duplicateFinder = new importer.DriveDuplicateFinder(); | 78 testHistory = new importer.TestImportHistory(); |
| 79 var tracker = new TestTracker(); | |
| 80 duplicateFinder = new importer.DriveDuplicateFinder(tracker); | |
| 81 | |
| 82 getDisposition = importer.DispositionChecker.createChecker( | |
| 83 testHistory, tracker); | |
| 72 } | 84 } |
| 73 | 85 |
| 74 // Verifies the correct result when a duplicate exists. | 86 // Verifies the correct result when a duplicate exists. |
| 75 function testCheckDuplicateTrue(callback) { | 87 function testCheckDuplicateTrue(callback) { |
| 76 var filePaths = ['/foo.txt']; | 88 var filePaths = ['/foo.txt']; |
| 77 var fileHashes = ['abc123']; | 89 var fileHashes = ['abc123']; |
| 78 var files = setupHashes(filePaths, fileHashes); | 90 var files = setupHashes(filePaths, fileHashes); |
| 79 | 91 |
| 80 reportPromise( | 92 reportPromise( |
| 81 duplicateFinder.checkDuplicate(files[0]) | 93 duplicateFinder.isDuplicate(files[0]) |
| 82 .then( | 94 .then( |
| 83 function(isDuplicate) { | 95 function(isDuplicate) { |
| 84 assertTrue(isDuplicate); | 96 assertTrue(isDuplicate); |
| 85 }), | 97 }), |
| 86 callback); | 98 callback); |
| 87 }; | 99 }; |
| 88 | 100 |
| 89 // Verifies the correct result when a duplicate doesn't exist. | 101 // Verifies the correct result when a duplicate doesn't exist. |
| 90 function testCheckDuplicateFalse(callback) { | 102 function testCheckDuplicateFalse(callback) { |
| 91 var filePaths = ['/foo.txt']; | 103 var filePaths = ['/foo.txt']; |
| 92 var fileHashes = ['abc123']; | 104 var fileHashes = ['abc123']; |
| 93 var files = setupHashes(filePaths, fileHashes); | 105 var files = setupHashes(filePaths, fileHashes); |
| 94 | 106 |
| 95 // Make another file. | 107 // Make another file. |
| 96 var newFilePath = '/bar.txt'; | 108 var newFilePath = '/bar.txt'; |
| 97 fileSystem.populate([newFilePath]); | 109 fileSystem.populate([newFilePath]); |
| 98 var newFile = fileSystem.entries[newFilePath]; | 110 var newFile = fileSystem.entries[newFilePath]; |
| 99 | 111 |
| 100 reportPromise( | 112 reportPromise( |
| 101 duplicateFinder.checkDuplicate(newFile) | 113 duplicateFinder.isDuplicate(newFile) |
| 102 .then( | 114 .then( |
| 103 function(isDuplicate) { | 115 function(isDuplicate) { |
| 104 assertFalse(isDuplicate); | 116 assertFalse(isDuplicate); |
| 105 }), | 117 }), |
| 106 callback); | 118 callback); |
| 107 }; | 119 }; |
| 108 | 120 |
| 121 // Verifies the correct result when a duplicate doesn't exist. | |
|
Ben Kwa
2015/03/05 20:05:10
"when a content duplicate exists."
Steve McKay
2015/03/05 21:39:03
Removed line entirely.
| |
| 122 function testDispositionChecker_ContentDupe(callback) { | |
| 123 var filePaths = ['/foo.txt']; | |
| 124 var fileHashes = ['abc123']; | |
| 125 var files = setupHashes(filePaths, fileHashes); | |
| 126 | |
| 127 reportPromise( | |
| 128 getDisposition(files[0], importer.Destination.GOOGLE_DRIVE) | |
| 129 .then( | |
| 130 function(disposition) { | |
| 131 assertEquals( | |
| 132 importer.Disposition.CONTENT_DUPLICATE, | |
| 133 disposition); | |
| 134 }), | |
| 135 callback); | |
| 136 }; | |
| 137 | |
| 138 // Verifies the correct result when a duplicate doesn't exist. | |
|
Ben Kwa
2015/03/05 20:05:10
"when a history duplicate exists."
Steve McKay
2015/03/05 21:39:03
Ditto.
| |
| 139 function testDispositionChecker_HistoryDupe(callback) { | |
| 140 var filePaths = ['/foo.txt']; | |
| 141 var fileHashes = ['abc123']; | |
| 142 var files = setupHashes(filePaths, fileHashes); | |
| 143 | |
| 144 testHistory.importedPaths[ | |
|
mtomasz
2015/03/05 04:36:52
nit: Line wrappings look off.
Steve McKay
2015/03/05 21:39:03
Done.
| |
| 145 '/foo.txt'] = | |
| 146 [importer.Destination.GOOGLE_DRIVE]; | |
| 147 | |
| 148 reportPromise( | |
| 149 getDisposition(files[0], importer.Destination.GOOGLE_DRIVE) | |
| 150 .then( | |
| 151 function(disposition) { | |
| 152 assertEquals( | |
| 153 importer.Disposition.HISTORY_DUPLICATE, | |
| 154 disposition); | |
| 155 }), | |
| 156 callback); | |
| 157 }; | |
| 158 | |
| 159 // Verifies the correct result when a duplicate doesn't exist. | |
| 160 function testDispositionChecker_Original(callback) { | |
| 161 var filePaths = ['/foo.txt']; | |
| 162 var fileHashes = ['abc123']; | |
| 163 var files = setupHashes(filePaths, fileHashes); | |
| 164 | |
| 165 // Make another file. | |
| 166 var newFilePath = '/bar.txt'; | |
| 167 fileSystem.populate([newFilePath]); | |
| 168 var newFile = fileSystem.entries[newFilePath]; | |
| 169 | |
| 170 reportPromise( | |
| 171 getDisposition(newFile, importer.Destination.GOOGLE_DRIVE) | |
| 172 .then( | |
| 173 function(disposition) { | |
| 174 assertEquals(importer.Disposition.ORIGINAL, disposition); | |
| 175 }), | |
| 176 callback); | |
| 177 }; | |
| 178 | |
| 109 /** | 179 /** |
| 110 * @param {!Array.<string>} filePaths | 180 * @param {!Array.<string>} filePaths |
| 111 * @param {!Array.<string>} fileHashes | 181 * @param {!Array.<string>} fileHashes |
| 112 * @return {!Array.<!FileEntry>} Created files. | 182 * @return {!Array.<!FileEntry>} Created files. |
| 113 */ | 183 */ |
| 114 function setupHashes(filePaths, fileHashes) { | 184 function setupHashes(filePaths, fileHashes) { |
| 115 // Set up a filesystem with some files. | 185 // Set up a filesystem with some files. |
| 116 fileSystem.populate(filePaths); | 186 fileSystem.populate(filePaths); |
| 117 | 187 |
| 118 var files = filePaths.map( | 188 var files = filePaths.map( |
| 119 function(filename) { | 189 function(filename) { |
| 120 return fileSystem.entries[filename]; | 190 return fileSystem.entries[filename]; |
| 121 }); | 191 }); |
| 122 | 192 |
| 123 files.forEach(function(file, index) { | 193 files.forEach(function(file, index) { |
| 124 hashes[file.toURL()] = fileHashes[index]; | 194 hashes[file.toURL()] = fileHashes[index]; |
| 125 fileUrls[fileHashes[index]] = file.toURL(); | 195 fileUrls[fileHashes[index]] = file.toURL(); |
| 126 }); | 196 }); |
| 127 | 197 |
| 128 return files; | 198 return files; |
| 129 } | 199 } |
| OLD | NEW |