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

Unified Diff: chrome/browser/google/google_url_tracker_unittest.cc

Issue 285193002: Create GoogleURLTrackerClient interface and //chrome implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to review Created 6 years, 7 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
Index: chrome/browser/google/google_url_tracker_unittest.cc
diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc
index 1ebe61369cfad3fc5d09681fe5f7d55e12707313..1b4427051e08594baeb90266a9797b9ac9f1a57f 100644
--- a/chrome/browser/google/google_url_tracker_unittest.cc
+++ b/chrome/browser/google/google_url_tracker_unittest.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/google/google_url_tracker_navigation_helper.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
+#include "components/google/core/browser/google_url_tracker_client.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h"
#include "content/public/browser/notification_service.h"
@@ -93,8 +94,38 @@ void TestNotificationObserver::Observe(
notified_ = true;
}
+// TestGoogleURLTrackerClient -------------------------------------------------
-// TestGoogleURLTrackerNavigationHelper -------------------------------------
+class TestGoogleURLTrackerClient : public GoogleURLTrackerClient {
+ public:
+ TestGoogleURLTrackerClient();
+ virtual ~TestGoogleURLTrackerClient();
+
+ virtual void SetListeningForNavigationStart(bool listen) OVERRIDE;
+ virtual bool IsListeningForNavigationStart() OVERRIDE;
+
+ private:
+ bool observe_nav_start_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerClient);
+};
+
+TestGoogleURLTrackerClient::TestGoogleURLTrackerClient()
+ : observe_nav_start_(false) {
+}
+
+TestGoogleURLTrackerClient::~TestGoogleURLTrackerClient() {
+}
+
+void TestGoogleURLTrackerClient::SetListeningForNavigationStart(bool listen) {
+ observe_nav_start_ = listen;
+}
+
+bool TestGoogleURLTrackerClient::IsListeningForNavigationStart() {
+ return observe_nav_start_;
+}
+
+// TestGoogleURLTrackerNavigationHelper ---------------------------------------
class TestGoogleURLTrackerNavigationHelper
: public GoogleURLTrackerNavigationHelper {
@@ -103,8 +134,6 @@ class TestGoogleURLTrackerNavigationHelper
virtual ~TestGoogleURLTrackerNavigationHelper();
virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE;
- virtual void SetListeningForNavigationStart(bool listen) OVERRIDE;
- virtual bool IsListeningForNavigationStart() OVERRIDE;
virtual void SetListeningForNavigationCommit(
const content::NavigationController* nav_controller,
bool listen) OVERRIDE;
@@ -118,7 +147,6 @@ class TestGoogleURLTrackerNavigationHelper
private:
GoogleURLTracker* tracker_;
- bool observe_nav_start_;
std::set<const content::NavigationController*>
nav_controller_commit_listeners_;
std::set<const content::NavigationController*>
@@ -126,8 +154,7 @@ class TestGoogleURLTrackerNavigationHelper
};
TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper()
- : tracker_(NULL),
- observe_nav_start_(false) {
+ : tracker_(NULL) {
}
TestGoogleURLTrackerNavigationHelper::
@@ -139,15 +166,6 @@ void TestGoogleURLTrackerNavigationHelper::SetGoogleURLTracker(
tracker_ = tracker;
}
-void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationStart(
- bool listen) {
- observe_nav_start_ = listen;
-}
-
-bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationStart() {
- return observe_nav_start_;
-}
-
void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit(
const content::NavigationController* nav_controller,
bool listen) {
@@ -253,6 +271,7 @@ class GoogleURLTrackerTest : public testing::Test {
net::TestURLFetcherFactory fetcher_factory_;
content::NotificationRegistrar registrar_;
TestNotificationObserver observer_;
+ GoogleURLTrackerClient* client_;
GoogleURLTrackerNavigationHelper* nav_helper_;
TestingProfile profile_;
scoped_ptr<GoogleURLTracker> google_url_tracker_;
@@ -291,12 +310,16 @@ GoogleURLTrackerTest::~GoogleURLTrackerTest() {
void GoogleURLTrackerTest::SetUp() {
network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
- // Ownership is passed to google_url_tracker_, but a weak pointer is kept;
- // this is safe since GoogleURLTracker keeps the observer for its lifetime.
+ // Ownership is passed to google_url_tracker_, but weak pointers are kept;
+ // this is safe since GoogleURLTracker keeps these objects for its lifetime.
+ client_ = new TestGoogleURLTrackerClient();
nav_helper_ = new TestGoogleURLTrackerNavigationHelper();
+ scoped_ptr<GoogleURLTrackerClient> client(client_);
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(nav_helper_);
google_url_tracker_.reset(
- new GoogleURLTracker(&profile_, nav_helper.Pass(),
+ new GoogleURLTracker(&profile_,
+ client.Pass(),
+ nav_helper.Pass(),
GoogleURLTracker::UNIT_TEST_MODE));
google_url_tracker_->infobar_creator_ = base::Bind(
&GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this));
@@ -305,10 +328,6 @@ void GoogleURLTrackerTest::SetUp() {
void GoogleURLTrackerTest::TearDown() {
while (!unique_ids_seen_.empty())
CloseTab(*unique_ids_seen_.begin());
-
- nav_helper_ = NULL;
- google_url_tracker_.reset();
- network_change_notifier_.reset();
}
net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() {
@@ -367,7 +386,7 @@ void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id,
// for navigation starts if the searchdomaincheck response was bogus.
}
unique_ids_seen_.insert(unique_id);
- if (nav_helper_->IsListeningForNavigationStart()) {
+ if (client_->IsListeningForNavigationStart()) {
google_url_tracker_->OnNavigationPending(
reinterpret_cast<content::NavigationController*>(unique_id),
reinterpret_cast<InfoBarService*>(unique_id), unique_id);

Powered by Google App Engine
This is Rietveld 408576698