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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 static_cast<content::BrowserContext*>(NULL))); | 191 static_cast<content::BrowserContext*>(NULL))); |
192 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 192 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
193 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 193 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
194 match_filename)); | 194 match_filename)); |
195 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 195 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
196 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 196 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
197 fail_filename)); | 197 fail_filename)); |
198 GURL fail_url("http://example.com/fail"); | 198 GURL fail_url("http://example.com/fail"); |
199 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 199 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
200 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 200 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 201 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
| 202 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
201 std::vector<std::string> query_terms; | 203 std::vector<std::string> query_terms; |
202 query_terms.push_back("query"); | 204 query_terms.push_back("query"); |
203 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); | 205 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
204 ExpectStandardFilterResults(); | 206 ExpectStandardFilterResults(); |
205 } | 207 } |
206 | 208 |
207 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) { | 209 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryOriginalUrl) { |
208 CreateMocks(2); | 210 CreateMocks(2); |
209 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( | 211 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
210 static_cast<content::BrowserContext*>(NULL))); | 212 static_cast<content::BrowserContext*>(NULL))); |
211 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( | 213 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
212 static_cast<content::BrowserContext*>(NULL))); | 214 static_cast<content::BrowserContext*>(NULL))); |
213 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 215 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
214 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 216 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
215 fail_filename)); | 217 fail_filename)); |
216 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 218 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
217 fail_filename)); | 219 fail_filename)); |
218 GURL match_url("http://query.com/query"); | 220 GURL match_url("http://query.com/query"); |
219 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | 221 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); |
220 GURL fail_url("http://example.com/fail"); | 222 GURL fail_url("http://example.com/fail"); |
221 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 223 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 224 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
| 225 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
222 std::vector<std::string> query_terms; | 226 std::vector<std::string> query_terms; |
223 query_terms.push_back("query"); | 227 query_terms.push_back("query"); |
224 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); | 228 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
| 229 ExpectStandardFilterResults(); |
| 230 } |
| 231 |
| 232 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) { |
| 233 CreateMocks(2); |
| 234 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
| 235 static_cast<content::BrowserContext*>(NULL))); |
| 236 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
| 237 static_cast<content::BrowserContext*>(NULL))); |
| 238 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
| 239 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
| 240 fail_filename)); |
| 241 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
| 242 fail_filename)); |
| 243 GURL match_url("http://query.com/query"); |
| 244 GURL fail_url("http://example.com/fail"); |
| 245 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 246 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 247 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); |
| 248 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
| 249 std::vector<std::string> query_terms; |
| 250 query_terms.push_back("query"); |
| 251 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
225 ExpectStandardFilterResults(); | 252 ExpectStandardFilterResults(); |
226 } | 253 } |
227 | 254 |
228 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) { | 255 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) { |
229 CreateMocks(2); | 256 CreateMocks(2); |
230 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( | 257 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
231 static_cast<content::BrowserContext*>(NULL))); | 258 static_cast<content::BrowserContext*>(NULL))); |
232 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( | 259 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
233 static_cast<content::BrowserContext*>(NULL))); | 260 static_cast<content::BrowserContext*>(NULL))); |
234 const base::FilePath::StringType kTestString( | 261 const base::FilePath::StringType kTestString( |
235 #if defined(OS_POSIX) | 262 #if defined(OS_POSIX) |
236 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd" | 263 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd" |
237 #elif defined(OS_WIN) | 264 #elif defined(OS_WIN) |
238 L"/\x4f60\x597d\x4f60\x597d" | 265 L"/\x4f60\x597d\x4f60\x597d" |
239 #endif | 266 #endif |
240 ); | 267 ); |
241 base::FilePath match_filename(kTestString); | 268 base::FilePath match_filename(kTestString); |
242 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 269 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
243 match_filename)); | 270 match_filename)); |
244 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 271 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
245 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 272 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
246 fail_filename)); | 273 fail_filename)); |
247 GURL fail_url("http://example.com/fail"); | 274 GURL fail_url("http://example.com/fail"); |
248 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 275 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
249 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 276 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 277 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
| 278 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
250 std::vector<base::FilePath::StringType> query_terms; | 279 std::vector<base::FilePath::StringType> query_terms; |
251 query_terms.push_back(kTestString); | 280 query_terms.push_back(kTestString); |
252 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); | 281 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
253 ExpectStandardFilterResults(); | 282 ExpectStandardFilterResults(); |
254 } | 283 } |
255 | 284 |
256 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) { | 285 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) { |
257 CreateMocks(2); | 286 CreateMocks(2); |
258 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 287 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
259 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 288 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
(...skipping 22 matching lines...) Expand all Loading... |
282 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 311 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
283 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 312 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
284 match_filename)); | 313 match_filename)); |
285 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 314 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
286 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 315 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
287 fail_filename)); | 316 fail_filename)); |
288 AddFilter(DownloadQuery::FILTER_FILENAME, match_filename.value().c_str()); | 317 AddFilter(DownloadQuery::FILTER_FILENAME, match_filename.value().c_str()); |
289 ExpectStandardFilterResults(); | 318 ExpectStandardFilterResults(); |
290 } | 319 } |
291 | 320 |
| 321 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterOriginalUrlRegex) { |
| 322 CreateMocks(2); |
| 323 GURL match_url("http://query.com/query"); |
| 324 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); |
| 325 GURL fail_url("http://example.com/fail"); |
| 326 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 327 AddFilter(DownloadQuery::FILTER_ORIGINAL_URL_REGEX, "query"); |
| 328 ExpectStandardFilterResults(); |
| 329 } |
| 330 |
| 331 TEST_F(DownloadQueryTest, DownloadQueryTest_SortOriginalUrl) { |
| 332 CreateMocks(2); |
| 333 GURL b_url("http://example.com/b"); |
| 334 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(b_url)); |
| 335 GURL a_url("http://example.com/a"); |
| 336 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(a_url)); |
| 337 query()->AddSorter( |
| 338 DownloadQuery::SORT_ORIGINAL_URL, DownloadQuery::ASCENDING); |
| 339 ExpectSortInverted(); |
| 340 } |
| 341 |
| 342 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterOriginalUrl) { |
| 343 CreateMocks(2); |
| 344 GURL match_url("http://query.com/query"); |
| 345 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); |
| 346 GURL fail_url("http://example.com/fail"); |
| 347 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
| 348 AddFilter(DownloadQuery::FILTER_ORIGINAL_URL, match_url.spec().c_str()); |
| 349 ExpectStandardFilterResults(); |
| 350 } |
| 351 |
292 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrlRegex) { | 352 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrlRegex) { |
293 CreateMocks(2); | 353 CreateMocks(2); |
294 GURL match_url("http://query.com/query"); | 354 GURL match_url("http://query.com/query"); |
295 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | 355 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); |
296 GURL fail_url("http://example.com/fail"); | 356 GURL fail_url("http://example.com/fail"); |
297 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 357 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
298 AddFilter(DownloadQuery::FILTER_URL_REGEX, "query"); | 358 AddFilter(DownloadQuery::FILTER_URL_REGEX, "query"); |
299 ExpectStandardFilterResults(); | 359 ExpectStandardFilterResults(); |
300 } | 360 } |
301 | 361 |
302 TEST_F(DownloadQueryTest, DownloadQueryTest_SortUrl) { | 362 TEST_F(DownloadQueryTest, DownloadQueryTest_SortUrl) { |
303 CreateMocks(2); | 363 CreateMocks(2); |
304 GURL b_url("http://example.com/b"); | 364 GURL b_url("http://example.com/b"); |
305 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(b_url)); | 365 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(b_url)); |
306 GURL a_url("http://example.com/a"); | 366 GURL a_url("http://example.com/a"); |
307 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(a_url)); | 367 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(a_url)); |
308 query()->AddSorter(DownloadQuery::SORT_URL, DownloadQuery::ASCENDING); | 368 query()->AddSorter(DownloadQuery::SORT_URL, DownloadQuery::ASCENDING); |
309 ExpectSortInverted(); | 369 ExpectSortInverted(); |
310 } | 370 } |
311 | 371 |
312 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrl) { | 372 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterUrl) { |
313 CreateMocks(2); | 373 CreateMocks(2); |
314 GURL match_url("http://query.com/query"); | 374 GURL match_url("http://query.com/query"); |
315 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | 375 EXPECT_CALL(mock(0), GetURL()).WillRepeatedly(ReturnRef(match_url)); |
316 GURL fail_url("http://example.com/fail"); | 376 GURL fail_url("http://example.com/fail"); |
317 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 377 EXPECT_CALL(mock(1), GetURL()).WillRepeatedly(ReturnRef(fail_url)); |
318 AddFilter(DownloadQuery::FILTER_URL, match_url.spec().c_str()); | 378 AddFilter(DownloadQuery::FILTER_URL, match_url.spec().c_str()); |
319 ExpectStandardFilterResults(); | 379 ExpectStandardFilterResults(); |
320 } | 380 } |
321 | 381 |
322 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterCallback) { | 382 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterCallback) { |
323 CreateMocks(2); | 383 CreateMocks(2); |
324 CHECK(query()->AddFilter(base::Bind(&IdNotEqual, 1))); | 384 CHECK(query()->AddFilter(base::Bind(&IdNotEqual, 1))); |
325 ExpectStandardFilterResults(); | 385 ExpectStandardFilterResults(); |
326 } | 386 } |
327 | 387 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 base::Time start = base::Time::Now(); | 670 base::Time start = base::Time::Now(); |
611 Search(); | 671 Search(); |
612 base::Time end = base::Time::Now(); | 672 base::Time end = base::Time::Now(); |
613 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; | 673 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; |
614 double nanos_per_item = nanos / static_cast<double>(kNumItems); | 674 double nanos_per_item = nanos / static_cast<double>(kNumItems); |
615 double nanos_per_item_per_filter = nanos_per_item | 675 double nanos_per_item_per_filter = nanos_per_item |
616 / static_cast<double>(kNumFilters); | 676 / static_cast<double>(kNumFilters); |
617 std::cout << "Search took " << nanos_per_item_per_filter | 677 std::cout << "Search took " << nanos_per_item_per_filter |
618 << " nanoseconds per item per filter.\n"; | 678 << " nanoseconds per item per filter.\n"; |
619 } | 679 } |
OLD | NEW |