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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <map>
7 #include <set> 8 #include <set>
8 #include <string> 9 #include <string>
9 10
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/google/google_url_tracker_factory.h" 14 #include "chrome/browser/google/google_url_tracker_factory.h"
14 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" 15 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h"
15 #include "chrome/browser/google/google_url_tracker_navigation_helper.h" 16 #include "chrome/browser/google/google_url_tracker_navigation_helper.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 TestNotificationObserver::~TestNotificationObserver() { 88 TestNotificationObserver::~TestNotificationObserver() {
88 } 89 }
89 90
90 void TestNotificationObserver::Observe( 91 void TestNotificationObserver::Observe(
91 int type, 92 int type,
92 const content::NotificationSource& source, 93 const content::NotificationSource& source,
93 const content::NotificationDetails& details) { 94 const content::NotificationDetails& details) {
94 notified_ = true; 95 notified_ = true;
95 } 96 }
96 97
97
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.
98 // TestGoogleURLTrackerClient ------------------------------------------------- 98 // TestGoogleURLTrackerClient -------------------------------------------------
99 99
100 class TestGoogleURLTrackerClient : public GoogleURLTrackerClient { 100 class TestGoogleURLTrackerClient : public GoogleURLTrackerClient {
101 public: 101 public:
102 TestGoogleURLTrackerClient(); 102 TestGoogleURLTrackerClient();
103 virtual ~TestGoogleURLTrackerClient(); 103 virtual ~TestGoogleURLTrackerClient();
104 104
105 virtual void SetListeningForNavigationStart(bool listen) OVERRIDE; 105 virtual void SetListeningForNavigationStart(bool listen) OVERRIDE;
106 virtual bool IsListeningForNavigationStart() OVERRIDE; 106 virtual bool IsListeningForNavigationStart() OVERRIDE;
107 107
108 private: 108 private:
109 bool observe_nav_start_; 109 bool observe_nav_start_;
110 110
111 DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerClient); 111 DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerClient);
112 }; 112 };
113 113
114 TestGoogleURLTrackerClient::TestGoogleURLTrackerClient() 114 TestGoogleURLTrackerClient::TestGoogleURLTrackerClient()
115 : observe_nav_start_(false) { 115 : observe_nav_start_(false) {
116 } 116 }
117 117
118 TestGoogleURLTrackerClient::~TestGoogleURLTrackerClient() { 118 TestGoogleURLTrackerClient::~TestGoogleURLTrackerClient() {
119 } 119 }
120 120
121 void TestGoogleURLTrackerClient::SetListeningForNavigationStart( 121 void TestGoogleURLTrackerClient::SetListeningForNavigationStart(bool listen) {
122 bool listen) {
123 observe_nav_start_ = listen; 122 observe_nav_start_ = listen;
124 } 123 }
125 124
126 bool TestGoogleURLTrackerClient::IsListeningForNavigationStart() { 125 bool TestGoogleURLTrackerClient::IsListeningForNavigationStart() {
127 return observe_nav_start_; 126 return observe_nav_start_;
128 } 127 }
129 128
130 // TestGoogleURLTrackerNavigationHelper --------------------------------------- 129 // TestGoogleURLTrackerNavigationHelper ---------------------------------------
131 130
132 class TestGoogleURLTrackerNavigationHelper 131 class TestGoogleURLTrackerNavigationHelper
133 : public GoogleURLTrackerNavigationHelper { 132 : public GoogleURLTrackerNavigationHelper {
134 public: 133 public:
135 TestGoogleURLTrackerNavigationHelper(); 134 TestGoogleURLTrackerNavigationHelper(GoogleURLTracker* tracker);
Peter Kasting 2014/05/15 21:29:52 Nit: Explicit
blundell 2014/05/16 11:54:18 Done.
136 virtual ~TestGoogleURLTrackerNavigationHelper(); 135 virtual ~TestGoogleURLTrackerNavigationHelper();
137 136
138 virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE;
139 virtual void SetListeningForNavigationCommit( 137 virtual void SetListeningForNavigationCommit(
140 const content::NavigationController* nav_controller,
141 bool listen) OVERRIDE; 138 bool listen) OVERRIDE;
142 virtual bool IsListeningForNavigationCommit( 139 virtual bool IsListeningForNavigationCommit() OVERRIDE;
143 const content::NavigationController* nav_controller) OVERRIDE;
144 virtual void SetListeningForTabDestruction( 140 virtual void SetListeningForTabDestruction(
145 const content::NavigationController* nav_controller,
146 bool listen) OVERRIDE; 141 bool listen) OVERRIDE;
147 virtual bool IsListeningForTabDestruction( 142 virtual bool IsListeningForTabDestruction() OVERRIDE;
148 const content::NavigationController* nav_controller) OVERRIDE;
149 143
150 private: 144 private:
151 GoogleURLTracker* tracker_; 145 bool listening_for_nav_commit_;
152 std::set<const content::NavigationController*> 146 bool listening_for_tab_destruction_;
153 nav_controller_commit_listeners_;
154 std::set<const content::NavigationController*>
155 nav_controller_tab_close_listeners_;
156 }; 147 };
Peter Kasting 2014/05/15 21:29:52 Nit: While here: DISALLOW_COPY_AND_ASSIGN
blundell 2014/05/16 11:54:18 Done.
157 148
158 TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper() 149 TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper(
159 : tracker_(NULL) { 150 GoogleURLTracker* tracker)
151 : GoogleURLTrackerNavigationHelper(tracker),
152 listening_for_nav_commit_(false),
153 listening_for_tab_destruction_(false) {
160 } 154 }
161 155
162 TestGoogleURLTrackerNavigationHelper:: 156 TestGoogleURLTrackerNavigationHelper::
163 ~TestGoogleURLTrackerNavigationHelper() { 157 ~TestGoogleURLTrackerNavigationHelper() {
164 } 158 }
165 159
166 void TestGoogleURLTrackerNavigationHelper::SetGoogleURLTracker( 160 void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit(
167 GoogleURLTracker* tracker) { 161 bool listen) {
168 tracker_ = tracker; 162 listening_for_nav_commit_ = listen;
169 } 163 }
170 164
171 void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit( 165 bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationCommit() {
172 const content::NavigationController* nav_controller, 166 return listening_for_nav_commit_;
173 bool listen) {
174 if (listen)
175 nav_controller_commit_listeners_.insert(nav_controller);
176 else
177 nav_controller_commit_listeners_.erase(nav_controller);
178 }
179
180 bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationCommit(
181 const content::NavigationController* nav_controller) {
182 return nav_controller_commit_listeners_.count(nav_controller) > 0;
183 } 167 }
184 168
185 void TestGoogleURLTrackerNavigationHelper::SetListeningForTabDestruction( 169 void TestGoogleURLTrackerNavigationHelper::SetListeningForTabDestruction(
186 const content::NavigationController* nav_controller,
187 bool listen) { 170 bool listen) {
188 if (listen) 171 listening_for_tab_destruction_ = listen;
189 nav_controller_tab_close_listeners_.insert(nav_controller);
190 else
191 nav_controller_tab_close_listeners_.erase(nav_controller);
192 } 172 }
193 173
194 bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction( 174 bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction() {
195 const content::NavigationController* nav_controller) { 175 return listening_for_tab_destruction_;
196 return nav_controller_tab_close_listeners_.count(nav_controller) > 0;
197 } 176 }
198 177
199 } // namespace 178 } // namespace
200 179
201 180
202 // GoogleURLTrackerTest ------------------------------------------------------- 181 // GoogleURLTrackerTest -------------------------------------------------------
203 182
204 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more 183 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more
205 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions 184 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions
206 // are carefully written so that many of the functions which take 185 // are carefully written so that many of the functions which take
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 222 }
244 GURL google_url() const { return google_url_tracker_->google_url(); } 223 GURL google_url() const { return google_url_tracker_->google_url(); }
245 void SetLastPromptedGoogleURL(const GURL& url); 224 void SetLastPromptedGoogleURL(const GURL& url);
246 GURL GetLastPromptedGoogleURL(); 225 GURL GetLastPromptedGoogleURL();
247 void SetNavigationPending(intptr_t unique_id, bool is_search); 226 void SetNavigationPending(intptr_t unique_id, bool is_search);
248 void CommitNonSearch(intptr_t unique_id); 227 void CommitNonSearch(intptr_t unique_id);
249 void CommitSearch(intptr_t unique_id, const GURL& search_url); 228 void CommitSearch(intptr_t unique_id, const GURL& search_url);
250 void CloseTab(intptr_t unique_id); 229 void CloseTab(intptr_t unique_id);
251 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); 230 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id);
252 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id); 231 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id);
232 GoogleURLTrackerNavigationHelper* GetNavigationHelper(intptr_t unique_id);
253 void ExpectDefaultURLs() const; 233 void ExpectDefaultURLs() const;
254 void ExpectListeningForCommit(intptr_t unique_id, bool listening); 234 void ExpectListeningForCommit(intptr_t unique_id, bool listening);
255 bool observer_notified() const { return observer_.notified(); } 235 bool observer_notified() const { return observer_.notified(); }
256 void clear_observer_notified() { observer_.clear_notified(); } 236 void clear_observer_notified() { observer_.clear_notified(); }
257 237
258 private: 238 private:
259 // Since |infobar_service| is really a magic number rather than an actual 239 // Since |infobar_service| is really a magic number rather than an actual
260 // object, we don't add the created infobar to it. Instead we will simulate 240 // object, we don't add the created infobar to it. Instead we will simulate
261 // any helper<->infobar interaction necessary. The returned object will be 241 // any helper<->infobar interaction necessary. The returned object will be
262 // cleaned up in OnInfoBarClosed(). 242 // cleaned up in OnInfoBarClosed().
263 infobars::InfoBar* CreateTestInfoBar(InfoBarService* infobar_service, 243 infobars::InfoBar* CreateTestInfoBar(InfoBarService* infobar_service,
264 GoogleURLTracker* google_url_tracker, 244 GoogleURLTracker* google_url_tracker,
265 const GURL& search_url); 245 const GURL& search_url);
266 246
267 // These are required by the TestURLFetchers GoogleURLTracker will create (see 247 // These are required by the TestURLFetchers GoogleURLTracker will create (see
268 // test_url_fetcher_factory.h). 248 // test_url_fetcher_factory.h).
269 content::TestBrowserThreadBundle thread_bundle_; 249 content::TestBrowserThreadBundle thread_bundle_;
270 // Creating this allows us to call 250 // Creating this allows us to call
271 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). 251 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests().
272 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 252 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
273 net::TestURLFetcherFactory fetcher_factory_; 253 net::TestURLFetcherFactory fetcher_factory_;
274 content::NotificationRegistrar registrar_; 254 content::NotificationRegistrar registrar_;
275 TestNotificationObserver observer_; 255 TestNotificationObserver observer_;
276 GoogleURLTrackerClient* client_; 256 GoogleURLTrackerClient* client_;
277 GoogleURLTrackerNavigationHelper* nav_helper_; 257
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
258 // Owns created TestGoogleURLTrackerNavigationHelpers to avoid leakage.
259 ScopedVector<GoogleURLTrackerNavigationHelper> nav_helpers_;
278 TestingProfile profile_; 260 TestingProfile profile_;
279 scoped_ptr<GoogleURLTracker> google_url_tracker_; 261 scoped_ptr<GoogleURLTracker> google_url_tracker_;
280 // This tracks the different "tabs" a test has "opened", so we can close them 262 // This tracks the different "tabs" a test has "opened", so we can close them
281 // properly before shutting down |google_url_tracker_|, which expects that. 263 // properly before shutting down |google_url_tracker_|, which expects that.
282 std::set<int> unique_ids_seen_; 264 std::set<int> unique_ids_seen_;
283 }; 265 };
284 266
285 void GoogleURLTrackerTest::OnInfoBarClosed( 267 void GoogleURLTrackerTest::OnInfoBarClosed(
286 scoped_ptr<infobars::InfoBar> infobar, 268 scoped_ptr<infobars::InfoBar> infobar,
287 InfoBarService* infobar_service) { 269 InfoBarService* infobar_service) {
(...skipping 17 matching lines...) Expand all
305 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 287 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
306 GoogleURLTrackerFactory::GetInstance()-> 288 GoogleURLTrackerFactory::GetInstance()->
307 RegisterUserPrefsOnBrowserContextForTest(&profile_); 289 RegisterUserPrefsOnBrowserContextForTest(&profile_);
308 } 290 }
309 291
310 GoogleURLTrackerTest::~GoogleURLTrackerTest() { 292 GoogleURLTrackerTest::~GoogleURLTrackerTest() {
311 } 293 }
312 294
313 void GoogleURLTrackerTest::SetUp() { 295 void GoogleURLTrackerTest::SetUp() {
314 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); 296 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
315 // Ownership is passed to google_url_tracker_, but weak pointers are kept; 297 // Ownership is passed to google_url_tracker_, but a weak pointer is kept;
316 // this is safe since GoogleURLTracker keeps these objects for its lifetime. 298 // this is safe since GoogleURLTracker keeps the client for its lifetime.
317 client_ = new TestGoogleURLTrackerClient(); 299 client_ = new TestGoogleURLTrackerClient();
318 nav_helper_ = new TestGoogleURLTrackerNavigationHelper();
319 scoped_ptr<GoogleURLTrackerClient> client(client_); 300 scoped_ptr<GoogleURLTrackerClient> client(client_);
320 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(nav_helper_); 301 google_url_tracker_.reset(new GoogleURLTracker(
321 google_url_tracker_.reset( 302 &profile_, client.Pass(), GoogleURLTracker::UNIT_TEST_MODE));
322 new GoogleURLTracker(&profile_, client.Pass(), nav_helper.Pass(),
323 GoogleURLTracker::UNIT_TEST_MODE));
324 google_url_tracker_->infobar_creator_ = base::Bind( 303 google_url_tracker_->infobar_creator_ = base::Bind(
325 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this)); 304 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this));
326 } 305 }
327 306
328 void GoogleURLTrackerTest::TearDown() { 307 void GoogleURLTrackerTest::TearDown() {
329 while (!unique_ids_seen_.empty()) 308 while (!unique_ids_seen_.empty())
330 CloseTab(*unique_ids_seen_.begin()); 309 CloseTab(*unique_ids_seen_.begin());
331 } 310 }
332 311
333 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { 312 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 359
381 void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id, 360 void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id,
382 bool is_search) { 361 bool is_search) {
383 if (is_search) { 362 if (is_search) {
384 google_url_tracker_->SearchCommitted(); 363 google_url_tracker_->SearchCommitted();
385 // Note that the call above might not have actually registered a listener 364 // Note that the call above might not have actually registered a listener
386 // for navigation starts if the searchdomaincheck response was bogus. 365 // for navigation starts if the searchdomaincheck response was bogus.
387 } 366 }
388 unique_ids_seen_.insert(unique_id); 367 unique_ids_seen_.insert(unique_id);
389 if (client_->IsListeningForNavigationStart()) { 368 if (client_->IsListeningForNavigationStart()) {
369 GoogleURLTrackerNavigationHelper* nav_helper =
370 GetNavigationHelper(unique_id);
371 if (!nav_helper) {
372 nav_helper =
373 new TestGoogleURLTrackerNavigationHelper(google_url_tracker_.get());
374 nav_helpers_.push_back(nav_helper);
375 }
390 google_url_tracker_->OnNavigationPending( 376 google_url_tracker_->OnNavigationPending(
391 reinterpret_cast<content::NavigationController*>(unique_id), 377 nav_helper, reinterpret_cast<InfoBarService*>(unique_id), unique_id);
392 reinterpret_cast<InfoBarService*>(unique_id), unique_id);
393 } 378 }
394 } 379 }
395 380
396 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { 381 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) {
397 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); 382 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
398 if (!map_entry) 383 if (!map_entry)
399 return; 384 return;
400 385
401 ExpectListeningForCommit(unique_id, false); 386 ExpectListeningForCommit(unique_id, false);
402 387
403 // The infobar should be showing; otherwise the pending non-search should 388 // The infobar should be showing; otherwise the pending non-search should
404 // have closed it. 389 // have closed it.
405 ASSERT_TRUE(map_entry->has_infobar_delegate()); 390 ASSERT_TRUE(map_entry->has_infobar_delegate());
406 391
407 // The pending_id should have been reset to 0 when the non-search became 392 // The pending_id should have been reset to 0 when the non-search became
408 // pending. 393 // pending.
409 EXPECT_EQ(0, map_entry->infobar_delegate()->pending_id()); 394 EXPECT_EQ(0, map_entry->infobar_delegate()->pending_id());
410 395
411 // Committing the navigation would close the infobar. 396 // Committing the navigation would close the infobar.
412 map_entry->infobar_delegate()->Close(false); 397 map_entry->infobar_delegate()->Close(false);
413 } 398 }
414 399
415 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, 400 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id,
416 const GURL& search_url) { 401 const GURL& search_url) {
417 DCHECK(search_url.is_valid()); 402 DCHECK(search_url.is_valid());
418 if (nav_helper_->IsListeningForNavigationCommit( 403 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.
419 reinterpret_cast<content::NavigationController*>(unique_id))) { 404 GetNavigationHelper(unique_id)->IsListeningForNavigationCommit()) {
420 google_url_tracker_->OnNavigationCommitted( 405 google_url_tracker_->OnNavigationCommitted(
421 reinterpret_cast<InfoBarService*>(unique_id), search_url); 406 reinterpret_cast<InfoBarService*>(unique_id), search_url);
422 } 407 }
423 } 408 }
424 409
425 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) { 410 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) {
426 unique_ids_seen_.erase(unique_id); 411 unique_ids_seen_.erase(unique_id);
427 content::NavigationController* nav_controller = 412 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.
428 reinterpret_cast<content::NavigationController*>(unique_id); 413 GetNavigationHelper(unique_id)->IsListeningForTabDestruction()) {
429 if (nav_helper_->IsListeningForTabDestruction(nav_controller)) { 414 google_url_tracker_->OnTabClosed(GetNavigationHelper(unique_id));
430 google_url_tracker_->OnTabClosed(nav_controller);
431 } else { 415 } else {
432 // Closing a tab with an infobar showing would close the infobar. 416 // Closing a tab with an infobar showing would close the infobar.
433 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id); 417 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id);
434 if (delegate) 418 if (delegate)
435 delegate->Close(false); 419 delegate->Close(false);
436 } 420 }
437 } 421 }
438 422
439 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry( 423 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry(
440 intptr_t unique_id) { 424 intptr_t unique_id) {
441 GoogleURLTracker::EntryMap::const_iterator i = 425 GoogleURLTracker::EntryMap::const_iterator i =
442 google_url_tracker_->entry_map_.find( 426 google_url_tracker_->entry_map_.find(
443 reinterpret_cast<InfoBarService*>(unique_id)); 427 reinterpret_cast<InfoBarService*>(unique_id));
444 return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second; 428 return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second;
445 } 429 }
446 430
447 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate( 431 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate(
448 intptr_t unique_id) { 432 intptr_t unique_id) {
449 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); 433 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
450 return map_entry ? map_entry->infobar_delegate() : NULL; 434 return map_entry ? map_entry->infobar_delegate() : NULL;
451 } 435 }
452 436
437 GoogleURLTrackerNavigationHelper* GoogleURLTrackerTest::GetNavigationHelper(
438 intptr_t unique_id) {
439 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
440 return map_entry ? map_entry->navigation_helper() : NULL;
441 }
442
453 void GoogleURLTrackerTest::ExpectDefaultURLs() const { 443 void GoogleURLTrackerTest::ExpectDefaultURLs() const {
454 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 444 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
455 EXPECT_EQ(GURL(), fetched_google_url()); 445 EXPECT_EQ(GURL(), fetched_google_url());
456 } 446 }
457 447
458 void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id, 448 void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id,
459 bool listening) { 449 bool listening) {
460 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); 450 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
461 if (map_entry) { 451 if (map_entry) {
462 EXPECT_EQ(listening, nav_helper_->IsListeningForNavigationCommit( 452 EXPECT_EQ(listening,
463 map_entry->navigation_controller())); 453 map_entry->navigation_helper()->IsListeningForNavigationCommit());
464 } else { 454 } else {
465 EXPECT_FALSE(listening); 455 EXPECT_FALSE(listening);
466 } 456 }
467 } 457 }
468 458
469 infobars::InfoBar* GoogleURLTrackerTest::CreateTestInfoBar( 459 infobars::InfoBar* GoogleURLTrackerTest::CreateTestInfoBar(
470 InfoBarService* infobar_service, 460 InfoBarService* infobar_service,
471 GoogleURLTracker* google_url_tracker, 461 GoogleURLTracker* google_url_tracker,
472 const GURL& search_url) { 462 const GURL& search_url) {
473 return TestInfoBarDelegate::Create(this, infobar_service, google_url_tracker, 463 return TestInfoBarDelegate::Create(this, infobar_service, google_url_tracker,
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); 1086 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2"));
1097 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); 1087 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL);
1098 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); 1088 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2);
1099 ASSERT_FALSE(delegate2 == NULL); 1089 ASSERT_FALSE(delegate2 == NULL);
1100 SetNavigationPending(1, true); 1090 SetNavigationPending(1, true);
1101 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); 1091 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true));
1102 delegate2->Close(false); 1092 delegate2->Close(false);
1103 SetNavigationPending(1, false); 1093 SetNavigationPending(1, false);
1104 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); 1094 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false));
1105 } 1095 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698