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/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/testing_browser_process_test.h" | 14 #include "chrome/test/testing_browser_process_test.h" |
14 #include "chrome/test/testing_pref_service.h" | 15 #include "chrome/test/testing_pref_service.h" |
15 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
16 #include "content/common/notification_service.h" | 17 #include "content/common/notification_service.h" |
17 #include "content/common/test_url_fetcher_factory.h" | 18 #include "content/common/test_url_fetcher_factory.h" |
18 #include "content/common/url_fetcher.h" | 19 #include "content/common/url_fetcher.h" |
19 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
21 #include "net/url_request/url_request_test_util.h" | 22 #include "net/url_request/url_request_test_util.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 // TestNotificationObserver --------------------------------------------------- | 25 // TestNotificationObserver --------------------------------------------------- |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 class TestNotificationObserver : public NotificationObserver { | 29 class TestNotificationObserver : public NotificationObserver { |
29 public: | 30 public: |
30 TestNotificationObserver(); | 31 TestNotificationObserver(); |
31 virtual ~TestNotificationObserver(); | 32 virtual ~TestNotificationObserver(); |
32 | 33 |
33 virtual void Observe(NotificationType type, | 34 virtual void Observe(int type, |
34 const NotificationSource& source, | 35 const NotificationSource& source, |
35 const NotificationDetails& details); | 36 const NotificationDetails& details); |
36 bool notified() const { return notified_; } | 37 bool notified() const { return notified_; } |
37 void clear_notified() { notified_ = false; } | 38 void clear_notified() { notified_ = false; } |
38 | 39 |
39 private: | 40 private: |
40 bool notified_; | 41 bool notified_; |
41 }; | 42 }; |
42 | 43 |
43 TestNotificationObserver::TestNotificationObserver() : notified_(false) { | 44 TestNotificationObserver::TestNotificationObserver() : notified_(false) { |
44 } | 45 } |
45 | 46 |
46 TestNotificationObserver::~TestNotificationObserver() { | 47 TestNotificationObserver::~TestNotificationObserver() { |
47 } | 48 } |
48 | 49 |
49 void TestNotificationObserver::Observe(NotificationType type, | 50 void TestNotificationObserver::Observe(int type, |
50 const NotificationSource& source, | 51 const NotificationSource& source, |
51 const NotificationDetails& details) { | 52 const NotificationDetails& details) { |
52 notified_ = true; | 53 notified_ = true; |
53 } | 54 } |
54 | 55 |
55 | 56 |
56 // TestInfoBarDelegate -------------------------------------------------------- | 57 // TestInfoBarDelegate -------------------------------------------------------- |
57 | 58 |
58 class TestInfoBarDelegate : public InfoBarDelegate { | 59 class TestInfoBarDelegate : public InfoBarDelegate { |
59 public: | 60 public: |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 return; | 180 return; |
180 fetcher->delegate()->OnURLFetchComplete(fetcher, | 181 fetcher->delegate()->OnURLFetchComplete(fetcher, |
181 GURL(GoogleURLTracker::kSearchDomainCheckURL), net::URLRequestStatus(), | 182 GURL(GoogleURLTracker::kSearchDomainCheckURL), net::URLRequestStatus(), |
182 200, net::ResponseCookies(), domain); | 183 200, net::ResponseCookies(), domain); |
183 // At this point, |fetcher| is deleted. | 184 // At this point, |fetcher| is deleted. |
184 MessageLoop::current()->RunAllPending(); | 185 MessageLoop::current()->RunAllPending(); |
185 } | 186 } |
186 | 187 |
187 void GoogleURLTrackerTest::RequestServerCheck() { | 188 void GoogleURLTrackerTest::RequestServerCheck() { |
188 if (!registrar_.IsRegistered(observer_.get(), | 189 if (!registrar_.IsRegistered(observer_.get(), |
189 NotificationType::GOOGLE_URL_UPDATED, | 190 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
190 NotificationService::AllSources())) { | 191 NotificationService::AllSources())) { |
191 registrar_.Add(observer_.get(), NotificationType::GOOGLE_URL_UPDATED, | 192 registrar_.Add(observer_.get(), chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
192 NotificationService::AllSources()); | 193 NotificationService::AllSources()); |
193 } | 194 } |
194 GoogleURLTracker::RequestServerCheck(); | 195 GoogleURLTracker::RequestServerCheck(); |
195 MessageLoop::current()->RunAllPending(); | 196 MessageLoop::current()->RunAllPending(); |
196 } | 197 } |
197 | 198 |
198 void GoogleURLTrackerTest::FinishSleep() { | 199 void GoogleURLTrackerTest::FinishSleep() { |
199 g_browser_process->google_url_tracker()->FinishSleep(); | 200 g_browser_process->google_url_tracker()->FinishSleep(); |
200 MessageLoop::current()->RunAllPending(); | 201 MessageLoop::current()->RunAllPending(); |
201 } | 202 } |
(...skipping 19 matching lines...) Expand all Loading... |
221 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { | 222 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { |
222 return GURL(g_browser_process->local_state()->GetString( | 223 return GURL(g_browser_process->local_state()->GetString( |
223 prefs::kLastPromptedGoogleURL)); | 224 prefs::kLastPromptedGoogleURL)); |
224 } | 225 } |
225 | 226 |
226 void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) { | 227 void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) { |
227 GoogleURLTracker* google_url_tracker = | 228 GoogleURLTracker* google_url_tracker = |
228 g_browser_process->google_url_tracker(); | 229 g_browser_process->google_url_tracker(); |
229 google_url_tracker->SearchCommitted(); | 230 google_url_tracker->SearchCommitted(); |
230 if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, | 231 if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, |
231 NotificationType::NAV_ENTRY_PENDING, | 232 content::NOTIFICATION_NAV_ENTRY_PENDING, |
232 NotificationService::AllSources())) | 233 NotificationService::AllSources())) |
233 google_url_tracker->search_url_ = search_url; | 234 google_url_tracker->search_url_ = search_url; |
234 } | 235 } |
235 | 236 |
236 void GoogleURLTrackerTest::NavEntryCommitted() { | 237 void GoogleURLTrackerTest::NavEntryCommitted() { |
237 GoogleURLTracker* google_url_tracker = | 238 GoogleURLTracker* google_url_tracker = |
238 g_browser_process->google_url_tracker(); | 239 g_browser_process->google_url_tracker(); |
239 google_url_tracker->ShowGoogleURLInfoBarIfNecessary(NULL); | 240 google_url_tracker->ShowGoogleURLInfoBarIfNecessary(NULL); |
240 } | 241 } |
241 | 242 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 NavEntryCommitted(); | 443 NavEntryCommitted(); |
443 EXPECT_TRUE(InfoBarIsShown()); | 444 EXPECT_TRUE(InfoBarIsShown()); |
444 | 445 |
445 AcceptGoogleURL(); | 446 AcceptGoogleURL(); |
446 InfoBarClosed(); | 447 InfoBarClosed(); |
447 EXPECT_FALSE(InfoBarIsShown()); | 448 EXPECT_FALSE(InfoBarIsShown()); |
448 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); | 449 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); |
449 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 450 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
450 EXPECT_TRUE(observer_->notified()); | 451 EXPECT_TRUE(observer_->notified()); |
451 } | 452 } |
OLD | NEW |