Chromium Code Reviews| 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> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "content/public/test/mock_download_item.h" | 23 #include "content/public/test/mock_download_item.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 using ::testing::Return; | 27 using ::testing::Return; |
| 28 using ::testing::ReturnRef; | 28 using ::testing::ReturnRef; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // anonymous namespace | 54 } // anonymous namespace |
| 55 | 55 |
| 56 class DownloadQueryTest : public testing::Test { | 56 class DownloadQueryTest : public testing::Test { |
| 57 public: | 57 public: |
| 58 DownloadQueryTest() {} | 58 DownloadQueryTest() {} |
| 59 | 59 |
| 60 ~DownloadQueryTest() override {} | 60 ~DownloadQueryTest() override {} |
| 61 | 61 |
| 62 void TearDown() override { base::STLDeleteElements(&mocks_); } | 62 void TearDown() override {} |
| 63 | 63 |
| 64 void CreateMocks(int count) { | 64 void CreateMocks(int count) { |
| 65 for (int i = 0; i < count; ++i) { | 65 for (int i = 0; i < count; ++i) { |
| 66 mocks_.push_back(new content::MockDownloadItem()); | 66 owned_mocks_.push_back(base::MakeUnique<content::MockDownloadItem>()); |
| 67 mocks_.push_back(owned_mocks_.back().get()); | |
| 67 EXPECT_CALL(mock(mocks_.size() - 1), GetId()).WillRepeatedly(Return( | 68 EXPECT_CALL(mock(mocks_.size() - 1), GetId()).WillRepeatedly(Return( |
| 68 mocks_.size() - 1)); | 69 mocks_.size() - 1)); |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 content::MockDownloadItem& mock(int index) { return *mocks_[index]; } | 73 content::MockDownloadItem& mock(int index) { return *mocks_[index]; } |
| 73 | 74 |
| 74 DownloadQuery* query() { return &query_; } | 75 DownloadQuery* query() { return &query_; } |
| 75 | 76 |
| 76 template<typename ValueType> void AddFilter( | 77 template<typename ValueType> void AddFilter( |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 94 // ascending. In order to test that a sorter distinguishes between two items, | 95 // ascending. In order to test that a sorter distinguishes between two items, |
| 95 // the sorter must sort them by ID descending. | 96 // the sorter must sort them by ID descending. |
| 96 void ExpectSortInverted() { | 97 void ExpectSortInverted() { |
| 97 Search(); | 98 Search(); |
| 98 ASSERT_EQ(2U, results()->size()); | 99 ASSERT_EQ(2U, results()->size()); |
| 99 ASSERT_EQ(1U, results()->at(0)->GetId()); | 100 ASSERT_EQ(1U, results()->at(0)->GetId()); |
| 100 ASSERT_EQ(0U, results()->at(1)->GetId()); | 101 ASSERT_EQ(0U, results()->at(1)->GetId()); |
| 101 } | 102 } |
| 102 | 103 |
| 103 private: | 104 private: |
| 104 std::vector<content::MockDownloadItem*> mocks_; | 105 std::vector<content::MockDownloadItem*> mocks_; |
|
sky
2016/10/28 13:33:59
It's unfortunate that two vectors with the same th
Avi (use Gerrit)
2016/10/28 14:04:10
Done.
| |
| 106 std::vector<std::unique_ptr<content::MockDownloadItem>> owned_mocks_; | |
| 105 DownloadQuery query_; | 107 DownloadQuery query_; |
| 106 DownloadVector results_; | 108 DownloadVector results_; |
| 107 | 109 |
| 108 DISALLOW_COPY_AND_ASSIGN(DownloadQueryTest); | 110 DISALLOW_COPY_AND_ASSIGN(DownloadQueryTest); |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 template<> void DownloadQueryTest::AddFilter( | 113 template<> void DownloadQueryTest::AddFilter( |
| 112 DownloadQuery::FilterType name, bool cpp_value) { | 114 DownloadQuery::FilterType name, bool cpp_value) { |
| 113 std::unique_ptr<base::Value> value(new base::FundamentalValue(cpp_value)); | 115 std::unique_ptr<base::Value> value(new base::FundamentalValue(cpp_value)); |
| 114 CHECK(query_.AddFilter(name, *value.get())); | 116 CHECK(query_.AddFilter(name, *value.get())); |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 787 base::Time start = base::Time::Now(); | 789 base::Time start = base::Time::Now(); |
| 788 Search(); | 790 Search(); |
| 789 base::Time end = base::Time::Now(); | 791 base::Time end = base::Time::Now(); |
| 790 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; | 792 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; |
| 791 double nanos_per_item = nanos / static_cast<double>(kNumItems); | 793 double nanos_per_item = nanos / static_cast<double>(kNumItems); |
| 792 double nanos_per_item_per_filter = nanos_per_item | 794 double nanos_per_item_per_filter = nanos_per_item |
| 793 / static_cast<double>(kNumFilters); | 795 / static_cast<double>(kNumFilters); |
| 794 std::cout << "Search took " << nanos_per_item_per_filter | 796 std::cout << "Search took " << nanos_per_item_per_filter |
| 795 << " nanoseconds per item per filter.\n"; | 797 << " nanoseconds per item per filter.\n"; |
| 796 } | 798 } |
| OLD | NEW |