OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/download/download_query.h" | 5 #include "chrome/browser/download/download_query.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 static_cast<content::BrowserContext*>(NULL))); | 197 static_cast<content::BrowserContext*>(NULL))); |
198 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 198 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
199 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 199 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
200 match_filename)); | 200 match_filename)); |
201 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 201 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
202 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 202 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
203 fail_filename)); | 203 fail_filename)); |
204 GURL fail_url("http://example.com/fail"); | 204 GURL fail_url("http://example.com/fail"); |
205 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 205 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
206 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 206 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
207 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url)); | |
208 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); | |
207 std::vector<std::string> query_terms; | 209 std::vector<std::string> query_terms; |
208 query_terms.push_back("query"); | 210 query_terms.push_back("query"); |
209 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); | 211 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
210 ExpectStandardFilterResults(); | 212 ExpectStandardFilterResults(); |
211 } | 213 } |
212 | 214 |
213 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) { | 215 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryOriginalUrl) { |
214 CreateMocks(2); | 216 CreateMocks(2); |
215 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( | 217 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
216 static_cast<content::BrowserContext*>(NULL))); | 218 static_cast<content::BrowserContext*>(NULL))); |
217 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( | 219 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
218 static_cast<content::BrowserContext*>(NULL))); | 220 static_cast<content::BrowserContext*>(NULL))); |
219 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 221 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
220 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 222 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
221 fail_filename)); | 223 fail_filename)); |
222 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 224 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
223 fail_filename)); | 225 fail_filename)); |
224 GURL match_url("http://query.com/query"); | 226 GURL match_url("http://query.com/query"); |
225 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | 227 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); |
226 GURL fail_url("http://example.com/fail"); | 228 GURL fail_url("http://example.com/fail"); |
227 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 229 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
230 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url)); | |
231 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); | |
228 std::vector<std::string> query_terms; | 232 std::vector<std::string> query_terms; |
229 query_terms.push_back("query"); | 233 query_terms.push_back("query"); |
230 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); | 234 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
235 ExpectStandardFilterResults(); | |
236 } | |
237 | |
238 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) { | |
239 CreateMocks(2); | |
240 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( | |
241 static_cast<content::BrowserContext*>(NULL))); | |
242 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( | |
243 static_cast<content::BrowserContext*>(NULL))); | |
244 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | |
245 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | |
246 fail_filename)); | |
247 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | |
248 fail_filename)); | |
249 GURL match_url("http://query.com/query"); | |
asanka
2016/07/07 19:28:31
Should also test with something like http://exampl
mharanczyk
2016/07/08 10:10:54
Added unescaping tests for original url and url qu
| |
250 GURL fail_url("http://example.com/fail"); | |
251 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | |
252 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | |
253 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); | |
254 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); | |
255 std::vector<std::string> query_terms; | |
256 query_terms.push_back("query"); | |
257 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); | |
231 ExpectStandardFilterResults(); | 258 ExpectStandardFilterResults(); |
232 } | 259 } |
233 | 260 |
234 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) { | 261 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) { |
235 CreateMocks(2); | 262 CreateMocks(2); |
236 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( | 263 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
237 static_cast<content::BrowserContext*>(NULL))); | 264 static_cast<content::BrowserContext*>(NULL))); |
238 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( | 265 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
239 static_cast<content::BrowserContext*>(NULL))); | 266 static_cast<content::BrowserContext*>(NULL))); |
240 const base::FilePath::StringType kTestString( | 267 const base::FilePath::StringType kTestString( |
241 #if defined(OS_POSIX) | 268 #if defined(OS_POSIX) |
242 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd" | 269 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd" |
243 #elif defined(OS_WIN) | 270 #elif defined(OS_WIN) |
244 L"/\x4f60\x597d\x4f60\x597d" | 271 L"/\x4f60\x597d\x4f60\x597d" |
245 #endif | 272 #endif |
246 ); | 273 ); |
247 base::FilePath match_filename(kTestString); | 274 base::FilePath match_filename(kTestString); |
248 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 275 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
249 match_filename)); | 276 match_filename)); |
250 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 277 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
251 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 278 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
252 fail_filename)); | 279 fail_filename)); |
253 GURL fail_url("http://example.com/fail"); | 280 GURL fail_url("http://example.com/fail"); |
254 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 281 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
255 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 282 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
283 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url)); | |
284 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); | |
256 std::vector<base::FilePath::StringType> query_terms; | 285 std::vector<base::FilePath::StringType> query_terms; |
257 query_terms.push_back(kTestString); | 286 query_terms.push_back(kTestString); |
258 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); | 287 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
259 ExpectStandardFilterResults(); | 288 ExpectStandardFilterResults(); |
260 } | 289 } |
261 | 290 |
262 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) { | 291 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) { |
263 CreateMocks(2); | 292 CreateMocks(2); |
264 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 293 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
265 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 294 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
(...skipping 22 matching lines...) Expand all Loading... | |
288 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 317 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
289 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 318 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
290 match_filename)); | 319 match_filename)); |
291 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 320 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
292 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 321 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
293 fail_filename)); | 322 fail_filename)); |
294 AddFilter(DownloadQuery::FILTER_FILENAME, match_filename.value().c_str()); | 323 AddFilter(DownloadQuery::FILTER_FILENAME, match_filename.value().c_str()); |
295 ExpectStandardFilterResults(); | 324 ExpectStandardFilterResults(); |
296 } | 325 } |
297 | 326 |
327 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterOriginalUrlRegex) { | |
328 CreateMocks(2); | |
329 GURL match_url("http://query.com/query"); | |
330 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | |
331 GURL fail_url("http://example.com/fail"); | |
332 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | |
333 AddFilter(DownloadQuery::FILTER_ORIGINAL_URL_REGEX, "query"); | |
334 ExpectStandardFilterResults(); | |
335 } | |
336 | |
337 TEST_F(DownloadQueryTest, DownloadQueryTest_SortOriginalUrl) { | |
338 CreateMocks(2); | |
339 GURL b_url("http://example.com/b"); | |
340 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(b_url)); | |
341 GURL a_url("http://example.com/a"); | |
342 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(a_url)); | |
343 query()->AddSorter( | |
344 DownloadQuery::SORT_ORIGINAL_URL, DownloadQuery::ASCENDING); | |
345 ExpectSortInverted(); | |
346 } | |
347 | |
348 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterOriginalUrl) { | |
349 CreateMocks(2); | |
350 GURL match_url("http://query.com/query"); | |
351 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | |
352 GURL fail_url("http://example.com/fail"); | |
353 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | |
354 AddFilter(DownloadQuery::FILTER_ORIGINAL_URL, match_url.spec().c_str()); | |
355 ExpectStandardFilterResults(); | |
356 } | |
357 | |
298 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrlRegex) { | 358 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrlRegex) { |
299 CreateMocks(2); | 359 CreateMocks(2); |
300 GURL match_url("http://query.com/query"); | 360 GURL match_url("http://query.com/query"); |
301 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | 361 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); |
302 GURL fail_url("http://example.com/fail"); | 362 GURL fail_url("http://example.com/fail"); |
303 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 363 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
304 AddFilter(DownloadQuery::FILTER_URL_REGEX, "query"); | 364 AddFilter(DownloadQuery::FILTER_URL_REGEX, "query"); |
305 ExpectStandardFilterResults(); | 365 ExpectStandardFilterResults(); |
306 } | 366 } |
307 | 367 |
308 TEST_F(DownloadQueryTest, DownloadQueryTest_SortUrl) { | 368 TEST_F(DownloadQueryTest, DownloadQueryTest_SortUrl) { |
309 CreateMocks(2); | 369 CreateMocks(2); |
310 GURL b_url("http://example.com/b"); | 370 GURL b_url("http://example.com/b"); |
311 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(b_url)); | 371 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(b_url)); |
312 GURL a_url("http://example.com/a"); | 372 GURL a_url("http://example.com/a"); |
313 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(a_url)); | 373 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(a_url)); |
314 query()->AddSorter(DownloadQuery::SORT_URL, DownloadQuery::ASCENDING); | 374 query()->AddSorter(DownloadQuery::SORT_URL, DownloadQuery::ASCENDING); |
315 ExpectSortInverted(); | 375 ExpectSortInverted(); |
316 } | 376 } |
317 | 377 |
318 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrl) { | 378 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrl) { |
319 CreateMocks(2); | 379 CreateMocks(2); |
320 GURL match_url("http://query.com/query"); | 380 GURL match_url("http://query.com/query"); |
321 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | 381 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); |
322 GURL fail_url("http://example.com/fail"); | 382 GURL fail_url("http://example.com/fail"); |
323 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 383 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
324 AddFilter(DownloadQuery::FILTER_URL, match_url.spec().c_str()); | 384 AddFilter(DownloadQuery::FILTER_URL, match_url.spec().c_str()); |
325 ExpectStandardFilterResults(); | 385 ExpectStandardFilterResults(); |
326 } | 386 } |
327 | 387 |
328 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterCallback) { | 388 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterCallback) { |
329 CreateMocks(2); | 389 CreateMocks(2); |
330 CHECK(query()->AddFilter(base::Bind(&IdNotEqual, 1))); | 390 CHECK(query()->AddFilter(base::Bind(&IdNotEqual, 1))); |
331 ExpectStandardFilterResults(); | 391 ExpectStandardFilterResults(); |
332 } | 392 } |
333 | 393 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 base::Time start = base::Time::Now(); | 740 base::Time start = base::Time::Now(); |
681 Search(); | 741 Search(); |
682 base::Time end = base::Time::Now(); | 742 base::Time end = base::Time::Now(); |
683 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; | 743 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; |
684 double nanos_per_item = nanos / static_cast<double>(kNumItems); | 744 double nanos_per_item = nanos / static_cast<double>(kNumItems); |
685 double nanos_per_item_per_filter = nanos_per_item | 745 double nanos_per_item_per_filter = nanos_per_item |
686 / static_cast<double>(kNumFilters); | 746 / static_cast<double>(kNumFilters); |
687 std::cout << "Search took " << nanos_per_item_per_filter | 747 std::cout << "Search took " << nanos_per_item_per_filter |
688 << " nanoseconds per item per filter.\n"; | 748 << " nanoseconds per item per filter.\n"; |
689 } | 749 } |
OLD | NEW |