| Index: chrome/browser/autocomplete/shortcuts_provider_extension_unittest.cc
|
| diff --git a/chrome/browser/autocomplete/shortcuts_provider_extension_unittest.cc b/chrome/browser/autocomplete/shortcuts_provider_extension_unittest.cc
|
| index 46d373eccc0716e482bd456e94de9b972aab4a45..05ca95e366d671ddf69f2d823a6ed5a51069b48e 100644
|
| --- a/chrome/browser/autocomplete/shortcuts_provider_extension_unittest.cc
|
| +++ b/chrome/browser/autocomplete/shortcuts_provider_extension_unittest.cc
|
| @@ -21,6 +21,7 @@
|
| #include "components/omnibox/browser/autocomplete_match.h"
|
| #include "components/omnibox/browser/autocomplete_result.h"
|
| #include "components/omnibox/browser/shortcuts_backend.h"
|
| +#include "components/omnibox/browser/shortcuts_provider_test_util.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "content/public/test/test_browser_thread.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -33,30 +34,13 @@
|
|
|
| using base::ASCIIToUTF16;
|
|
|
| -// TestShortcutInfo -----------------------------------------------------------
|
| -
|
| namespace {
|
|
|
| -struct TestShortcutInfo {
|
| - std::string guid;
|
| - std::string text;
|
| - std::string fill_into_edit;
|
| - std::string destination_url;
|
| - std::string contents;
|
| - std::string contents_class;
|
| - std::string description;
|
| - std::string description_class;
|
| - ui::PageTransition transition;
|
| - AutocompleteMatch::Type type;
|
| - std::string keyword;
|
| - int days_from_now;
|
| - int number_of_hits;
|
| -} shortcut_test_db[] = {
|
| - { "BD85DBA2-8C29-49F9-84AE-48E1E90880F1", "echo echo", "echo echo",
|
| - "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo",
|
| - "Run Echo command: echo", "0,0", "Echo", "0,4",
|
| - ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::EXTENSION_APP,
|
| - "echo", 1, 1 },
|
| +struct TestShortcutInfo shortcut_test_db[] = {
|
| + {"BD85DBA2-8C29-49F9-84AE-48E1E90880F1", "echo echo", "echo echo",
|
| + "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo",
|
| + "Run Echo command: echo", "0,0", "Echo", "0,4", ui::PAGE_TRANSITION_TYPED,
|
| + AutocompleteMatchType::EXTENSION_APP, "echo", 1, 1},
|
| };
|
|
|
| } // namespace
|
| @@ -68,51 +52,14 @@ class ShortcutsProviderExtensionTest : public testing::Test {
|
| ShortcutsProviderExtensionTest();
|
|
|
| protected:
|
| - typedef std::pair<std::string, bool> ExpectedURLAndAllowedToBeDefault;
|
| - typedef std::vector<ExpectedURLAndAllowedToBeDefault> ExpectedURLs;
|
| -
|
| - class SetShouldContain
|
| - : public std::unary_function<const ExpectedURLAndAllowedToBeDefault&,
|
| - std::set<std::string> > {
|
| - public:
|
| - explicit SetShouldContain(const ACMatches& matched_urls);
|
| -
|
| - void operator()(const ExpectedURLAndAllowedToBeDefault& expected);
|
| - std::set<ExpectedURLAndAllowedToBeDefault> Leftovers() const {
|
| - return matches_;
|
| - }
|
| -
|
| - private:
|
| - std::set<ExpectedURLAndAllowedToBeDefault> matches_;
|
| - };
|
| -
|
| void SetUp() override;
|
| void TearDown() override;
|
|
|
| - // Fills test data into the provider.
|
| - void FillData(TestShortcutInfo* db, size_t db_size);
|
| -
|
| - // Runs an autocomplete query on |text| with the provided
|
| - // |prevent_inline_autocomplete| setting and checks to see that the returned
|
| - // results' destination URLs match those provided. |expected_urls| does not
|
| - // need to be in sorted order, but |expected_top_result| should be the top
|
| - // match, and it should have inline autocompletion
|
| - // |top_result_inline_autocompletion|.
|
| - void RunTest(const base::string16 text,
|
| - bool prevent_inline_autocomplete,
|
| - const ExpectedURLs& expected_urls,
|
| - std::string expected_top_result,
|
| - base::string16 top_result_inline_autocompletion);
|
| -
|
| base::MessageLoopForUI message_loop_;
|
| content::TestBrowserThread ui_thread_;
|
| content::TestBrowserThread file_thread_;
|
| -
|
| TestingProfile profile_;
|
| ChromeAutocompleteProviderClient client_;
|
| -
|
| - ACMatches ac_matches_; // The resulting matches after running RunTest.
|
| -
|
| scoped_refptr<ShortcutsBackend> backend_;
|
| scoped_refptr<ShortcutsProvider> provider_;
|
| };
|
| @@ -130,7 +77,9 @@ void ShortcutsProviderExtensionTest::SetUp() {
|
| ASSERT_TRUE(backend_.get());
|
| ASSERT_TRUE(profile_.CreateHistoryService(true, false));
|
| provider_ = new ShortcutsProvider(&client_);
|
| - FillData(shortcut_test_db, arraysize(shortcut_test_db));
|
| + PopulateShortcutsBackendWithTestShortcutData(client_.GetShortcutsBackend(),
|
| + shortcut_test_db,
|
| + arraysize(shortcut_test_db));
|
| }
|
|
|
| void ShortcutsProviderExtensionTest::TearDown() {
|
| @@ -141,79 +90,6 @@ void ShortcutsProviderExtensionTest::TearDown() {
|
| provider_ = NULL;
|
| }
|
|
|
| -void ShortcutsProviderExtensionTest::FillData(
|
| - TestShortcutInfo* db, size_t db_size) {
|
| - DCHECK(provider_.get());
|
| - size_t expected_size = backend_->shortcuts_map().size() + db_size;
|
| - for (size_t i = 0; i < db_size; ++i) {
|
| - const TestShortcutInfo& cur = db[i];
|
| - ShortcutsDatabase::Shortcut shortcut(
|
| - cur.guid, ASCIIToUTF16(cur.text),
|
| - ShortcutsDatabase::Shortcut::MatchCore(
|
| - ASCIIToUTF16(cur.fill_into_edit), GURL(cur.destination_url),
|
| - ASCIIToUTF16(cur.contents), cur.contents_class,
|
| - ASCIIToUTF16(cur.description), cur.description_class,
|
| - cur.transition, cur.type, ASCIIToUTF16(cur.keyword)),
|
| - base::Time::Now() - base::TimeDelta::FromDays(cur.days_from_now),
|
| - cur.number_of_hits);
|
| - backend_->AddShortcut(shortcut);
|
| - }
|
| - EXPECT_EQ(expected_size, backend_->shortcuts_map().size());
|
| -}
|
| -
|
| -ShortcutsProviderExtensionTest::SetShouldContain::SetShouldContain(
|
| - const ACMatches& matched_urls) {
|
| - for (ACMatches::const_iterator iter = matched_urls.begin();
|
| - iter != matched_urls.end(); ++iter)
|
| - matches_.insert(ExpectedURLAndAllowedToBeDefault(
|
| - iter->destination_url.spec(), iter->allowed_to_be_default_match));
|
| -}
|
| -
|
| -void ShortcutsProviderExtensionTest::SetShouldContain::operator()(
|
| - const ExpectedURLAndAllowedToBeDefault& expected) {
|
| - EXPECT_EQ(1U, matches_.erase(expected));
|
| -}
|
| -
|
| -void ShortcutsProviderExtensionTest::RunTest(
|
| - const base::string16 text,
|
| - bool prevent_inline_autocomplete,
|
| - const ExpectedURLs& expected_urls,
|
| - std::string expected_top_result,
|
| - base::string16 top_result_inline_autocompletion) {
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| - AutocompleteInput input(text, base::string16::npos, std::string(), GURL(),
|
| - metrics::OmniboxEventProto::INVALID_SPEC,
|
| - prevent_inline_autocomplete, false, true, true, false,
|
| - ChromeAutocompleteSchemeClassifier(&profile_));
|
| - provider_->Start(input, false);
|
| - EXPECT_TRUE(provider_->done());
|
| -
|
| - ac_matches_ = provider_->matches();
|
| -
|
| - // We should have gotten back at most AutocompleteProvider::kMaxMatches.
|
| - EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches);
|
| -
|
| - // If the number of expected and actual matches aren't equal then we need
|
| - // test no further, but let's do anyway so that we know which URLs failed.
|
| - EXPECT_EQ(expected_urls.size(), ac_matches_.size());
|
| -
|
| - // Verify that all expected URLs were found and that all found URLs
|
| - // were expected.
|
| - std::set<ExpectedURLAndAllowedToBeDefault> Leftovers =
|
| - for_each(expected_urls.begin(), expected_urls.end(),
|
| - SetShouldContain(ac_matches_)).Leftovers();
|
| - EXPECT_EQ(0U, Leftovers.size());
|
| -
|
| - // See if we got the expected top scorer.
|
| - if (!ac_matches_.empty()) {
|
| - std::partial_sort(ac_matches_.begin(), ac_matches_.begin() + 1,
|
| - ac_matches_.end(), AutocompleteMatch::MoreRelevant);
|
| - EXPECT_EQ(expected_top_result, ac_matches_[0].destination_url.spec());
|
| - EXPECT_EQ(top_result_inline_autocompletion,
|
| - ac_matches_[0].inline_autocompletion);
|
| - }
|
| -}
|
| -
|
| // Actual tests ---------------------------------------------------------------
|
|
|
| #if defined(ENABLE_EXTENSIONS)
|
| @@ -222,9 +98,12 @@ TEST_F(ShortcutsProviderExtensionTest, Extension) {
|
| base::string16 text(ASCIIToUTF16("echo"));
|
| std::string expected_url(
|
| "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo");
|
| - ExpectedURLs expected_urls;
|
| - expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true));
|
| - RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(" echo"));
|
| + ShortcutExpectedURLs expected_urls;
|
| + expected_urls.push_back(
|
| + ShortcutExpectedURLAndAllowedToBeDefault(expected_url, true));
|
| +
|
| + RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
|
| + ASCIIToUTF16(" echo"));
|
|
|
| // Claim the extension has been unloaded.
|
| scoped_refptr<const extensions::Extension> extension =
|
| @@ -242,6 +121,7 @@ TEST_F(ShortcutsProviderExtensionTest, Extension) {
|
| content::Details<extensions::UnloadedExtensionInfo>(&details));
|
|
|
| // Now the URL should have disappeared.
|
| - RunTest(text, false, ExpectedURLs(), std::string(), base::string16());
|
| + RunShortcutsProviderTest(provider_, text, false, ShortcutExpectedURLs(),
|
| + std::string(), base::string16());
|
| }
|
| #endif
|
|
|