Commit 51d51dbc authored by blundell's avatar blundell Committed by Commit bot

Componentize GoogleURLTracker unittest

Minor changes needed to avoid requiring TestingProfile.

BUG=373244

Review URL: https://codereview.chromium.org/501393004

Cr-Commit-Position: refs/heads/master@{#294787}
parent b4d09b93
...@@ -452,7 +452,6 @@ ...@@ -452,7 +452,6 @@
'browser/google/google_search_counter_android_unittest.cc', 'browser/google/google_search_counter_android_unittest.cc',
'browser/google/google_search_counter_unittest.cc', 'browser/google/google_search_counter_unittest.cc',
'browser/google/google_update_settings_unittest.cc', 'browser/google/google_update_settings_unittest.cc',
'browser/google/google_url_tracker_unittest.cc',
'browser/history/android/android_cache_database_unittest.cc', 'browser/history/android/android_cache_database_unittest.cc',
'browser/history/android/android_history_provider_service_unittest.cc', 'browser/history/android/android_history_provider_service_unittest.cc',
'browser/history/android/android_history_types_unittest.cc', 'browser/history/android/android_history_types_unittest.cc',
......
...@@ -128,6 +128,7 @@ ...@@ -128,6 +128,7 @@
'gcm_driver/gcm_delayed_task_controller_unittest.cc', 'gcm_driver/gcm_delayed_task_controller_unittest.cc',
'gcm_driver/gcm_driver_desktop_unittest.cc', 'gcm_driver/gcm_driver_desktop_unittest.cc',
'gcm_driver/gcm_stats_recorder_impl_unittest.cc', 'gcm_driver/gcm_stats_recorder_impl_unittest.cc',
'google/core/browser/google_url_tracker_unittest.cc',
'google/core/browser/google_util_unittest.cc', 'google/core/browser/google_util_unittest.cc',
'history/core/browser/url_database_unittest.cc', 'history/core/browser/url_database_unittest.cc',
'history/core/common/thumbnail_score_unittest.cc', 'history/core/common/thumbnail_score_unittest.cc',
......
...@@ -9,18 +9,18 @@ ...@@ -9,18 +9,18 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/google/google_url_tracker_factory.h" #include "base/prefs/testing_pref_service.h"
#include "chrome/test/base/testing_profile.h"
#include "components/google/core/browser/google_pref_names.h" #include "components/google/core/browser/google_pref_names.h"
#include "components/google/core/browser/google_url_tracker_client.h" #include "components/google/core/browser/google_url_tracker_client.h"
#include "components/google/core/browser/google_url_tracker_infobar_delegate.h" #include "components/google/core/browser/google_url_tracker_infobar_delegate.h"
#include "components/google/core/browser/google_url_tracker_navigation_helper.h" #include "components/google/core/browser/google_url_tracker_navigation_helper.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h" #include "components/infobars/core/infobar_delegate.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
...@@ -71,7 +71,7 @@ void TestCallbackListener::RegisterCallback( ...@@ -71,7 +71,7 @@ void TestCallbackListener::RegisterCallback(
class TestGoogleURLTrackerClient : public GoogleURLTrackerClient { class TestGoogleURLTrackerClient : public GoogleURLTrackerClient {
public: public:
explicit TestGoogleURLTrackerClient(Profile* profile_); explicit TestGoogleURLTrackerClient(PrefService* prefs_);
virtual ~TestGoogleURLTrackerClient(); virtual ~TestGoogleURLTrackerClient();
virtual void SetListeningForNavigationStart(bool listen) OVERRIDE; virtual void SetListeningForNavigationStart(bool listen) OVERRIDE;
...@@ -81,14 +81,17 @@ class TestGoogleURLTrackerClient : public GoogleURLTrackerClient { ...@@ -81,14 +81,17 @@ class TestGoogleURLTrackerClient : public GoogleURLTrackerClient {
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
private: private:
Profile* profile_; PrefService* prefs_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_;
bool observe_nav_start_; bool observe_nav_start_;
DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerClient); DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerClient);
}; };
TestGoogleURLTrackerClient::TestGoogleURLTrackerClient(Profile* profile) TestGoogleURLTrackerClient::TestGoogleURLTrackerClient(PrefService* prefs)
: profile_(profile), : prefs_(prefs),
request_context_(new net::TestURLRequestContextGetter(
base::MessageLoopProxy::current())),
observe_nav_start_(false) { observe_nav_start_(false) {
} }
...@@ -108,11 +111,11 @@ bool TestGoogleURLTrackerClient::IsBackgroundNetworkingEnabled() { ...@@ -108,11 +111,11 @@ bool TestGoogleURLTrackerClient::IsBackgroundNetworkingEnabled() {
} }
PrefService* TestGoogleURLTrackerClient::GetPrefs() { PrefService* TestGoogleURLTrackerClient::GetPrefs() {
return profile_->GetPrefs(); return prefs_;
} }
net::URLRequestContextGetter* TestGoogleURLTrackerClient::GetRequestContext() { net::URLRequestContextGetter* TestGoogleURLTrackerClient::GetRequestContext() {
return profile_->GetRequestContext(); return request_context_.get();
} }
...@@ -243,16 +246,14 @@ class GoogleURLTrackerTest : public testing::Test { ...@@ -243,16 +246,14 @@ class GoogleURLTrackerTest : public testing::Test {
void clear_listener_notified() { listener_.clear_notified(); } void clear_listener_notified() { listener_.clear_notified(); }
private: private:
// These are required by the TestURLFetchers GoogleURLTracker will create (see base::MessageLoop message_loop_;
// test_url_fetcher_factory.h). TestingPrefServiceSimple prefs_;
content::TestBrowserThreadBundle thread_bundle_;
// Creating this allows us to call // Creating this allows us to call
// net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(). // net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests().
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
net::TestURLFetcherFactory fetcher_factory_; net::TestURLFetcherFactory fetcher_factory_;
GoogleURLTrackerClient* client_; GoogleURLTrackerClient* client_;
TestingProfile profile_;
scoped_ptr<GoogleURLTracker> google_url_tracker_; scoped_ptr<GoogleURLTracker> google_url_tracker_;
TestCallbackListener listener_; TestCallbackListener listener_;
// This tracks the different "tabs" a test has "opened", so we can close them // This tracks the different "tabs" a test has "opened", so we can close them
...@@ -260,10 +261,13 @@ class GoogleURLTrackerTest : public testing::Test { ...@@ -260,10 +261,13 @@ class GoogleURLTrackerTest : public testing::Test {
std::set<infobars::InfoBarManager*> infobar_managers_seen_; std::set<infobars::InfoBarManager*> infobar_managers_seen_;
}; };
GoogleURLTrackerTest::GoogleURLTrackerTest() GoogleURLTrackerTest::GoogleURLTrackerTest() {
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { prefs_.registry()->RegisterStringPref(
GoogleURLTrackerFactory::GetInstance()-> prefs::kLastKnownGoogleURL,
RegisterUserPrefsOnBrowserContextForTest(&profile_); GoogleURLTracker::kDefaultGoogleHomepage);
prefs_.registry()->RegisterStringPref(
prefs::kLastPromptedGoogleURL,
std::string());
} }
GoogleURLTrackerTest::~GoogleURLTrackerTest() { GoogleURLTrackerTest::~GoogleURLTrackerTest() {
...@@ -273,7 +277,7 @@ void GoogleURLTrackerTest::SetUp() { ...@@ -273,7 +277,7 @@ void GoogleURLTrackerTest::SetUp() {
network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
// Ownership is passed to google_url_tracker_, but a weak pointer is kept; // Ownership is passed to google_url_tracker_, but a weak pointer is kept;
// this is safe since GoogleURLTracker keeps the client for its lifetime. // this is safe since GoogleURLTracker keeps the client for its lifetime.
client_ = new TestGoogleURLTrackerClient(&profile_); client_ = new TestGoogleURLTrackerClient(&prefs_);
scoped_ptr<GoogleURLTrackerClient> client(client_); scoped_ptr<GoogleURLTrackerClient> client(client_);
google_url_tracker_.reset(new GoogleURLTracker( google_url_tracker_.reset(new GoogleURLTracker(
client.Pass(), GoogleURLTracker::UNIT_TEST_MODE)); client.Pass(), GoogleURLTracker::UNIT_TEST_MODE));
...@@ -323,11 +327,11 @@ void GoogleURLTrackerTest::NotifyNetworkChanged() { ...@@ -323,11 +327,11 @@ void GoogleURLTrackerTest::NotifyNetworkChanged() {
} }
void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) {
profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); prefs_.SetString(prefs::kLastPromptedGoogleURL, url.spec());
} }
GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() {
return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); return GURL(prefs_.GetString(prefs::kLastPromptedGoogleURL));
} }
void GoogleURLTrackerTest::SetNavigationPending( void GoogleURLTrackerTest::SetNavigationPending(
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#include "components/infobars/core/confirm_infobar_delegate.h" #include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
// Provides dummy definitions of static variables and functions that are // Provides definitions of static variables and functions that are declared in
// declared in the component but defined in the embedder in order to allow // the component but defined in the embedder.
// components_unittests to link.
// TODO(blundell): The component shouldn't be declaring statics that it's not // TODO(blundell): The component shouldn't be declaring statics that it's not
// defining. crbug.com/386171 // defining; instead, this information should be obtained via a client,
// which can have a test implementation. crbug.com/386171
// On Android, these variables are defined in ../core/infobar_android.cc. // On Android, these variables are defined in ../core/infobar_android.cc.
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
...@@ -24,8 +24,10 @@ const int infobars::InfoBar::kMaximumArrowTargetHalfWidth = 14; ...@@ -24,8 +24,10 @@ const int infobars::InfoBar::kMaximumArrowTargetHalfWidth = 14;
const int infobars::InfoBar::kDefaultBarTargetHeight = 36; const int infobars::InfoBar::kDefaultBarTargetHeight = 36;
#endif #endif
// Some components' unittests exercise code that requires that
// ConfirmInfoBarDelegate::CreateInfoBar() return a non-NULL infobar.
scoped_ptr<infobars::InfoBar> ConfirmInfoBarDelegate::CreateInfoBar( scoped_ptr<infobars::InfoBar> ConfirmInfoBarDelegate::CreateInfoBar(
scoped_ptr<ConfirmInfoBarDelegate> delegate) { scoped_ptr<ConfirmInfoBarDelegate> delegate) {
NOTREACHED(); return scoped_ptr<infobars::InfoBar>(new infobars::InfoBar(
return scoped_ptr<infobars::InfoBar>(); delegate.PassAs<infobars::InfoBarDelegate>()));
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment