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

Side by Side Diff: ui/file_manager/file_manager/background/js/duplicate_finder_unittest.js

Issue 980603003: Move content deduplication into the scan process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review comments. Created 5 years, 9 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 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
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 function testDispositionChecker_ContentDupe(callback) {
122 var filePaths = ['/foo.txt'];
123 var fileHashes = ['abc123'];
124 var files = setupHashes(filePaths, fileHashes);
125
126 reportPromise(
127 getDisposition(files[0], importer.Destination.GOOGLE_DRIVE)
128 .then(
129 function(disposition) {
130 assertEquals(
131 importer.Disposition.CONTENT_DUPLICATE,
132 disposition);
133 }),
134 callback);
135 };
136
137 function testDispositionChecker_HistoryDupe(callback) {
138 var filePaths = ['/foo.txt'];
139 var fileHashes = ['abc123'];
140 var files = setupHashes(filePaths, fileHashes);
141
142 testHistory.importedPaths['/foo.txt'] =
143 [importer.Destination.GOOGLE_DRIVE];
144
145 reportPromise(
146 getDisposition(files[0], importer.Destination.GOOGLE_DRIVE)
147 .then(
148 function(disposition) {
149 assertEquals(
150 importer.Disposition.HISTORY_DUPLICATE,
151 disposition);
152 }),
153 callback);
154 };
155
156 function testDispositionChecker_Original(callback) {
157 var filePaths = ['/foo.txt'];
158 var fileHashes = ['abc123'];
159 var files = setupHashes(filePaths, fileHashes);
160
161 var newFilePath = '/bar.txt';
162 fileSystem.populate([newFilePath]);
163 var newFile = fileSystem.entries[newFilePath];
164
165 reportPromise(
166 getDisposition(newFile, importer.Destination.GOOGLE_DRIVE)
167 .then(
168 function(disposition) {
169 assertEquals(importer.Disposition.ORIGINAL, disposition);
170 }),
171 callback);
172 };
173
109 /** 174 /**
110 * @param {!Array.<string>} filePaths 175 * @param {!Array.<string>} filePaths
111 * @param {!Array.<string>} fileHashes 176 * @param {!Array.<string>} fileHashes
112 * @return {!Array.<!FileEntry>} Created files. 177 * @return {!Array.<!FileEntry>} Created files.
113 */ 178 */
114 function setupHashes(filePaths, fileHashes) { 179 function setupHashes(filePaths, fileHashes) {
115 // Set up a filesystem with some files. 180 // Set up a filesystem with some files.
116 fileSystem.populate(filePaths); 181 fileSystem.populate(filePaths);
117 182
118 var files = filePaths.map( 183 var files = filePaths.map(
119 function(filename) { 184 function(filename) {
120 return fileSystem.entries[filename]; 185 return fileSystem.entries[filename];
121 }); 186 });
122 187
123 files.forEach(function(file, index) { 188 files.forEach(function(file, index) {
124 hashes[file.toURL()] = fileHashes[index]; 189 hashes[file.toURL()] = fileHashes[index];
125 fileUrls[fileHashes[index]] = file.toURL(); 190 fileUrls[fileHashes[index]] = file.toURL();
126 }); 191 });
127 192
128 return files; 193 return files;
129 } 194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698