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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 private: | 93 private: |
94 std::vector<content::MockDownloadItem*> mocks_; | 94 std::vector<content::MockDownloadItem*> mocks_; |
95 DownloadQuery query_; | 95 DownloadQuery query_; |
96 DownloadVector results_; | 96 DownloadVector results_; |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(DownloadQueryTest); | 98 DISALLOW_COPY_AND_ASSIGN(DownloadQueryTest); |
99 }; | 99 }; |
100 | 100 |
101 template<> void DownloadQueryTest::AddFilter( | 101 template<> void DownloadQueryTest::AddFilter( |
102 DownloadQuery::FilterType name, bool cpp_value) { | 102 DownloadQuery::FilterType name, bool cpp_value) { |
103 scoped_ptr<base::Value> value(Value::CreateBooleanValue(cpp_value)); | 103 scoped_ptr<base::Value> value(base::Value::CreateBooleanValue(cpp_value)); |
104 CHECK(query_.AddFilter(name, *value.get())); | 104 CHECK(query_.AddFilter(name, *value.get())); |
105 } | 105 } |
106 | 106 |
107 template<> void DownloadQueryTest::AddFilter( | 107 template<> void DownloadQueryTest::AddFilter( |
108 DownloadQuery::FilterType name, int cpp_value) { | 108 DownloadQuery::FilterType name, int cpp_value) { |
109 scoped_ptr<base::Value> value(Value::CreateIntegerValue(cpp_value)); | 109 scoped_ptr<base::Value> value(base::Value::CreateIntegerValue(cpp_value)); |
110 CHECK(query_.AddFilter(name, *value.get())); | 110 CHECK(query_.AddFilter(name, *value.get())); |
111 } | 111 } |
112 | 112 |
113 template<> void DownloadQueryTest::AddFilter( | 113 template<> void DownloadQueryTest::AddFilter( |
114 DownloadQuery::FilterType name, const char* cpp_value) { | 114 DownloadQuery::FilterType name, const char* cpp_value) { |
115 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value)); | 115 scoped_ptr<base::Value> value(base::Value::CreateStringValue(cpp_value)); |
116 CHECK(query_.AddFilter(name, *value.get())); | 116 CHECK(query_.AddFilter(name, *value.get())); |
117 } | 117 } |
118 | 118 |
119 template<> void DownloadQueryTest::AddFilter( | 119 template<> void DownloadQueryTest::AddFilter( |
120 DownloadQuery::FilterType name, std::string cpp_value) { | 120 DownloadQuery::FilterType name, std::string cpp_value) { |
121 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value)); | 121 scoped_ptr<base::Value> value(base::Value::CreateStringValue(cpp_value)); |
122 CHECK(query_.AddFilter(name, *value.get())); | 122 CHECK(query_.AddFilter(name, *value.get())); |
123 } | 123 } |
124 | 124 |
125 template<> void DownloadQueryTest::AddFilter( | 125 template<> void DownloadQueryTest::AddFilter( |
126 DownloadQuery::FilterType name, const char16* cpp_value) { | 126 DownloadQuery::FilterType name, const char16* cpp_value) { |
127 scoped_ptr<base::Value> value( | 127 scoped_ptr<base::Value> value( |
128 Value::CreateStringValue(base::string16(cpp_value))); | 128 base::Value::CreateStringValue(base::string16(cpp_value))); |
129 CHECK(query_.AddFilter(name, *value.get())); | 129 CHECK(query_.AddFilter(name, *value.get())); |
130 } | 130 } |
131 | 131 |
132 template<> void DownloadQueryTest::AddFilter( | 132 template<> void DownloadQueryTest::AddFilter( |
133 DownloadQuery::FilterType name, std::vector<base::string16> cpp_value) { | 133 DownloadQuery::FilterType name, std::vector<base::string16> cpp_value) { |
134 scoped_ptr<base::ListValue> list(new base::ListValue()); | 134 scoped_ptr<base::ListValue> list(new base::ListValue()); |
135 for (std::vector<base::string16>::const_iterator it = cpp_value.begin(); | 135 for (std::vector<base::string16>::const_iterator it = cpp_value.begin(); |
136 it != cpp_value.end(); ++it) { | 136 it != cpp_value.end(); ++it) { |
137 list->Append(Value::CreateStringValue(*it)); | 137 list->Append(base::Value::CreateStringValue(*it)); |
138 } | 138 } |
139 CHECK(query_.AddFilter(name, *list.get())); | 139 CHECK(query_.AddFilter(name, *list.get())); |
140 } | 140 } |
141 | 141 |
142 template<> void DownloadQueryTest::AddFilter( | 142 template<> void DownloadQueryTest::AddFilter( |
143 DownloadQuery::FilterType name, std::vector<std::string> cpp_value) { | 143 DownloadQuery::FilterType name, std::vector<std::string> cpp_value) { |
144 scoped_ptr<base::ListValue> list(new base::ListValue()); | 144 scoped_ptr<base::ListValue> list(new base::ListValue()); |
145 for (std::vector<std::string>::const_iterator it = cpp_value.begin(); | 145 for (std::vector<std::string>::const_iterator it = cpp_value.begin(); |
146 it != cpp_value.end(); ++it) { | 146 it != cpp_value.end(); ++it) { |
147 list->Append(Value::CreateStringValue(*it)); | 147 list->Append(base::Value::CreateStringValue(*it)); |
148 } | 148 } |
149 CHECK(query_.AddFilter(name, *list.get())); | 149 CHECK(query_.AddFilter(name, *list.get())); |
150 } | 150 } |
151 | 151 |
152 #if defined(OS_WIN) | 152 #if defined(OS_WIN) |
153 template<> void DownloadQueryTest::AddFilter( | 153 template<> void DownloadQueryTest::AddFilter( |
154 DownloadQuery::FilterType name, std::wstring cpp_value) { | 154 DownloadQuery::FilterType name, std::wstring cpp_value) { |
155 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value)); | 155 scoped_ptr<base::Value> value(base::Value::CreateStringValue(cpp_value)); |
156 CHECK(query_.AddFilter(name, *value.get())); | 156 CHECK(query_.AddFilter(name, *value.get())); |
157 } | 157 } |
158 #endif | 158 #endif |
159 | 159 |
160 TEST_F(DownloadQueryTest, DownloadQueryTest_ZeroItems) { | 160 TEST_F(DownloadQueryTest, DownloadQueryTest_ZeroItems) { |
161 Search(); | 161 Search(); |
162 EXPECT_EQ(0U, results()->size()); | 162 EXPECT_EQ(0U, results()->size()); |
163 } | 163 } |
164 | 164 |
165 TEST_F(DownloadQueryTest, DownloadQueryTest_InvalidFilter) { | 165 TEST_F(DownloadQueryTest, DownloadQueryTest_InvalidFilter) { |
166 scoped_ptr<base::Value> value(Value::CreateIntegerValue(0)); | 166 scoped_ptr<base::Value> value(base::Value::CreateIntegerValue(0)); |
167 EXPECT_FALSE(query()->AddFilter( | 167 EXPECT_FALSE(query()->AddFilter( |
168 static_cast<DownloadQuery::FilterType>(kint32max), | 168 static_cast<DownloadQuery::FilterType>(kint32max), |
169 *value.get())); | 169 *value.get())); |
170 } | 170 } |
171 | 171 |
172 TEST_F(DownloadQueryTest, DownloadQueryTest_EmptyQuery) { | 172 TEST_F(DownloadQueryTest, DownloadQueryTest_EmptyQuery) { |
173 CreateMocks(2); | 173 CreateMocks(2); |
174 Search(); | 174 Search(); |
175 ASSERT_EQ(2U, results()->size()); | 175 ASSERT_EQ(2U, results()->size()); |
176 ASSERT_EQ(0U, results()->at(0)->GetId()); | 176 ASSERT_EQ(0U, results()->at(0)->GetId()); |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 base::Time start = base::Time::Now(); | 610 base::Time start = base::Time::Now(); |
611 Search(); | 611 Search(); |
612 base::Time end = base::Time::Now(); | 612 base::Time end = base::Time::Now(); |
613 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; | 613 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; |
614 double nanos_per_item = nanos / static_cast<double>(kNumItems); | 614 double nanos_per_item = nanos / static_cast<double>(kNumItems); |
615 double nanos_per_item_per_filter = nanos_per_item | 615 double nanos_per_item_per_filter = nanos_per_item |
616 / static_cast<double>(kNumFilters); | 616 / static_cast<double>(kNumFilters); |
617 std::cout << "Search took " << nanos_per_item_per_filter | 617 std::cout << "Search took " << nanos_per_item_per_filter |
618 << " nanoseconds per item per filter.\n"; | 618 << " nanoseconds per item per filter.\n"; |
619 } | 619 } |
OLD | NEW |