OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
| 11 #include "chrome/browser/prefs/browser_prefs.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/tab_contents/infobar_delegate.h" | 13 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 14 #include "chrome/common/net/test_url_fetcher_factory.h" |
13 #include "chrome/common/net/url_fetcher.h" | 15 #include "chrome/common/net/url_fetcher.h" |
14 #include "chrome/common/net/url_request_context_getter.h" | 16 #include "chrome/common/net/url_request_context_getter.h" |
15 #include "chrome/common/net/test_url_fetcher_factory.h" | |
16 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/testing_browser_process.h" | 19 #include "chrome/test/testing_browser_process.h" |
19 #include "chrome/test/testing_pref_service.h" | 20 #include "chrome/test/testing_pref_service.h" |
20 #include "chrome/test/testing_profile.h" | 21 #include "chrome/test/testing_profile.h" |
21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
22 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 // TestNotificationObserver --------------------------------------------------- | 26 // TestNotificationObserver --------------------------------------------------- |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 void CancelGoogleURL(); | 129 void CancelGoogleURL(); |
129 void InfoBarClosed(); | 130 void InfoBarClosed(); |
130 void ExpectDefaultURLs(); | 131 void ExpectDefaultURLs(); |
131 | 132 |
132 scoped_ptr<TestNotificationObserver> observer_; | 133 scoped_ptr<TestNotificationObserver> observer_; |
133 | 134 |
134 private: | 135 private: |
135 MessageLoop* message_loop_; | 136 MessageLoop* message_loop_; |
136 BrowserThread* io_thread_; | 137 BrowserThread* io_thread_; |
137 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 138 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 139 TestingPrefService local_state_; |
138 scoped_ptr<TestingProfile> testing_profile_; | 140 scoped_ptr<TestingProfile> testing_profile_; |
139 | 141 |
140 TestURLFetcherFactory fetcher_factory_; | 142 TestURLFetcherFactory fetcher_factory_; |
141 NotificationRegistrar registrar_; | 143 NotificationRegistrar registrar_; |
142 | 144 |
143 URLRequestContextGetter* original_default_request_context_; | 145 URLRequestContextGetter* original_default_request_context_; |
144 }; | 146 }; |
145 | 147 |
146 GoogleURLTrackerTest::GoogleURLTrackerTest() | 148 GoogleURLTrackerTest::GoogleURLTrackerTest() |
147 : observer_(new TestNotificationObserver), | 149 : observer_(new TestNotificationObserver), |
148 message_loop_(NULL), | 150 message_loop_(NULL), |
149 io_thread_(NULL), | 151 io_thread_(NULL), |
150 original_default_request_context_(NULL) { | 152 original_default_request_context_(NULL) { |
151 } | 153 } |
152 | 154 |
153 GoogleURLTrackerTest::~GoogleURLTrackerTest() { | 155 GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
154 } | 156 } |
155 | 157 |
156 void GoogleURLTrackerTest::SetUp() { | 158 void GoogleURLTrackerTest::SetUp() { |
157 original_default_request_context_ = Profile::GetDefaultRequestContext(); | 159 original_default_request_context_ = Profile::GetDefaultRequestContext(); |
158 Profile::set_default_request_context(NULL); | 160 Profile::set_default_request_context(NULL); |
159 message_loop_ = new MessageLoop(MessageLoop::TYPE_IO); | 161 message_loop_ = new MessageLoop(MessageLoop::TYPE_IO); |
160 io_thread_ = new BrowserThread(BrowserThread::IO, message_loop_); | 162 io_thread_ = new BrowserThread(BrowserThread::IO, message_loop_); |
161 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 163 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
162 testing_profile_.reset(new TestingProfile); | 164 testing_profile_.reset(new TestingProfile); |
| 165 browser::RegisterLocalState(&local_state_); |
163 TestingBrowserProcess* testing_browser_process = | 166 TestingBrowserProcess* testing_browser_process = |
164 static_cast<TestingBrowserProcess*>(g_browser_process); | 167 static_cast<TestingBrowserProcess*>(g_browser_process); |
165 PrefService* pref_service = testing_profile_->GetPrefs(); | 168 testing_browser_process->SetPrefService(&local_state_); |
166 testing_browser_process->SetPrefService(pref_service); | |
167 GoogleURLTracker* tracker = new GoogleURLTracker; | 169 GoogleURLTracker* tracker = new GoogleURLTracker; |
168 tracker->queue_wakeup_task_ = false; | 170 tracker->queue_wakeup_task_ = false; |
169 MessageLoop::current()->RunAllPending(); | 171 MessageLoop::current()->RunAllPending(); |
170 testing_browser_process->SetGoogleURLTracker(tracker); | 172 testing_browser_process->SetGoogleURLTracker(tracker); |
171 | 173 |
172 URLFetcher::set_factory(&fetcher_factory_); | 174 URLFetcher::set_factory(&fetcher_factory_); |
173 g_browser_process->google_url_tracker()->infobar_creator_ = | 175 g_browser_process->google_url_tracker()->infobar_creator_ = |
174 &CreateTestInfobar; | 176 &CreateTestInfobar; |
175 } | 177 } |
176 | 178 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 NavEntryCommitted(); | 484 NavEntryCommitted(); |
483 EXPECT_TRUE(InfoBarIsShown()); | 485 EXPECT_TRUE(InfoBarIsShown()); |
484 | 486 |
485 AcceptGoogleURL(); | 487 AcceptGoogleURL(); |
486 InfoBarClosed(); | 488 InfoBarClosed(); |
487 EXPECT_FALSE(InfoBarIsShown()); | 489 EXPECT_FALSE(InfoBarIsShown()); |
488 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); | 490 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); |
489 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 491 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
490 EXPECT_TRUE(observer_->notified()); | 492 EXPECT_TRUE(observer_->notified()); |
491 } | 493 } |
OLD | NEW |