OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // object, we don't add the created infobar to it. Instead we will simulate | 242 // object, we don't add the created infobar to it. Instead we will simulate |
243 // any helper<->infobar interaction necessary. The returned object will be | 243 // any helper<->infobar interaction necessary. The returned object will be |
244 // cleaned up in CloseTab(). | 244 // cleaned up in CloseTab(). |
245 GoogleURLTrackerInfoBarDelegate* CreateTestInfoBar( | 245 GoogleURLTrackerInfoBarDelegate* CreateTestInfoBar( |
246 InfoBarService* infobar_service, | 246 InfoBarService* infobar_service, |
247 GoogleURLTracker* google_url_tracker, | 247 GoogleURLTracker* google_url_tracker, |
248 const GURL& search_url); | 248 const GURL& search_url); |
249 | 249 |
250 // These are required by the TestURLFetchers GoogleURLTracker will create (see | 250 // These are required by the TestURLFetchers GoogleURLTracker will create (see |
251 // test_url_fetcher_factory.h). | 251 // test_url_fetcher_factory.h). |
252 MessageLoop message_loop_; | 252 base::MessageLoop message_loop_; |
253 content::TestBrowserThread io_thread_; | 253 content::TestBrowserThread io_thread_; |
254 // Creating this allows us to call | 254 // Creating this allows us to call |
255 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). | 255 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). |
256 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 256 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
257 net::TestURLFetcherFactory fetcher_factory_; | 257 net::TestURLFetcherFactory fetcher_factory_; |
258 content::NotificationRegistrar registrar_; | 258 content::NotificationRegistrar registrar_; |
259 TestNotificationObserver observer_; | 259 TestNotificationObserver observer_; |
260 GoogleURLTrackerNavigationHelper* nav_helper_; | 260 GoogleURLTrackerNavigationHelper* nav_helper_; |
261 TestingProfile profile_; | 261 TestingProfile profile_; |
262 scoped_ptr<GoogleURLTracker> google_url_tracker_; | 262 scoped_ptr<GoogleURLTracker> google_url_tracker_; |
(...skipping 13 matching lines...) Expand all Loading... |
276 ASSERT_EQ(infobar, map_entry->infobar()); | 276 ASSERT_EQ(infobar, map_entry->infobar()); |
277 map_entry->Observe(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 277 map_entry->Observe(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
278 content::Source<InfoBarService>(infobar_service), | 278 content::Source<InfoBarService>(infobar_service), |
279 content::Details<InfoBarRemovedDetails>(&removed_details)); | 279 content::Details<InfoBarRemovedDetails>(&removed_details)); |
280 | 280 |
281 // Second, simulate the infobar container closing the infobar in response. | 281 // Second, simulate the infobar container closing the infobar in response. |
282 delete infobar; | 282 delete infobar; |
283 } | 283 } |
284 | 284 |
285 GoogleURLTrackerTest::GoogleURLTrackerTest() | 285 GoogleURLTrackerTest::GoogleURLTrackerTest() |
286 : message_loop_(MessageLoop::TYPE_IO), | 286 : message_loop_(base::MessageLoop::TYPE_IO), |
287 io_thread_(content::BrowserThread::IO, &message_loop_) { | 287 io_thread_(content::BrowserThread::IO, &message_loop_) { |
288 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); | 288 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); |
289 } | 289 } |
290 | 290 |
291 GoogleURLTrackerTest::~GoogleURLTrackerTest() { | 291 GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
292 } | 292 } |
293 | 293 |
294 void GoogleURLTrackerTest::SetUp() { | 294 void GoogleURLTrackerTest::SetUp() { |
295 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 295 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
296 // Ownership is passed to google_url_tracker_, but a weak pointer is kept; | 296 // Ownership is passed to google_url_tracker_, but a weak pointer is kept; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 343 } |
344 | 344 |
345 void GoogleURLTrackerTest::FinishSleep() { | 345 void GoogleURLTrackerTest::FinishSleep() { |
346 google_url_tracker_->FinishSleep(); | 346 google_url_tracker_->FinishSleep(); |
347 } | 347 } |
348 | 348 |
349 void GoogleURLTrackerTest::NotifyIPAddressChanged() { | 349 void GoogleURLTrackerTest::NotifyIPAddressChanged() { |
350 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 350 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
351 // For thread safety, the NCN queues tasks to do the actual notifications, so | 351 // For thread safety, the NCN queues tasks to do the actual notifications, so |
352 // we need to spin the message loop so the tracker will actually be notified. | 352 // we need to spin the message loop so the tracker will actually be notified. |
353 MessageLoop::current()->RunUntilIdle(); | 353 base::MessageLoop::current()->RunUntilIdle(); |
354 } | 354 } |
355 | 355 |
356 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { | 356 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { |
357 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); | 357 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); |
358 } | 358 } |
359 | 359 |
360 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { | 360 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { |
361 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); | 361 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); |
362 } | 362 } |
363 | 363 |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 1077 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
1078 EXPECT_FALSE(GetInfoBar(1) == NULL); | 1078 EXPECT_FALSE(GetInfoBar(1) == NULL); |
1079 GoogleURLTrackerInfoBarDelegate* infobar2 = GetInfoBar(2); | 1079 GoogleURLTrackerInfoBarDelegate* infobar2 = GetInfoBar(2); |
1080 ASSERT_FALSE(infobar2 == NULL); | 1080 ASSERT_FALSE(infobar2 == NULL); |
1081 SetNavigationPending(1, true); | 1081 SetNavigationPending(1, true); |
1082 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1082 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
1083 infobar2->Close(false); | 1083 infobar2->Close(false); |
1084 SetNavigationPending(1, false); | 1084 SetNavigationPending(1, false); |
1085 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 1085 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
1086 } | 1086 } |
OLD | NEW |