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 "chrome/browser/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 const content::NotificationDetails& details) { | 53 const content::NotificationDetails& details) { |
54 notified_ = true; | 54 notified_ = true; |
55 } | 55 } |
56 | 56 |
57 | 57 |
58 // TestInfoBarDelegate -------------------------------------------------------- | 58 // TestInfoBarDelegate -------------------------------------------------------- |
59 | 59 |
60 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { | 60 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { |
61 public: | 61 public: |
62 TestInfoBarDelegate(InfoBarTabHelper* infobar_helper, | 62 TestInfoBarDelegate(InfoBarTabHelper* infobar_helper, |
63 const GURL& search_url, | |
64 GoogleURLTracker* google_url_tracker, | 63 GoogleURLTracker* google_url_tracker, |
65 const GURL& new_google_url); | 64 const GURL& new_google_url); |
66 virtual ~TestInfoBarDelegate(); | 65 virtual ~TestInfoBarDelegate(); |
67 | 66 |
68 GURL search_url() const { return search_url_; } | 67 GURL search_url() const { return search_url_; } |
69 GURL new_google_url() const { return new_google_url_; } | 68 GURL new_google_url() const { return new_google_url_; } |
70 bool showing() const { return showing_; } | 69 int pending_id() const { return pending_id_; } |
71 | 70 |
72 private: | 71 private: |
73 // GoogleURLTrackerInfoBarDelegate: | 72 // GoogleURLTrackerInfoBarDelegate: |
74 virtual void Show() OVERRIDE; | 73 virtual void Show(const GURL& search_url) OVERRIDE; |
75 virtual void Close(bool redo_search) OVERRIDE; | 74 virtual void Close(bool redo_search) OVERRIDE; |
76 }; | 75 }; |
77 | 76 |
78 TestInfoBarDelegate::TestInfoBarDelegate(InfoBarTabHelper* infobar_helper, | 77 TestInfoBarDelegate::TestInfoBarDelegate(InfoBarTabHelper* infobar_helper, |
79 const GURL& search_url, | |
80 GoogleURLTracker* google_url_tracker, | 78 GoogleURLTracker* google_url_tracker, |
81 const GURL& new_google_url) | 79 const GURL& new_google_url) |
82 : GoogleURLTrackerInfoBarDelegate(NULL, search_url, google_url_tracker, | 80 : GoogleURLTrackerInfoBarDelegate(NULL, google_url_tracker, new_google_url) { |
83 new_google_url) { | |
84 // We set |map_key_| here instead of in the superclass constructor so that the | 81 // We set |map_key_| here instead of in the superclass constructor so that the |
85 // InfoBarDelegate base class will not try to dereference it, which would fail | 82 // InfoBarDelegate base class will not try to dereference it, which would fail |
86 // since this is really a magic number and not an actual pointer. | 83 // since this is really a magic number and not an actual pointer. |
87 map_key_ = infobar_helper; | 84 map_key_ = infobar_helper; |
88 } | 85 } |
89 | 86 |
90 void TestInfoBarDelegate::Show() { | 87 void TestInfoBarDelegate::Show(const GURL& search_url) { |
| 88 search_url_ = search_url; |
| 89 pending_id_ = 0; |
91 showing_ = true; | 90 showing_ = true; |
92 } | 91 } |
93 | 92 |
94 void TestInfoBarDelegate::Close(bool redo_search) { | 93 void TestInfoBarDelegate::Close(bool redo_search) { |
95 InfoBarClosed(); | 94 InfoBarClosed(); |
96 } | 95 } |
97 | 96 |
98 TestInfoBarDelegate::~TestInfoBarDelegate() { | 97 TestInfoBarDelegate::~TestInfoBarDelegate() { |
99 } | 98 } |
100 | 99 |
101 GoogleURLTrackerInfoBarDelegate* CreateTestInfobar( | 100 GoogleURLTrackerInfoBarDelegate* CreateTestInfobar( |
102 InfoBarTabHelper* infobar_helper, | 101 InfoBarTabHelper* infobar_helper, |
103 const GURL& search_url, | |
104 GoogleURLTracker* google_url_tracker, | 102 GoogleURLTracker* google_url_tracker, |
105 const GURL& new_google_url) { | 103 const GURL& new_google_url) { |
106 return new TestInfoBarDelegate(infobar_helper, search_url, google_url_tracker, | 104 return new TestInfoBarDelegate(infobar_helper, google_url_tracker, |
107 new_google_url); | 105 new_google_url); |
108 } | 106 } |
109 | 107 |
110 } // namespace | 108 } // namespace |
111 | 109 |
112 | 110 |
113 // GoogleURLTrackerTest ------------------------------------------------------- | 111 // GoogleURLTrackerTest ------------------------------------------------------- |
114 | 112 |
115 class GoogleURLTrackerTest : public testing::Test { | 113 class GoogleURLTrackerTest : public testing::Test { |
116 protected: | 114 protected: |
(...skipping 11 matching lines...) Expand all Loading... |
128 void NotifyIPAddressChanged(); | 126 void NotifyIPAddressChanged(); |
129 GURL fetched_google_url() const { | 127 GURL fetched_google_url() const { |
130 return google_url_tracker_->fetched_google_url_; | 128 return google_url_tracker_->fetched_google_url_; |
131 } | 129 } |
132 void set_google_url(const GURL& url) { | 130 void set_google_url(const GURL& url) { |
133 google_url_tracker_->google_url_ = url; | 131 google_url_tracker_->google_url_ = url; |
134 } | 132 } |
135 GURL google_url() const { return google_url_tracker_->google_url_; } | 133 GURL google_url() const { return google_url_tracker_->google_url_; } |
136 void SetLastPromptedGoogleURL(const GURL& url); | 134 void SetLastPromptedGoogleURL(const GURL& url); |
137 GURL GetLastPromptedGoogleURL(); | 135 GURL GetLastPromptedGoogleURL(); |
138 void SetSearchPending(const GURL& search_url, int unique_id); | 136 void SetNonSearchPending(int unique_id); |
139 void CommitSearch(int unique_id); | 137 void SetSearchPending(int unique_id); |
| 138 void CommitNonSearch(int unique_id); |
| 139 void CommitSearch(const GURL& search_url, int unique_id); |
140 void CloseTab(int unique_id); | 140 void CloseTab(int unique_id); |
141 TestInfoBarDelegate* GetInfoBar(int unique_id); | 141 TestInfoBarDelegate* GetInfoBar(int unique_id); |
142 void ExpectDefaultURLs(); | 142 void ExpectDefaultURLs() const; |
| 143 void ExpectListeningForCommit(int unique_id, bool listening) const; |
143 | 144 |
144 scoped_ptr<TestNotificationObserver> observer_; | 145 scoped_ptr<TestNotificationObserver> observer_; |
145 | 146 |
146 private: | 147 private: |
147 // These are required by the TestURLFetchers GoogleURLTracker will create (see | 148 // These are required by the TestURLFetchers GoogleURLTracker will create (see |
148 // test_url_fetcher_factory.h). | 149 // test_url_fetcher_factory.h). |
149 MessageLoop message_loop_; | 150 MessageLoop message_loop_; |
150 content::TestBrowserThread io_thread_; | 151 content::TestBrowserThread io_thread_; |
151 // Creating this allows us to call | 152 // Creating this allows us to call |
152 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). | 153 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 227 } |
227 | 228 |
228 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { | 229 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { |
229 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); | 230 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); |
230 } | 231 } |
231 | 232 |
232 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { | 233 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { |
233 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); | 234 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); |
234 } | 235 } |
235 | 236 |
236 void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url, | 237 void GoogleURLTrackerTest::SetNonSearchPending(int unique_id) { |
237 int unique_id) { | |
238 unique_ids_seen_.insert(unique_id); | 238 unique_ids_seen_.insert(unique_id); |
239 google_url_tracker_->SearchCommitted(); | |
240 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 239 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
241 content::NOTIFICATION_NAV_ENTRY_PENDING, | 240 content::NOTIFICATION_NAV_ENTRY_PENDING, |
242 content::NotificationService::AllBrowserContextsAndSources())) { | 241 content::NotificationService::AllBrowserContextsAndSources())) { |
243 google_url_tracker_->OnNavigationPending( | 242 google_url_tracker_->OnNavigationPending( |
244 content::Source<content::NavigationController>( | 243 content::Source<content::NavigationController>( |
245 reinterpret_cast<content::NavigationController*>(unique_id)), | 244 reinterpret_cast<content::NavigationController*>(unique_id)), |
246 content::Source<TabContents>(reinterpret_cast<TabContents*>(unique_id)), | 245 content::Source<TabContents>(reinterpret_cast<TabContents*>(unique_id)), |
247 reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url); | 246 reinterpret_cast<InfoBarTabHelper*>(unique_id), unique_id); |
248 } | 247 } |
249 } | 248 } |
250 | 249 |
251 void GoogleURLTrackerTest::CommitSearch(int unique_id) { | 250 void GoogleURLTrackerTest::SetSearchPending(int unique_id) { |
252 content::Source<content::NavigationController> source( | 251 google_url_tracker_->SearchCommitted(); |
253 reinterpret_cast<content::NavigationController*>(unique_id)); | 252 // Note that the call above might not have actually registered a listener for |
| 253 // NOTIFICATION_NAV_ENTRY_PENDING if the searchdomaincheck response was bogus. |
| 254 SetNonSearchPending(unique_id); |
| 255 } |
| 256 |
| 257 void GoogleURLTrackerTest::CommitNonSearch(int unique_id) { |
| 258 GoogleURLTracker::InfoBarMap::iterator i = |
| 259 google_url_tracker_->infobar_map_.find( |
| 260 reinterpret_cast<InfoBarTabHelper*>(unique_id)); |
| 261 if (i != google_url_tracker_->infobar_map_.end()) { |
| 262 ExpectListeningForCommit(unique_id, false); |
| 263 TestInfoBarDelegate* infobar = |
| 264 static_cast<TestInfoBarDelegate*>(i->second.infobar); |
| 265 // The infobar should be showing; otherwise the pending non-search should |
| 266 // have closed it. |
| 267 EXPECT_TRUE(infobar->showing()); |
| 268 // The pending_id should have been reset to 0 when the non-search became |
| 269 // pending. |
| 270 EXPECT_EQ(0, infobar->pending_id()); |
| 271 infobar->InfoBarClosed(); |
| 272 } |
| 273 } |
| 274 |
| 275 void GoogleURLTrackerTest::CommitSearch(const GURL& search_url, int unique_id) { |
254 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 276 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
255 content::NOTIFICATION_NAV_ENTRY_COMMITTED, source)) { | 277 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
256 google_url_tracker_->OnNavigationCommittedOrTabClosed(source, | 278 content::Source<content::NavigationController>( |
257 content::Source<TabContents>(reinterpret_cast<TabContents*>(unique_id)), | 279 reinterpret_cast<content::NavigationController*>(unique_id)))) { |
258 reinterpret_cast<InfoBarTabHelper*>(unique_id), true); | 280 google_url_tracker_->OnNavigationCommittedOrTabClosed( |
| 281 reinterpret_cast<InfoBarTabHelper*>(unique_id), |
| 282 search_url); |
259 } | 283 } |
260 } | 284 } |
261 | 285 |
262 void GoogleURLTrackerTest::CloseTab(int unique_id) { | 286 void GoogleURLTrackerTest::CloseTab(int unique_id) { |
263 unique_ids_seen_.erase(unique_id); | 287 unique_ids_seen_.erase(unique_id); |
264 content::Source<TabContents> source( | |
265 reinterpret_cast<TabContents*>(unique_id)); | |
266 InfoBarTabHelper* infobar_helper = | 288 InfoBarTabHelper* infobar_helper = |
267 reinterpret_cast<InfoBarTabHelper*>(unique_id); | 289 reinterpret_cast<InfoBarTabHelper*>(unique_id); |
268 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 290 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
269 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, source)) { | 291 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, content::Source<TabContents>( |
270 google_url_tracker_->OnNavigationCommittedOrTabClosed( | 292 reinterpret_cast<TabContents*>(unique_id)))) { |
271 content::Source<content::NavigationController>( | 293 google_url_tracker_->OnNavigationCommittedOrTabClosed(infobar_helper, |
272 reinterpret_cast<content::NavigationController*>(unique_id)), | 294 GURL()); |
273 source, infobar_helper, false); | |
274 } else { | 295 } else { |
275 // Normally, closing a tab with an infobar showing will close the infobar. | 296 // Normally, closing a tab with an infobar showing will close the infobar. |
276 // Since we don't have real tabs and are just faking things with magic | 297 // Since we don't have real tabs and are just faking things with magic |
277 // numbers, we have to manually close the infobar, if any. | 298 // numbers, we have to manually close the infobar, if any. |
278 GoogleURLTracker::InfoBarMap::iterator i = | 299 GoogleURLTracker::InfoBarMap::iterator i = |
279 google_url_tracker_->infobar_map_.find(infobar_helper); | 300 google_url_tracker_->infobar_map_.find(infobar_helper); |
280 if (i != google_url_tracker_->infobar_map_.end()) { | 301 if (i != google_url_tracker_->infobar_map_.end()) { |
281 TestInfoBarDelegate* infobar = | 302 TestInfoBarDelegate* infobar = |
282 static_cast<TestInfoBarDelegate*>(i->second); | 303 static_cast<TestInfoBarDelegate*>(i->second.infobar); |
283 DCHECK(infobar->showing()); | 304 EXPECT_TRUE(infobar->showing()); |
284 infobar->InfoBarClosed(); | 305 infobar->InfoBarClosed(); |
285 } | 306 } |
286 } | 307 } |
287 } | 308 } |
288 | 309 |
289 TestInfoBarDelegate* GoogleURLTrackerTest::GetInfoBar(int unique_id) { | 310 TestInfoBarDelegate* GoogleURLTrackerTest::GetInfoBar(int unique_id) { |
290 GoogleURLTracker::InfoBarMap::const_iterator i = | 311 GoogleURLTracker::InfoBarMap::const_iterator i = |
291 google_url_tracker_->infobar_map_.find( | 312 google_url_tracker_->infobar_map_.find( |
292 reinterpret_cast<InfoBarTabHelper*>(unique_id)); | 313 reinterpret_cast<InfoBarTabHelper*>(unique_id)); |
293 return (i == google_url_tracker_->infobar_map_.end()) ? | 314 return (i == google_url_tracker_->infobar_map_.end()) ? |
294 NULL : static_cast<TestInfoBarDelegate*>(i->second); | 315 NULL : static_cast<TestInfoBarDelegate*>(i->second.infobar); |
295 } | 316 } |
296 | 317 |
297 void GoogleURLTrackerTest::ExpectDefaultURLs() { | 318 void GoogleURLTrackerTest::ExpectDefaultURLs() const { |
298 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 319 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
299 EXPECT_EQ(GURL(), fetched_google_url()); | 320 EXPECT_EQ(GURL(), fetched_google_url()); |
300 } | 321 } |
301 | 322 |
| 323 void GoogleURLTrackerTest::ExpectListeningForCommit(int unique_id, |
| 324 bool listening) const { |
| 325 GoogleURLTracker::InfoBarMap::iterator i = |
| 326 google_url_tracker_->infobar_map_.find( |
| 327 reinterpret_cast<InfoBarTabHelper*>(unique_id)); |
| 328 ASSERT_FALSE(i == google_url_tracker_->infobar_map_.end()); |
| 329 EXPECT_EQ(listening, google_url_tracker_->registrar_.IsRegistered( |
| 330 google_url_tracker_.get(), content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 331 i->second.navigation_controller_source)); |
| 332 } |
| 333 |
302 | 334 |
303 // Tests ---------------------------------------------------------------------- | 335 // Tests ---------------------------------------------------------------------- |
304 | 336 |
305 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 337 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
306 ExpectDefaultURLs(); | 338 ExpectDefaultURLs(); |
307 FinishSleep(); | 339 FinishSleep(); |
308 // No one called RequestServerCheck() so nothing should have happened. | 340 // No one called RequestServerCheck() so nothing should have happened. |
309 EXPECT_FALSE(GetFetcher()); | 341 EXPECT_FALSE(GetFetcher()); |
310 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 342 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
311 ExpectDefaultURLs(); | 343 ExpectDefaultURLs(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 EXPECT_FALSE(GetFetcher()); | 382 EXPECT_FALSE(GetFetcher()); |
351 ExpectDefaultURLs(); | 383 ExpectDefaultURLs(); |
352 EXPECT_FALSE(observer_->notified()); | 384 EXPECT_FALSE(observer_->notified()); |
353 | 385 |
354 // Old-style domain string. | 386 // Old-style domain string. |
355 FinishSleep(); | 387 FinishSleep(); |
356 MockSearchDomainCheckResponse(".google.co.in"); | 388 MockSearchDomainCheckResponse(".google.co.in"); |
357 EXPECT_EQ(GURL(), fetched_google_url()); | 389 EXPECT_EQ(GURL(), fetched_google_url()); |
358 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 390 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
359 EXPECT_FALSE(observer_->notified()); | 391 EXPECT_FALSE(observer_->notified()); |
360 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 392 SetSearchPending(1); |
361 CommitSearch(1); | 393 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
362 EXPECT_TRUE(GetInfoBar(1) == NULL); | 394 EXPECT_TRUE(GetInfoBar(1) == NULL); |
363 | 395 |
364 // Bad subdomain. | 396 // Bad subdomain. |
365 NotifyIPAddressChanged(); | 397 NotifyIPAddressChanged(); |
366 MockSearchDomainCheckResponse("http://mail.google.com/"); | 398 MockSearchDomainCheckResponse("http://mail.google.com/"); |
367 EXPECT_EQ(GURL(), fetched_google_url()); | 399 EXPECT_EQ(GURL(), fetched_google_url()); |
368 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 400 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
369 EXPECT_FALSE(observer_->notified()); | 401 EXPECT_FALSE(observer_->notified()); |
370 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 402 SetSearchPending(1); |
371 CommitSearch(1); | 403 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
372 EXPECT_TRUE(GetInfoBar(1) == NULL); | 404 EXPECT_TRUE(GetInfoBar(1) == NULL); |
373 | 405 |
374 // Non-empty path. | 406 // Non-empty path. |
375 NotifyIPAddressChanged(); | 407 NotifyIPAddressChanged(); |
376 MockSearchDomainCheckResponse("http://www.google.com/search"); | 408 MockSearchDomainCheckResponse("http://www.google.com/search"); |
377 EXPECT_EQ(GURL(), fetched_google_url()); | 409 EXPECT_EQ(GURL(), fetched_google_url()); |
378 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 410 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
379 EXPECT_FALSE(observer_->notified()); | 411 EXPECT_FALSE(observer_->notified()); |
380 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 412 SetSearchPending(1); |
381 CommitSearch(1); | 413 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
382 EXPECT_TRUE(GetInfoBar(1) == NULL); | 414 EXPECT_TRUE(GetInfoBar(1) == NULL); |
383 | 415 |
384 // Non-empty query. | 416 // Non-empty query. |
385 NotifyIPAddressChanged(); | 417 NotifyIPAddressChanged(); |
386 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); | 418 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); |
387 EXPECT_EQ(GURL(), fetched_google_url()); | 419 EXPECT_EQ(GURL(), fetched_google_url()); |
388 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 420 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
389 EXPECT_FALSE(observer_->notified()); | 421 EXPECT_FALSE(observer_->notified()); |
390 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 422 SetSearchPending(1); |
391 CommitSearch(1); | 423 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
392 EXPECT_TRUE(GetInfoBar(1) == NULL); | 424 EXPECT_TRUE(GetInfoBar(1) == NULL); |
393 | 425 |
394 // Non-empty ref. | 426 // Non-empty ref. |
395 NotifyIPAddressChanged(); | 427 NotifyIPAddressChanged(); |
396 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); | 428 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); |
397 EXPECT_EQ(GURL(), fetched_google_url()); | 429 EXPECT_EQ(GURL(), fetched_google_url()); |
398 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 430 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
399 EXPECT_FALSE(observer_->notified()); | 431 EXPECT_FALSE(observer_->notified()); |
400 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 432 SetSearchPending(1); |
401 CommitSearch(1); | 433 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
402 EXPECT_TRUE(GetInfoBar(1) == NULL); | 434 EXPECT_TRUE(GetInfoBar(1) == NULL); |
403 | 435 |
404 // Complete garbage. | 436 // Complete garbage. |
405 NotifyIPAddressChanged(); | 437 NotifyIPAddressChanged(); |
406 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); | 438 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); |
407 EXPECT_EQ(GURL(), fetched_google_url()); | 439 EXPECT_EQ(GURL(), fetched_google_url()); |
408 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 440 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
409 EXPECT_FALSE(observer_->notified()); | 441 EXPECT_FALSE(observer_->notified()); |
410 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 442 SetSearchPending(1); |
411 CommitSearch(1); | 443 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
412 EXPECT_TRUE(GetInfoBar(1) == NULL); | 444 EXPECT_TRUE(GetInfoBar(1) == NULL); |
413 } | 445 } |
414 | 446 |
415 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { | 447 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { |
416 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 448 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
417 set_google_url(GURL("http://www.google.co.uk/")); | 449 set_google_url(GURL("http://www.google.co.uk/")); |
418 RequestServerCheck(); | 450 RequestServerCheck(); |
419 FinishSleep(); | 451 FinishSleep(); |
420 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 452 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
421 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 453 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { | 544 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
513 RequestServerCheck(); | 545 RequestServerCheck(); |
514 FinishSleep(); | 546 FinishSleep(); |
515 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 547 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
516 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 548 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
517 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 549 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
518 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 550 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
519 EXPECT_TRUE(observer_->notified()); | 551 EXPECT_TRUE(observer_->notified()); |
520 observer_->clear_notified(); | 552 observer_->clear_notified(); |
521 | 553 |
522 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 554 SetSearchPending(1); |
523 CommitSearch(1); | 555 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
524 TestInfoBarDelegate* infobar = GetInfoBar(1); | 556 TestInfoBarDelegate* infobar = GetInfoBar(1); |
525 EXPECT_TRUE(infobar == NULL); | 557 EXPECT_TRUE(infobar == NULL); |
526 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 558 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
527 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 559 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
528 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 560 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
529 EXPECT_FALSE(observer_->notified()); | 561 EXPECT_FALSE(observer_->notified()); |
530 } | 562 } |
531 | 563 |
532 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { | 564 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { |
533 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 565 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
534 RequestServerCheck(); | 566 RequestServerCheck(); |
535 FinishSleep(); | 567 FinishSleep(); |
536 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 568 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
537 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 569 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
538 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); | 570 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); |
539 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 571 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
540 EXPECT_FALSE(observer_->notified()); | 572 EXPECT_FALSE(observer_->notified()); |
541 | 573 |
542 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 574 SetSearchPending(1); |
543 TestInfoBarDelegate* infobar = GetInfoBar(1); | 575 TestInfoBarDelegate* infobar = GetInfoBar(1); |
544 ASSERT_FALSE(infobar == NULL); | 576 ASSERT_FALSE(infobar == NULL); |
545 EXPECT_FALSE(infobar->showing()); | 577 EXPECT_FALSE(infobar->showing()); |
546 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 578 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
547 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), | |
548 infobar->search_url()); | |
549 EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url()); | 579 EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url()); |
550 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 580 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
551 EXPECT_FALSE(observer_->notified()); | 581 EXPECT_FALSE(observer_->notified()); |
552 | 582 |
553 CloseTab(1); | 583 CloseTab(1); |
554 EXPECT_TRUE(GetInfoBar(1) == NULL); | 584 EXPECT_TRUE(GetInfoBar(1) == NULL); |
555 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 585 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
556 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 586 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
557 EXPECT_FALSE(observer_->notified()); | 587 EXPECT_FALSE(observer_->notified()); |
558 } | 588 } |
559 | 589 |
560 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { | 590 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { |
561 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 591 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
562 RequestServerCheck(); | 592 RequestServerCheck(); |
563 FinishSleep(); | 593 FinishSleep(); |
564 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 594 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
565 | 595 |
566 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 596 SetSearchPending(1); |
567 CommitSearch(1); | 597 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
568 TestInfoBarDelegate* infobar = GetInfoBar(1); | 598 TestInfoBarDelegate* infobar = GetInfoBar(1); |
569 ASSERT_FALSE(infobar == NULL); | 599 ASSERT_FALSE(infobar == NULL); |
570 EXPECT_TRUE(infobar->showing()); | 600 EXPECT_TRUE(infobar->showing()); |
571 | 601 |
572 CloseTab(1); | 602 CloseTab(1); |
573 EXPECT_TRUE(GetInfoBar(1) == NULL); | 603 EXPECT_TRUE(GetInfoBar(1) == NULL); |
574 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 604 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
575 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 605 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
576 EXPECT_FALSE(observer_->notified()); | 606 EXPECT_FALSE(observer_->notified()); |
577 } | 607 } |
578 | 608 |
579 TEST_F(GoogleURLTrackerTest, InfobarClosed) { | 609 TEST_F(GoogleURLTrackerTest, InfobarClosed) { |
580 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 610 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
581 RequestServerCheck(); | 611 RequestServerCheck(); |
582 FinishSleep(); | 612 FinishSleep(); |
583 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 613 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
584 | 614 |
585 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 615 SetSearchPending(1); |
586 CommitSearch(1); | 616 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
587 TestInfoBarDelegate* infobar = GetInfoBar(1); | 617 TestInfoBarDelegate* infobar = GetInfoBar(1); |
588 ASSERT_FALSE(infobar == NULL); | 618 ASSERT_FALSE(infobar == NULL); |
589 | 619 |
590 infobar->InfoBarClosed(); | 620 infobar->InfoBarClosed(); |
591 EXPECT_TRUE(GetInfoBar(1) == NULL); | 621 EXPECT_TRUE(GetInfoBar(1) == NULL); |
592 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 622 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
593 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 623 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
594 EXPECT_FALSE(observer_->notified()); | 624 EXPECT_FALSE(observer_->notified()); |
595 } | 625 } |
596 | 626 |
597 TEST_F(GoogleURLTrackerTest, InfobarRefused) { | 627 TEST_F(GoogleURLTrackerTest, InfobarRefused) { |
598 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 628 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
599 RequestServerCheck(); | 629 RequestServerCheck(); |
600 FinishSleep(); | 630 FinishSleep(); |
601 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 631 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
602 | 632 |
603 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 633 SetSearchPending(1); |
604 CommitSearch(1); | 634 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
605 TestInfoBarDelegate* infobar = GetInfoBar(1); | 635 TestInfoBarDelegate* infobar = GetInfoBar(1); |
606 ASSERT_FALSE(infobar == NULL); | 636 ASSERT_FALSE(infobar == NULL); |
607 | 637 |
608 infobar->Cancel(); | 638 infobar->Cancel(); |
609 EXPECT_TRUE(GetInfoBar(1) == NULL); | 639 EXPECT_TRUE(GetInfoBar(1) == NULL); |
610 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 640 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
611 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 641 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
612 EXPECT_FALSE(observer_->notified()); | 642 EXPECT_FALSE(observer_->notified()); |
613 } | 643 } |
614 | 644 |
615 TEST_F(GoogleURLTrackerTest, InfobarAccepted) { | 645 TEST_F(GoogleURLTrackerTest, InfobarAccepted) { |
616 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 646 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
617 RequestServerCheck(); | 647 RequestServerCheck(); |
618 FinishSleep(); | 648 FinishSleep(); |
619 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 649 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
620 | 650 |
621 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 651 SetSearchPending(1); |
622 CommitSearch(1); | 652 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
623 TestInfoBarDelegate* infobar = GetInfoBar(1); | 653 TestInfoBarDelegate* infobar = GetInfoBar(1); |
624 ASSERT_FALSE(infobar == NULL); | 654 ASSERT_FALSE(infobar == NULL); |
625 | 655 |
626 infobar->Accept(); | 656 infobar->Accept(); |
627 EXPECT_TRUE(GetInfoBar(1) == NULL); | 657 EXPECT_TRUE(GetInfoBar(1) == NULL); |
628 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 658 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
629 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 659 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
630 EXPECT_TRUE(observer_->notified()); | 660 EXPECT_TRUE(observer_->notified()); |
631 } | 661 } |
632 | 662 |
633 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfobars) { | 663 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfobars) { |
634 RequestServerCheck(); | 664 RequestServerCheck(); |
635 FinishSleep(); | 665 FinishSleep(); |
636 MockSearchDomainCheckResponse(google_url().spec()); | 666 MockSearchDomainCheckResponse(google_url().spec()); |
637 | 667 |
638 // Re-fetching the accepted URL after showing an infobar for another URL | 668 // Re-fetching the accepted URL after showing an infobar for another URL |
639 // should close the infobar. | 669 // should close the infobar. |
640 NotifyIPAddressChanged(); | 670 NotifyIPAddressChanged(); |
641 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 671 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
642 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); | 672 SetSearchPending(1); |
643 CommitSearch(1); | 673 CommitSearch(GURL("http://www.google.com/search?q=test"), 1); |
644 EXPECT_FALSE(GetInfoBar(1) == NULL); | 674 EXPECT_FALSE(GetInfoBar(1) == NULL); |
645 NotifyIPAddressChanged(); | 675 NotifyIPAddressChanged(); |
646 MockSearchDomainCheckResponse(google_url().spec()); | 676 MockSearchDomainCheckResponse(google_url().spec()); |
647 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); | 677 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); |
648 EXPECT_TRUE(GetInfoBar(1) == NULL); | 678 EXPECT_TRUE(GetInfoBar(1) == NULL); |
649 | 679 |
650 // As should fetching a URL that differs from the accepted only by the scheme. | 680 // As should fetching a URL that differs from the accepted only by the scheme. |
651 NotifyIPAddressChanged(); | 681 NotifyIPAddressChanged(); |
652 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 682 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
653 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); | 683 SetSearchPending(1); |
654 CommitSearch(1); | 684 CommitSearch(GURL("http://www.google.com/search?q=test"), 1); |
655 EXPECT_FALSE(GetInfoBar(1) == NULL); | 685 EXPECT_FALSE(GetInfoBar(1) == NULL); |
656 NotifyIPAddressChanged(); | 686 NotifyIPAddressChanged(); |
657 url_canon::Replacements<char> replacements; | 687 url_canon::Replacements<char> replacements; |
658 const std::string& scheme("https"); | 688 const std::string& scheme("https"); |
659 replacements.SetScheme(scheme.data(), | 689 replacements.SetScheme(scheme.data(), |
660 url_parse::Component(0, scheme.length())); | 690 url_parse::Component(0, scheme.length())); |
661 GURL new_google_url(google_url().ReplaceComponents(replacements)); | 691 GURL new_google_url(google_url().ReplaceComponents(replacements)); |
662 MockSearchDomainCheckResponse(new_google_url.spec()); | 692 MockSearchDomainCheckResponse(new_google_url.spec()); |
663 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); | 693 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); |
664 EXPECT_TRUE(GetInfoBar(1) == NULL); | 694 EXPECT_TRUE(GetInfoBar(1) == NULL); |
665 | 695 |
666 // As should re-fetching the last prompted URL. | 696 // As should re-fetching the last prompted URL. |
667 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 697 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
668 NotifyIPAddressChanged(); | 698 NotifyIPAddressChanged(); |
669 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 699 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
670 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); | 700 SetSearchPending(1); |
671 CommitSearch(1); | 701 CommitSearch(GURL("http://www.google.com/search?q=test"), 1); |
672 EXPECT_FALSE(GetInfoBar(1) == NULL); | 702 EXPECT_FALSE(GetInfoBar(1) == NULL); |
673 NotifyIPAddressChanged(); | 703 NotifyIPAddressChanged(); |
674 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 704 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
675 EXPECT_EQ(new_google_url, google_url()); | 705 EXPECT_EQ(new_google_url, google_url()); |
676 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 706 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
677 EXPECT_TRUE(GetInfoBar(1) == NULL); | 707 EXPECT_TRUE(GetInfoBar(1) == NULL); |
678 | 708 |
679 // And one that differs from the last prompted URL only by the scheme. | 709 // And one that differs from the last prompted URL only by the scheme. |
680 NotifyIPAddressChanged(); | 710 NotifyIPAddressChanged(); |
681 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 711 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
682 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); | 712 SetSearchPending(1); |
683 CommitSearch(1); | 713 CommitSearch(GURL("http://www.google.com/search?q=test"), 1); |
684 EXPECT_FALSE(GetInfoBar(1) == NULL); | 714 EXPECT_FALSE(GetInfoBar(1) == NULL); |
685 NotifyIPAddressChanged(); | 715 NotifyIPAddressChanged(); |
686 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | 716 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
687 EXPECT_EQ(new_google_url, google_url()); | 717 EXPECT_EQ(new_google_url, google_url()); |
688 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 718 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
689 EXPECT_TRUE(GetInfoBar(1) == NULL); | 719 EXPECT_TRUE(GetInfoBar(1) == NULL); |
690 | 720 |
691 // And fetching a different URL entirely. | 721 // And fetching a different URL entirely. |
692 NotifyIPAddressChanged(); | 722 NotifyIPAddressChanged(); |
693 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 723 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
694 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); | 724 SetSearchPending(1); |
695 CommitSearch(1); | 725 CommitSearch(GURL("http://www.google.com/search?q=test"), 1); |
696 EXPECT_FALSE(GetInfoBar(1) == NULL); | 726 EXPECT_FALSE(GetInfoBar(1) == NULL); |
697 NotifyIPAddressChanged(); | 727 NotifyIPAddressChanged(); |
698 MockSearchDomainCheckResponse("https://www.google.co.in/"); | 728 MockSearchDomainCheckResponse("https://www.google.co.in/"); |
699 EXPECT_EQ(new_google_url, google_url()); | 729 EXPECT_EQ(new_google_url, google_url()); |
700 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 730 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
701 EXPECT_TRUE(GetInfoBar(1) == NULL); | 731 EXPECT_TRUE(GetInfoBar(1) == NULL); |
702 } | 732 } |
703 | 733 |
704 TEST_F(GoogleURLTrackerTest, ResetInfobarGoogleURLs) { | 734 TEST_F(GoogleURLTrackerTest, ResetInfobarGoogleURLs) { |
705 RequestServerCheck(); | 735 RequestServerCheck(); |
706 FinishSleep(); | 736 FinishSleep(); |
707 MockSearchDomainCheckResponse(google_url().spec()); | 737 MockSearchDomainCheckResponse(google_url().spec()); |
708 | 738 |
709 NotifyIPAddressChanged(); | 739 NotifyIPAddressChanged(); |
710 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 740 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
711 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); | 741 SetSearchPending(1); |
712 CommitSearch(1); | |
713 TestInfoBarDelegate* infobar = GetInfoBar(1); | 742 TestInfoBarDelegate* infobar = GetInfoBar(1); |
714 ASSERT_FALSE(infobar == NULL); | 743 ASSERT_FALSE(infobar == NULL); |
715 EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url()); | 744 EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url()); |
716 | 745 |
717 // If while an infobar is showing we fetch a new URL that differs from the | 746 // If while an infobar is pending we fetch a new URL that differs from the |
718 // infobar's only by scheme, the infobar should stay open but have its Google | 747 // infobar's only by scheme, the infobar should stay pending but have its |
719 // URL reset. | 748 // Google URL reset. |
720 NotifyIPAddressChanged(); | 749 NotifyIPAddressChanged(); |
721 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | 750 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
722 TestInfoBarDelegate* new_infobar = GetInfoBar(1); | 751 TestInfoBarDelegate* new_infobar = GetInfoBar(1); |
723 ASSERT_FALSE(new_infobar == NULL); | 752 ASSERT_FALSE(new_infobar == NULL); |
724 EXPECT_EQ(infobar, new_infobar); | 753 EXPECT_EQ(infobar, new_infobar); |
725 EXPECT_EQ(GURL("https://www.google.co.uk/"), new_infobar->new_google_url()); | 754 EXPECT_EQ(GURL("https://www.google.co.uk/"), new_infobar->new_google_url()); |
| 755 |
| 756 // Same with an infobar that is showing. |
| 757 CommitSearch(GURL("http://www.google.com/search?q=test"), 1); |
| 758 EXPECT_TRUE(infobar->showing()); |
| 759 NotifyIPAddressChanged(); |
| 760 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 761 new_infobar = GetInfoBar(1); |
| 762 ASSERT_FALSE(new_infobar == NULL); |
| 763 EXPECT_EQ(infobar, new_infobar); |
| 764 EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url()); |
| 765 EXPECT_TRUE(infobar->showing()); |
726 } | 766 } |
727 | 767 |
728 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterPendingSearch) { | 768 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) { |
729 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 769 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
730 RequestServerCheck(); | 770 RequestServerCheck(); |
731 FinishSleep(); | 771 FinishSleep(); |
732 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 772 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
733 | 773 |
734 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 774 // A pending non-search after a pending search should close the infobar. |
| 775 SetSearchPending(1); |
735 TestInfoBarDelegate* infobar = GetInfoBar(1); | 776 TestInfoBarDelegate* infobar = GetInfoBar(1); |
736 ASSERT_FALSE(infobar == NULL); | 777 ASSERT_FALSE(infobar == NULL); |
737 EXPECT_FALSE(infobar->showing()); | 778 EXPECT_FALSE(infobar->showing()); |
738 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), | 779 SetNonSearchPending(1); |
739 infobar->search_url()); | 780 infobar = GetInfoBar(1); |
| 781 EXPECT_TRUE(infobar == NULL); |
740 | 782 |
741 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); | 783 // A pending search after a pending search should leave the infobar alive. |
742 TestInfoBarDelegate* infobar2 = GetInfoBar(1); | 784 SetSearchPending(1); |
743 ASSERT_FALSE(infobar2 == NULL); | 785 infobar = GetInfoBar(1); |
744 EXPECT_FALSE(infobar2->showing()); | 786 ASSERT_FALSE(infobar == NULL); |
745 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), | 787 EXPECT_FALSE(infobar->showing()); |
746 infobar2->search_url()); | 788 SetSearchPending(1); |
| 789 TestInfoBarDelegate* new_infobar = GetInfoBar(1); |
| 790 ASSERT_FALSE(new_infobar == NULL); |
| 791 EXPECT_EQ(infobar, new_infobar); |
| 792 EXPECT_FALSE(infobar->showing()); |
| 793 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
747 | 794 |
748 CommitSearch(1); | 795 // Committing this search should show the infobar. |
749 EXPECT_TRUE(infobar2->showing()); | 796 CommitSearch(GURL("http://www.google.co.uk/search?q=test2"), 1); |
| 797 EXPECT_TRUE(infobar->showing()); |
750 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 798 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
751 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 799 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
752 EXPECT_FALSE(observer_->notified()); | 800 EXPECT_FALSE(observer_->notified()); |
| 801 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
753 } | 802 } |
754 | 803 |
755 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterCommittedSearch) { | 804 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { |
756 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 805 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
757 RequestServerCheck(); | 806 RequestServerCheck(); |
758 FinishSleep(); | 807 FinishSleep(); |
759 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 808 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
760 | 809 SetSearchPending(1); |
761 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 810 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
762 CommitSearch(1); | |
763 TestInfoBarDelegate* infobar = GetInfoBar(1); | 811 TestInfoBarDelegate* infobar = GetInfoBar(1); |
764 ASSERT_FALSE(infobar == NULL); | 812 ASSERT_FALSE(infobar == NULL); |
765 EXPECT_TRUE(infobar->showing()); | 813 EXPECT_TRUE(infobar->showing()); |
| 814 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
766 | 815 |
767 // In real usage, the upcoming pending navigation for "test2" would close | 816 // A pending non-search on a visible infobar should basically do nothing. |
768 // |infobar|. Since we're not actually doing navigations, we need to clean it | 817 SetNonSearchPending(1); |
769 // up manually to prevent leaks. | 818 TestInfoBarDelegate* new_infobar = GetInfoBar(1); |
770 delete infobar; | 819 ASSERT_FALSE(new_infobar == NULL); |
| 820 EXPECT_EQ(infobar, new_infobar); |
| 821 EXPECT_TRUE(infobar->showing()); |
| 822 EXPECT_EQ(0, infobar->pending_id()); |
| 823 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
771 | 824 |
772 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); | 825 // As should another pending non-search after the first. |
773 TestInfoBarDelegate* infobar2 = GetInfoBar(1); | 826 SetNonSearchPending(1); |
774 ASSERT_FALSE(infobar2 == NULL); | 827 new_infobar = GetInfoBar(1); |
775 EXPECT_FALSE(infobar2->showing()); | 828 ASSERT_FALSE(new_infobar == NULL); |
| 829 EXPECT_EQ(infobar, new_infobar); |
| 830 EXPECT_TRUE(infobar->showing()); |
| 831 EXPECT_EQ(0, infobar->pending_id()); |
| 832 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
776 | 833 |
777 CommitSearch(1); | 834 // Committing this non-search should close the infobar. The control flow in |
778 EXPECT_TRUE(infobar2->showing()); | 835 // these tests is not really comparable to in the real browser, but at least a |
| 836 // few sanity-checks will be performed. |
| 837 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1)); |
| 838 new_infobar = GetInfoBar(1); |
| 839 EXPECT_TRUE(new_infobar == NULL); |
| 840 |
| 841 // A pending search on a visible infobar should cause the infobar to listen |
| 842 // for the search to commit. |
| 843 SetSearchPending(1); |
| 844 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 845 infobar = GetInfoBar(1); |
| 846 ASSERT_FALSE(infobar == NULL); |
| 847 EXPECT_TRUE(infobar->showing()); |
| 848 SetSearchPending(1); |
| 849 new_infobar = GetInfoBar(1); |
| 850 ASSERT_FALSE(new_infobar == NULL); |
| 851 EXPECT_EQ(infobar, new_infobar); |
| 852 EXPECT_TRUE(infobar->showing()); |
| 853 EXPECT_EQ(1, infobar->pending_id()); |
| 854 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 855 |
| 856 // But a non-search after this should cancel that state. |
| 857 SetNonSearchPending(1); |
| 858 new_infobar = GetInfoBar(1); |
| 859 ASSERT_FALSE(new_infobar == NULL); |
| 860 EXPECT_EQ(infobar, new_infobar); |
| 861 EXPECT_TRUE(infobar->showing()); |
| 862 EXPECT_EQ(0, infobar->pending_id()); |
| 863 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 864 |
| 865 // Another pending search after the non-search should put us back into |
| 866 // "waiting for commit" mode. |
| 867 SetSearchPending(1); |
| 868 new_infobar = GetInfoBar(1); |
| 869 ASSERT_FALSE(new_infobar == NULL); |
| 870 EXPECT_EQ(infobar, new_infobar); |
| 871 EXPECT_TRUE(infobar->showing()); |
| 872 EXPECT_EQ(1, infobar->pending_id()); |
| 873 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 874 |
| 875 // A second pending search after the first should not really change anything. |
| 876 SetSearchPending(1); |
| 877 new_infobar = GetInfoBar(1); |
| 878 ASSERT_FALSE(new_infobar == NULL); |
| 879 EXPECT_EQ(infobar, new_infobar); |
| 880 EXPECT_TRUE(infobar->showing()); |
| 881 EXPECT_EQ(1, infobar->pending_id()); |
| 882 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 883 |
| 884 // Committing this search should change the visible infobar's search_url. |
| 885 CommitSearch(GURL("http://www.google.co.uk/search?q=test2"), 1); |
| 886 new_infobar = GetInfoBar(1); |
| 887 ASSERT_FALSE(new_infobar == NULL); |
| 888 EXPECT_EQ(infobar, new_infobar); |
| 889 EXPECT_TRUE(infobar->showing()); |
| 890 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), infobar->search_url(
)); |
| 891 EXPECT_EQ(0, infobar->pending_id()); |
| 892 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
779 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 893 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
780 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 894 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
781 EXPECT_FALSE(observer_->notified()); | 895 EXPECT_FALSE(observer_->notified()); |
782 } | 896 } |
783 | 897 |
784 TEST_F(GoogleURLTrackerTest, MultipleInfobars) { | 898 TEST_F(GoogleURLTrackerTest, MultipleInfobars) { |
785 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 899 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
786 RequestServerCheck(); | 900 RequestServerCheck(); |
787 FinishSleep(); | 901 FinishSleep(); |
788 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 902 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
789 | 903 |
790 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 904 SetSearchPending(1); |
791 TestInfoBarDelegate* infobar = GetInfoBar(1); | 905 TestInfoBarDelegate* infobar = GetInfoBar(1); |
792 ASSERT_FALSE(infobar == NULL); | 906 ASSERT_FALSE(infobar == NULL); |
793 EXPECT_FALSE(infobar->showing()); | 907 EXPECT_FALSE(infobar->showing()); |
794 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), | |
795 infobar->search_url()); | |
796 | 908 |
797 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 2); | 909 SetSearchPending(2); |
798 CommitSearch(2); | 910 CommitSearch(GURL("http://www.google.co.uk/search?q=test2"), 2); |
799 TestInfoBarDelegate* infobar2 = GetInfoBar(2); | 911 TestInfoBarDelegate* infobar2 = GetInfoBar(2); |
800 ASSERT_FALSE(infobar2 == NULL); | 912 ASSERT_FALSE(infobar2 == NULL); |
801 EXPECT_TRUE(infobar2->showing()); | 913 EXPECT_TRUE(infobar2->showing()); |
802 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), | 914 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
803 infobar2->search_url()); | 915 infobar2->search_url()); |
804 | 916 |
805 SetSearchPending(GURL("http://www.google.co.uk/search?q=test3"), 3); | 917 SetSearchPending(3); |
806 TestInfoBarDelegate* infobar3 = GetInfoBar(3); | 918 TestInfoBarDelegate* infobar3 = GetInfoBar(3); |
807 ASSERT_FALSE(infobar3 == NULL); | 919 ASSERT_FALSE(infobar3 == NULL); |
808 EXPECT_FALSE(infobar3->showing()); | 920 EXPECT_FALSE(infobar3->showing()); |
809 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test3"), | |
810 infobar3->search_url()); | |
811 | 921 |
812 SetSearchPending(GURL("http://www.google.co.uk/search?q=test4"), 4); | 922 SetSearchPending(4); |
813 CommitSearch(4); | 923 CommitSearch(GURL("http://www.google.co.uk/search?q=test4"), 4); |
814 TestInfoBarDelegate* infobar4 = GetInfoBar(4); | 924 TestInfoBarDelegate* infobar4 = GetInfoBar(4); |
815 ASSERT_FALSE(infobar4 == NULL); | 925 ASSERT_FALSE(infobar4 == NULL); |
816 EXPECT_TRUE(infobar4->showing()); | 926 EXPECT_TRUE(infobar4->showing()); |
817 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), | 927 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), |
818 infobar4->search_url()); | 928 infobar4->search_url()); |
819 | 929 |
820 CommitSearch(1); | 930 CommitSearch(GURL("http://www.google.co.uk/search?q=test"), 1); |
821 EXPECT_TRUE(infobar->showing()); | 931 EXPECT_TRUE(infobar->showing()); |
822 | 932 |
823 infobar2->InfoBarClosed(); | 933 infobar2->InfoBarClosed(); |
824 EXPECT_TRUE(GetInfoBar(2) == NULL); | 934 EXPECT_TRUE(GetInfoBar(2) == NULL); |
825 EXPECT_FALSE(observer_->notified()); | 935 EXPECT_FALSE(observer_->notified()); |
826 | 936 |
827 infobar4->Accept(); | 937 infobar4->Accept(); |
828 EXPECT_TRUE(GetInfoBar(1) == NULL); | 938 EXPECT_TRUE(GetInfoBar(1) == NULL); |
829 EXPECT_TRUE(GetInfoBar(3) == NULL); | 939 EXPECT_TRUE(GetInfoBar(3) == NULL); |
830 EXPECT_TRUE(GetInfoBar(4) == NULL); | 940 EXPECT_TRUE(GetInfoBar(4) == NULL); |
831 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 941 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
832 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 942 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
833 EXPECT_TRUE(observer_->notified()); | 943 EXPECT_TRUE(observer_->notified()); |
834 } | 944 } |
OLD | NEW |