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, |
| 239 DownloadQueryTest_FilterGenericQueryOriginalUrlUnescaping) { |
| 240 CreateMocks(2); |
| 241 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
| 242 static_cast<content::BrowserContext*>(NULL))); |
| 243 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
| 244 static_cast<content::BrowserContext*>(NULL))); |
| 245 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
| 246 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
| 247 fail_filename)); |
| 248 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
| 249 fail_filename)); |
| 250 GURL match_url("http://q%75%65%72y.c%6Fm/%71uer%79"); |
| 251 GURL fail_url("http://%65xampl%65.com/%66ai%6C"); |
| 252 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); |
| 253 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 254 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
| 255 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
| 256 std::vector<std::string> query_terms; |
| 257 query_terms.push_back("query"); |
| 258 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
| 259 ExpectStandardFilterResults(); |
| 260 } |
| 261 |
| 262 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) { |
| 263 CreateMocks(2); |
| 264 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
| 265 static_cast<content::BrowserContext*>(NULL))); |
| 266 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
| 267 static_cast<content::BrowserContext*>(NULL))); |
| 268 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
| 269 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
| 270 fail_filename)); |
| 271 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
| 272 fail_filename)); |
| 273 GURL match_url("http://query.com/query"); |
| 274 GURL fail_url("http://example.com/fail"); |
| 275 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 276 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 277 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); |
| 278 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
| 279 std::vector<std::string> query_terms; |
| 280 query_terms.push_back("query"); |
| 281 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
| 282 ExpectStandardFilterResults(); |
| 283 } |
| 284 |
| 285 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrlUnescaping) { |
| 286 CreateMocks(2); |
| 287 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
| 288 static_cast<content::BrowserContext*>(NULL))); |
| 289 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
| 290 static_cast<content::BrowserContext*>(NULL))); |
| 291 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
| 292 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
| 293 fail_filename)); |
| 294 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
| 295 fail_filename)); |
| 296 GURL match_url("http://%71uer%79.com/qu%65ry"); |
| 297 GURL fail_url("http://e%78am%70le.com/f%61il"); |
| 298 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 299 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 300 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); |
| 301 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
| 302 std::vector<std::string> query_terms; |
| 303 query_terms.push_back("query"); |
| 304 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
231 ExpectStandardFilterResults(); | 305 ExpectStandardFilterResults(); |
232 } | 306 } |
233 | 307 |
234 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) { | 308 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) { |
235 CreateMocks(2); | 309 CreateMocks(2); |
236 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( | 310 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
237 static_cast<content::BrowserContext*>(NULL))); | 311 static_cast<content::BrowserContext*>(NULL))); |
238 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( | 312 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
239 static_cast<content::BrowserContext*>(NULL))); | 313 static_cast<content::BrowserContext*>(NULL))); |
240 const base::FilePath::StringType kTestString( | 314 const base::FilePath::StringType kTestString( |
241 #if defined(OS_POSIX) | 315 #if defined(OS_POSIX) |
242 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd" | 316 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd" |
243 #elif defined(OS_WIN) | 317 #elif defined(OS_WIN) |
244 L"/\x4f60\x597d\x4f60\x597d" | 318 L"/\x4f60\x597d\x4f60\x597d" |
245 #endif | 319 #endif |
246 ); | 320 ); |
247 base::FilePath match_filename(kTestString); | 321 base::FilePath match_filename(kTestString); |
248 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 322 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
249 match_filename)); | 323 match_filename)); |
250 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 324 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
251 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 325 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
252 fail_filename)); | 326 fail_filename)); |
253 GURL fail_url("http://example.com/fail"); | 327 GURL fail_url("http://example.com/fail"); |
254 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 328 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
255 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 329 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 330 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
| 331 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
256 std::vector<base::FilePath::StringType> query_terms; | 332 std::vector<base::FilePath::StringType> query_terms; |
257 query_terms.push_back(kTestString); | 333 query_terms.push_back(kTestString); |
258 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); | 334 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
259 ExpectStandardFilterResults(); | 335 ExpectStandardFilterResults(); |
260 } | 336 } |
261 | 337 |
262 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) { | 338 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) { |
263 CreateMocks(2); | 339 CreateMocks(2); |
264 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 340 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
265 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 341 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
(...skipping 22 matching lines...) Expand all Loading... |
288 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 364 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
289 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 365 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
290 match_filename)); | 366 match_filename)); |
291 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 367 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
292 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 368 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
293 fail_filename)); | 369 fail_filename)); |
294 AddFilter(DownloadQuery::FILTER_FILENAME, match_filename.value().c_str()); | 370 AddFilter(DownloadQuery::FILTER_FILENAME, match_filename.value().c_str()); |
295 ExpectStandardFilterResults(); | 371 ExpectStandardFilterResults(); |
296 } | 372 } |
297 | 373 |
| 374 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterOriginalUrlRegex) { |
| 375 CreateMocks(2); |
| 376 GURL match_url("http://query.com/query"); |
| 377 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); |
| 378 GURL fail_url("http://example.com/fail"); |
| 379 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 380 AddFilter(DownloadQuery::FILTER_ORIGINAL_URL_REGEX, "query"); |
| 381 ExpectStandardFilterResults(); |
| 382 } |
| 383 |
| 384 TEST_F(DownloadQueryTest, DownloadQueryTest_SortOriginalUrl) { |
| 385 CreateMocks(2); |
| 386 GURL b_url("http://example.com/b"); |
| 387 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(b_url)); |
| 388 GURL a_url("http://example.com/a"); |
| 389 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(a_url)); |
| 390 query()->AddSorter( |
| 391 DownloadQuery::SORT_ORIGINAL_URL, DownloadQuery::ASCENDING); |
| 392 ExpectSortInverted(); |
| 393 } |
| 394 |
| 395 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterOriginalUrl) { |
| 396 CreateMocks(2); |
| 397 GURL match_url("http://query.com/query"); |
| 398 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); |
| 399 GURL fail_url("http://example.com/fail"); |
| 400 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 401 AddFilter(DownloadQuery::FILTER_ORIGINAL_URL, match_url.spec().c_str()); |
| 402 ExpectStandardFilterResults(); |
| 403 } |
| 404 |
298 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrlRegex) { | 405 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrlRegex) { |
299 CreateMocks(2); | 406 CreateMocks(2); |
300 GURL match_url("http://query.com/query"); | 407 GURL match_url("http://query.com/query"); |
301 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | 408 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); |
302 GURL fail_url("http://example.com/fail"); | 409 GURL fail_url("http://example.com/fail"); |
303 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 410 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
304 AddFilter(DownloadQuery::FILTER_URL_REGEX, "query"); | 411 AddFilter(DownloadQuery::FILTER_URL_REGEX, "query"); |
305 ExpectStandardFilterResults(); | 412 ExpectStandardFilterResults(); |
306 } | 413 } |
307 | 414 |
308 TEST_F(DownloadQueryTest, DownloadQueryTest_SortUrl) { | 415 TEST_F(DownloadQueryTest, DownloadQueryTest_SortUrl) { |
309 CreateMocks(2); | 416 CreateMocks(2); |
310 GURL b_url("http://example.com/b"); | 417 GURL b_url("http://example.com/b"); |
311 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(b_url)); | 418 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(b_url)); |
312 GURL a_url("http://example.com/a"); | 419 GURL a_url("http://example.com/a"); |
313 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(a_url)); | 420 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(a_url)); |
314 query()->AddSorter(DownloadQuery::SORT_URL, DownloadQuery::ASCENDING); | 421 query()->AddSorter(DownloadQuery::SORT_URL, DownloadQuery::ASCENDING); |
315 ExpectSortInverted(); | 422 ExpectSortInverted(); |
316 } | 423 } |
317 | 424 |
318 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrl) { | 425 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrl) { |
319 CreateMocks(2); | 426 CreateMocks(2); |
320 GURL match_url("http://query.com/query"); | 427 GURL match_url("http://query.com/query"); |
321 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | 428 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); |
322 GURL fail_url("http://example.com/fail"); | 429 GURL fail_url("http://example.com/fail"); |
323 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 430 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
324 AddFilter(DownloadQuery::FILTER_URL, match_url.spec().c_str()); | 431 AddFilter(DownloadQuery::FILTER_URL, match_url.spec().c_str()); |
325 ExpectStandardFilterResults(); | 432 ExpectStandardFilterResults(); |
326 } | 433 } |
327 | 434 |
328 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterCallback) { | 435 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterCallback) { |
329 CreateMocks(2); | 436 CreateMocks(2); |
330 CHECK(query()->AddFilter(base::Bind(&IdNotEqual, 1))); | 437 CHECK(query()->AddFilter(base::Bind(&IdNotEqual, 1))); |
331 ExpectStandardFilterResults(); | 438 ExpectStandardFilterResults(); |
332 } | 439 } |
333 | 440 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 base::Time start = base::Time::Now(); | 787 base::Time start = base::Time::Now(); |
681 Search(); | 788 Search(); |
682 base::Time end = base::Time::Now(); | 789 base::Time end = base::Time::Now(); |
683 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; | 790 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; |
684 double nanos_per_item = nanos / static_cast<double>(kNumItems); | 791 double nanos_per_item = nanos / static_cast<double>(kNumItems); |
685 double nanos_per_item_per_filter = nanos_per_item | 792 double nanos_per_item_per_filter = nanos_per_item |
686 / static_cast<double>(kNumFilters); | 793 / static_cast<double>(kNumFilters); |
687 std::cout << "Search took " << nanos_per_item_per_filter | 794 std::cout << "Search took " << nanos_per_item_per_filter |
688 << " nanoseconds per item per filter.\n"; | 795 << " nanoseconds per item per filter.\n"; |
689 } | 796 } |
OLD | NEW |