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

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

Issue 283413002: Turn GoogleURLTrackerNavigationHelper(Impl) into a per-tab object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit 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 089f2220d431ef808eef69979fcd3977b96abf8f..2a5dfb89b27a05200177aeb3f1cc852b3138c19e 100644
--- a/chrome/browser/google/google_url_tracker_unittest.cc
+++ b/chrome/browser/google/google_url_tracker_unittest.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/google/google_url_tracker.h"
+#include <map>
#include <set>
#include <string>
@@ -94,7 +95,6 @@ void TestNotificationObserver::Observe(
notified_ = true;
}
-
Peter Kasting 2014/05/15 21:29:52 Nit: Don't remove this blank line (really, TestGoo
blundell 2014/05/16 11:54:18 Done.
// TestGoogleURLTrackerClient -------------------------------------------------
class TestGoogleURLTrackerClient : public GoogleURLTrackerClient {
@@ -118,8 +118,7 @@ TestGoogleURLTrackerClient::TestGoogleURLTrackerClient()
TestGoogleURLTrackerClient::~TestGoogleURLTrackerClient() {
}
-void TestGoogleURLTrackerClient::SetListeningForNavigationStart(
- bool listen) {
+void TestGoogleURLTrackerClient::SetListeningForNavigationStart(bool listen) {
observe_nav_start_ = listen;
}
@@ -132,68 +131,48 @@ bool TestGoogleURLTrackerClient::IsListeningForNavigationStart() {
class TestGoogleURLTrackerNavigationHelper
: public GoogleURLTrackerNavigationHelper {
public:
- TestGoogleURLTrackerNavigationHelper();
+ TestGoogleURLTrackerNavigationHelper(GoogleURLTracker* tracker);
Peter Kasting 2014/05/15 21:29:52 Nit: Explicit
blundell 2014/05/16 11:54:18 Done.
virtual ~TestGoogleURLTrackerNavigationHelper();
- virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE;
virtual void SetListeningForNavigationCommit(
- const content::NavigationController* nav_controller,
bool listen) OVERRIDE;
- virtual bool IsListeningForNavigationCommit(
- const content::NavigationController* nav_controller) OVERRIDE;
+ virtual bool IsListeningForNavigationCommit() OVERRIDE;
virtual void SetListeningForTabDestruction(
- const content::NavigationController* nav_controller,
bool listen) OVERRIDE;
- virtual bool IsListeningForTabDestruction(
- const content::NavigationController* nav_controller) OVERRIDE;
+ virtual bool IsListeningForTabDestruction() OVERRIDE;
private:
- GoogleURLTracker* tracker_;
- std::set<const content::NavigationController*>
- nav_controller_commit_listeners_;
- std::set<const content::NavigationController*>
- nav_controller_tab_close_listeners_;
+ bool listening_for_nav_commit_;
+ bool listening_for_tab_destruction_;
};
Peter Kasting 2014/05/15 21:29:52 Nit: While here: DISALLOW_COPY_AND_ASSIGN
blundell 2014/05/16 11:54:18 Done.
-TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper()
- : tracker_(NULL) {
+TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper(
+ GoogleURLTracker* tracker)
+ : GoogleURLTrackerNavigationHelper(tracker),
+ listening_for_nav_commit_(false),
+ listening_for_tab_destruction_(false) {
}
TestGoogleURLTrackerNavigationHelper::
~TestGoogleURLTrackerNavigationHelper() {
}
-void TestGoogleURLTrackerNavigationHelper::SetGoogleURLTracker(
- GoogleURLTracker* tracker) {
- tracker_ = tracker;
-}
-
void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit(
- const content::NavigationController* nav_controller,
bool listen) {
- if (listen)
- nav_controller_commit_listeners_.insert(nav_controller);
- else
- nav_controller_commit_listeners_.erase(nav_controller);
+ listening_for_nav_commit_ = listen;
}
-bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationCommit(
- const content::NavigationController* nav_controller) {
- return nav_controller_commit_listeners_.count(nav_controller) > 0;
+bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationCommit() {
+ return listening_for_nav_commit_;
}
void TestGoogleURLTrackerNavigationHelper::SetListeningForTabDestruction(
- const content::NavigationController* nav_controller,
bool listen) {
- if (listen)
- nav_controller_tab_close_listeners_.insert(nav_controller);
- else
- nav_controller_tab_close_listeners_.erase(nav_controller);
+ listening_for_tab_destruction_ = listen;
}
-bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction(
- const content::NavigationController* nav_controller) {
- return nav_controller_tab_close_listeners_.count(nav_controller) > 0;
+bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction() {
+ return listening_for_tab_destruction_;
}
} // namespace
@@ -250,6 +229,7 @@ class GoogleURLTrackerTest : public testing::Test {
void CloseTab(intptr_t unique_id);
GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id);
GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id);
+ GoogleURLTrackerNavigationHelper* GetNavigationHelper(intptr_t unique_id);
void ExpectDefaultURLs() const;
void ExpectListeningForCommit(intptr_t unique_id, bool listening);
bool observer_notified() const { return observer_.notified(); }
@@ -274,7 +254,9 @@ class GoogleURLTrackerTest : public testing::Test {
content::NotificationRegistrar registrar_;
TestNotificationObserver observer_;
GoogleURLTrackerClient* client_;
- GoogleURLTrackerNavigationHelper* nav_helper_;
+
Peter Kasting 2014/05/15 21:29:52 Nit: No blank line here
blundell 2014/05/16 11:54:18 Code removed. On 2014/05/15 21:29:52, Peter Kasti
+ // Owns created TestGoogleURLTrackerNavigationHelpers to avoid leakage.
+ ScopedVector<GoogleURLTrackerNavigationHelper> nav_helpers_;
TestingProfile profile_;
scoped_ptr<GoogleURLTracker> google_url_tracker_;
// This tracks the different "tabs" a test has "opened", so we can close them
@@ -312,15 +294,12 @@ GoogleURLTrackerTest::~GoogleURLTrackerTest() {
void GoogleURLTrackerTest::SetUp() {
network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
- // Ownership is passed to google_url_tracker_, but weak pointers are kept;
- // this is safe since GoogleURLTracker keeps these objects for its lifetime.
+ // Ownership is passed to google_url_tracker_, but a weak pointer is kept;
+ // this is safe since GoogleURLTracker keeps the client 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_, client.Pass(), nav_helper.Pass(),
- GoogleURLTracker::UNIT_TEST_MODE));
+ google_url_tracker_.reset(new GoogleURLTracker(
+ &profile_, client.Pass(), GoogleURLTracker::UNIT_TEST_MODE));
google_url_tracker_->infobar_creator_ = base::Bind(
&GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this));
}
@@ -387,9 +366,15 @@ void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id,
}
unique_ids_seen_.insert(unique_id);
if (client_->IsListeningForNavigationStart()) {
+ GoogleURLTrackerNavigationHelper* nav_helper =
+ GetNavigationHelper(unique_id);
+ if (!nav_helper) {
+ nav_helper =
+ new TestGoogleURLTrackerNavigationHelper(google_url_tracker_.get());
+ nav_helpers_.push_back(nav_helper);
+ }
google_url_tracker_->OnNavigationPending(
- reinterpret_cast<content::NavigationController*>(unique_id),
- reinterpret_cast<InfoBarService*>(unique_id), unique_id);
+ nav_helper, reinterpret_cast<InfoBarService*>(unique_id), unique_id);
}
}
@@ -415,8 +400,8 @@ void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) {
void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id,
const GURL& search_url) {
DCHECK(search_url.is_valid());
- if (nav_helper_->IsListeningForNavigationCommit(
- reinterpret_cast<content::NavigationController*>(unique_id))) {
+ if (GetNavigationHelper(unique_id) &&
Peter Kasting 2014/05/15 21:29:52 Nit: Factor GetNavigationHelper() calls out to a t
blundell 2014/05/16 11:54:18 Done.
+ GetNavigationHelper(unique_id)->IsListeningForNavigationCommit()) {
google_url_tracker_->OnNavigationCommitted(
reinterpret_cast<InfoBarService*>(unique_id), search_url);
}
@@ -424,10 +409,9 @@ void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id,
void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) {
unique_ids_seen_.erase(unique_id);
- content::NavigationController* nav_controller =
- reinterpret_cast<content::NavigationController*>(unique_id);
- if (nav_helper_->IsListeningForTabDestruction(nav_controller)) {
- google_url_tracker_->OnTabClosed(nav_controller);
+ if (GetNavigationHelper(unique_id) &&
Peter Kasting 2014/05/15 21:29:52 Nit: Factor GetNavigationHelper() calls out to a t
blundell 2014/05/16 11:54:18 Done.
+ GetNavigationHelper(unique_id)->IsListeningForTabDestruction()) {
+ google_url_tracker_->OnTabClosed(GetNavigationHelper(unique_id));
} else {
// Closing a tab with an infobar showing would close the infobar.
GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id);
@@ -450,6 +434,12 @@ GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate(
return map_entry ? map_entry->infobar_delegate() : NULL;
}
+GoogleURLTrackerNavigationHelper* GoogleURLTrackerTest::GetNavigationHelper(
+ intptr_t unique_id) {
+ GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
+ return map_entry ? map_entry->navigation_helper() : NULL;
+}
+
void GoogleURLTrackerTest::ExpectDefaultURLs() const {
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
EXPECT_EQ(GURL(), fetched_google_url());
@@ -459,8 +449,8 @@ void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id,
bool listening) {
GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
if (map_entry) {
- EXPECT_EQ(listening, nav_helper_->IsListeningForNavigationCommit(
- map_entry->navigation_controller()));
+ EXPECT_EQ(listening,
+ map_entry->navigation_helper()->IsListeningForNavigationCommit());
} else {
EXPECT_FALSE(listening);
}

Powered by Google App Engine
This is Rietveld 408576698