Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: chrome/browser/autocomplete/bookmark_provider_unittest.cc

Issue 343523003: Remove AutocompleteInput Type and PageClassification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/autocomplete/bookmark_provider.h" 5 #include "chrome/browser/autocomplete/bookmark_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/autocomplete/autocomplete_provider.h" 17 #include "chrome/browser/autocomplete/autocomplete_provider.h"
18 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 18 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "components/bookmarks/browser/bookmark_match.h" 20 #include "components/bookmarks/browser/bookmark_match.h"
21 #include "components/bookmarks/browser/bookmark_model.h" 21 #include "components/bookmarks/browser/bookmark_model.h"
22 #include "components/bookmarks/test/test_bookmark_client.h" 22 #include "components/bookmarks/test/test_bookmark_client.h"
23 #include "components/metrics/proto/omnibox_event.pb.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 using bookmarks::BookmarkMatch; 26 using bookmarks::BookmarkMatch;
26 27
27 // The bookmark corpus against which we will simulate searches. 28 // The bookmark corpus against which we will simulate searches.
28 struct BookmarksTestInfo { 29 struct BookmarksTestInfo {
29 std::string title; 30 std::string title;
30 std::string url; 31 std::string url;
31 } bookmark_provider_test_data[] = { 32 } bookmark_provider_test_data[] = {
32 { "abc def", "http://www.catsanddogs.com/a" }, 33 { "abc def", "http://www.catsanddogs.com/a" },
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 {"frank", 1, {{{0, 5}, {8, 13}, {16, 21}, {0, 0}}}}, 255 {"frank", 1, {{{0, 5}, {8, 13}, {16, 21}, {0, 0}}}},
255 {"frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}}, 256 {"frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}},
256 {"frankly frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}}, 257 {"frankly frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}},
257 {"foobar foo", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, 258 {"foobar foo", 1, {{{0, 6}, {7, 13}, {0, 0}}}},
258 {"foo foobar", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, 259 {"foo foobar", 1, {{{0, 6}, {7, 13}, {0, 0}}}},
259 }; 260 };
260 261
261 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { 262 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) {
262 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), 263 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
263 base::string16::npos, base::string16(), GURL(), 264 base::string16::npos, base::string16(), GURL(),
264 AutocompleteInput::INVALID_SPEC, false, false, 265 metrics::OmniboxEventProto::INVALID_SPEC, false,
265 false, true); 266 false, false, true);
266 provider_->Start(input, false); 267 provider_->Start(input, false);
267 const ACMatches& matches(provider_->matches()); 268 const ACMatches& matches(provider_->matches());
268 // Validate number of results is as expected. 269 // Validate number of results is as expected.
269 EXPECT_LE(matches.size(), query_data[i].match_count) 270 EXPECT_LE(matches.size(), query_data[i].match_count)
270 << "One or more of the following matches were unexpected:\n" 271 << "One or more of the following matches were unexpected:\n"
271 << MatchesAsString16(matches) 272 << MatchesAsString16(matches)
272 << "For query '" << query_data[i].query << "'."; 273 << "For query '" << query_data[i].query << "'.";
273 EXPECT_GE(matches.size(), query_data[i].match_count) 274 EXPECT_GE(matches.size(), query_data[i].match_count)
274 << "One or more expected matches are missing. Matches found:\n" 275 << "One or more expected matches are missing. Matches found:\n"
275 << MatchesAsString16(matches) 276 << MatchesAsString16(matches)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 // Ranking of prefix matches with URL boost. Note that a query of 332 // Ranking of prefix matches with URL boost. Note that a query of
332 // "worm burn" will have the same results. 333 // "worm burn" will have the same results.
333 {"burn worm", 3, {"burning worms #2", // boosted 334 {"burn worm", 3, {"burning worms #2", // boosted
334 "worming burns #20", // boosted 335 "worming burns #20", // boosted
335 "burning worms #1"}}, // not boosted but shorter 336 "burning worms #1"}}, // not boosted but shorter
336 }; 337 };
337 338
338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { 339 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) {
339 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), 340 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
340 base::string16::npos, base::string16(), GURL(), 341 base::string16::npos, base::string16(), GURL(),
341 AutocompleteInput::INVALID_SPEC, false, false, 342 metrics::OmniboxEventProto::INVALID_SPEC, false,
342 false, true); 343 false, false, true);
343 provider_->Start(input, false); 344 provider_->Start(input, false);
344 const ACMatches& matches(provider_->matches()); 345 const ACMatches& matches(provider_->matches());
345 // Validate number and content of results is as expected. 346 // Validate number and content of results is as expected.
346 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size()); 347 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size());
347 ++j) { 348 ++j) {
348 EXPECT_LT(j, query_data[i].match_count) << " Unexpected match '" 349 EXPECT_LT(j, query_data[i].match_count) << " Unexpected match '"
349 << base::UTF16ToUTF8(matches[j].description) << "' for query: '" 350 << base::UTF16ToUTF8(matches[j].description) << "' for query: '"
350 << query_data[i].query << "'."; 351 << query_data[i].query << "'.";
351 if (j >= query_data[i].match_count) 352 if (j >= query_data[i].match_count)
352 continue; 353 continue;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 // need to be in the bookmarks list because BookmarkProvider's 388 // need to be in the bookmarks list because BookmarkProvider's
388 // TitleMatchToACMatch() has an assertion that verifies the URL is 389 // TitleMatchToACMatch() has an assertion that verifies the URL is
389 // actually bookmarked. 390 // actually bookmarked.
390 }; 391 };
391 392
392 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { 393 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) {
393 const std::string description = "for query=" + query_data[i].query + 394 const std::string description = "for query=" + query_data[i].query +
394 " and url=" + query_data[i].url; 395 " and url=" + query_data[i].url;
395 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), 396 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
396 base::string16::npos, base::string16(), GURL(), 397 base::string16::npos, base::string16(), GURL(),
397 AutocompleteInput::INVALID_SPEC, false, false, 398 metrics::OmniboxEventProto::INVALID_SPEC, false,
398 false, true); 399 false, false, true);
399 const base::string16 fixed_up_input( 400 const base::string16 fixed_up_input(
400 provider_->FixupUserInput(input).second); 401 provider_->FixupUserInput(input).second);
401 BookmarkNode node(GURL(query_data[i].url)); 402 BookmarkNode node(GURL(query_data[i].url));
402 node.SetTitle(base::ASCIIToUTF16(query_data[i].url)); 403 node.SetTitle(base::ASCIIToUTF16(query_data[i].url));
403 BookmarkMatch bookmark_match; 404 BookmarkMatch bookmark_match;
404 bookmark_match.node = &node; 405 bookmark_match.node = &node;
405 const AutocompleteMatch& ac_match = provider_->BookmarkMatchToACMatch( 406 const AutocompleteMatch& ac_match = provider_->BookmarkMatchToACMatch(
406 input, fixed_up_input, bookmark_match); 407 input, fixed_up_input, bookmark_match);
407 EXPECT_EQ(query_data[i].allowed_to_be_default_match, 408 EXPECT_EQ(query_data[i].allowed_to_be_default_match,
408 ac_match.allowed_to_be_default_match) << description; 409 ac_match.allowed_to_be_default_match) << description;
(...skipping 24 matching lines...) Expand all
433 }; 434 };
434 435
435 // Reload the bookmarks index with |index_urls| == true. 436 // Reload the bookmarks index with |index_urls| == true.
436 model_ = client_.CreateModel(true); 437 model_ = client_.CreateModel(true);
437 SetUp(); 438 SetUp();
438 439
439 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { 440 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) {
440 std::string description = "for query=" + query_data[i].query; 441 std::string description = "for query=" + query_data[i].query;
441 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), 442 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
442 base::string16::npos, base::string16(), GURL(), 443 base::string16::npos, base::string16(), GURL(),
443 AutocompleteInput::INVALID_SPEC, false, false, 444 metrics::OmniboxEventProto::INVALID_SPEC, false,
444 false, true); 445 false, false, true);
445 provider_->Start(input, false); 446 provider_->Start(input, false);
446 const ACMatches& matches(provider_->matches()); 447 const ACMatches& matches(provider_->matches());
447 ASSERT_EQ(1U, matches.size()) << description; 448 ASSERT_EQ(1U, matches.size()) << description;
448 const AutocompleteMatch& match = matches[0]; 449 const AutocompleteMatch& match = matches[0];
449 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].expected_contents), 450 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].expected_contents),
450 match.contents) << description; 451 match.contents) << description;
451 std::vector<std::string> class_strings; 452 std::vector<std::string> class_strings;
452 base::SplitString( 453 base::SplitString(
453 query_data[i].expected_contents_class, ',', &class_strings); 454 query_data[i].expected_contents_class, ',', &class_strings);
454 ASSERT_EQ(class_strings.size(), match.contents_class.size()) 455 ASSERT_EQ(class_strings.size(), match.contents_class.size())
455 << description; 456 << description;
456 for (size_t i = 0; i < class_strings.size(); ++i) { 457 for (size_t i = 0; i < class_strings.size(); ++i) {
457 std::vector<std::string> chunks; 458 std::vector<std::string> chunks;
458 base::SplitString(class_strings[i], ':', &chunks); 459 base::SplitString(class_strings[i], ':', &chunks);
459 ASSERT_EQ(2U, chunks.size()) << description; 460 ASSERT_EQ(2U, chunks.size()) << description;
460 size_t offset; 461 size_t offset;
461 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; 462 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description;
462 EXPECT_EQ(offset, match.contents_class[i].offset) << description; 463 EXPECT_EQ(offset, match.contents_class[i].offset) << description;
463 int style; 464 int style;
464 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; 465 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description;
465 EXPECT_EQ(style, match.contents_class[i].style) << description; 466 EXPECT_EQ(style, match.contents_class[i].style) << description;
466 } 467 }
467 } 468 }
468 } 469 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/base_search_provider.cc ('k') | chrome/browser/autocomplete/builtin_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698