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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "chrome/browser/google/google_url_tracker.h" | 6 #include "chrome/browser/google/google_url_tracker.h" |
7 #include "chrome/browser/prefs/browser_prefs.h" | 7 #include "chrome/browser/prefs/browser_prefs.h" |
8 #include "chrome/common/chrome_notification_types.h" | 8 #include "chrome/common/chrome_notification_types.h" |
9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
10 #include "chrome/test/base/testing_browser_process.h" | 10 #include "chrome/test/base/testing_browser_process.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 return; | 181 return; |
182 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL)); | 182 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL)); |
183 fetcher->set_response_code(200); | 183 fetcher->set_response_code(200); |
184 fetcher->SetResponseString(domain); | 184 fetcher->SetResponseString(domain); |
185 fetcher->delegate()->OnURLFetchComplete(fetcher); | 185 fetcher->delegate()->OnURLFetchComplete(fetcher); |
186 // At this point, |fetcher| is deleted. | 186 // At this point, |fetcher| is deleted. |
187 } | 187 } |
188 | 188 |
189 void GoogleURLTrackerTest::RequestServerCheck() { | 189 void GoogleURLTrackerTest::RequestServerCheck() { |
190 if (!registrar_.IsRegistered(observer_.get(), | 190 if (!registrar_.IsRegistered(observer_.get(), |
191 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 191 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
192 content::NotificationService::AllSources())) { | 192 content::NotificationService::AllBrowserContextsAndSources())) { |
193 registrar_.Add(observer_.get(), chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 193 registrar_.Add(observer_.get(), chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
194 content::NotificationService::AllSources()); | 194 content::NotificationService::AllBrowserContextsAndSources()); |
195 } | 195 } |
196 google_url_tracker_->SetNeedToFetch(); | 196 google_url_tracker_->SetNeedToFetch(); |
197 } | 197 } |
198 | 198 |
199 void GoogleURLTrackerTest::FinishSleep() { | 199 void GoogleURLTrackerTest::FinishSleep() { |
200 google_url_tracker_->FinishSleep(); | 200 google_url_tracker_->FinishSleep(); |
201 } | 201 } |
202 | 202 |
203 void GoogleURLTrackerTest::NotifyIPAddressChanged() { | 203 void GoogleURLTrackerTest::NotifyIPAddressChanged() { |
204 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 204 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
205 // For thread safety, the NCN queues tasks to do the actual notifications, so | 205 // For thread safety, the NCN queues tasks to do the actual notifications, so |
206 // we need to spin the message loop so the tracker will actually be notified. | 206 // we need to spin the message loop so the tracker will actually be notified. |
207 MessageLoop::current()->RunAllPending(); | 207 MessageLoop::current()->RunAllPending(); |
208 } | 208 } |
209 | 209 |
210 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { | 210 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { |
211 g_browser_process->local_state()->SetString( | 211 g_browser_process->local_state()->SetString( |
212 prefs::kLastPromptedGoogleURL, url.spec()); | 212 prefs::kLastPromptedGoogleURL, url.spec()); |
213 } | 213 } |
214 | 214 |
215 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { | 215 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { |
216 return GURL(g_browser_process->local_state()->GetString( | 216 return GURL(g_browser_process->local_state()->GetString( |
217 prefs::kLastPromptedGoogleURL)); | 217 prefs::kLastPromptedGoogleURL)); |
218 } | 218 } |
219 | 219 |
220 void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) { | 220 void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) { |
221 google_url_tracker_->SearchCommitted(); | 221 google_url_tracker_->SearchCommitted(); |
222 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 222 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
223 content::NOTIFICATION_NAV_ENTRY_PENDING, | 223 content::NOTIFICATION_NAV_ENTRY_PENDING, |
224 content::NotificationService::AllSources())) | 224 content::NotificationService::AllBrowserContextsAndSources())) |
225 google_url_tracker_->search_url_ = search_url; | 225 google_url_tracker_->search_url_ = search_url; |
226 } | 226 } |
227 | 227 |
228 void GoogleURLTrackerTest::NavEntryCommitted() { | 228 void GoogleURLTrackerTest::NavEntryCommitted() { |
229 google_url_tracker_->ShowGoogleURLInfoBarIfNecessary(NULL); | 229 google_url_tracker_->ShowGoogleURLInfoBarIfNecessary(NULL); |
230 } | 230 } |
231 | 231 |
232 void GoogleURLTrackerTest::AcceptGoogleURL() { | 232 void GoogleURLTrackerTest::AcceptGoogleURL() { |
233 TestInfoBarDelegate* infobar = | 233 TestInfoBarDelegate* infobar = |
234 static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_); | 234 static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_); |
(...skipping 16 matching lines...) Expand all Loading... |
251 TestInfoBarDelegate* infobar = | 251 TestInfoBarDelegate* infobar = |
252 static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_); | 252 static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_); |
253 ASSERT_TRUE(infobar); | 253 ASSERT_TRUE(infobar); |
254 ASSERT_TRUE(infobar->google_url_tracker()); | 254 ASSERT_TRUE(infobar->google_url_tracker()); |
255 ASSERT_EQ(google_url_tracker_, infobar->google_url_tracker()); | 255 ASSERT_EQ(google_url_tracker_, infobar->google_url_tracker()); |
256 google_url_tracker_->InfoBarClosed(); | 256 google_url_tracker_->InfoBarClosed(); |
257 delete infobar; | 257 delete infobar; |
258 } | 258 } |
259 | 259 |
260 void GoogleURLTrackerTest::ExpectDefaultURLs() { | 260 void GoogleURLTrackerTest::ExpectDefaultURLs() { |
261 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), | 261 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
262 google_url_tracker_->google_url_); | |
263 EXPECT_EQ(GURL(), fetched_google_url()); | 262 EXPECT_EQ(GURL(), fetched_google_url()); |
264 } | 263 } |
265 | 264 |
266 | 265 |
267 // Tests ---------------------------------------------------------------------- | 266 // Tests ---------------------------------------------------------------------- |
268 | 267 |
269 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 268 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
270 ExpectDefaultURLs(); | 269 ExpectDefaultURLs(); |
271 FinishSleep(); | 270 FinishSleep(); |
272 // No one called RequestServerCheck() so nothing should have happened. | 271 // No one called RequestServerCheck() so nothing should have happened. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 NavEntryCommitted(); | 420 NavEntryCommitted(); |
422 EXPECT_TRUE(infobar_showing()); | 421 EXPECT_TRUE(infobar_showing()); |
423 | 422 |
424 AcceptGoogleURL(); | 423 AcceptGoogleURL(); |
425 InfoBarClosed(); | 424 InfoBarClosed(); |
426 EXPECT_FALSE(infobar_showing()); | 425 EXPECT_FALSE(infobar_showing()); |
427 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 426 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
428 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 427 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
429 EXPECT_TRUE(observer_->notified()); | 428 EXPECT_TRUE(observer_->notified()); |
430 } | 429 } |
OLD | NEW |