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

Unified Diff: chrome/browser/autocomplete/autocomplete_provider_unittest.cc

Issue 1425013002: Removing bad dependencies from autocomplete_provider_unittest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/autocomplete_provider_unittest.cc
diff --git a/chrome/browser/autocomplete/autocomplete_provider_unittest.cc b/chrome/browser/autocomplete/autocomplete_provider_unittest.cc
index 3c876a2adcc19879021a5786e22cb09d44bf4cbb..f4bf6abdad0a722cc5587e70d225c79a5bb70946 100644
--- a/chrome/browser/autocomplete/autocomplete_provider_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_provider_unittest.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/location.h"
+#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string16.h"
@@ -15,10 +16,8 @@
#include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
-#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
-#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/metrics/proto/omnibox_event.pb.h"
#include "components/omnibox/browser/autocomplete_controller.h"
@@ -26,16 +25,20 @@
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/keyword_provider.h"
+#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
#include "components/omnibox/browser/search_provider.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
+#include "components/search_engines/template_url_service_client.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
+using testing::NiceMock;
+
static std::ostream& operator<<(std::ostream& os,
const AutocompleteResult::const_iterator& it) {
return os << static_cast<const AutocompleteMatch*>(&(*it));
@@ -44,7 +47,18 @@ static std::ostream& operator<<(std::ostream& os,
namespace {
const size_t kResultsPerProvider = 3;
const char kTestTemplateURLKeyword[] = "t";
-}
+
+class TestingSchemeClassifier : public AutocompleteSchemeClassifier {
+ public:
+ metrics::OmniboxInputType::Type GetInputTypeForScheme(
+ const std::string& scheme) const override {
+ if (net::URLRequest::IsHandledProtocol(scheme))
+ return metrics::OmniboxInputType::URL;
+ return metrics::OmniboxInputType::INVALID;
+ }
+};
+
+} // namespace
// Autocomplete provider that provides known results. Note that this is
// refcounted so that it can also be a task on the message loop.
@@ -176,6 +190,8 @@ class AutocompleteProviderTest : public testing::Test,
};
protected:
+ ~AutocompleteProviderTest() override {}
+
// Registers a test TemplateURL under the given keyword.
void RegisterTemplateURL(const base::string16 keyword,
const std::string& template_url);
@@ -186,6 +202,8 @@ class AutocompleteProviderTest : public testing::Test,
TestProvider** provider1_ptr,
TestProvider** provider2_ptr);
+ void SetUp() override;
+
// Runs a query on the input "a", and makes sure both providers' input is
// properly collected.
void RunTest();
@@ -238,8 +256,19 @@ class AutocompleteProviderTest : public testing::Test,
content::NotificationRegistrar registrar_;
TestingProfile profile_;
scoped_ptr<AutocompleteController> controller_;
+ scoped_ptr<MockAutocompleteProviderClient> client_;
};
+void AutocompleteProviderTest::SetUp() {
+ scoped_ptr<TemplateURLService> template_url_service(
+ new TemplateURLService(
+ nullptr, scoped_ptr<SearchTermsData>(new SearchTermsData),
+ nullptr, scoped_ptr<TemplateURLServiceClient>(), nullptr,
+ nullptr, base::Closure()));
+ client_.reset(new NiceMock<MockAutocompleteProviderClient>());
+ client_->set_template_url_service(template_url_service.Pass());
+}
+
void AutocompleteProviderTest::RegisterTemplateURL(
const base::string16 keyword,
const std::string& template_url) {
@@ -413,7 +442,7 @@ void AutocompleteProviderTest::RunKeywordTest(const base::string16& input,
input, base::string16::npos, std::string(), GURL(),
metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS,
false, true, true, true, false,
- ChromeAutocompleteSchemeClassifier(&profile_));
+ TestingSchemeClassifier());
AutocompleteResult result;
result.AppendMatches(controller_->input_, matches);
controller_->UpdateAssociatedKeywords(&result);
@@ -459,7 +488,7 @@ void AutocompleteProviderTest::RunQuery(const base::string16 query) {
controller_->Start(AutocompleteInput(
query, base::string16::npos, std::string(), GURL(),
metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true, false,
- ChromeAutocompleteSchemeClassifier(&profile_)));
+ TestingSchemeClassifier()));
if (!controller_->done())
// The message loop will terminate when all autocomplete input has been
@@ -479,7 +508,7 @@ void AutocompleteProviderTest::RunExactKeymatchTest(
base::ASCIIToUTF16("k test"), base::string16::npos, std::string(), GURL(),
metrics::OmniboxEventProto::INVALID_SPEC, true, false,
allow_exact_keyword_match, false, false,
- ChromeAutocompleteSchemeClassifier(&profile_)));
+ TestingSchemeClassifier()));
EXPECT_TRUE(controller_->done());
EXPECT_EQ(AutocompleteProvider::TYPE_SEARCH,
controller_->result().default_match()->provider->type());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698