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