| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 class GoogleURLTrackerTest; | 25 class GoogleURLTrackerTest; |
| 26 | 26 |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // TestInfoBarDelegate -------------------------------------------------------- | 30 // TestInfoBarDelegate -------------------------------------------------------- |
| 31 | 31 |
| 32 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { | 32 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { |
| 33 public: | 33 public: |
| 34 // Creates a test delegate and returns it. Unlike the parent class, this does |
| 35 // not create add the infobar to |infobar_service|, since that "pointer" is |
| 36 // really just a magic number. Thus there is no InfoBarService ownership of |
| 37 // the returned object; and since the caller doesn't own the returned object, |
| 38 // we rely on |test_harness| cleaning this up eventually in |
| 39 // GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks. |
| 40 static GoogleURLTrackerInfoBarDelegate* Create( |
| 41 GoogleURLTrackerTest* test_harness, |
| 42 InfoBarService* infobar_service, |
| 43 GoogleURLTracker* google_url_tracker, |
| 44 const GURL& search_url); |
| 45 |
| 46 private: |
| 34 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, | 47 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, |
| 35 InfoBarService* infobar_service, | 48 InfoBarService* infobar_service, |
| 36 GoogleURLTracker* google_url_tracker, | 49 GoogleURLTracker* google_url_tracker, |
| 37 const GURL& search_url); | 50 const GURL& search_url); |
| 38 virtual ~TestInfoBarDelegate(); | 51 virtual ~TestInfoBarDelegate(); |
| 39 | 52 |
| 40 private: | |
| 41 // GoogleURLTrackerInfoBarDelegate: | 53 // GoogleURLTrackerInfoBarDelegate: |
| 42 virtual void Update(const GURL& search_url) OVERRIDE; | 54 virtual void Update(const GURL& search_url) OVERRIDE; |
| 43 virtual void Close(bool redo_search) OVERRIDE; | 55 virtual void Close(bool redo_search) OVERRIDE; |
| 44 | 56 |
| 45 GoogleURLTrackerTest* test_harness_; | 57 GoogleURLTrackerTest* test_harness_; |
| 46 InfoBarService* infobar_service_; | 58 InfoBarService* infobar_service_; |
| 47 | 59 |
| 48 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate); | 60 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate); |
| 49 }; | 61 }; |
| 50 | 62 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // make everything continue to work. | 111 // make everything continue to work. |
| 100 // | 112 // |
| 101 // Technically, the C++98 spec defines the result of casting | 113 // Technically, the C++98 spec defines the result of casting |
| 102 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what | 114 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what |
| 103 // we use here) is "implementation-defined". Since I've never seen a compiler | 115 // we use here) is "implementation-defined". Since I've never seen a compiler |
| 104 // break this, though, and the result would simply be a failing test rather than | 116 // break this, though, and the result would simply be a failing test rather than |
| 105 // a bug in Chrome, we'll use it anyway. | 117 // a bug in Chrome, we'll use it anyway. |
| 106 class GoogleURLTrackerTest : public testing::Test { | 118 class GoogleURLTrackerTest : public testing::Test { |
| 107 public: | 119 public: |
| 108 // Called by TestInfoBarDelegate::Close(). | 120 // Called by TestInfoBarDelegate::Close(). |
| 109 void OnInfoBarClosed(GoogleURLTrackerInfoBarDelegate* infobar, | 121 void OnInfoBarClosed(InfoBarDelegate* infobar, |
| 110 InfoBarService* infobar_service); | 122 InfoBarService* infobar_service); |
| 111 | 123 |
| 112 protected: | 124 protected: |
| 113 GoogleURLTrackerTest(); | 125 GoogleURLTrackerTest(); |
| 114 virtual ~GoogleURLTrackerTest(); | 126 virtual ~GoogleURLTrackerTest(); |
| 115 | 127 |
| 116 // testing::Test | 128 // testing::Test |
| 117 virtual void SetUp() OVERRIDE; | 129 virtual void SetUp() OVERRIDE; |
| 118 virtual void TearDown() OVERRIDE; | 130 virtual void TearDown() OVERRIDE; |
| 119 | 131 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 net::TestURLFetcherFactory fetcher_factory_; | 175 net::TestURLFetcherFactory fetcher_factory_; |
| 164 content::NotificationRegistrar registrar_; | 176 content::NotificationRegistrar registrar_; |
| 165 TestNotificationObserver observer_; | 177 TestNotificationObserver observer_; |
| 166 TestingProfile profile_; | 178 TestingProfile profile_; |
| 167 scoped_ptr<GoogleURLTracker> google_url_tracker_; | 179 scoped_ptr<GoogleURLTracker> google_url_tracker_; |
| 168 // This tracks the different "tabs" a test has "opened", so we can close them | 180 // This tracks the different "tabs" a test has "opened", so we can close them |
| 169 // properly before shutting down |google_url_tracker_|, which expects that. | 181 // properly before shutting down |google_url_tracker_|, which expects that. |
| 170 std::set<int> unique_ids_seen_; | 182 std::set<int> unique_ids_seen_; |
| 171 }; | 183 }; |
| 172 | 184 |
| 173 void GoogleURLTrackerTest::OnInfoBarClosed( | 185 void GoogleURLTrackerTest::OnInfoBarClosed(InfoBarDelegate* infobar, |
| 174 GoogleURLTrackerInfoBarDelegate* infobar, | 186 InfoBarService* infobar_service) { |
| 175 InfoBarService* infobar_service) { | |
| 176 // First, simulate the InfoBarService firing INFOBAR_REMOVED. | 187 // First, simulate the InfoBarService firing INFOBAR_REMOVED. |
| 177 InfoBarRemovedDetails removed_details(infobar, false); | 188 InfoBarRemovedDetails removed_details(infobar, false); |
| 178 GoogleURLTracker::EntryMap::const_iterator i = | 189 GoogleURLTracker::EntryMap::const_iterator i = |
| 179 google_url_tracker_->entry_map_.find(infobar_service); | 190 google_url_tracker_->entry_map_.find(infobar_service); |
| 180 ASSERT_FALSE(i == google_url_tracker_->entry_map_.end()); | 191 ASSERT_FALSE(i == google_url_tracker_->entry_map_.end()); |
| 181 GoogleURLTrackerMapEntry* map_entry = i->second; | 192 GoogleURLTrackerMapEntry* map_entry = i->second; |
| 182 ASSERT_EQ(infobar, map_entry->infobar()); | 193 ASSERT_EQ(infobar, map_entry->infobar()); |
| 183 map_entry->Observe(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 194 map_entry->Observe(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 184 content::Source<InfoBarService>(infobar_service), | 195 content::Source<InfoBarService>(infobar_service), |
| 185 content::Details<InfoBarRemovedDetails>(&removed_details)); | 196 content::Details<InfoBarRemovedDetails>(&removed_details)); |
| 186 | 197 |
| 187 // Second, simulate the infobar container closing the infobar in response. | 198 // Second, simulate the infobar container closing the infobar in response. |
| 188 infobar->InfoBarClosed(); | 199 delete infobar; |
| 189 } | 200 } |
| 190 | 201 |
| 191 GoogleURLTrackerTest::GoogleURLTrackerTest() | 202 GoogleURLTrackerTest::GoogleURLTrackerTest() |
| 192 : message_loop_(MessageLoop::TYPE_IO), | 203 : message_loop_(MessageLoop::TYPE_IO), |
| 193 io_thread_(content::BrowserThread::IO, &message_loop_) { | 204 io_thread_(content::BrowserThread::IO, &message_loop_) { |
| 194 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); | 205 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); |
| 195 } | 206 } |
| 196 | 207 |
| 197 GoogleURLTrackerTest::~GoogleURLTrackerTest() { | 208 GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
| 198 } | 209 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 map_entry->navigation_controller_source())); | 390 map_entry->navigation_controller_source())); |
| 380 } else { | 391 } else { |
| 381 EXPECT_FALSE(listening); | 392 EXPECT_FALSE(listening); |
| 382 } | 393 } |
| 383 } | 394 } |
| 384 | 395 |
| 385 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::CreateTestInfoBar( | 396 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::CreateTestInfoBar( |
| 386 InfoBarService* infobar_service, | 397 InfoBarService* infobar_service, |
| 387 GoogleURLTracker* google_url_tracker, | 398 GoogleURLTracker* google_url_tracker, |
| 388 const GURL& search_url) { | 399 const GURL& search_url) { |
| 389 return new TestInfoBarDelegate(this, infobar_service, google_url_tracker, | 400 return TestInfoBarDelegate::Create(this, infobar_service, google_url_tracker, |
| 390 search_url); | 401 search_url); |
| 391 } | 402 } |
| 392 | 403 |
| 393 | 404 |
| 394 // TestInfoBarDelegate -------------------------------------------------------- | 405 // TestInfoBarDelegate -------------------------------------------------------- |
| 395 | 406 |
| 396 namespace { | 407 namespace { |
| 397 | 408 |
| 409 // static |
| 410 GoogleURLTrackerInfoBarDelegate* TestInfoBarDelegate::Create( |
| 411 GoogleURLTrackerTest* test_harness, |
| 412 InfoBarService* infobar_service, |
| 413 GoogleURLTracker* google_url_tracker, |
| 414 const GURL& search_url) { |
| 415 return new TestInfoBarDelegate(test_harness, infobar_service, |
| 416 google_url_tracker, search_url); |
| 417 } |
| 418 |
| 398 TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, | 419 TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, |
| 399 InfoBarService* infobar_service, | 420 InfoBarService* infobar_service, |
| 400 GoogleURLTracker* google_url_tracker, | 421 GoogleURLTracker* google_url_tracker, |
| 401 const GURL& search_url) | 422 const GURL& search_url) |
| 402 : GoogleURLTrackerInfoBarDelegate(NULL, google_url_tracker, search_url), | 423 : GoogleURLTrackerInfoBarDelegate(NULL, google_url_tracker, search_url), |
| 403 test_harness_(test_harness), | 424 test_harness_(test_harness), |
| 404 infobar_service_(infobar_service) { | 425 infobar_service_(infobar_service) { |
| 405 } | 426 } |
| 406 | 427 |
| 407 TestInfoBarDelegate::~TestInfoBarDelegate() { | 428 TestInfoBarDelegate::~TestInfoBarDelegate() { |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 1050 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
| 1030 EXPECT_FALSE(GetInfoBar(1) == NULL); | 1051 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 1031 GoogleURLTrackerInfoBarDelegate* infobar2 = GetInfoBar(2); | 1052 GoogleURLTrackerInfoBarDelegate* infobar2 = GetInfoBar(2); |
| 1032 ASSERT_FALSE(infobar2 == NULL); | 1053 ASSERT_FALSE(infobar2 == NULL); |
| 1033 SetNavigationPending(1, true); | 1054 SetNavigationPending(1, true); |
| 1034 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1055 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 1035 infobar2->Close(false); | 1056 infobar2->Close(false); |
| 1036 SetNavigationPending(1, false); | 1057 SetNavigationPending(1, false); |
| 1037 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 1058 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 1038 } | 1059 } |
| OLD | NEW |