| Index: chrome/browser/autocomplete/bookmark_provider_unittest.cc
|
| diff --git a/chrome/browser/autocomplete/bookmark_provider_unittest.cc b/chrome/browser/autocomplete/bookmark_provider_unittest.cc
|
| index 100f0ee870300a42f3f3158e2baea533f3bc18a5..7fa13bb5936a0bd1d3c1e6f8a30a67856f80007d 100644
|
| --- a/chrome/browser/autocomplete/bookmark_provider_unittest.cc
|
| +++ b/chrome/browser/autocomplete/bookmark_provider_unittest.cc
|
| @@ -10,15 +10,20 @@
|
|
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/metrics/field_trial.h"
|
| #include "base/strings/string16.h"
|
| #include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/string_split.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/autocomplete/autocomplete_provider.h"
|
| #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
|
| +#include "chrome/browser/bookmarks/bookmark_match.h"
|
| #include "chrome/browser/bookmarks/bookmark_model.h"
|
| #include "chrome/browser/bookmarks/bookmark_model_factory.h"
|
| -#include "chrome/browser/bookmarks/bookmark_title_match.h"
|
| +#include "chrome/browser/omnibox/omnibox_field_trial.h"
|
| +#include "chrome/common/metrics/variations/variations_util.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| +#include "components/variations/entropy_provider.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| // The bookmark corpus against which we will simulate searches.
|
| @@ -35,6 +40,8 @@ struct BookmarksTestInfo {
|
| { "jkl ghi", "http://www.catsanddogs.com/g" },
|
| { "frankly frankly frank", "http://www.catsanddogs.com/h" },
|
| { "foobar foobar", "http://www.foobar.com/" },
|
| + { "domain", "http://www.domain.com/http/" },
|
| + { "repeat", "http://www.repeat.com/1/repeat/2/" },
|
| // For testing inline_autocompletion.
|
| { "http://blah.com/", "http://blah.com/" },
|
| { "http://fiddle.com/", "http://fiddle.com/" },
|
| @@ -61,7 +68,7 @@ struct BookmarksTestInfo {
|
| class BookmarkProviderTest : public testing::Test,
|
| public AutocompleteProviderListener {
|
| public:
|
| - BookmarkProviderTest() : model_(new BookmarkModel(NULL)) {}
|
| + BookmarkProviderTest();
|
|
|
| // AutocompleteProviderListener: Not called.
|
| virtual void OnProviderUpdate(bool updated_matches) OVERRIDE {}
|
| @@ -74,9 +81,21 @@ class BookmarkProviderTest : public testing::Test,
|
| scoped_refptr<BookmarkProvider> provider_;
|
|
|
| private:
|
| + scoped_ptr<base::FieldTrialList> field_trial_list_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(BookmarkProviderTest);
|
| };
|
|
|
| +BookmarkProviderTest::BookmarkProviderTest() {
|
| + model_.reset(new BookmarkModel(NULL));
|
| + // Destroy the existing FieldTrialList before creating a new one to avoid
|
| + // a DCHECK.
|
| + field_trial_list_.reset();
|
| + field_trial_list_.reset(new base::FieldTrialList(
|
| + new metrics::SHA1EntropyProvider("foo")));
|
| + chrome_variations::testing::ClearAllVariationParams();
|
| +}
|
| +
|
| void BookmarkProviderTest::SetUp() {
|
| profile_.reset(new TestingProfile());
|
| DCHECK(profile_.get());
|
| @@ -387,13 +406,78 @@ TEST_F(BookmarkProviderTest, InlineAutocompletion) {
|
| provider_->FixupUserInput(&fixed_up_input);
|
| BookmarkNode node(GURL(query_data[i].url));
|
| node.SetTitle(base::ASCIIToUTF16(query_data[i].url));
|
| - BookmarkTitleMatch bookmark_match;
|
| + BookmarkMatch bookmark_match;
|
| bookmark_match.node = &node;
|
| - const AutocompleteMatch& ac_match =
|
| - provider_->TitleMatchToACMatch(input, fixed_up_input, bookmark_match);
|
| + const AutocompleteMatch& ac_match = provider_->BookmarkMatchToACMatch(
|
| + input, fixed_up_input, bookmark_match);
|
| EXPECT_EQ(query_data[i].allowed_to_be_default_match,
|
| ac_match.allowed_to_be_default_match) << description;
|
| EXPECT_EQ(base::ASCIIToUTF16(query_data[i].inline_autocompletion),
|
| ac_match.inline_autocompletion) << description;
|
| }
|
| }
|
| +
|
| +TEST_F(BookmarkProviderTest, StripHttpAndAdjustOffsets) {
|
| + // Simulate searches.
|
| + struct QueryData {
|
| + const std::string query;
|
| + const std::string expected_contents;
|
| + // |expected_contents_class| is in format offset:style,offset:style,...
|
| + const std::string expected_contents_class;
|
| + } query_data[] = {
|
| + { "foo", "www.foobar.com", "0:1,4:3,7:1" },
|
| + { "www foo", "www.foobar.com", "0:3,3:1,4:3,7:1" },
|
| + { "foo www", "www.foobar.com", "0:3,3:1,4:3,7:1" },
|
| + { "foo http", "http://www.foobar.com", "0:3,4:1,11:3,14:1" },
|
| + { "blah", "blah.com", "0:3,4:1" },
|
| + { "http blah", "http://blah.com", "0:3,4:1,7:3,11:1" },
|
| + { "dom", "www.domain.com/http/", "0:1,4:3,7:1" },
|
| + { "dom http", "http://www.domain.com/http/",
|
| + "0:3,4:1,11:3,14:1,22:3,26:1" },
|
| + { "rep", "www.repeat.com/1/repeat/2/", "0:1,4:3,7:1,17:3,20:1" },
|
| + { "versi", "chrome://version", "0:1,9:3,14:1" }
|
| + };
|
| +
|
| + // Set the field trial parameter to enable indexing URLs.
|
| + {
|
| + std::map<std::string, std::string> params;
|
| + params[OmniboxFieldTrial::kBookmarksIndexURLsRule] = "true";
|
| + ASSERT_TRUE(chrome_variations::AssociateVariationParams(
|
| + OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
|
| + }
|
| + base::FieldTrialList::CreateFieldTrial(
|
| + OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
|
| + // Reload the bookmarks index now that the field trial is set.
|
| + model_.reset(new BookmarkModel(NULL));
|
| + SetUp();
|
| +
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) {
|
| + std::string description = "for query=" + query_data[i].query;
|
| + AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
|
| + base::string16::npos, base::string16(), GURL(),
|
| + AutocompleteInput::INVALID_SPEC, false, false,
|
| + false, AutocompleteInput::ALL_MATCHES);
|
| + provider_->Start(input, false);
|
| + const ACMatches& matches(provider_->matches());
|
| + ASSERT_EQ(1U, matches.size()) << description;
|
| + const AutocompleteMatch& match = matches[0];
|
| + EXPECT_EQ(base::ASCIIToUTF16(query_data[i].expected_contents),
|
| + match.contents) << description;
|
| + std::vector<std::string> class_strings;
|
| + base::SplitString(
|
| + query_data[i].expected_contents_class, ',', &class_strings);
|
| + ASSERT_EQ(class_strings.size(), match.contents_class.size())
|
| + << description;
|
| + for (size_t i = 0; i < class_strings.size(); ++i) {
|
| + std::vector<std::string> chunks;
|
| + base::SplitString(class_strings[i], ':', &chunks);
|
| + ASSERT_EQ(2U, chunks.size()) << description;
|
| + size_t offset;
|
| + EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description;
|
| + EXPECT_EQ(offset, match.contents_class[i].offset) << description;
|
| + int style;
|
| + EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description;
|
| + EXPECT_EQ(style, match.contents_class[i].style) << description;
|
| + }
|
| + }
|
| +}
|
|
|