| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_url_tracker.h" | 5 #include "chrome/browser/google_url_tracker.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
| 9 #include "chrome/browser/tab_contents/infobar_delegate.h" | 9 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 10 #include "chrome/common/net/url_fetcher.h" | 10 #include "chrome/common/net/url_fetcher.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 const GURL& new_google_url) { | 63 const GURL& new_google_url) { |
| 64 return new TestInfoBar(google_url_tracker, new_google_url); | 64 return new TestInfoBar(google_url_tracker, new_google_url); |
| 65 } | 65 } |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 } // anonymous namespace | 68 } // anonymous namespace |
| 69 | 69 |
| 70 class GoogleURLTrackerTest : public testing::Test { | 70 class GoogleURLTrackerTest : public testing::Test { |
| 71 protected: | 71 protected: |
| 72 GoogleURLTrackerTest() | 72 GoogleURLTrackerTest() |
| 73 : message_loop_(MessageLoop::TYPE_IO), | 73 : original_default_request_context_(NULL) { |
| 74 io_thread_(ChromeThread::IO, &message_loop_), | |
| 75 original_default_request_context_(NULL) { | |
| 76 } | 74 } |
| 77 | 75 |
| 78 void SetUp() { | 76 void SetUp() { |
| 79 original_default_request_context_ = Profile::GetDefaultRequestContext(); | 77 original_default_request_context_ = Profile::GetDefaultRequestContext(); |
| 80 Profile::set_default_request_context(NULL); | 78 Profile::set_default_request_context(NULL); |
| 79 message_loop_ = new MessageLoop(MessageLoop::TYPE_IO); |
| 81 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 80 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
| 82 testing_profile_.reset(new TestingProfile); | 81 testing_profile_.reset(new TestingProfile); |
| 83 TestingBrowserProcess* testing_browser_process = | 82 TestingBrowserProcess* testing_browser_process = |
| 84 static_cast<TestingBrowserProcess*>(g_browser_process); | 83 static_cast<TestingBrowserProcess*>(g_browser_process); |
| 85 PrefService* pref_service = testing_profile_->GetPrefs(); | 84 PrefService* pref_service = testing_profile_->GetPrefs(); |
| 86 testing_browser_process->SetPrefService(pref_service); | 85 testing_browser_process->SetPrefService(pref_service); |
| 87 testing_browser_process->SetGoogleURLTracker(new GoogleURLTracker); | 86 testing_browser_process->SetGoogleURLTracker(new GoogleURLTracker); |
| 88 | 87 |
| 89 URLFetcher::set_factory(&fetcher_factory_); | 88 URLFetcher::set_factory(&fetcher_factory_); |
| 90 observer_.reset(new TestNotificationObserver); | 89 observer_.reset(new TestNotificationObserver); |
| 91 g_browser_process->google_url_tracker()->infobar_factory_.reset( | 90 g_browser_process->google_url_tracker()->infobar_factory_.reset( |
| 92 new TestInfoBarDelegateFactory); | 91 new TestInfoBarDelegateFactory); |
| 93 } | 92 } |
| 94 | 93 |
| 95 void TearDown() { | 94 void TearDown() { |
| 96 URLFetcher::set_factory(NULL); | 95 URLFetcher::set_factory(NULL); |
| 97 TestingBrowserProcess* testing_browser_process = | 96 TestingBrowserProcess* testing_browser_process = |
| 98 static_cast<TestingBrowserProcess*>(g_browser_process); | 97 static_cast<TestingBrowserProcess*>(g_browser_process); |
| 99 testing_browser_process->SetGoogleURLTracker(NULL); | 98 testing_browser_process->SetGoogleURLTracker(NULL); |
| 100 testing_browser_process->SetPrefService(NULL); | 99 testing_browser_process->SetPrefService(NULL); |
| 101 testing_profile_.reset(); | 100 testing_profile_.reset(); |
| 102 network_change_notifier_.reset(); | 101 network_change_notifier_.reset(); |
| 102 delete message_loop_; |
| 103 Profile::set_default_request_context(original_default_request_context_); | 103 Profile::set_default_request_context(original_default_request_context_); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void CreateRequestContext() { | 106 void CreateRequestContext() { |
| 107 testing_profile_->CreateRequestContext(); | 107 testing_profile_->CreateRequestContext(); |
| 108 Profile::set_default_request_context(testing_profile_->GetRequestContext()); | 108 Profile::set_default_request_context(testing_profile_->GetRequestContext()); |
| 109 NotificationService::current()->Notify( | 109 NotificationService::current()->Notify( |
| 110 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 110 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
| 111 NotificationService::AllSources(), NotificationService::NoDetails()); | 111 NotificationService::AllSources(), NotificationService::NoDetails()); |
| 112 } | 112 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 delete infobar; | 207 delete infobar; |
| 208 } | 208 } |
| 209 | 209 |
| 210 void ExpectDefaultURLs() { | 210 void ExpectDefaultURLs() { |
| 211 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), | 211 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
| 212 GoogleURLTracker::GoogleURL()); | 212 GoogleURLTracker::GoogleURL()); |
| 213 EXPECT_EQ(GURL(), GetFetchedGoogleURL()); | 213 EXPECT_EQ(GURL(), GetFetchedGoogleURL()); |
| 214 } | 214 } |
| 215 | 215 |
| 216 private: | 216 private: |
| 217 MessageLoop message_loop_; | 217 MessageLoop* message_loop_; |
| 218 ChromeThread io_thread_; | |
| 219 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 218 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 220 scoped_ptr<TestingProfile> testing_profile_; | 219 scoped_ptr<TestingProfile> testing_profile_; |
| 221 | 220 |
| 222 TestURLFetcherFactory fetcher_factory_; | 221 TestURLFetcherFactory fetcher_factory_; |
| 223 NotificationRegistrar registrar_; | 222 NotificationRegistrar registrar_; |
| 224 scoped_ptr<NotificationObserver> observer_; | 223 scoped_ptr<NotificationObserver> observer_; |
| 225 | 224 |
| 226 URLRequestContextGetter* original_default_request_context_; | 225 URLRequestContextGetter* original_default_request_context_; |
| 227 }; | 226 }; |
| 228 | 227 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 443 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 445 | 444 |
| 446 SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); | 445 SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); |
| 447 NavEntryCommitted(); | 446 NavEntryCommitted(); |
| 448 | 447 |
| 449 EXPECT_FALSE(InfoBarIsShown()); | 448 EXPECT_FALSE(InfoBarIsShown()); |
| 450 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); | 449 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
| 451 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); | 450 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
| 452 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 451 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 453 } | 452 } |
| OLD | NEW |