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