| 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 d62eaa6ef7d66dcf5c5741cc1cbca3b06650f77e..6b2fedf80f4973e100919f6b575e168c3f55f8eb 100644
|
| --- a/chrome/browser/google/google_url_tracker_unittest.cc
|
| +++ b/chrome/browser/google/google_url_tracker_unittest.cc
|
| @@ -137,53 +137,73 @@
|
| return observe_nav_start_;
|
| }
|
|
|
| -
|
| // TestGoogleURLTrackerNavigationHelper ---------------------------------------
|
|
|
| class TestGoogleURLTrackerNavigationHelper
|
| : public GoogleURLTrackerNavigationHelper {
|
| public:
|
| - explicit TestGoogleURLTrackerNavigationHelper(GoogleURLTracker* tracker);
|
| + TestGoogleURLTrackerNavigationHelper();
|
| virtual ~TestGoogleURLTrackerNavigationHelper();
|
|
|
| - virtual void SetListeningForNavigationCommit(bool listen) OVERRIDE;
|
| - virtual bool IsListeningForNavigationCommit() OVERRIDE;
|
| - virtual void SetListeningForTabDestruction(bool listen) OVERRIDE;
|
| - virtual bool IsListeningForTabDestruction() OVERRIDE;
|
| + 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 void SetListeningForTabDestruction(
|
| + const content::NavigationController* nav_controller,
|
| + bool listen) OVERRIDE;
|
| + virtual bool IsListeningForTabDestruction(
|
| + const content::NavigationController* nav_controller) OVERRIDE;
|
|
|
| private:
|
| - bool listening_for_nav_commit_;
|
| - bool listening_for_tab_destruction_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerNavigationHelper);
|
| + GoogleURLTracker* tracker_;
|
| + std::set<const content::NavigationController*>
|
| + nav_controller_commit_listeners_;
|
| + std::set<const content::NavigationController*>
|
| + nav_controller_tab_close_listeners_;
|
| };
|
|
|
| -TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper(
|
| - GoogleURLTracker* tracker)
|
| - : GoogleURLTrackerNavigationHelper(tracker),
|
| - listening_for_nav_commit_(false),
|
| - listening_for_tab_destruction_(false) {
|
| -}
|
| -
|
| -TestGoogleURLTrackerNavigationHelper::~TestGoogleURLTrackerNavigationHelper() {
|
| +TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper()
|
| + : tracker_(NULL) {
|
| +}
|
| +
|
| +TestGoogleURLTrackerNavigationHelper::
|
| + ~TestGoogleURLTrackerNavigationHelper() {
|
| +}
|
| +
|
| +void TestGoogleURLTrackerNavigationHelper::SetGoogleURLTracker(
|
| + GoogleURLTracker* tracker) {
|
| + tracker_ = tracker;
|
| }
|
|
|
| void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit(
|
| + const content::NavigationController* nav_controller,
|
| bool listen) {
|
| - listening_for_nav_commit_ = listen;
|
| -}
|
| -
|
| -bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationCommit() {
|
| - return listening_for_nav_commit_;
|
| + if (listen)
|
| + nav_controller_commit_listeners_.insert(nav_controller);
|
| + else
|
| + nav_controller_commit_listeners_.erase(nav_controller);
|
| +}
|
| +
|
| +bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationCommit(
|
| + const content::NavigationController* nav_controller) {
|
| + return nav_controller_commit_listeners_.count(nav_controller) > 0;
|
| }
|
|
|
| void TestGoogleURLTrackerNavigationHelper::SetListeningForTabDestruction(
|
| + const content::NavigationController* nav_controller,
|
| bool listen) {
|
| - listening_for_tab_destruction_ = listen;
|
| -}
|
| -
|
| -bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction() {
|
| - return listening_for_tab_destruction_;
|
| + if (listen)
|
| + nav_controller_tab_close_listeners_.insert(nav_controller);
|
| + else
|
| + nav_controller_tab_close_listeners_.erase(nav_controller);
|
| +}
|
| +
|
| +bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction(
|
| + const content::NavigationController* nav_controller) {
|
| + return nav_controller_tab_close_listeners_.count(nav_controller) > 0;
|
| }
|
|
|
| } // namespace
|
| @@ -240,7 +260,6 @@
|
| 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 listener_notified() const { return listener_.notified(); }
|
| @@ -263,6 +282,7 @@
|
| scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
|
| net::TestURLFetcherFactory fetcher_factory_;
|
| GoogleURLTrackerClient* client_;
|
| + GoogleURLTrackerNavigationHelper* nav_helper_;
|
| TestingProfile profile_;
|
| scoped_ptr<GoogleURLTracker> google_url_tracker_;
|
| TestCallbackListener listener_;
|
| @@ -301,12 +321,17 @@
|
|
|
| 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 client 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_);
|
| - google_url_tracker_.reset(new GoogleURLTracker(
|
| - &profile_, client.Pass(), GoogleURLTracker::UNIT_TEST_MODE));
|
| + 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_->infobar_creator_ = base::Bind(
|
| &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this));
|
| }
|
| @@ -370,11 +395,8 @@
|
| unique_ids_seen_.insert(unique_id);
|
| if (client_->IsListeningForNavigationStart()) {
|
| google_url_tracker_->OnNavigationPending(
|
| - scoped_ptr<GoogleURLTrackerNavigationHelper>(
|
| - new TestGoogleURLTrackerNavigationHelper(
|
| - google_url_tracker_.get())),
|
| - reinterpret_cast<InfoBarService*>(unique_id),
|
| - unique_id);
|
| + reinterpret_cast<content::NavigationController*>(unique_id),
|
| + reinterpret_cast<InfoBarService*>(unique_id), unique_id);
|
| }
|
| }
|
|
|
| @@ -400,8 +422,8 @@
|
| void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id,
|
| const GURL& search_url) {
|
| DCHECK(search_url.is_valid());
|
| - GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id);
|
| - if (nav_helper && nav_helper->IsListeningForNavigationCommit()) {
|
| + if (nav_helper_->IsListeningForNavigationCommit(
|
| + reinterpret_cast<content::NavigationController*>(unique_id))) {
|
| google_url_tracker_->OnNavigationCommitted(
|
| reinterpret_cast<InfoBarService*>(unique_id), search_url);
|
| }
|
| @@ -409,9 +431,10 @@
|
|
|
| void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) {
|
| unique_ids_seen_.erase(unique_id);
|
| - GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id);
|
| - if (nav_helper && nav_helper->IsListeningForTabDestruction()) {
|
| - google_url_tracker_->OnTabClosed(nav_helper);
|
| + content::NavigationController* nav_controller =
|
| + reinterpret_cast<content::NavigationController*>(unique_id);
|
| + if (nav_helper_->IsListeningForTabDestruction(nav_controller)) {
|
| + google_url_tracker_->OnTabClosed(nav_controller);
|
| } else {
|
| // Closing a tab with an infobar showing would close the infobar.
|
| GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id);
|
| @@ -434,12 +457,6 @@
|
| 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());
|
| @@ -449,8 +466,8 @@
|
| bool listening) {
|
| GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
|
| if (map_entry) {
|
| - EXPECT_EQ(listening,
|
| - map_entry->navigation_helper()->IsListeningForNavigationCommit());
|
| + EXPECT_EQ(listening, nav_helper_->IsListeningForNavigationCommit(
|
| + map_entry->navigation_controller()));
|
| } else {
|
| EXPECT_FALSE(listening);
|
| }
|
|
|