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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value)); | 121 scoped_ptr<base::Value> value(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(Value::CreateStringValue(string16(cpp_value))); | 127 scoped_ptr<base::Value> value(Value::CreateStringValue(string16(cpp_value))); |
128 CHECK(query_.AddFilter(name, *value.get())); | 128 CHECK(query_.AddFilter(name, *value.get())); |
129 } | 129 } |
130 | 130 |
| 131 template<> void DownloadQueryTest::AddFilter( |
| 132 DownloadQuery::FilterType name, std::vector<string16> cpp_value) { |
| 133 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 134 for (std::vector<string16>::const_iterator it = cpp_value.begin(); |
| 135 it != cpp_value.end(); ++it) { |
| 136 list->Append(Value::CreateStringValue(*it)); |
| 137 } |
| 138 CHECK(query_.AddFilter(name, *list.get())); |
| 139 } |
| 140 |
| 141 template<> void DownloadQueryTest::AddFilter( |
| 142 DownloadQuery::FilterType name, std::vector<std::string> cpp_value) { |
| 143 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 144 for (std::vector<std::string>::const_iterator it = cpp_value.begin(); |
| 145 it != cpp_value.end(); ++it) { |
| 146 list->Append(Value::CreateStringValue(*it)); |
| 147 } |
| 148 CHECK(query_.AddFilter(name, *list.get())); |
| 149 } |
| 150 |
131 #if defined(OS_WIN) | 151 #if defined(OS_WIN) |
132 template<> void DownloadQueryTest::AddFilter( | 152 template<> void DownloadQueryTest::AddFilter( |
133 DownloadQuery::FilterType name, std::wstring cpp_value) { | 153 DownloadQuery::FilterType name, std::wstring cpp_value) { |
134 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value)); | 154 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value)); |
135 CHECK(query_.AddFilter(name, *value.get())); | 155 CHECK(query_.AddFilter(name, *value.get())); |
136 } | 156 } |
| 157 |
| 158 template<> void DownloadQueryTest::AddFilter( |
| 159 DownloadQuery::FilterType name, std::vector<std::wstring> cpp_value) { |
| 160 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 161 for (std::vector<std::wstring>::const_iterator it = cpp_value.begin(); |
| 162 it != cpp_value.end(); ++it) { |
| 163 list->Append(Value::CreateStringValue(*it)); |
| 164 } |
| 165 CHECK(query_.AddFilter(name, *list.get())); |
| 166 } |
137 #endif | 167 #endif |
138 | 168 |
139 TEST_F(DownloadQueryTest, DownloadQueryTest_ZeroItems) { | 169 TEST_F(DownloadQueryTest, DownloadQueryTest_ZeroItems) { |
140 Search(); | 170 Search(); |
141 EXPECT_EQ(0U, results()->size()); | 171 EXPECT_EQ(0U, results()->size()); |
142 } | 172 } |
143 | 173 |
144 TEST_F(DownloadQueryTest, DownloadQueryTest_InvalidFilter) { | 174 TEST_F(DownloadQueryTest, DownloadQueryTest_InvalidFilter) { |
145 scoped_ptr<base::Value> value(Value::CreateIntegerValue(0)); | 175 scoped_ptr<base::Value> value(Value::CreateIntegerValue(0)); |
146 EXPECT_FALSE(query()->AddFilter( | 176 EXPECT_FALSE(query()->AddFilter( |
(...skipping 23 matching lines...) Expand all Loading... |
170 static_cast<content::BrowserContext*>(NULL))); | 200 static_cast<content::BrowserContext*>(NULL))); |
171 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 201 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
172 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 202 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
173 match_filename)); | 203 match_filename)); |
174 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 204 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
175 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 205 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
176 fail_filename)); | 206 fail_filename)); |
177 GURL fail_url("http://example.com/fail"); | 207 GURL fail_url("http://example.com/fail"); |
178 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 208 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
179 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 209 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
180 AddFilter(DownloadQuery::FILTER_QUERY, "query"); | 210 std::vector<std::string> query_terms; |
| 211 query_terms.push_back("query"); |
| 212 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
181 ExpectStandardFilterResults(); | 213 ExpectStandardFilterResults(); |
182 } | 214 } |
183 | 215 |
184 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) { | 216 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) { |
185 CreateMocks(2); | 217 CreateMocks(2); |
186 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( | 218 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
187 static_cast<content::BrowserContext*>(NULL))); | 219 static_cast<content::BrowserContext*>(NULL))); |
188 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( | 220 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
189 static_cast<content::BrowserContext*>(NULL))); | 221 static_cast<content::BrowserContext*>(NULL))); |
190 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 222 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
191 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 223 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
192 fail_filename)); | 224 fail_filename)); |
193 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 225 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
194 fail_filename)); | 226 fail_filename)); |
195 GURL match_url("http://query.com/query"); | 227 GURL match_url("http://query.com/query"); |
196 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); | 228 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); |
197 GURL fail_url("http://example.com/fail"); | 229 GURL fail_url("http://example.com/fail"); |
198 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 230 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
199 AddFilter(DownloadQuery::FILTER_QUERY, "query"); | 231 std::vector<std::string> query_terms; |
| 232 query_terms.push_back("query"); |
| 233 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
200 ExpectStandardFilterResults(); | 234 ExpectStandardFilterResults(); |
201 } | 235 } |
202 | 236 |
203 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) { | 237 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) { |
204 CreateMocks(2); | 238 CreateMocks(2); |
205 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( | 239 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( |
206 static_cast<content::BrowserContext*>(NULL))); | 240 static_cast<content::BrowserContext*>(NULL))); |
207 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( | 241 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( |
208 static_cast<content::BrowserContext*>(NULL))); | 242 static_cast<content::BrowserContext*>(NULL))); |
209 const base::FilePath::StringType kTestString( | 243 const base::FilePath::StringType kTestString( |
210 #if defined(OS_POSIX) | 244 #if defined(OS_POSIX) |
211 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd" | 245 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd" |
212 #elif defined(OS_WIN) | 246 #elif defined(OS_WIN) |
213 L"/\x4f60\x597d\x4f60\x597d" | 247 L"/\x4f60\x597d\x4f60\x597d" |
214 #endif | 248 #endif |
215 ); | 249 ); |
216 base::FilePath match_filename(kTestString); | 250 base::FilePath match_filename(kTestString); |
217 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 251 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
218 match_filename)); | 252 match_filename)); |
219 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 253 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
220 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 254 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
221 fail_filename)); | 255 fail_filename)); |
222 GURL fail_url("http://example.com/fail"); | 256 GURL fail_url("http://example.com/fail"); |
223 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 257 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
224 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); | 258 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); |
225 AddFilter(DownloadQuery::FILTER_QUERY, kTestString); | 259 std::vector<base::FilePath::StringType> query_terms; |
| 260 query_terms.push_back(kTestString); |
| 261 AddFilter(DownloadQuery::FILTER_QUERY, query_terms); |
226 ExpectStandardFilterResults(); | 262 ExpectStandardFilterResults(); |
227 } | 263 } |
228 | 264 |
229 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) { | 265 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) { |
230 CreateMocks(2); | 266 CreateMocks(2); |
231 base::FilePath match_filename(FILE_PATH_LITERAL("query")); | 267 base::FilePath match_filename(FILE_PATH_LITERAL("query")); |
232 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 268 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
233 match_filename)); | 269 match_filename)); |
234 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); | 270 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); |
235 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( | 271 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 base::Time start = base::Time::Now(); | 619 base::Time start = base::Time::Now(); |
584 Search(); | 620 Search(); |
585 base::Time end = base::Time::Now(); | 621 base::Time end = base::Time::Now(); |
586 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; | 622 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; |
587 double nanos_per_item = nanos / static_cast<double>(kNumItems); | 623 double nanos_per_item = nanos / static_cast<double>(kNumItems); |
588 double nanos_per_item_per_filter = nanos_per_item | 624 double nanos_per_item_per_filter = nanos_per_item |
589 / static_cast<double>(kNumFilters); | 625 / static_cast<double>(kNumFilters); |
590 std::cout << "Search took " << nanos_per_item_per_filter | 626 std::cout << "Search took " << nanos_per_item_per_filter |
591 << " nanoseconds per item per filter.\n"; | 627 << " nanoseconds per item per filter.\n"; |
592 } | 628 } |
OLD | NEW |