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 20 matching lines...) Expand all Loading... |
31 using base::Value; | 31 using base::Value; |
32 using content::DownloadItem; | 32 using content::DownloadItem; |
33 typedef DownloadQuery::DownloadVector DownloadVector; | 33 typedef DownloadQuery::DownloadVector DownloadVector; |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 static const int kSomeKnownTime = 1355864160; | 37 static const int kSomeKnownTime = 1355864160; |
38 static const char kSomeKnownTime8601[] = "2012-12-18T20:56:0"; | 38 static const char kSomeKnownTime8601[] = "2012-12-18T20:56:0"; |
39 static const char k8601Suffix[] = ".000Z"; | 39 static const char k8601Suffix[] = ".000Z"; |
40 | 40 |
| 41 static const int64_t kEightGB = 1LL << 33; |
| 42 static const int64_t kSixteenGB = 1LL << 34; |
| 43 static const double kEightGBDouble = 8.0 * (1LL << 30); |
| 44 static const double kNineGBDouble = 9.0 * (1LL << 30); |
| 45 |
41 bool IdNotEqual(uint32_t not_id, const DownloadItem& item) { | 46 bool IdNotEqual(uint32_t not_id, const DownloadItem& item) { |
42 return item.GetId() != not_id; | 47 return item.GetId() != not_id; |
43 } | 48 } |
44 | 49 |
45 bool AlwaysReturn(bool result, const DownloadItem& item) { | 50 bool AlwaysReturn(bool result, const DownloadItem& item) { |
46 return result; | 51 return result; |
47 } | 52 } |
48 | 53 |
49 } // anonymous namespace | 54 } // anonymous namespace |
50 | 55 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 107 |
103 DISALLOW_COPY_AND_ASSIGN(DownloadQueryTest); | 108 DISALLOW_COPY_AND_ASSIGN(DownloadQueryTest); |
104 }; | 109 }; |
105 | 110 |
106 template<> void DownloadQueryTest::AddFilter( | 111 template<> void DownloadQueryTest::AddFilter( |
107 DownloadQuery::FilterType name, bool cpp_value) { | 112 DownloadQuery::FilterType name, bool cpp_value) { |
108 std::unique_ptr<base::Value> value(new base::FundamentalValue(cpp_value)); | 113 std::unique_ptr<base::Value> value(new base::FundamentalValue(cpp_value)); |
109 CHECK(query_.AddFilter(name, *value.get())); | 114 CHECK(query_.AddFilter(name, *value.get())); |
110 } | 115 } |
111 | 116 |
112 template<> void DownloadQueryTest::AddFilter( | 117 template <> |
113 DownloadQuery::FilterType name, int cpp_value) { | 118 void DownloadQueryTest::AddFilter(DownloadQuery::FilterType name, |
| 119 double cpp_value) { |
114 std::unique_ptr<base::Value> value(new base::FundamentalValue(cpp_value)); | 120 std::unique_ptr<base::Value> value(new base::FundamentalValue(cpp_value)); |
115 CHECK(query_.AddFilter(name, *value.get())); | 121 CHECK(query_.AddFilter(name, *value.get())); |
116 } | 122 } |
117 | 123 |
118 template<> void DownloadQueryTest::AddFilter( | 124 template<> void DownloadQueryTest::AddFilter( |
119 DownloadQuery::FilterType name, const char* cpp_value) { | 125 DownloadQuery::FilterType name, const char* cpp_value) { |
120 CHECK(query_.AddFilter(name, base::StringValue(cpp_value))); | 126 CHECK(query_.AddFilter(name, base::StringValue(cpp_value))); |
121 } | 127 } |
122 | 128 |
123 template<> void DownloadQueryTest::AddFilter( | 129 template<> void DownloadQueryTest::AddFilter( |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterCallback) { | 328 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterCallback) { |
323 CreateMocks(2); | 329 CreateMocks(2); |
324 CHECK(query()->AddFilter(base::Bind(&IdNotEqual, 1))); | 330 CHECK(query()->AddFilter(base::Bind(&IdNotEqual, 1))); |
325 ExpectStandardFilterResults(); | 331 ExpectStandardFilterResults(); |
326 } | 332 } |
327 | 333 |
328 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterBytesReceived) { | 334 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterBytesReceived) { |
329 CreateMocks(2); | 335 CreateMocks(2); |
330 EXPECT_CALL(mock(0), GetReceivedBytes()).WillRepeatedly(Return(0)); | 336 EXPECT_CALL(mock(0), GetReceivedBytes()).WillRepeatedly(Return(0)); |
331 EXPECT_CALL(mock(1), GetReceivedBytes()).WillRepeatedly(Return(1)); | 337 EXPECT_CALL(mock(1), GetReceivedBytes()).WillRepeatedly(Return(1)); |
332 AddFilter(DownloadQuery::FILTER_BYTES_RECEIVED, 0); | 338 AddFilter(DownloadQuery::FILTER_BYTES_RECEIVED, 0.0); |
333 ExpectStandardFilterResults(); | 339 ExpectStandardFilterResults(); |
334 } | 340 } |
335 | 341 |
336 TEST_F(DownloadQueryTest, DownloadQueryTest_SortBytesReceived) { | 342 TEST_F(DownloadQueryTest, DownloadQueryTest_SortBytesReceived) { |
337 CreateMocks(2); | 343 CreateMocks(2); |
338 EXPECT_CALL(mock(0), GetReceivedBytes()).WillRepeatedly(Return(0)); | 344 EXPECT_CALL(mock(0), GetReceivedBytes()).WillRepeatedly(Return(0)); |
339 EXPECT_CALL(mock(1), GetReceivedBytes()).WillRepeatedly(Return(1)); | 345 EXPECT_CALL(mock(1), GetReceivedBytes()).WillRepeatedly(Return(1)); |
340 query()->AddSorter(DownloadQuery::SORT_BYTES_RECEIVED, | 346 query()->AddSorter(DownloadQuery::SORT_BYTES_RECEIVED, |
341 DownloadQuery::DESCENDING); | 347 DownloadQuery::DESCENDING); |
342 ExpectSortInverted(); | 348 ExpectSortInverted(); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 TEST_F(DownloadQueryTest, DownloadQueryTest_SortEndTime) { | 501 TEST_F(DownloadQueryTest, DownloadQueryTest_SortEndTime) { |
496 CreateMocks(2); | 502 CreateMocks(2); |
497 EXPECT_CALL(mock(0), GetEndTime()).WillRepeatedly(Return( | 503 EXPECT_CALL(mock(0), GetEndTime()).WillRepeatedly(Return( |
498 base::Time::FromTimeT(kSomeKnownTime + 2))); | 504 base::Time::FromTimeT(kSomeKnownTime + 2))); |
499 EXPECT_CALL(mock(1), GetEndTime()).WillRepeatedly(Return( | 505 EXPECT_CALL(mock(1), GetEndTime()).WillRepeatedly(Return( |
500 base::Time::FromTimeT(kSomeKnownTime + 4))); | 506 base::Time::FromTimeT(kSomeKnownTime + 4))); |
501 query()->AddSorter(DownloadQuery::SORT_END_TIME, DownloadQuery::DESCENDING); | 507 query()->AddSorter(DownloadQuery::SORT_END_TIME, DownloadQuery::DESCENDING); |
502 ExpectSortInverted(); | 508 ExpectSortInverted(); |
503 } | 509 } |
504 | 510 |
505 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesGreater) { | 511 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesGreater1) { |
506 CreateMocks(2); | 512 CreateMocks(2); |
507 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(2)); | 513 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(2)); |
508 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(1)); | 514 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(1)); |
509 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_GREATER, 1); | 515 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_GREATER, 1.0); |
510 ExpectStandardFilterResults(); | 516 ExpectStandardFilterResults(); |
511 } | 517 } |
512 | 518 |
513 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesLess) { | 519 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesGreater2) { |
| 520 CreateMocks(2); |
| 521 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(2)); |
| 522 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(1)); |
| 523 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_GREATER, 1.2); |
| 524 ExpectStandardFilterResults(); |
| 525 } |
| 526 |
| 527 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesGreater3) { |
| 528 CreateMocks(2); |
| 529 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(kSixteenGB)); |
| 530 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(kEightGB)); |
| 531 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_GREATER, kNineGBDouble); |
| 532 ExpectStandardFilterResults(); |
| 533 } |
| 534 |
| 535 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesGreater4) { |
| 536 CreateMocks(2); |
| 537 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(kSixteenGB)); |
| 538 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(kEightGB)); |
| 539 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_GREATER, kEightGBDouble + 1.0); |
| 540 ExpectStandardFilterResults(); |
| 541 } |
| 542 |
| 543 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesLess1) { |
514 CreateMocks(2); | 544 CreateMocks(2); |
515 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(2)); | 545 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(2)); |
516 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(4)); | 546 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(4)); |
517 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_LESS, 4); | 547 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_LESS, 4.0); |
518 ExpectStandardFilterResults(); | 548 ExpectStandardFilterResults(); |
519 } | 549 } |
520 | 550 |
521 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytes) { | 551 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesLess2) { |
| 552 CreateMocks(2); |
| 553 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(1)); |
| 554 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(2)); |
| 555 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_LESS, 1.2); |
| 556 ExpectStandardFilterResults(); |
| 557 } |
| 558 |
| 559 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesLess3) { |
| 560 CreateMocks(2); |
| 561 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(kEightGB)); |
| 562 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(kSixteenGB)); |
| 563 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_LESS, kEightGBDouble + 1.0); |
| 564 ExpectStandardFilterResults(); |
| 565 } |
| 566 |
| 567 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytesLess4) { |
| 568 CreateMocks(2); |
| 569 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(kEightGB)); |
| 570 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(kSixteenGB)); |
| 571 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES_LESS, kNineGBDouble); |
| 572 ExpectStandardFilterResults(); |
| 573 } |
| 574 |
| 575 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytes1) { |
522 CreateMocks(2); | 576 CreateMocks(2); |
523 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(2)); | 577 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(2)); |
524 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(4)); | 578 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(4)); |
525 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES, 2); | 579 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES, 2.0); |
526 ExpectStandardFilterResults(); | 580 ExpectStandardFilterResults(); |
527 } | 581 } |
528 | 582 |
| 583 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytes2) { |
| 584 CreateMocks(2); |
| 585 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(1)); |
| 586 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(2)); |
| 587 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES, 1.0); |
| 588 ExpectStandardFilterResults(); |
| 589 } |
| 590 |
| 591 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterTotalBytes3) { |
| 592 CreateMocks(2); |
| 593 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(kEightGB)); |
| 594 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(kSixteenGB)); |
| 595 AddFilter(DownloadQuery::FILTER_TOTAL_BYTES, kEightGBDouble); |
| 596 ExpectStandardFilterResults(); |
| 597 } |
| 598 |
529 TEST_F(DownloadQueryTest, DownloadQueryTest_SortTotalBytes) { | 599 TEST_F(DownloadQueryTest, DownloadQueryTest_SortTotalBytes) { |
530 CreateMocks(2); | 600 CreateMocks(2); |
531 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(2)); | 601 EXPECT_CALL(mock(0), GetTotalBytes()).WillRepeatedly(Return(2)); |
532 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(4)); | 602 EXPECT_CALL(mock(1), GetTotalBytes()).WillRepeatedly(Return(4)); |
533 query()->AddSorter(DownloadQuery::SORT_TOTAL_BYTES, | 603 query()->AddSorter(DownloadQuery::SORT_TOTAL_BYTES, |
534 DownloadQuery::DESCENDING); | 604 DownloadQuery::DESCENDING); |
535 ExpectSortInverted(); | 605 ExpectSortInverted(); |
536 } | 606 } |
537 | 607 |
538 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterState) { | 608 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterState) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 base::Time start = base::Time::Now(); | 680 base::Time start = base::Time::Now(); |
611 Search(); | 681 Search(); |
612 base::Time end = base::Time::Now(); | 682 base::Time end = base::Time::Now(); |
613 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; | 683 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; |
614 double nanos_per_item = nanos / static_cast<double>(kNumItems); | 684 double nanos_per_item = nanos / static_cast<double>(kNumItems); |
615 double nanos_per_item_per_filter = nanos_per_item | 685 double nanos_per_item_per_filter = nanos_per_item |
616 / static_cast<double>(kNumFilters); | 686 / static_cast<double>(kNumFilters); |
617 std::cout << "Search took " << nanos_per_item_per_filter | 687 std::cout << "Search took " << nanos_per_item_per_filter |
618 << " nanoseconds per item per filter.\n"; | 688 << " nanoseconds per item per filter.\n"; |
619 } | 689 } |
OLD | NEW |