| 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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 class GoogleURLTrackerTest; | 27 class GoogleURLTrackerTest; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // TestInfoBarDelegate -------------------------------------------------------- | 31 // TestInfoBarDelegate -------------------------------------------------------- |
| 32 | 32 |
| 33 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { | 33 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { |
| 34 public: | 34 public: |
| 35 // Creates a test infobar and delegate and returns the infobar. Unlike the | 35 // Creates a test infobar and delegate and returns the infobar. Unlike the |
| 36 // parent class, this does not add the infobar to |infobar_service|, since | 36 // parent class, this does not add the infobar to |infobar_manager|, since |
| 37 // that "pointer" is really just a magic number. Thus there is no | 37 // that "pointer" is really just a magic number. Thus there is no |
| 38 // InfoBarService ownership of the returned object; and since the caller | 38 // InfoBarManager ownership of the returned object; and since the caller |
| 39 // doesn't own the returned object, we rely on |test_harness| cleaning this up | 39 // doesn't own the returned object, we rely on |test_harness| cleaning this |
| 40 // eventually in GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks. | 40 // up eventually in GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks. |
| 41 static infobars::InfoBar* Create(GoogleURLTrackerTest* test_harness, | 41 static infobars::InfoBar* Create( |
| 42 InfoBarService* infobar_service, | 42 GoogleURLTrackerTest* test_harness, |
| 43 GoogleURLTracker* google_url_tracker, | 43 infobars::InfoBarManager* infobar_manager, |
| 44 const GURL& search_url); | 44 GoogleURLTracker* google_url_tracker, |
| 45 const GURL& search_url); |
| 45 | 46 |
| 46 private: | 47 private: |
| 47 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, | 48 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, |
| 48 InfoBarService* infobar_service, | 49 infobars::InfoBarManager* infobar_manager, |
| 49 GoogleURLTracker* google_url_tracker, | 50 GoogleURLTracker* google_url_tracker, |
| 50 const GURL& search_url); | 51 const GURL& search_url); |
| 51 virtual ~TestInfoBarDelegate(); | 52 virtual ~TestInfoBarDelegate(); |
| 52 | 53 |
| 53 // GoogleURLTrackerInfoBarDelegate: | 54 // GoogleURLTrackerInfoBarDelegate: |
| 54 virtual void Update(const GURL& search_url) OVERRIDE; | 55 virtual void Update(const GURL& search_url) OVERRIDE; |
| 55 virtual void Close(bool redo_search) OVERRIDE; | 56 virtual void Close(bool redo_search) OVERRIDE; |
| 56 | 57 |
| 57 GoogleURLTrackerTest* test_harness_; | 58 GoogleURLTrackerTest* test_harness_; |
| 58 InfoBarService* infobar_service_; | 59 infobars::InfoBarManager* infobar_manager_; |
| 59 | 60 |
| 60 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate); | 61 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate); |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 // The member function definitions come after the declaration of | 64 // The member function definitions come after the declaration of |
| 64 // GoogleURLTrackerTest, so they can call members on it. | 65 // GoogleURLTrackerTest, so they can call members on it. |
| 65 | 66 |
| 66 | 67 |
| 67 // TestCallbackListener --------------------------------------------------- | 68 // TestCallbackListener --------------------------------------------------- |
| 68 | 69 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 class TestGoogleURLTrackerNavigationHelper | 144 class TestGoogleURLTrackerNavigationHelper |
| 144 : public GoogleURLTrackerNavigationHelper { | 145 : public GoogleURLTrackerNavigationHelper { |
| 145 public: | 146 public: |
| 146 explicit TestGoogleURLTrackerNavigationHelper(GoogleURLTracker* tracker); | 147 explicit TestGoogleURLTrackerNavigationHelper(GoogleURLTracker* tracker); |
| 147 virtual ~TestGoogleURLTrackerNavigationHelper(); | 148 virtual ~TestGoogleURLTrackerNavigationHelper(); |
| 148 | 149 |
| 149 virtual void SetListeningForNavigationCommit(bool listen) OVERRIDE; | 150 virtual void SetListeningForNavigationCommit(bool listen) OVERRIDE; |
| 150 virtual bool IsListeningForNavigationCommit() OVERRIDE; | 151 virtual bool IsListeningForNavigationCommit() OVERRIDE; |
| 151 virtual void SetListeningForTabDestruction(bool listen) OVERRIDE; | 152 virtual void SetListeningForTabDestruction(bool listen) OVERRIDE; |
| 152 virtual bool IsListeningForTabDestruction() OVERRIDE; | 153 virtual bool IsListeningForTabDestruction() OVERRIDE; |
| 154 virtual void OpenURL(GURL url, |
| 155 WindowOpenDisposition disposition, |
| 156 bool user_clicked_on_link) OVERRIDE; |
| 153 | 157 |
| 154 private: | 158 private: |
| 155 bool listening_for_nav_commit_; | 159 bool listening_for_nav_commit_; |
| 156 bool listening_for_tab_destruction_; | 160 bool listening_for_tab_destruction_; |
| 157 | 161 |
| 158 DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerNavigationHelper); | 162 DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerNavigationHelper); |
| 159 }; | 163 }; |
| 160 | 164 |
| 161 TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper( | 165 TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper( |
| 162 GoogleURLTracker* tracker) | 166 GoogleURLTracker* tracker) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 179 | 183 |
| 180 void TestGoogleURLTrackerNavigationHelper::SetListeningForTabDestruction( | 184 void TestGoogleURLTrackerNavigationHelper::SetListeningForTabDestruction( |
| 181 bool listen) { | 185 bool listen) { |
| 182 listening_for_tab_destruction_ = listen; | 186 listening_for_tab_destruction_ = listen; |
| 183 } | 187 } |
| 184 | 188 |
| 185 bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction() { | 189 bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction() { |
| 186 return listening_for_tab_destruction_; | 190 return listening_for_tab_destruction_; |
| 187 } | 191 } |
| 188 | 192 |
| 193 void TestGoogleURLTrackerNavigationHelper::OpenURL( |
| 194 GURL url, |
| 195 WindowOpenDisposition disposition, |
| 196 bool user_clicked_on_link) { |
| 197 } |
| 198 |
| 189 } // namespace | 199 } // namespace |
| 190 | 200 |
| 191 | 201 |
| 192 // GoogleURLTrackerTest ------------------------------------------------------- | 202 // GoogleURLTrackerTest ------------------------------------------------------- |
| 193 | 203 |
| 194 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more | 204 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more |
| 195 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions | 205 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions |
| 196 // are carefully written so that many of the functions which take | 206 // are carefully written so that many of the functions which take |
| 197 // NavigationController* or InfoBarService* do not actually dereference the | 207 // NavigationController* or infobars::InfoBarManager* do not actually |
| 208 // dereference the |
| 198 // objects, merely use them for comparisons and lookups, e.g. in |entry_map_|. | 209 // objects, merely use them for comparisons and lookups, e.g. in |entry_map_|. |
| 199 // This then allows the test code here to not create any of these objects, and | 210 // This then allows the test code here to not create any of these objects, and |
| 200 // instead supply "pointers" that are actually reinterpret_cast<>()ed magic | 211 // instead supply "pointers" that are actually reinterpret_cast<>()ed magic |
| 201 // numbers. Then we write the necessary stubs/hooks, here and in | 212 // numbers. Then we write the necessary stubs/hooks, here and in |
| 202 // TestInfoBarDelegate above, to make everything continue to work. | 213 // TestInfoBarDelegate above, to make everything continue to work. |
| 203 // | 214 // |
| 204 // Technically, the C++98 spec defines the result of casting | 215 // Technically, the C++98 spec defines the result of casting |
| 205 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what | 216 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what |
| 206 // we use here) is "implementation-defined". Since I've never seen a compiler | 217 // we use here) is "implementation-defined". Since I've never seen a compiler |
| 207 // break this, though, and the result would simply be a failing test rather than | 218 // break this, though, and the result would simply be a failing test rather than |
| 208 // a bug in Chrome, we'll use it anyway. | 219 // a bug in Chrome, we'll use it anyway. |
| 209 class GoogleURLTrackerTest : public testing::Test { | 220 class GoogleURLTrackerTest : public testing::Test { |
| 210 public: | 221 public: |
| 211 // Called by TestInfoBarDelegate::Close(). | 222 // Called by TestInfoBarDelegate::Close(). |
| 212 void OnInfoBarClosed(scoped_ptr<infobars::InfoBar> infobar, | 223 void OnInfoBarClosed(scoped_ptr<infobars::InfoBar> infobar, |
| 213 InfoBarService* infobar_service); | 224 infobars::InfoBarManager* infobar_manager); |
| 214 | 225 |
| 215 protected: | 226 protected: |
| 216 GoogleURLTrackerTest(); | 227 GoogleURLTrackerTest(); |
| 217 virtual ~GoogleURLTrackerTest(); | 228 virtual ~GoogleURLTrackerTest(); |
| 218 | 229 |
| 219 // testing::Test | 230 // testing::Test |
| 220 virtual void SetUp() OVERRIDE; | 231 virtual void SetUp() OVERRIDE; |
| 221 virtual void TearDown() OVERRIDE; | 232 virtual void TearDown() OVERRIDE; |
| 222 | 233 |
| 223 net::TestURLFetcher* GetFetcher(); | 234 net::TestURLFetcher* GetFetcher(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 240 void CloseTab(intptr_t unique_id); | 251 void CloseTab(intptr_t unique_id); |
| 241 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); | 252 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); |
| 242 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id); | 253 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id); |
| 243 GoogleURLTrackerNavigationHelper* GetNavigationHelper(intptr_t unique_id); | 254 GoogleURLTrackerNavigationHelper* GetNavigationHelper(intptr_t unique_id); |
| 244 void ExpectDefaultURLs() const; | 255 void ExpectDefaultURLs() const; |
| 245 void ExpectListeningForCommit(intptr_t unique_id, bool listening); | 256 void ExpectListeningForCommit(intptr_t unique_id, bool listening); |
| 246 bool listener_notified() const { return listener_.notified(); } | 257 bool listener_notified() const { return listener_.notified(); } |
| 247 void clear_listener_notified() { listener_.clear_notified(); } | 258 void clear_listener_notified() { listener_.clear_notified(); } |
| 248 | 259 |
| 249 private: | 260 private: |
| 250 // Since |infobar_service| is really a magic number rather than an actual | 261 // Since |infobar_manager| is really a magic number rather than an actual |
| 251 // object, we don't add the created infobar to it. Instead we will simulate | 262 // object, we don't add the created infobar to it. Instead we will simulate |
| 252 // any helper<->infobar interaction necessary. The returned object will be | 263 // any helper<->infobar interaction necessary. The returned object will be |
| 253 // cleaned up in OnInfoBarClosed(). | 264 // cleaned up in OnInfoBarClosed(). |
| 254 infobars::InfoBar* CreateTestInfoBar(InfoBarService* infobar_service, | 265 infobars::InfoBar* CreateTestInfoBar( |
| 255 GoogleURLTracker* google_url_tracker, | 266 infobars::InfoBarManager* infobar_manager, |
| 256 const GURL& search_url); | 267 GoogleURLTracker* google_url_tracker, |
| 268 const GURL& search_url); |
| 257 | 269 |
| 258 // These are required by the TestURLFetchers GoogleURLTracker will create (see | 270 // These are required by the TestURLFetchers GoogleURLTracker will create (see |
| 259 // test_url_fetcher_factory.h). | 271 // test_url_fetcher_factory.h). |
| 260 content::TestBrowserThreadBundle thread_bundle_; | 272 content::TestBrowserThreadBundle thread_bundle_; |
| 261 // Creating this allows us to call | 273 // Creating this allows us to call |
| 262 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). | 274 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). |
| 263 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 275 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 264 net::TestURLFetcherFactory fetcher_factory_; | 276 net::TestURLFetcherFactory fetcher_factory_; |
| 265 GoogleURLTrackerClient* client_; | 277 GoogleURLTrackerClient* client_; |
| 266 TestingProfile profile_; | 278 TestingProfile profile_; |
| 267 scoped_ptr<GoogleURLTracker> google_url_tracker_; | 279 scoped_ptr<GoogleURLTracker> google_url_tracker_; |
| 268 TestCallbackListener listener_; | 280 TestCallbackListener listener_; |
| 269 // This tracks the different "tabs" a test has "opened", so we can close them | 281 // This tracks the different "tabs" a test has "opened", so we can close them |
| 270 // properly before shutting down |google_url_tracker_|, which expects that. | 282 // properly before shutting down |google_url_tracker_|, which expects that. |
| 271 std::set<int> unique_ids_seen_; | 283 std::set<int> unique_ids_seen_; |
| 272 }; | 284 }; |
| 273 | 285 |
| 274 void GoogleURLTrackerTest::OnInfoBarClosed( | 286 void GoogleURLTrackerTest::OnInfoBarClosed( |
| 275 scoped_ptr<infobars::InfoBar> infobar, | 287 scoped_ptr<infobars::InfoBar> infobar, |
| 276 InfoBarService* infobar_service) { | 288 infobars::InfoBarManager* infobar_manager) { |
| 277 // First, simulate the InfoBarService firing INFOBAR_REMOVED. | 289 // First, simulate the InfoBarManager firing INFOBAR_REMOVED. |
| 290 // TODO(droger): Replace this flow with a call to the observer method once |
| 291 // the map entry is observing InfoBarManager. crbug.com/373243 |
| 278 infobars::InfoBar::RemovedDetails removed_details(infobar.get(), false); | 292 infobars::InfoBar::RemovedDetails removed_details(infobar.get(), false); |
| 279 GoogleURLTracker::EntryMap::const_iterator i = | 293 GoogleURLTracker::EntryMap::const_iterator i = |
| 280 google_url_tracker_->entry_map_.find(infobar_service); | 294 google_url_tracker_->entry_map_.find(infobar_manager); |
| 281 ASSERT_FALSE(i == google_url_tracker_->entry_map_.end()); | 295 ASSERT_FALSE(i == google_url_tracker_->entry_map_.end()); |
| 282 GoogleURLTrackerMapEntry* map_entry = i->second; | 296 GoogleURLTrackerMapEntry* map_entry = i->second; |
| 283 ASSERT_EQ(infobar->delegate(), map_entry->infobar_delegate()); | 297 ASSERT_EQ(infobar->delegate(), map_entry->infobar_delegate()); |
| 284 map_entry->Observe( | 298 map_entry->Observe( |
| 285 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 299 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 286 content::Source<InfoBarService>(infobar_service), | 300 content::Source<infobars::InfoBarManager>(infobar_manager), |
| 287 content::Details<infobars::InfoBar::RemovedDetails>(&removed_details)); | 301 content::Details<infobars::InfoBar::RemovedDetails>(&removed_details)); |
| 288 | 302 |
| 289 // Second, simulate the infobar container closing the infobar in response. | 303 // Second, simulate the infobar container closing the infobar in response. |
| 290 // This happens automatically as |infobar| goes out of scope. | 304 // This happens automatically as |infobar| goes out of scope. |
| 291 } | 305 } |
| 292 | 306 |
| 293 GoogleURLTrackerTest::GoogleURLTrackerTest() | 307 GoogleURLTrackerTest::GoogleURLTrackerTest() |
| 294 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 308 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 295 GoogleURLTrackerFactory::GetInstance()-> | 309 GoogleURLTrackerFactory::GetInstance()-> |
| 296 RegisterUserPrefsOnBrowserContextForTest(&profile_); | 310 RegisterUserPrefsOnBrowserContextForTest(&profile_); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 google_url_tracker_->SearchCommitted(); | 381 google_url_tracker_->SearchCommitted(); |
| 368 // Note that the call above might not have actually registered a listener | 382 // Note that the call above might not have actually registered a listener |
| 369 // for navigation starts if the searchdomaincheck response was bogus. | 383 // for navigation starts if the searchdomaincheck response was bogus. |
| 370 } | 384 } |
| 371 unique_ids_seen_.insert(unique_id); | 385 unique_ids_seen_.insert(unique_id); |
| 372 if (client_->IsListeningForNavigationStart()) { | 386 if (client_->IsListeningForNavigationStart()) { |
| 373 google_url_tracker_->OnNavigationPending( | 387 google_url_tracker_->OnNavigationPending( |
| 374 scoped_ptr<GoogleURLTrackerNavigationHelper>( | 388 scoped_ptr<GoogleURLTrackerNavigationHelper>( |
| 375 new TestGoogleURLTrackerNavigationHelper( | 389 new TestGoogleURLTrackerNavigationHelper( |
| 376 google_url_tracker_.get())), | 390 google_url_tracker_.get())), |
| 377 reinterpret_cast<InfoBarService*>(unique_id), | 391 reinterpret_cast<infobars::InfoBarManager*>(unique_id), |
| 378 unique_id); | 392 unique_id); |
| 379 } | 393 } |
| 380 } | 394 } |
| 381 | 395 |
| 382 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { | 396 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { |
| 383 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); | 397 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
| 384 if (!map_entry) | 398 if (!map_entry) |
| 385 return; | 399 return; |
| 386 | 400 |
| 387 ExpectListeningForCommit(unique_id, false); | 401 ExpectListeningForCommit(unique_id, false); |
| 388 | 402 |
| 389 // The infobar should be showing; otherwise the pending non-search should | 403 // The infobar should be showing; otherwise the pending non-search should |
| 390 // have closed it. | 404 // have closed it. |
| 391 ASSERT_TRUE(map_entry->has_infobar_delegate()); | 405 ASSERT_TRUE(map_entry->has_infobar_delegate()); |
| 392 | 406 |
| 393 // The pending_id should have been reset to 0 when the non-search became | 407 // The pending_id should have been reset to 0 when the non-search became |
| 394 // pending. | 408 // pending. |
| 395 EXPECT_EQ(0, map_entry->infobar_delegate()->pending_id()); | 409 EXPECT_EQ(0, map_entry->infobar_delegate()->pending_id()); |
| 396 | 410 |
| 397 // Committing the navigation would close the infobar. | 411 // Committing the navigation would close the infobar. |
| 398 map_entry->infobar_delegate()->Close(false); | 412 map_entry->infobar_delegate()->Close(false); |
| 399 } | 413 } |
| 400 | 414 |
| 401 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, | 415 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, |
| 402 const GURL& search_url) { | 416 const GURL& search_url) { |
| 403 DCHECK(search_url.is_valid()); | 417 DCHECK(search_url.is_valid()); |
| 404 GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id); | 418 GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id); |
| 405 if (nav_helper && nav_helper->IsListeningForNavigationCommit()) { | 419 if (nav_helper && nav_helper->IsListeningForNavigationCommit()) { |
| 406 google_url_tracker_->OnNavigationCommitted( | 420 google_url_tracker_->OnNavigationCommitted( |
| 407 reinterpret_cast<InfoBarService*>(unique_id), search_url); | 421 reinterpret_cast<infobars::InfoBarManager*>(unique_id), search_url); |
| 408 } | 422 } |
| 409 } | 423 } |
| 410 | 424 |
| 411 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) { | 425 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) { |
| 412 unique_ids_seen_.erase(unique_id); | 426 unique_ids_seen_.erase(unique_id); |
| 413 GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id); | 427 GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id); |
| 414 if (nav_helper && nav_helper->IsListeningForTabDestruction()) { | 428 if (nav_helper && nav_helper->IsListeningForTabDestruction()) { |
| 415 google_url_tracker_->OnTabClosed(nav_helper); | 429 google_url_tracker_->OnTabClosed(nav_helper); |
| 416 } else { | 430 } else { |
| 417 // Closing a tab with an infobar showing would close the infobar. | 431 // Closing a tab with an infobar showing would close the infobar. |
| 418 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id); | 432 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id); |
| 419 if (delegate) | 433 if (delegate) |
| 420 delegate->Close(false); | 434 delegate->Close(false); |
| 421 } | 435 } |
| 422 } | 436 } |
| 423 | 437 |
| 424 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry( | 438 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry( |
| 425 intptr_t unique_id) { | 439 intptr_t unique_id) { |
| 426 GoogleURLTracker::EntryMap::const_iterator i = | 440 GoogleURLTracker::EntryMap::const_iterator i = |
| 427 google_url_tracker_->entry_map_.find( | 441 google_url_tracker_->entry_map_.find( |
| 428 reinterpret_cast<InfoBarService*>(unique_id)); | 442 reinterpret_cast<infobars::InfoBarManager*>(unique_id)); |
| 429 return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second; | 443 return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second; |
| 430 } | 444 } |
| 431 | 445 |
| 432 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate( | 446 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate( |
| 433 intptr_t unique_id) { | 447 intptr_t unique_id) { |
| 434 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); | 448 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
| 435 return map_entry ? map_entry->infobar_delegate() : NULL; | 449 return map_entry ? map_entry->infobar_delegate() : NULL; |
| 436 } | 450 } |
| 437 | 451 |
| 438 GoogleURLTrackerNavigationHelper* GoogleURLTrackerTest::GetNavigationHelper( | 452 GoogleURLTrackerNavigationHelper* GoogleURLTrackerTest::GetNavigationHelper( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 451 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); | 465 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
| 452 if (map_entry) { | 466 if (map_entry) { |
| 453 EXPECT_EQ(listening, | 467 EXPECT_EQ(listening, |
| 454 map_entry->navigation_helper()->IsListeningForNavigationCommit()); | 468 map_entry->navigation_helper()->IsListeningForNavigationCommit()); |
| 455 } else { | 469 } else { |
| 456 EXPECT_FALSE(listening); | 470 EXPECT_FALSE(listening); |
| 457 } | 471 } |
| 458 } | 472 } |
| 459 | 473 |
| 460 infobars::InfoBar* GoogleURLTrackerTest::CreateTestInfoBar( | 474 infobars::InfoBar* GoogleURLTrackerTest::CreateTestInfoBar( |
| 461 InfoBarService* infobar_service, | 475 infobars::InfoBarManager* infobar_manager, |
| 462 GoogleURLTracker* google_url_tracker, | 476 GoogleURLTracker* google_url_tracker, |
| 463 const GURL& search_url) { | 477 const GURL& search_url) { |
| 464 return TestInfoBarDelegate::Create(this, infobar_service, google_url_tracker, | 478 return TestInfoBarDelegate::Create( |
| 465 search_url); | 479 this, infobar_manager, google_url_tracker, search_url); |
| 466 } | 480 } |
| 467 | 481 |
| 468 | 482 |
| 469 // TestInfoBarDelegate -------------------------------------------------------- | 483 // TestInfoBarDelegate -------------------------------------------------------- |
| 470 | 484 |
| 471 namespace { | 485 namespace { |
| 472 | 486 |
| 473 // static | 487 // static |
| 474 infobars::InfoBar* TestInfoBarDelegate::Create( | 488 infobars::InfoBar* TestInfoBarDelegate::Create( |
| 475 GoogleURLTrackerTest* test_harness, | 489 GoogleURLTrackerTest* test_harness, |
| 476 InfoBarService* infobar_service, | 490 infobars::InfoBarManager* infobar_manager, |
| 477 GoogleURLTracker* google_url_tracker, | 491 GoogleURLTracker* google_url_tracker, |
| 478 const GURL& search_url) { | 492 const GURL& search_url) { |
| 479 return ConfirmInfoBarDelegate::CreateInfoBar( | 493 return ConfirmInfoBarDelegate::CreateInfoBar( |
| 480 scoped_ptr<ConfirmInfoBarDelegate>(new TestInfoBarDelegate( | 494 scoped_ptr<ConfirmInfoBarDelegate>(new TestInfoBarDelegate( |
| 481 test_harness, infobar_service, google_url_tracker, | 495 test_harness, |
| 496 infobar_manager, |
| 497 google_url_tracker, |
| 482 search_url))).release(); | 498 search_url))).release(); |
| 483 } | 499 } |
| 484 | 500 |
| 485 TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, | 501 TestInfoBarDelegate::TestInfoBarDelegate( |
| 486 InfoBarService* infobar_service, | 502 GoogleURLTrackerTest* test_harness, |
| 487 GoogleURLTracker* google_url_tracker, | 503 infobars::InfoBarManager* infobar_manager, |
| 488 const GURL& search_url) | 504 GoogleURLTracker* google_url_tracker, |
| 489 : GoogleURLTrackerInfoBarDelegate(google_url_tracker, search_url), | 505 const GURL& search_url) |
| 490 test_harness_(test_harness), | 506 : GoogleURLTrackerInfoBarDelegate(google_url_tracker, |
| 491 infobar_service_(infobar_service) { | 507 search_url), |
| 508 test_harness_(test_harness), |
| 509 infobar_manager_(infobar_manager) { |
| 492 } | 510 } |
| 493 | 511 |
| 494 TestInfoBarDelegate::~TestInfoBarDelegate() { | 512 TestInfoBarDelegate::~TestInfoBarDelegate() { |
| 495 } | 513 } |
| 496 | 514 |
| 497 void TestInfoBarDelegate::Update(const GURL& search_url) { | 515 void TestInfoBarDelegate::Update(const GURL& search_url) { |
| 498 set_search_url(search_url); | 516 set_search_url(search_url); |
| 499 set_pending_id(0); | 517 set_pending_id(0); |
| 500 } | 518 } |
| 501 | 519 |
| 502 void TestInfoBarDelegate::Close(bool redo_search) { | 520 void TestInfoBarDelegate::Close(bool redo_search) { |
| 503 test_harness_->OnInfoBarClosed(scoped_ptr<infobars::InfoBar>(infobar()), | 521 test_harness_->OnInfoBarClosed(scoped_ptr<infobars::InfoBar>(infobar()), |
| 504 infobar_service_); | 522 infobar_manager_); |
| 505 // WARNING: At this point |this| has been deleted! | 523 // WARNING: At this point |this| has been deleted! |
| 506 } | 524 } |
| 507 | 525 |
| 508 } // namespace | 526 } // namespace |
| 509 | 527 |
| 510 | 528 |
| 511 // Tests ---------------------------------------------------------------------- | 529 // Tests ---------------------------------------------------------------------- |
| 512 | 530 |
| 513 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 531 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
| 514 ExpectDefaultURLs(); | 532 ExpectDefaultURLs(); |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 1105 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
| 1088 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | 1106 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
| 1089 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); | 1107 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); |
| 1090 ASSERT_FALSE(delegate2 == NULL); | 1108 ASSERT_FALSE(delegate2 == NULL); |
| 1091 SetNavigationPending(1, true); | 1109 SetNavigationPending(1, true); |
| 1092 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1110 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 1093 delegate2->Close(false); | 1111 delegate2->Close(false); |
| 1094 SetNavigationPending(1, false); | 1112 SetNavigationPending(1, false); |
| 1095 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 1113 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 1096 } | 1114 } |
| OLD | NEW |