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_test.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/notification_service.h" | 17 #include "content/common/notification_service.h" |
18 #include "content/common/url_fetcher.h" | 18 #include "content/common/url_fetcher.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 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 GoogleURLTracker* google_url_tracker, | 93 GoogleURLTracker* google_url_tracker, |
94 const GURL& new_google_url) { | 94 const GURL& new_google_url) { |
95 return new TestInfoBarDelegate(google_url_tracker, new_google_url); | 95 return new TestInfoBarDelegate(google_url_tracker, new_google_url); |
96 } | 96 } |
97 | 97 |
98 } // namespace | 98 } // namespace |
99 | 99 |
100 | 100 |
101 // GoogleURLTrackerTest ------------------------------------------------------- | 101 // GoogleURLTrackerTest ------------------------------------------------------- |
102 | 102 |
103 class GoogleURLTrackerTest : public TestingBrowserProcessTest { | 103 class GoogleURLTrackerTest : public testing::Test { |
104 protected: | 104 protected: |
105 GoogleURLTrackerTest(); | 105 GoogleURLTrackerTest(); |
106 virtual ~GoogleURLTrackerTest(); | 106 virtual ~GoogleURLTrackerTest(); |
107 | 107 |
108 // testing::Test | 108 // testing::Test |
109 virtual void SetUp(); | 109 virtual void SetUp(); |
110 virtual void TearDown(); | 110 virtual void TearDown(); |
111 | 111 |
112 TestURLFetcher* GetFetcherByID(int expected_id); | 112 TestURLFetcher* GetFetcherByID(int expected_id); |
113 void MockSearchDomainCheckResponse(int expected_id, | 113 void MockSearchDomainCheckResponse(int expected_id, |
(...skipping 23 matching lines...) Expand all Loading... |
137 ScopedTestingLocalState local_state_; | 137 ScopedTestingLocalState local_state_; |
138 | 138 |
139 TestURLFetcherFactory fetcher_factory_; | 139 TestURLFetcherFactory fetcher_factory_; |
140 NotificationRegistrar registrar_; | 140 NotificationRegistrar registrar_; |
141 }; | 141 }; |
142 | 142 |
143 GoogleURLTrackerTest::GoogleURLTrackerTest() | 143 GoogleURLTrackerTest::GoogleURLTrackerTest() |
144 : observer_(new TestNotificationObserver), | 144 : observer_(new TestNotificationObserver), |
145 message_loop_(MessageLoop::TYPE_IO), | 145 message_loop_(MessageLoop::TYPE_IO), |
146 io_thread_(BrowserThread::IO, &message_loop_), | 146 io_thread_(BrowserThread::IO, &message_loop_), |
147 local_state_(testing_browser_process_.get()) { | 147 local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) { |
148 } | 148 } |
149 | 149 |
150 GoogleURLTrackerTest::~GoogleURLTrackerTest() { | 150 GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
151 } | 151 } |
152 | 152 |
153 void GoogleURLTrackerTest::SetUp() { | 153 void GoogleURLTrackerTest::SetUp() { |
154 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 154 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
155 GoogleURLTracker* tracker = new GoogleURLTracker; | 155 GoogleURLTracker* tracker = new GoogleURLTracker; |
156 tracker->queue_wakeup_task_ = false; | 156 tracker->queue_wakeup_task_ = false; |
157 MessageLoop::current()->RunAllPending(); | 157 MessageLoop::current()->RunAllPending(); |
158 testing_browser_process_.get()->SetGoogleURLTracker(tracker); | 158 static_cast<TestingBrowserProcess*>(g_browser_process)->SetGoogleURLTracker( |
| 159 tracker); |
159 | 160 |
160 g_browser_process->google_url_tracker()->infobar_creator_ = | 161 g_browser_process->google_url_tracker()->infobar_creator_ = |
161 &CreateTestInfobar; | 162 &CreateTestInfobar; |
162 } | 163 } |
163 | 164 |
164 void GoogleURLTrackerTest::TearDown() { | 165 void GoogleURLTrackerTest::TearDown() { |
165 testing_browser_process_.get()->SetGoogleURLTracker(NULL); | 166 static_cast<TestingBrowserProcess*>(g_browser_process)->SetGoogleURLTracker( |
| 167 NULL); |
166 network_change_notifier_.reset(); | 168 network_change_notifier_.reset(); |
167 } | 169 } |
168 | 170 |
169 TestURLFetcher* GoogleURLTrackerTest::GetFetcherByID(int expected_id) { | 171 TestURLFetcher* GoogleURLTrackerTest::GetFetcherByID(int expected_id) { |
170 return fetcher_factory_.GetFetcherByID(expected_id); | 172 return fetcher_factory_.GetFetcherByID(expected_id); |
171 } | 173 } |
172 | 174 |
173 void GoogleURLTrackerTest::MockSearchDomainCheckResponse( | 175 void GoogleURLTrackerTest::MockSearchDomainCheckResponse( |
174 int expected_id, | 176 int expected_id, |
175 const std::string& domain) { | 177 const std::string& domain) { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 NavEntryCommitted(); | 443 NavEntryCommitted(); |
442 EXPECT_TRUE(InfoBarIsShown()); | 444 EXPECT_TRUE(InfoBarIsShown()); |
443 | 445 |
444 AcceptGoogleURL(); | 446 AcceptGoogleURL(); |
445 InfoBarClosed(); | 447 InfoBarClosed(); |
446 EXPECT_FALSE(InfoBarIsShown()); | 448 EXPECT_FALSE(InfoBarIsShown()); |
447 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); | 449 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); |
448 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 450 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
449 EXPECT_TRUE(observer_->notified()); | 451 EXPECT_TRUE(observer_->notified()); |
450 } | 452 } |
OLD | NEW |