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

Side by Side Diff: chrome/browser/google/google_url_tracker_unittest.cc

Issue 290453005: Remove Infobars notifications from GoogleURLTrackerMapEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: format 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
« no previous file with comments | « chrome/browser/google/google_url_tracker_map_entry.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/containers/scoped_ptr_hash_map.h"
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"
17 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
17 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
18 #include "components/google/core/browser/google_url_tracker_client.h" 21 #include "components/google/core/browser/google_url_tracker_client.h"
19 #include "components/infobars/core/infobar.h" 22 #include "components/infobars/core/infobar.h"
20 #include "components/infobars/core/infobar_delegate.h" 23 #include "components/infobars/core/infobar_delegate.h"
24 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
22 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "net/url_request/test_url_fetcher_factory.h" 27 #include "net/url_request/test_url_fetcher_factory.h"
24 #include "net/url_request/url_fetcher.h" 28 #include "net/url_request/url_fetcher.h"
25 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
26 30
27 class GoogleURLTrackerTest; 31 class GoogleURLTrackerTest;
28 32
29 namespace { 33 namespace {
30 34
31 // TestInfoBarDelegate -------------------------------------------------------- 35 // TestInfoBarDelegate --------------------------------------------------------
32 36
33 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { 37 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate {
34 public: 38 public:
35 // Creates a test infobar and delegate and returns the infobar. Unlike the 39 // 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 40 // parent class, this does not add the infobar to |infobar_service|.
37 // that "pointer" is really just a magic number. Thus there is no 41 // Thus there is no InfoBarService ownership of the returned object; and since
38 // InfoBarService ownership of the returned object; and since the caller 42 // the caller doesn't own the returned object, we rely on |test_harness|
blundell 2014/05/26 15:45:36 Add a TODO(blundell) in here to simplify this test
39 // doesn't own the returned object, we rely on |test_harness| cleaning this up 43 // cleaning this up eventually in GoogleURLTrackerTest::OnInfoBarClosed() to
40 // eventually in GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks. 44 // avoid leaks.
41 static infobars::InfoBar* Create(GoogleURLTrackerTest* test_harness, 45 static infobars::InfoBar* Create(GoogleURLTrackerTest* test_harness,
42 InfoBarService* infobar_service, 46 InfoBarService* infobar_service,
43 GoogleURLTracker* google_url_tracker, 47 GoogleURLTracker* google_url_tracker,
44 const GURL& search_url); 48 const GURL& search_url);
45 49
46 private: 50 private:
47 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, 51 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness,
48 InfoBarService* infobar_service, 52 InfoBarService* infobar_service,
49 GoogleURLTracker* google_url_tracker, 53 GoogleURLTracker* google_url_tracker,
50 const GURL& search_url); 54 const GURL& search_url);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 211 }
208 212
209 } // namespace 213 } // namespace
210 214
211 215
212 // GoogleURLTrackerTest ------------------------------------------------------- 216 // GoogleURLTrackerTest -------------------------------------------------------
213 217
214 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more 218 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more
215 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions 219 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions
216 // are carefully written so that many of the functions which take 220 // are carefully written so that many of the functions which take
217 // NavigationController* or InfoBarService* do not actually dereference the 221 // NavigationController* do not actually dereference the objects, merely use
218 // objects, merely use them for comparisons and lookups, e.g. in |entry_map_|. 222 // them for comparisons and lookups, e.g. in |entry_map_|.
219 // This then allows the test code here to not create any of these objects, and 223 // This then allows the test code here to not create any of these objects, and
220 // instead supply "pointers" that are actually reinterpret_cast<>()ed magic 224 // instead supply "pointers" that are actually reinterpret_cast<>()ed magic
221 // numbers. Then we write the necessary stubs/hooks, here and in 225 // numbers. Then we write the necessary stubs/hooks, here and in
222 // TestInfoBarDelegate above, to make everything continue to work. 226 // TestInfoBarDelegate above, to make everything continue to work.
223 // 227 //
224 // Technically, the C++98 spec defines the result of casting 228 // Technically, the C++98 spec defines the result of casting
225 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what 229 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what
226 // we use here) is "implementation-defined". Since I've never seen a compiler 230 // we use here) is "implementation-defined". Since I've never seen a compiler
227 // break this, though, and the result would simply be a failing test rather than 231 // break this, though, and the result would simply be a failing test rather than
228 // a bug in Chrome, we'll use it anyway. 232 // a bug in Chrome, we'll use it anyway.
229 class GoogleURLTrackerTest : public testing::Test { 233 class GoogleURLTrackerTest : public ChromeRenderViewHostTestHarness {
230 public: 234 public:
231 // Called by TestInfoBarDelegate::Close(). 235 // Called by TestInfoBarDelegate::Close().
232 void OnInfoBarClosed(scoped_ptr<infobars::InfoBar> infobar, 236 void OnInfoBarClosed(scoped_ptr<infobars::InfoBar> infobar,
233 InfoBarService* infobar_service); 237 InfoBarService* infobar_service);
234 238
235 protected: 239 protected:
236 GoogleURLTrackerTest(); 240 GoogleURLTrackerTest();
237 virtual ~GoogleURLTrackerTest(); 241 virtual ~GoogleURLTrackerTest();
238 242
239 // testing::Test 243 // testing::Test
(...skipping 19 matching lines...) Expand all
259 void CommitSearch(intptr_t unique_id, const GURL& search_url); 263 void CommitSearch(intptr_t unique_id, const GURL& search_url);
260 void CloseTab(intptr_t unique_id); 264 void CloseTab(intptr_t unique_id);
261 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); 265 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id);
262 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id); 266 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id);
263 void ExpectDefaultURLs() const; 267 void ExpectDefaultURLs() const;
264 void ExpectListeningForCommit(intptr_t unique_id, bool listening); 268 void ExpectListeningForCommit(intptr_t unique_id, bool listening);
265 bool listener_notified() const { return listener_.notified(); } 269 bool listener_notified() const { return listener_.notified(); }
266 void clear_listener_notified() { listener_.clear_notified(); } 270 void clear_listener_notified() { listener_.clear_notified(); }
267 271
268 private: 272 private:
269 // Since |infobar_service| is really a magic number rather than an actual 273 // Infobars are not added to |infobar_service|. Instead we will simulate any
270 // object, we don't add the created infobar to it. Instead we will simulate 274 // helper<->infobar interaction necessary. The returned object will be
271 // any helper<->infobar interaction necessary. The returned object will be
272 // cleaned up in OnInfoBarClosed(). 275 // cleaned up in OnInfoBarClosed().
273 infobars::InfoBar* CreateTestInfoBar(InfoBarService* infobar_service, 276 infobars::InfoBar* CreateTestInfoBar(InfoBarService* infobar_service,
274 GoogleURLTracker* google_url_tracker, 277 GoogleURLTracker* google_url_tracker,
275 const GURL& search_url); 278 const GURL& search_url);
276 279
277 // These are required by the TestURLFetchers GoogleURLTracker will create (see 280 // Gets the infobar service indexed by |unique_id|.
278 // test_url_fetcher_factory.h). 281 // Lazily creates WebContents instances, adds them in |web_contents_| and
279 content::TestBrowserThreadBundle thread_bundle_; 282 // attaches InfoBarServices to them.
283 InfoBarService* GetInfoBarService(intptr_t unique_id);
284
280 // Creating this allows us to call 285 // Creating this allows us to call
281 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). 286 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests().
282 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 287 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
283 net::TestURLFetcherFactory fetcher_factory_; 288 net::TestURLFetcherFactory fetcher_factory_;
284 GoogleURLTrackerClient* client_; 289 GoogleURLTrackerClient* client_;
285 GoogleURLTrackerNavigationHelper* nav_helper_; 290 GoogleURLTrackerNavigationHelper* nav_helper_;
286 TestingProfile profile_;
287 scoped_ptr<GoogleURLTracker> google_url_tracker_; 291 scoped_ptr<GoogleURLTracker> google_url_tracker_;
288 TestCallbackListener listener_; 292 TestCallbackListener listener_;
293 base::ScopedPtrHashMap<intptr_t, content::WebContents> web_contents_;
289 // This tracks the different "tabs" a test has "opened", so we can close them 294 // This tracks the different "tabs" a test has "opened", so we can close them
290 // properly before shutting down |google_url_tracker_|, which expects that. 295 // properly before shutting down |google_url_tracker_|, which expects that.
291 std::set<int> unique_ids_seen_; 296 std::set<int> unique_ids_seen_;
292 }; 297 };
293 298
294 void GoogleURLTrackerTest::OnInfoBarClosed( 299 void GoogleURLTrackerTest::OnInfoBarClosed(
295 scoped_ptr<infobars::InfoBar> infobar, 300 scoped_ptr<infobars::InfoBar> infobar,
296 InfoBarService* infobar_service) { 301 InfoBarService* infobar_service) {
297 // First, simulate the InfoBarService firing INFOBAR_REMOVED. 302 // First, simulate the InfoBarService firing OnInfoBarRemoved().
298 infobars::InfoBar::RemovedDetails removed_details(infobar.get(), false);
299 GoogleURLTracker::EntryMap::const_iterator i = 303 GoogleURLTracker::EntryMap::const_iterator i =
300 google_url_tracker_->entry_map_.find(infobar_service); 304 google_url_tracker_->entry_map_.find(infobar_service);
301 ASSERT_FALSE(i == google_url_tracker_->entry_map_.end()); 305 ASSERT_FALSE(i == google_url_tracker_->entry_map_.end());
302 GoogleURLTrackerMapEntry* map_entry = i->second; 306 GoogleURLTrackerMapEntry* map_entry = i->second;
303 ASSERT_EQ(infobar->delegate(), map_entry->infobar_delegate()); 307 ASSERT_EQ(infobar->delegate(), map_entry->infobar_delegate());
304 map_entry->Observe( 308 map_entry->OnInfoBarRemoved(infobar.get(), false);
305 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
306 content::Source<InfoBarService>(infobar_service),
307 content::Details<infobars::InfoBar::RemovedDetails>(&removed_details));
308 309
309 // Second, simulate the infobar container closing the infobar in response. 310 // Second, simulate the infobar container closing the infobar in response.
310 // This happens automatically as |infobar| goes out of scope. 311 // This happens automatically as |infobar| goes out of scope.
311 } 312 }
312 313
313 GoogleURLTrackerTest::GoogleURLTrackerTest() 314 GoogleURLTrackerTest::GoogleURLTrackerTest() {
314 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 315 ChromeRenderViewHostTestHarness::SetUp();
315 GoogleURLTrackerFactory::GetInstance()-> 316 GoogleURLTrackerFactory::GetInstance()
316 RegisterUserPrefsOnBrowserContextForTest(&profile_); 317 ->RegisterUserPrefsOnBrowserContextForTest(profile());
317 } 318 }
318 319
319 GoogleURLTrackerTest::~GoogleURLTrackerTest() { 320 GoogleURLTrackerTest::~GoogleURLTrackerTest() {
321 ChromeRenderViewHostTestHarness::TearDown();
320 } 322 }
321 323
322 void GoogleURLTrackerTest::SetUp() { 324 void GoogleURLTrackerTest::SetUp() {
323 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); 325 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
324 // Ownership is passed to google_url_tracker_, but weak pointers are kept; 326 // Ownership is passed to google_url_tracker_, but weak pointers are kept;
325 // this is safe since GoogleURLTracker keeps these objects for its lifetime. 327 // this is safe since GoogleURLTracker keeps these objects for its lifetime.
326 client_ = new TestGoogleURLTrackerClient(); 328 client_ = new TestGoogleURLTrackerClient();
327 nav_helper_ = new TestGoogleURLTrackerNavigationHelper(); 329 nav_helper_ = new TestGoogleURLTrackerNavigationHelper();
328 scoped_ptr<GoogleURLTrackerClient> client(client_); 330 scoped_ptr<GoogleURLTrackerClient> client(client_);
329 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(nav_helper_); 331 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(nav_helper_);
330 google_url_tracker_.reset( 332 google_url_tracker_.reset(
331 new GoogleURLTracker(&profile_, 333 new GoogleURLTracker(profile(),
332 client.Pass(), 334 client.Pass(),
333 nav_helper.Pass(), 335 nav_helper.Pass(),
334 GoogleURLTracker::UNIT_TEST_MODE)); 336 GoogleURLTracker::UNIT_TEST_MODE));
335 google_url_tracker_->infobar_creator_ = base::Bind( 337 google_url_tracker_->infobar_creator_ = base::Bind(
336 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this)); 338 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this));
337 } 339 }
338 340
339 void GoogleURLTrackerTest::TearDown() { 341 void GoogleURLTrackerTest::TearDown() {
340 while (!unique_ids_seen_.empty()) 342 while (!unique_ids_seen_.empty())
341 CloseTab(*unique_ids_seen_.begin()); 343 CloseTab(*unique_ids_seen_.begin());
344 web_contents_.clear();
342 } 345 }
343 346
344 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { 347 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() {
345 // This will return the last fetcher created. If no fetchers have been 348 // This will return the last fetcher created. If no fetchers have been
346 // created, we'll pass GetFetcherByID() "-1", and it will return NULL. 349 // created, we'll pass GetFetcherByID() "-1", and it will return NULL.
347 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1); 350 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1);
348 } 351 }
349 352
350 void GoogleURLTrackerTest::MockSearchDomainCheckResponse( 353 void GoogleURLTrackerTest::MockSearchDomainCheckResponse(
351 const std::string& domain) { 354 const std::string& domain) {
(...skipping 19 matching lines...) Expand all
371 } 374 }
372 375
373 void GoogleURLTrackerTest::NotifyIPAddressChanged() { 376 void GoogleURLTrackerTest::NotifyIPAddressChanged() {
374 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 377 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
375 // For thread safety, the NCN queues tasks to do the actual notifications, so 378 // For thread safety, the NCN queues tasks to do the actual notifications, so
376 // we need to spin the message loop so the tracker will actually be notified. 379 // we need to spin the message loop so the tracker will actually be notified.
377 base::MessageLoop::current()->RunUntilIdle(); 380 base::MessageLoop::current()->RunUntilIdle();
378 } 381 }
379 382
380 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { 383 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) {
381 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); 384 profile()->GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec());
382 } 385 }
383 386
384 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { 387 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() {
385 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); 388 return GURL(profile()->GetPrefs()->GetString(prefs::kLastPromptedGoogleURL));
386 } 389 }
387 390
388 void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id, 391 void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id,
389 bool is_search) { 392 bool is_search) {
390 if (is_search) { 393 if (is_search) {
391 google_url_tracker_->SearchCommitted(); 394 google_url_tracker_->SearchCommitted();
392 // Note that the call above might not have actually registered a listener 395 // Note that the call above might not have actually registered a listener
393 // for navigation starts if the searchdomaincheck response was bogus. 396 // for navigation starts if the searchdomaincheck response was bogus.
394 } 397 }
395 unique_ids_seen_.insert(unique_id); 398 unique_ids_seen_.insert(unique_id);
396 if (client_->IsListeningForNavigationStart()) { 399 if (client_->IsListeningForNavigationStart()) {
397 google_url_tracker_->OnNavigationPending( 400 google_url_tracker_->OnNavigationPending(
398 reinterpret_cast<content::NavigationController*>(unique_id), 401 reinterpret_cast<content::NavigationController*>(unique_id),
399 reinterpret_cast<InfoBarService*>(unique_id), unique_id); 402 GetInfoBarService(unique_id), unique_id);
400 } 403 }
401 } 404 }
402 405
403 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { 406 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) {
404 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); 407 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
405 if (!map_entry) 408 if (!map_entry)
406 return; 409 return;
407 410
408 ExpectListeningForCommit(unique_id, false); 411 ExpectListeningForCommit(unique_id, false);
409 412
410 // The infobar should be showing; otherwise the pending non-search should 413 // The infobar should be showing; otherwise the pending non-search should
411 // have closed it. 414 // have closed it.
412 ASSERT_TRUE(map_entry->has_infobar_delegate()); 415 ASSERT_TRUE(map_entry->has_infobar_delegate());
413 416
414 // The pending_id should have been reset to 0 when the non-search became 417 // The pending_id should have been reset to 0 when the non-search became
415 // pending. 418 // pending.
416 EXPECT_EQ(0, map_entry->infobar_delegate()->pending_id()); 419 EXPECT_EQ(0, map_entry->infobar_delegate()->pending_id());
417 420
418 // Committing the navigation would close the infobar. 421 // Committing the navigation would close the infobar.
419 map_entry->infobar_delegate()->Close(false); 422 map_entry->infobar_delegate()->Close(false);
420 } 423 }
421 424
422 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, 425 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id,
423 const GURL& search_url) { 426 const GURL& search_url) {
424 DCHECK(search_url.is_valid()); 427 DCHECK(search_url.is_valid());
425 if (nav_helper_->IsListeningForNavigationCommit( 428 if (nav_helper_->IsListeningForNavigationCommit(
426 reinterpret_cast<content::NavigationController*>(unique_id))) { 429 reinterpret_cast<content::NavigationController*>(unique_id))) {
427 google_url_tracker_->OnNavigationCommitted( 430 google_url_tracker_->OnNavigationCommitted(GetInfoBarService(unique_id),
428 reinterpret_cast<InfoBarService*>(unique_id), search_url); 431 search_url);
429 } 432 }
430 } 433 }
431 434
432 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) { 435 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) {
433 unique_ids_seen_.erase(unique_id); 436 unique_ids_seen_.erase(unique_id);
434 content::NavigationController* nav_controller = 437 content::NavigationController* nav_controller =
435 reinterpret_cast<content::NavigationController*>(unique_id); 438 reinterpret_cast<content::NavigationController*>(unique_id);
436 if (nav_helper_->IsListeningForTabDestruction(nav_controller)) { 439 if (nav_helper_->IsListeningForTabDestruction(nav_controller)) {
437 google_url_tracker_->OnTabClosed(nav_controller); 440 google_url_tracker_->OnTabClosed(nav_controller);
438 } else { 441 } else {
439 // Closing a tab with an infobar showing would close the infobar. 442 // Closing a tab with an infobar showing would close the infobar.
440 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id); 443 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id);
441 if (delegate) 444 if (delegate)
442 delegate->Close(false); 445 delegate->Close(false);
443 } 446 }
444 } 447 }
445 448
446 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry( 449 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry(
447 intptr_t unique_id) { 450 intptr_t unique_id) {
448 GoogleURLTracker::EntryMap::const_iterator i = 451 GoogleURLTracker::EntryMap::const_iterator i =
449 google_url_tracker_->entry_map_.find( 452 google_url_tracker_->entry_map_.find(GetInfoBarService(unique_id));
450 reinterpret_cast<InfoBarService*>(unique_id));
451 return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second; 453 return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second;
452 } 454 }
453 455
454 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate( 456 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate(
455 intptr_t unique_id) { 457 intptr_t unique_id) {
456 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); 458 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
457 return map_entry ? map_entry->infobar_delegate() : NULL; 459 return map_entry ? map_entry->infobar_delegate() : NULL;
458 } 460 }
459 461
460 void GoogleURLTrackerTest::ExpectDefaultURLs() const { 462 void GoogleURLTrackerTest::ExpectDefaultURLs() const {
(...skipping 13 matching lines...) Expand all
474 } 476 }
475 477
476 infobars::InfoBar* GoogleURLTrackerTest::CreateTestInfoBar( 478 infobars::InfoBar* GoogleURLTrackerTest::CreateTestInfoBar(
477 InfoBarService* infobar_service, 479 InfoBarService* infobar_service,
478 GoogleURLTracker* google_url_tracker, 480 GoogleURLTracker* google_url_tracker,
479 const GURL& search_url) { 481 const GURL& search_url) {
480 return TestInfoBarDelegate::Create(this, infobar_service, google_url_tracker, 482 return TestInfoBarDelegate::Create(this, infobar_service, google_url_tracker,
481 search_url); 483 search_url);
482 } 484 }
483 485
486 InfoBarService* GoogleURLTrackerTest::GetInfoBarService(intptr_t unique_id) {
487 base::ScopedPtrHashMap<intptr_t, content::WebContents>::const_iterator it =
488 web_contents_.find(unique_id);
blundell 2014/05/26 15:45:36 nit: I would call this web_contents_map_.
droger 2014/05/26 15:55:30 Done.
489
490 if (it == web_contents_.end()) {
491 // Lazily create an InfoBarService for |unique_id|.
492 scoped_ptr<content::WebContents> web_contents(CreateTestWebContents());
493 InfoBarService::CreateForWebContents(web_contents.get());
494 it = web_contents_.set(unique_id, web_contents.Pass());
495 }
496
497 InfoBarService* service = InfoBarService::FromWebContents(it->second);
498 DCHECK(service);
499 return service;
500 }
484 501
485 // TestInfoBarDelegate -------------------------------------------------------- 502 // TestInfoBarDelegate --------------------------------------------------------
486 503
487 namespace { 504 namespace {
488 505
489 // static 506 // static
490 infobars::InfoBar* TestInfoBarDelegate::Create( 507 infobars::InfoBar* TestInfoBarDelegate::Create(
491 GoogleURLTrackerTest* test_harness, 508 GoogleURLTrackerTest* test_harness,
492 InfoBarService* infobar_service, 509 InfoBarService* infobar_service,
493 GoogleURLTracker* google_url_tracker, 510 GoogleURLTracker* google_url_tracker,
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); 1120 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2"));
1104 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); 1121 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL);
1105 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); 1122 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2);
1106 ASSERT_FALSE(delegate2 == NULL); 1123 ASSERT_FALSE(delegate2 == NULL);
1107 SetNavigationPending(1, true); 1124 SetNavigationPending(1, true);
1108 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); 1125 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true));
1109 delegate2->Close(false); 1126 delegate2->Close(false);
1110 SetNavigationPending(1, false); 1127 SetNavigationPending(1, false);
1111 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); 1128 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false));
1112 } 1129 }
OLDNEW
« no previous file with comments | « chrome/browser/google/google_url_tracker_map_entry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698