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/prefs/browser_prefs.h" | 10 #include "chrome/browser/prefs/browser_prefs.h" |
11 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 11 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
15 #include "chrome/test/base/testing_pref_service.h" | 15 #include "chrome/test/base/testing_pref_service.h" |
16 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
17 #include "content/common/net/url_fetcher.h" | 17 #include "content/common/net/url_fetcher.h" |
18 #include "content/common/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/test/test_url_fetcher_factory.h" | 19 #include "content/test/test_url_fetcher_factory.h" |
20 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
21 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
22 #include "net/url_request/url_request_test_util.h" | 22 #include "net/url_request/url_request_test_util.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 // TestNotificationObserver --------------------------------------------------- | 25 // TestNotificationObserver --------------------------------------------------- |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 fetcher->delegate()->OnURLFetchComplete(fetcher, | 182 fetcher->delegate()->OnURLFetchComplete(fetcher, |
183 GURL(GoogleURLTracker::kSearchDomainCheckURL), net::URLRequestStatus(), | 183 GURL(GoogleURLTracker::kSearchDomainCheckURL), net::URLRequestStatus(), |
184 200, net::ResponseCookies(), domain); | 184 200, net::ResponseCookies(), domain); |
185 // At this point, |fetcher| is deleted. | 185 // At this point, |fetcher| is deleted. |
186 MessageLoop::current()->RunAllPending(); | 186 MessageLoop::current()->RunAllPending(); |
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 NotificationService::AllSources())) { | 192 content::NotificationService::AllSources())) { |
193 registrar_.Add(observer_.get(), chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 193 registrar_.Add(observer_.get(), chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
194 NotificationService::AllSources()); | 194 content::NotificationService::AllSources()); |
195 } | 195 } |
196 GoogleURLTracker::RequestServerCheck(); | 196 GoogleURLTracker::RequestServerCheck(); |
197 MessageLoop::current()->RunAllPending(); | 197 MessageLoop::current()->RunAllPending(); |
198 } | 198 } |
199 | 199 |
200 void GoogleURLTrackerTest::FinishSleep() { | 200 void GoogleURLTrackerTest::FinishSleep() { |
201 g_browser_process->google_url_tracker()->FinishSleep(); | 201 g_browser_process->google_url_tracker()->FinishSleep(); |
202 MessageLoop::current()->RunAllPending(); | 202 MessageLoop::current()->RunAllPending(); |
203 } | 203 } |
204 | 204 |
(...skipping 19 matching lines...) Expand all Loading... |
224 return GURL(g_browser_process->local_state()->GetString( | 224 return GURL(g_browser_process->local_state()->GetString( |
225 prefs::kLastPromptedGoogleURL)); | 225 prefs::kLastPromptedGoogleURL)); |
226 } | 226 } |
227 | 227 |
228 void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) { | 228 void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) { |
229 GoogleURLTracker* google_url_tracker = | 229 GoogleURLTracker* google_url_tracker = |
230 g_browser_process->google_url_tracker(); | 230 g_browser_process->google_url_tracker(); |
231 google_url_tracker->SearchCommitted(); | 231 google_url_tracker->SearchCommitted(); |
232 if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, | 232 if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, |
233 content::NOTIFICATION_NAV_ENTRY_PENDING, | 233 content::NOTIFICATION_NAV_ENTRY_PENDING, |
234 NotificationService::AllSources())) | 234 content::NotificationService::AllSources())) |
235 google_url_tracker->search_url_ = search_url; | 235 google_url_tracker->search_url_ = search_url; |
236 } | 236 } |
237 | 237 |
238 void GoogleURLTrackerTest::NavEntryCommitted() { | 238 void GoogleURLTrackerTest::NavEntryCommitted() { |
239 GoogleURLTracker* google_url_tracker = | 239 GoogleURLTracker* google_url_tracker = |
240 g_browser_process->google_url_tracker(); | 240 g_browser_process->google_url_tracker(); |
241 google_url_tracker->ShowGoogleURLInfoBarIfNecessary(NULL); | 241 google_url_tracker->ShowGoogleURLInfoBarIfNecessary(NULL); |
242 } | 242 } |
243 | 243 |
244 bool GoogleURLTrackerTest::InfoBarIsShown() { | 244 bool GoogleURLTrackerTest::InfoBarIsShown() { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 NavEntryCommitted(); | 444 NavEntryCommitted(); |
445 EXPECT_TRUE(InfoBarIsShown()); | 445 EXPECT_TRUE(InfoBarIsShown()); |
446 | 446 |
447 AcceptGoogleURL(); | 447 AcceptGoogleURL(); |
448 InfoBarClosed(); | 448 InfoBarClosed(); |
449 EXPECT_FALSE(InfoBarIsShown()); | 449 EXPECT_FALSE(InfoBarIsShown()); |
450 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); | 450 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); |
451 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 451 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
452 EXPECT_TRUE(observer_->notified()); | 452 EXPECT_TRUE(observer_->notified()); |
453 } | 453 } |
OLD | NEW |