OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
9 #include "chrome/browser/tab_contents/infobar_delegate.h" | 9 #include "chrome/browser/tab_contents/infobar_delegate.h" |
10 #include "chrome/common/net/url_fetcher.h" | 10 #include "chrome/common/net/url_fetcher.h" |
11 #include "chrome/common/net/url_request_context_getter.h" | |
12 #include "chrome/common/net/test_url_fetcher_factory.h" | 11 #include "chrome/common/net/test_url_fetcher_factory.h" |
13 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/testing_browser_process.h" | 14 #include "chrome/test/testing_browser_process.h" |
16 #include "chrome/test/testing_pref_service.h" | 15 #include "chrome/test/testing_pref_service.h" |
17 #include "chrome/test/testing_profile.h" | 16 #include "chrome/test/testing_profile.h" |
18 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
19 #include "net/url_request/url_request_unittest.h" | 18 #include "net/url_request/url_request_unittest.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 | 20 |
(...skipping 24 matching lines...) Expand all Loading... |
46 | 45 |
47 void TestNotificationObserver::Observe(NotificationType type, | 46 void TestNotificationObserver::Observe(NotificationType type, |
48 const NotificationSource& source, | 47 const NotificationSource& source, |
49 const NotificationDetails& details) { | 48 const NotificationDetails& details) { |
50 notified_ = true; | 49 notified_ = true; |
51 } | 50 } |
52 | 51 |
53 | 52 |
54 // TestInfoBarDelegate -------------------------------------------------------- | 53 // TestInfoBarDelegate -------------------------------------------------------- |
55 | 54 |
56 class TestInfoBarDelegate : public InfoBarDelegate { | 55 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { |
57 public: | 56 public: |
58 TestInfoBarDelegate(GoogleURLTracker* google_url_tracker, | 57 TestInfoBarDelegate(TabContents* tab_contents, |
| 58 const GURL& search_url, |
| 59 GoogleURLTracker* google_url_tracker, |
59 const GURL& new_google_url); | 60 const GURL& new_google_url); |
60 virtual ~TestInfoBarDelegate(); | |
61 | 61 |
62 // InfoBarDelegate | 62 // GoogleURLTrackerInfoBarDelegate |
63 virtual InfoBar* CreateInfoBar(); | 63 virtual bool Accept(); // Overridden to avoid dereferencing |tab_contents_|. |
| 64 virtual void Show(); |
| 65 virtual void Close(bool redo_search); |
64 | 66 |
65 GoogleURLTracker* google_url_tracker() const { return google_url_tracker_; } | 67 GURL search_url() const { return search_url_; } |
66 GURL new_google_url() const { return new_google_url_; } | 68 GURL new_google_url() const { return new_google_url_; } |
| 69 bool showing() const { return showing_; } |
67 | 70 |
68 private: | 71 private: |
69 GoogleURLTracker* google_url_tracker_; | 72 virtual ~TestInfoBarDelegate(); |
70 GURL new_google_url_; | |
71 }; | 73 }; |
72 | 74 |
73 TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTracker* google_url_tracker, | 75 TestInfoBarDelegate::TestInfoBarDelegate(TabContents* tab_contents, |
| 76 const GURL& search_url, |
| 77 GoogleURLTracker* google_url_tracker, |
74 const GURL& new_google_url) | 78 const GURL& new_google_url) |
75 : InfoBarDelegate(NULL), | 79 : GoogleURLTrackerInfoBarDelegate(NULL, search_url, google_url_tracker, |
76 google_url_tracker_(google_url_tracker), | 80 new_google_url) { |
77 new_google_url_(new_google_url) { | 81 // We set |tab_contents_| here instead of in the superclass constructor so |
| 82 // that the base class will not try to dereference the bogus |tab_contents|. |
| 83 tab_contents_ = tab_contents; |
| 84 } |
| 85 |
| 86 bool TestInfoBarDelegate::Accept() { |
| 87 google_url_tracker_->AcceptGoogleURL(new_google_url_); |
| 88 return false; |
| 89 } |
| 90 |
| 91 void TestInfoBarDelegate::Show() { |
| 92 showing_ = true; |
| 93 } |
| 94 |
| 95 void TestInfoBarDelegate::Close(bool redo_search) { |
| 96 InfoBarClosed(); |
78 } | 97 } |
79 | 98 |
80 TestInfoBarDelegate::~TestInfoBarDelegate() { | 99 TestInfoBarDelegate::~TestInfoBarDelegate() { |
81 } | 100 } |
82 | 101 |
83 InfoBar* TestInfoBarDelegate::CreateInfoBar() { | 102 GoogleURLTrackerInfoBarDelegate* CreateTestInfobar( |
84 return NULL; | |
85 } | |
86 | |
87 InfoBarDelegate* CreateTestInfobar( | |
88 TabContents* tab_contents, | 103 TabContents* tab_contents, |
| 104 const GURL& search_url, |
89 GoogleURLTracker* google_url_tracker, | 105 GoogleURLTracker* google_url_tracker, |
90 const GURL& new_google_url) { | 106 const GURL& new_google_url) { |
91 return new TestInfoBarDelegate(google_url_tracker, new_google_url); | 107 return new TestInfoBarDelegate(tab_contents, search_url, google_url_tracker, |
| 108 new_google_url); |
92 } | 109 } |
93 | 110 |
94 } // namespace | 111 } // namespace |
95 | 112 |
96 | 113 |
97 // GoogleURLTrackerTest ------------------------------------------------------- | 114 // GoogleURLTrackerTest ------------------------------------------------------- |
98 | 115 |
99 class GoogleURLTrackerTest : public testing::Test { | 116 class GoogleURLTrackerTest : public testing::Test { |
100 protected: | 117 protected: |
101 GoogleURLTrackerTest(); | 118 GoogleURLTrackerTest(); |
102 virtual ~GoogleURLTrackerTest(); | 119 virtual ~GoogleURLTrackerTest(); |
103 | 120 |
104 // testing::Test | 121 // testing::Test |
105 virtual void SetUp(); | 122 virtual void SetUp(); |
106 virtual void TearDown(); | 123 virtual void TearDown(); |
107 | 124 |
108 void CreateRequestContext(); | 125 TestURLFetcher* GetFetcher(); |
109 TestURLFetcher* GetFetcherByID(int expected_id); | 126 void MockSearchDomainCheckResponse(const std::string& domain); |
110 void MockSearchDomainCheckResponse(int expected_id, | |
111 const std::string& domain); | |
112 void RequestServerCheck(); | 127 void RequestServerCheck(); |
113 void FinishSleep(); | 128 void FinishSleep(); |
114 void NotifyIPAddressChanged(); | 129 void NotifyIPAddressChanged(); |
115 GURL GetFetchedGoogleURL(); | 130 GURL GetFetchedGoogleURL(); |
116 void SetGoogleURL(const GURL& url); | 131 void SetGoogleURL(const GURL& url); |
117 void SetLastPromptedGoogleURL(const GURL& url); | 132 void SetLastPromptedGoogleURL(const GURL& url); |
118 GURL GetLastPromptedGoogleURL(); | 133 GURL GetLastPromptedGoogleURL(); |
119 void SearchCommitted(const GURL& search_url); | 134 void SetSearchPending(const GURL& search_url, int unique_id); |
120 void NavEntryCommitted(); | 135 void CommitSearch(int unique_id); |
121 bool InfoBarIsShown(); | 136 void CloseTab(int unique_id); |
122 GURL GetInfoBarShowingURL(); | 137 TestInfoBarDelegate* GetInfoBar(int unique_id); |
123 void AcceptGoogleURL(); | |
124 void CancelGoogleURL(); | |
125 void InfoBarClosed(); | |
126 void ExpectDefaultURLs(); | 138 void ExpectDefaultURLs(); |
127 | 139 |
128 scoped_ptr<TestNotificationObserver> observer_; | 140 scoped_ptr<TestNotificationObserver> observer_; |
129 | 141 |
130 private: | 142 private: |
131 MessageLoop* message_loop_; | 143 MessageLoop* message_loop_; |
132 BrowserThread* io_thread_; | 144 BrowserThread* io_thread_; |
133 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 145 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
134 scoped_ptr<TestingProfile> testing_profile_; | 146 scoped_ptr<TestingProfile> testing_profile_; |
135 | 147 |
136 TestURLFetcherFactory fetcher_factory_; | 148 TestURLFetcherFactory fetcher_factory_; |
137 NotificationRegistrar registrar_; | 149 NotificationRegistrar registrar_; |
138 | |
139 URLRequestContextGetter* original_default_request_context_; | |
140 }; | 150 }; |
141 | 151 |
142 GoogleURLTrackerTest::GoogleURLTrackerTest() | 152 GoogleURLTrackerTest::GoogleURLTrackerTest() |
143 : observer_(new TestNotificationObserver), | 153 : observer_(new TestNotificationObserver), |
144 message_loop_(NULL), | 154 message_loop_(NULL), |
145 io_thread_(NULL), | 155 io_thread_(NULL) { |
146 original_default_request_context_(NULL) { | |
147 } | 156 } |
148 | 157 |
149 GoogleURLTrackerTest::~GoogleURLTrackerTest() { | 158 GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
150 } | 159 } |
151 | 160 |
152 void GoogleURLTrackerTest::SetUp() { | 161 void GoogleURLTrackerTest::SetUp() { |
153 original_default_request_context_ = Profile::GetDefaultRequestContext(); | |
154 Profile::set_default_request_context(NULL); | |
155 message_loop_ = new MessageLoop(MessageLoop::TYPE_IO); | 162 message_loop_ = new MessageLoop(MessageLoop::TYPE_IO); |
156 io_thread_ = new BrowserThread(BrowserThread::IO, message_loop_); | 163 io_thread_ = new BrowserThread(BrowserThread::IO, message_loop_); |
157 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 164 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
158 testing_profile_.reset(new TestingProfile); | 165 testing_profile_.reset(new TestingProfile); |
159 TestingBrowserProcess* testing_browser_process = | 166 TestingBrowserProcess* testing_browser_process = |
160 static_cast<TestingBrowserProcess*>(g_browser_process); | 167 static_cast<TestingBrowserProcess*>(g_browser_process); |
161 PrefService* pref_service = testing_profile_->GetPrefs(); | 168 PrefService* pref_service = testing_profile_->GetPrefs(); |
162 testing_browser_process->SetPrefService(pref_service); | 169 testing_browser_process->SetPrefService(pref_service); |
163 GoogleURLTracker* tracker = new GoogleURLTracker; | 170 GoogleURLTracker* tracker = new GoogleURLTracker; |
164 tracker->queue_wakeup_task_ = false; | 171 tracker->queue_wakeup_task_ = false; |
165 MessageLoop::current()->RunAllPending(); | 172 MessageLoop::current()->RunAllPending(); |
166 testing_browser_process->SetGoogleURLTracker(tracker); | 173 testing_browser_process->SetGoogleURLTracker(tracker); |
| 174 testing_profile_->CreateRequestContext(); |
| 175 Profile::set_default_request_context(testing_profile_->GetRequestContext()); |
167 | 176 |
168 URLFetcher::set_factory(&fetcher_factory_); | 177 URLFetcher::set_factory(&fetcher_factory_); |
169 g_browser_process->google_url_tracker()->infobar_creator_ = | 178 g_browser_process->google_url_tracker()->infobar_creator_ = |
170 &CreateTestInfobar; | 179 &CreateTestInfobar; |
171 } | 180 } |
172 | 181 |
173 void GoogleURLTrackerTest::TearDown() { | 182 void GoogleURLTrackerTest::TearDown() { |
174 URLFetcher::set_factory(NULL); | 183 URLFetcher::set_factory(NULL); |
175 TestingBrowserProcess* testing_browser_process = | 184 TestingBrowserProcess* testing_browser_process = |
176 static_cast<TestingBrowserProcess*>(g_browser_process); | 185 static_cast<TestingBrowserProcess*>(g_browser_process); |
177 testing_browser_process->SetGoogleURLTracker(NULL); | 186 testing_browser_process->SetGoogleURLTracker(NULL); |
178 testing_browser_process->SetPrefService(NULL); | 187 testing_browser_process->SetPrefService(NULL); |
179 testing_profile_.reset(); | 188 testing_profile_.reset(); |
180 network_change_notifier_.reset(); | 189 network_change_notifier_.reset(); |
181 delete io_thread_; | 190 delete io_thread_; |
182 delete message_loop_; | 191 delete message_loop_; |
183 Profile::set_default_request_context(original_default_request_context_); | |
184 original_default_request_context_ = NULL; | |
185 } | 192 } |
186 | 193 |
187 void GoogleURLTrackerTest::CreateRequestContext() { | 194 TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { |
188 testing_profile_->CreateRequestContext(); | 195 // This will return the last fetcher created. If no fetchers have been |
189 Profile::set_default_request_context(testing_profile_->GetRequestContext()); | 196 // created, we'll pass GetFetcherByID() "-1", and it will return NULL. |
190 NotificationService::current()->Notify( | 197 return fetcher_factory_.GetFetcherByID( |
191 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 198 g_browser_process->google_url_tracker()->fetcher_id_ - 1); |
192 NotificationService::AllSources(), NotificationService::NoDetails()); | |
193 } | |
194 | |
195 TestURLFetcher* GoogleURLTrackerTest::GetFetcherByID(int expected_id) { | |
196 return fetcher_factory_.GetFetcherByID(expected_id); | |
197 } | 199 } |
198 | 200 |
199 void GoogleURLTrackerTest::MockSearchDomainCheckResponse( | 201 void GoogleURLTrackerTest::MockSearchDomainCheckResponse( |
200 int expected_id, | |
201 const std::string& domain) { | 202 const std::string& domain) { |
202 TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(expected_id); | 203 TestURLFetcher* fetcher = GetFetcher(); |
203 if (!fetcher) | 204 if (!fetcher) |
204 return; | 205 return; |
| 206 fetcher_factory_.RemoveFetcherFromMap(fetcher->id()); |
205 fetcher->delegate()->OnURLFetchComplete(fetcher, | 207 fetcher->delegate()->OnURLFetchComplete(fetcher, |
206 GURL(GoogleURLTracker::kSearchDomainCheckURL), URLRequestStatus(), 200, | 208 GURL(GoogleURLTracker::kSearchDomainCheckURL), URLRequestStatus(), 200, |
207 ResponseCookies(), domain); | 209 ResponseCookies(), domain); |
208 // At this point, |fetcher| is deleted. | 210 // At this point, |fetcher| is deleted. |
209 MessageLoop::current()->RunAllPending(); | 211 MessageLoop::current()->RunAllPending(); |
210 } | 212 } |
211 | 213 |
212 void GoogleURLTrackerTest::RequestServerCheck() { | 214 void GoogleURLTrackerTest::RequestServerCheck() { |
213 if (!registrar_.IsRegistered(observer_.get(), | 215 if (!registrar_.IsRegistered(observer_.get(), |
214 NotificationType::GOOGLE_URL_UPDATED, | 216 NotificationType::GOOGLE_URL_UPDATED, |
(...skipping 26 matching lines...) Expand all Loading... |
241 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { | 243 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { |
242 g_browser_process->local_state()->SetString( | 244 g_browser_process->local_state()->SetString( |
243 prefs::kLastPromptedGoogleURL, url.spec()); | 245 prefs::kLastPromptedGoogleURL, url.spec()); |
244 } | 246 } |
245 | 247 |
246 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { | 248 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { |
247 return GURL(g_browser_process->local_state()->GetString( | 249 return GURL(g_browser_process->local_state()->GetString( |
248 prefs::kLastPromptedGoogleURL)); | 250 prefs::kLastPromptedGoogleURL)); |
249 } | 251 } |
250 | 252 |
251 void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) { | 253 void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url, |
| 254 int unique_id) { |
252 GoogleURLTracker* google_url_tracker = | 255 GoogleURLTracker* google_url_tracker = |
253 g_browser_process->google_url_tracker(); | 256 g_browser_process->google_url_tracker(); |
254 google_url_tracker->SearchCommitted(); | 257 google_url_tracker->SearchCommitted(); |
255 if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, | 258 if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, |
256 NotificationType::NAV_ENTRY_PENDING, | 259 NotificationType::NAV_ENTRY_PENDING, |
257 NotificationService::AllSources())) | 260 NotificationService::AllSources())) { |
258 google_url_tracker->search_url_ = search_url; | 261 google_url_tracker->OnNavigationPending(Source<NavigationController>( |
| 262 reinterpret_cast<NavigationController*>(unique_id)), |
| 263 reinterpret_cast<TabContents*>(unique_id), search_url); |
| 264 } |
259 } | 265 } |
260 | 266 |
261 void GoogleURLTrackerTest::NavEntryCommitted() { | 267 void GoogleURLTrackerTest::CommitSearch(int unique_id) { |
262 GoogleURLTracker* google_url_tracker = | 268 GoogleURLTracker* google_url_tracker = |
263 g_browser_process->google_url_tracker(); | 269 g_browser_process->google_url_tracker(); |
264 google_url_tracker->ShowGoogleURLInfoBarIfNecessary(NULL); | 270 Source<NavigationController> source( |
| 271 reinterpret_cast<NavigationController*>(unique_id)); |
| 272 if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, |
| 273 NotificationType::NAV_ENTRY_COMMITTED, source)) { |
| 274 google_url_tracker->OnNavigationCommittedOrTabClosed(source, |
| 275 reinterpret_cast<TabContents*>(unique_id), |
| 276 NotificationType::NAV_ENTRY_COMMITTED); |
| 277 } |
265 } | 278 } |
266 | 279 |
267 bool GoogleURLTrackerTest::InfoBarIsShown() { | 280 void GoogleURLTrackerTest::CloseTab(int unique_id) { |
268 return (g_browser_process->google_url_tracker()->infobar_ != NULL); | 281 GoogleURLTracker* google_url_tracker = |
| 282 g_browser_process->google_url_tracker(); |
| 283 Source<NavigationController> source( |
| 284 reinterpret_cast<NavigationController*>(unique_id)); |
| 285 TabContents* tab_contents = reinterpret_cast<TabContents*>(unique_id); |
| 286 if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, |
| 287 NotificationType::TAB_CLOSED, source)) { |
| 288 google_url_tracker->OnNavigationCommittedOrTabClosed(source, tab_contents, |
| 289 NotificationType::TAB_CLOSED); |
| 290 } else { |
| 291 // Normally, closing a tab with an infobar showing will close the infobar. |
| 292 // Since we don't have real tabs and are just faking things with magic |
| 293 // numbers, we have to manually close the infobar, if any. |
| 294 GoogleURLTracker::Infobars::iterator i = |
| 295 google_url_tracker->infobars_.find(tab_contents); |
| 296 if (i != google_url_tracker->infobars_.end()) { |
| 297 TestInfoBarDelegate* infobar = |
| 298 static_cast<TestInfoBarDelegate*>(i->second); |
| 299 DCHECK(infobar->showing()); |
| 300 infobar->InfoBarClosed(); |
| 301 } |
| 302 } |
269 } | 303 } |
270 | 304 |
271 GURL GoogleURLTrackerTest::GetInfoBarShowingURL() { | 305 TestInfoBarDelegate* GoogleURLTrackerTest::GetInfoBar(int unique_id) { |
272 TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( | 306 const GoogleURLTracker::Infobars& infobars = |
273 g_browser_process->google_url_tracker()->infobar_); | 307 g_browser_process->google_url_tracker()->infobars_; |
274 return infobar->new_google_url(); | 308 GoogleURLTracker::Infobars::const_iterator i = |
275 } | 309 infobars.find(reinterpret_cast<TabContents*>(unique_id)); |
276 | 310 return (i == infobars.end()) ? |
277 void GoogleURLTrackerTest::AcceptGoogleURL() { | 311 NULL : static_cast<TestInfoBarDelegate*>(i->second); |
278 TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( | |
279 g_browser_process->google_url_tracker()->infobar_); | |
280 ASSERT_TRUE(infobar); | |
281 ASSERT_TRUE(infobar->google_url_tracker()); | |
282 infobar->google_url_tracker()->AcceptGoogleURL(infobar->new_google_url()); | |
283 } | |
284 | |
285 void GoogleURLTrackerTest::CancelGoogleURL() { | |
286 TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( | |
287 g_browser_process->google_url_tracker()->infobar_); | |
288 ASSERT_TRUE(infobar); | |
289 ASSERT_TRUE(infobar->google_url_tracker()); | |
290 infobar->google_url_tracker()->CancelGoogleURL(infobar->new_google_url()); | |
291 } | |
292 | |
293 void GoogleURLTrackerTest::InfoBarClosed() { | |
294 TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( | |
295 g_browser_process->google_url_tracker()->infobar_); | |
296 ASSERT_TRUE(infobar); | |
297 ASSERT_TRUE(infobar->google_url_tracker()); | |
298 infobar->google_url_tracker()->InfoBarClosed(); | |
299 delete infobar; | |
300 } | 312 } |
301 | 313 |
302 void GoogleURLTrackerTest::ExpectDefaultURLs() { | 314 void GoogleURLTrackerTest::ExpectDefaultURLs() { |
303 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), | 315 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
304 GoogleURLTracker::GoogleURL()); | 316 GoogleURLTracker::GoogleURL()); |
305 EXPECT_EQ(GURL(), GetFetchedGoogleURL()); | 317 EXPECT_EQ(GURL(), GetFetchedGoogleURL()); |
306 } | 318 } |
307 | 319 |
308 | 320 |
309 // Tests ---------------------------------------------------------------------- | 321 // Tests ---------------------------------------------------------------------- |
310 | 322 |
311 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 323 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
312 CreateRequestContext(); | |
313 ExpectDefaultURLs(); | 324 ExpectDefaultURLs(); |
314 FinishSleep(); | 325 FinishSleep(); |
315 // No one called RequestServerCheck() so nothing should have happened. | 326 // No one called RequestServerCheck() so nothing should have happened. |
316 EXPECT_FALSE(GetFetcherByID(0)); | 327 EXPECT_FALSE(GetFetcher()); |
| 328 MockSearchDomainCheckResponse(".google.co.uk"); |
317 ExpectDefaultURLs(); | 329 ExpectDefaultURLs(); |
318 EXPECT_FALSE(observer_->notified()); | 330 EXPECT_FALSE(observer_->notified()); |
319 } | 331 } |
320 | 332 |
321 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { | 333 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { |
322 CreateRequestContext(); | |
323 RequestServerCheck(); | 334 RequestServerCheck(); |
324 EXPECT_FALSE(GetFetcherByID(0)); | 335 EXPECT_FALSE(GetFetcher()); |
325 ExpectDefaultURLs(); | 336 ExpectDefaultURLs(); |
326 EXPECT_FALSE(observer_->notified()); | 337 EXPECT_FALSE(observer_->notified()); |
327 | 338 |
328 FinishSleep(); | 339 FinishSleep(); |
329 MockSearchDomainCheckResponse(0, ".google.co.uk"); | 340 MockSearchDomainCheckResponse(".google.co.uk"); |
330 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); | 341 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
331 // GoogleURL should be updated, becase there was no last prompted URL. | 342 // GoogleURL should be updated, becase there was no last prompted URL. |
332 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); | 343 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
333 EXPECT_TRUE(observer_->notified()); | 344 EXPECT_TRUE(observer_->notified()); |
334 } | 345 } |
335 | 346 |
336 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { | 347 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { |
337 CreateRequestContext(); | |
338 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 348 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
339 | 349 |
340 RequestServerCheck(); | 350 RequestServerCheck(); |
341 EXPECT_FALSE(GetFetcherByID(0)); | 351 EXPECT_FALSE(GetFetcher()); |
342 ExpectDefaultURLs(); | 352 ExpectDefaultURLs(); |
343 EXPECT_FALSE(observer_->notified()); | 353 EXPECT_FALSE(observer_->notified()); |
344 | 354 |
345 FinishSleep(); | 355 FinishSleep(); |
346 MockSearchDomainCheckResponse(0, ".google.co.uk"); | 356 MockSearchDomainCheckResponse(".google.co.uk"); |
347 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); | 357 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
348 // GoogleURL should not be updated, because the fetched and prompted URLs | 358 // GoogleURL should not be updated, because the fetched and prompted URLs |
349 // match. | 359 // match. |
350 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), | 360 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
351 GoogleURLTracker::GoogleURL()); | 361 GoogleURLTracker::GoogleURL()); |
352 EXPECT_FALSE(observer_->notified()); | 362 EXPECT_FALSE(observer_->notified()); |
353 } | 363 } |
354 | 364 |
355 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { | 365 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { |
356 CreateRequestContext(); | |
357 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 366 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
358 SetGoogleURL(GURL("http://www.google.co.uk/")); | 367 SetGoogleURL(GURL("http://www.google.co.uk/")); |
359 RequestServerCheck(); | 368 RequestServerCheck(); |
360 FinishSleep(); | 369 FinishSleep(); |
361 MockSearchDomainCheckResponse(0, ".google.co.uk"); | 370 MockSearchDomainCheckResponse(".google.co.uk"); |
362 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); | 371 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
363 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); | 372 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
364 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 373 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
365 EXPECT_FALSE(observer_->notified()); | 374 EXPECT_FALSE(observer_->notified()); |
366 } | 375 } |
367 | 376 |
368 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { | 377 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { |
369 CreateRequestContext(); | |
370 RequestServerCheck(); | 378 RequestServerCheck(); |
371 FinishSleep(); | 379 FinishSleep(); |
372 MockSearchDomainCheckResponse(0, ".google.co.uk"); | 380 MockSearchDomainCheckResponse(".google.co.uk"); |
373 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); | 381 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
374 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); | 382 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
375 EXPECT_TRUE(observer_->notified()); | 383 EXPECT_TRUE(observer_->notified()); |
376 observer_->clear_notified(); | 384 observer_->clear_notified(); |
377 | 385 |
378 NotifyIPAddressChanged(); | 386 NotifyIPAddressChanged(); |
379 MockSearchDomainCheckResponse(1, ".google.co.in"); | 387 MockSearchDomainCheckResponse(".google.co.in"); |
380 EXPECT_EQ(GURL("http://www.google.co.in/"), GetFetchedGoogleURL()); | 388 EXPECT_EQ(GURL("http://www.google.co.in/"), GetFetchedGoogleURL()); |
381 // Just fetching a new URL shouldn't reset things without a prompt. | 389 // Just fetching a new URL shouldn't reset things without a prompt. |
382 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); | 390 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
383 EXPECT_FALSE(observer_->notified()); | 391 EXPECT_FALSE(observer_->notified()); |
384 } | 392 } |
385 | 393 |
386 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { | 394 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { |
387 CreateRequestContext(); | |
388 FinishSleep(); | 395 FinishSleep(); |
389 NotifyIPAddressChanged(); | 396 NotifyIPAddressChanged(); |
390 // No one called RequestServerCheck() so nothing should have happened. | 397 // No one called RequestServerCheck() so nothing should have happened. |
391 EXPECT_FALSE(GetFetcherByID(0)); | 398 EXPECT_FALSE(GetFetcher()); |
| 399 MockSearchDomainCheckResponse(".google.co.uk"); |
392 ExpectDefaultURLs(); | 400 ExpectDefaultURLs(); |
393 EXPECT_FALSE(observer_->notified()); | 401 EXPECT_FALSE(observer_->notified()); |
394 } | 402 } |
395 | 403 |
396 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { | 404 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { |
397 CreateRequestContext(); | |
398 FinishSleep(); | 405 FinishSleep(); |
399 NotifyIPAddressChanged(); | 406 NotifyIPAddressChanged(); |
| 407 MockSearchDomainCheckResponse(".google.co.jp"); |
400 | 408 |
401 RequestServerCheck(); | 409 RequestServerCheck(); |
402 // The first request for a check should trigger a fetch if it hasn't happened | 410 // The first request for a check should trigger a fetch if it hasn't happened |
403 // already. | 411 // already. |
404 MockSearchDomainCheckResponse(0, ".google.co.uk"); | 412 MockSearchDomainCheckResponse(".google.co.uk"); |
405 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); | 413 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
406 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); | 414 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
407 EXPECT_TRUE(observer_->notified()); | 415 EXPECT_TRUE(observer_->notified()); |
408 } | 416 } |
409 | 417 |
| 418 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { |
| 419 FinishSleep(); |
| 420 NotifyIPAddressChanged(); |
| 421 MockSearchDomainCheckResponse(".google.co.jp"); |
| 422 |
| 423 RequestServerCheck(); |
| 424 // The first request for a check should trigger a fetch if it hasn't happened |
| 425 // already. |
| 426 MockSearchDomainCheckResponse(".google.co.uk"); |
| 427 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
| 428 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
| 429 EXPECT_TRUE(observer_->notified()); |
| 430 observer_->clear_notified(); |
| 431 |
| 432 RequestServerCheck(); |
| 433 // The second request should be ignored. |
| 434 EXPECT_FALSE(GetFetcher()); |
| 435 MockSearchDomainCheckResponse(".google.co.in"); |
| 436 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
| 437 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
| 438 EXPECT_FALSE(observer_->notified()); |
| 439 } |
| 440 |
410 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { | 441 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
411 CreateRequestContext(); | |
412 RequestServerCheck(); | 442 RequestServerCheck(); |
413 FinishSleep(); | 443 FinishSleep(); |
414 MockSearchDomainCheckResponse(0, ".google.co.uk"); | 444 MockSearchDomainCheckResponse(".google.co.uk"); |
415 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); | 445 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
416 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); | 446 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
417 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 447 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
418 EXPECT_TRUE(observer_->notified()); | 448 EXPECT_TRUE(observer_->notified()); |
419 observer_->clear_notified(); | 449 observer_->clear_notified(); |
420 | 450 |
421 SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); | 451 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
422 NavEntryCommitted(); | 452 CommitSearch(1); |
423 EXPECT_FALSE(InfoBarIsShown()); | 453 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 454 ASSERT_TRUE(infobar == NULL); |
424 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); | 455 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
425 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); | 456 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
426 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 457 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
427 EXPECT_FALSE(observer_->notified()); | 458 EXPECT_FALSE(observer_->notified()); |
428 } | 459 } |
429 | 460 |
430 TEST_F(GoogleURLTrackerTest, InfobarClosed) { | 461 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { |
431 CreateRequestContext(); | |
432 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 462 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
433 RequestServerCheck(); | 463 RequestServerCheck(); |
434 FinishSleep(); | 464 FinishSleep(); |
435 MockSearchDomainCheckResponse(0, ".google.co.jp"); | 465 MockSearchDomainCheckResponse(".google.co.jp"); |
| 466 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
| 467 GoogleURLTracker::GoogleURL()); |
| 468 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetFetchedGoogleURL()); |
| 469 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 470 EXPECT_FALSE(observer_->notified()); |
436 | 471 |
437 SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); | 472 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
438 NavEntryCommitted(); | 473 TestInfoBarDelegate* infobar = GetInfoBar(1); |
439 EXPECT_TRUE(InfoBarIsShown()); | 474 ASSERT_FALSE(infobar == NULL); |
| 475 EXPECT_FALSE(infobar->showing()); |
| 476 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
| 477 GoogleURLTracker::GoogleURL()); |
| 478 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), |
| 479 infobar->search_url()); |
| 480 EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url()); |
| 481 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 482 EXPECT_FALSE(observer_->notified()); |
440 | 483 |
441 InfoBarClosed(); | 484 CloseTab(1); |
442 EXPECT_FALSE(InfoBarIsShown()); | 485 EXPECT_TRUE(GetInfoBar(1) == NULL); |
443 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), | 486 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
444 GoogleURLTracker::GoogleURL()); | 487 GoogleURLTracker::GoogleURL()); |
445 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 488 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 489 EXPECT_FALSE(observer_->notified()); |
| 490 } |
| 491 |
| 492 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { |
| 493 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 494 RequestServerCheck(); |
| 495 FinishSleep(); |
| 496 MockSearchDomainCheckResponse(".google.co.jp"); |
| 497 |
| 498 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 499 CommitSearch(1); |
| 500 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 501 ASSERT_FALSE(infobar == NULL); |
| 502 EXPECT_TRUE(infobar->showing()); |
| 503 |
| 504 CloseTab(1); |
| 505 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 506 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
| 507 GoogleURLTracker::GoogleURL()); |
| 508 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 509 EXPECT_FALSE(observer_->notified()); |
| 510 } |
| 511 |
| 512 TEST_F(GoogleURLTrackerTest, InfobarClosed) { |
| 513 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 514 RequestServerCheck(); |
| 515 FinishSleep(); |
| 516 MockSearchDomainCheckResponse(".google.co.jp"); |
| 517 |
| 518 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 519 CommitSearch(1); |
| 520 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 521 ASSERT_FALSE(infobar == NULL); |
| 522 |
| 523 infobar->InfoBarClosed(); |
| 524 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 525 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
| 526 GoogleURLTracker::GoogleURL()); |
| 527 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
446 EXPECT_FALSE(observer_->notified()); | 528 EXPECT_FALSE(observer_->notified()); |
447 } | 529 } |
448 | 530 |
449 TEST_F(GoogleURLTrackerTest, InfobarRefused) { | 531 TEST_F(GoogleURLTrackerTest, InfobarRefused) { |
450 CreateRequestContext(); | |
451 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 532 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
452 RequestServerCheck(); | 533 RequestServerCheck(); |
453 FinishSleep(); | 534 FinishSleep(); |
454 MockSearchDomainCheckResponse(0, ".google.co.jp"); | 535 MockSearchDomainCheckResponse(".google.co.jp"); |
455 | 536 |
456 SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); | 537 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
457 NavEntryCommitted(); | 538 CommitSearch(1); |
458 EXPECT_TRUE(InfoBarIsShown()); | 539 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 540 ASSERT_FALSE(infobar == NULL); |
459 | 541 |
460 CancelGoogleURL(); | 542 infobar->Cancel(); |
461 InfoBarClosed(); | 543 EXPECT_TRUE(GetInfoBar(1) == NULL); |
462 EXPECT_FALSE(InfoBarIsShown()); | |
463 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), | 544 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
464 GoogleURLTracker::GoogleURL()); | 545 GoogleURLTracker::GoogleURL()); |
465 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 546 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
466 EXPECT_FALSE(observer_->notified()); | 547 EXPECT_FALSE(observer_->notified()); |
467 } | 548 } |
468 | 549 |
469 TEST_F(GoogleURLTrackerTest, InfobarAccepted) { | 550 TEST_F(GoogleURLTrackerTest, InfobarAccepted) { |
470 CreateRequestContext(); | |
471 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 551 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
472 RequestServerCheck(); | 552 RequestServerCheck(); |
473 FinishSleep(); | 553 FinishSleep(); |
474 MockSearchDomainCheckResponse(0, ".google.co.jp"); | 554 MockSearchDomainCheckResponse(".google.co.jp"); |
475 | 555 |
476 SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); | 556 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
477 NavEntryCommitted(); | 557 CommitSearch(1); |
478 EXPECT_TRUE(InfoBarIsShown()); | 558 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 559 ASSERT_FALSE(infobar == NULL); |
479 | 560 |
480 AcceptGoogleURL(); | 561 infobar->Accept(); |
481 InfoBarClosed(); | 562 EXPECT_TRUE(GetInfoBar(1) == NULL); |
482 EXPECT_FALSE(InfoBarIsShown()); | |
483 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); | 563 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); |
484 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 564 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
485 EXPECT_TRUE(observer_->notified()); | 565 EXPECT_TRUE(observer_->notified()); |
486 } | 566 } |
| 567 |
| 568 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterPendingSearch) { |
| 569 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 570 RequestServerCheck(); |
| 571 FinishSleep(); |
| 572 MockSearchDomainCheckResponse(".google.co.jp"); |
| 573 |
| 574 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 575 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 576 ASSERT_FALSE(infobar == NULL); |
| 577 EXPECT_FALSE(infobar->showing()); |
| 578 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), |
| 579 infobar->search_url()); |
| 580 |
| 581 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); |
| 582 TestInfoBarDelegate* infobar2 = GetInfoBar(1); |
| 583 ASSERT_FALSE(infobar2 == NULL); |
| 584 EXPECT_FALSE(infobar2->showing()); |
| 585 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
| 586 infobar2->search_url()); |
| 587 |
| 588 CommitSearch(1); |
| 589 EXPECT_TRUE(infobar2->showing()); |
| 590 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
| 591 GoogleURLTracker::GoogleURL()); |
| 592 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 593 EXPECT_FALSE(observer_->notified()); |
| 594 |
| 595 CloseTab(1); |
| 596 } |
| 597 |
| 598 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterCommittedSearch) { |
| 599 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 600 RequestServerCheck(); |
| 601 FinishSleep(); |
| 602 MockSearchDomainCheckResponse(".google.co.jp"); |
| 603 |
| 604 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 605 CommitSearch(1); |
| 606 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 607 ASSERT_FALSE(infobar == NULL); |
| 608 EXPECT_TRUE(infobar->showing()); |
| 609 |
| 610 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); |
| 611 TestInfoBarDelegate* infobar2 = GetInfoBar(1); |
| 612 ASSERT_FALSE(infobar2 == NULL); |
| 613 EXPECT_FALSE(infobar2->showing()); |
| 614 |
| 615 CommitSearch(1); |
| 616 EXPECT_TRUE(infobar2->showing()); |
| 617 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
| 618 GoogleURLTracker::GoogleURL()); |
| 619 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 620 EXPECT_FALSE(observer_->notified()); |
| 621 |
| 622 CloseTab(1); |
| 623 } |
| 624 |
| 625 TEST_F(GoogleURLTrackerTest, MultipleInfobars) { |
| 626 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 627 RequestServerCheck(); |
| 628 FinishSleep(); |
| 629 MockSearchDomainCheckResponse(".google.co.jp"); |
| 630 |
| 631 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 632 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 633 ASSERT_FALSE(infobar == NULL); |
| 634 EXPECT_FALSE(infobar->showing()); |
| 635 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), |
| 636 infobar->search_url()); |
| 637 |
| 638 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 2); |
| 639 CommitSearch(2); |
| 640 TestInfoBarDelegate* infobar2 = GetInfoBar(2); |
| 641 ASSERT_FALSE(infobar2 == NULL); |
| 642 EXPECT_TRUE(infobar2->showing()); |
| 643 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
| 644 infobar2->search_url()); |
| 645 |
| 646 SetSearchPending(GURL("http://www.google.co.uk/search?q=test3"), 3); |
| 647 TestInfoBarDelegate* infobar3 = GetInfoBar(3); |
| 648 ASSERT_FALSE(infobar3 == NULL); |
| 649 EXPECT_FALSE(infobar3->showing()); |
| 650 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test3"), |
| 651 infobar3->search_url()); |
| 652 |
| 653 SetSearchPending(GURL("http://www.google.co.uk/search?q=test4"), 4); |
| 654 CommitSearch(4); |
| 655 TestInfoBarDelegate* infobar4 = GetInfoBar(4); |
| 656 ASSERT_FALSE(infobar4 == NULL); |
| 657 EXPECT_TRUE(infobar4->showing()); |
| 658 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), |
| 659 infobar4->search_url()); |
| 660 |
| 661 CommitSearch(1); |
| 662 EXPECT_TRUE(infobar->showing()); |
| 663 |
| 664 infobar2->InfoBarClosed(); |
| 665 EXPECT_TRUE(GetInfoBar(2) == NULL); |
| 666 EXPECT_FALSE(observer_->notified()); |
| 667 |
| 668 infobar4->Accept(); |
| 669 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 670 EXPECT_TRUE(GetInfoBar(3) == NULL); |
| 671 EXPECT_TRUE(GetInfoBar(4) == NULL); |
| 672 EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); |
| 673 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 674 EXPECT_TRUE(observer_->notified()); |
| 675 } |
OLD | NEW |