Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/google/google_url_tracker_unittest.cc

Issue 10382091: Support scheme-setting for GoogleURLTracker. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
Ilya Sherman 2012/05/09 22:14:44 nit: No need to promote this to the top of the fil
Peter Kasting 2012/05/09 23:24:18 I had thought so too, but another readability revi
Ilya Sherman 2012/05/09 23:30:21 Ah, interesting. Good to know, thanks for pointin
6
7 #include <set>
8 #include <string>
9
5 #include "base/message_loop.h" 10 #include "base/message_loop.h"
6 #include "chrome/browser/infobars/infobar_delegate.h" 11 #include "chrome/browser/infobars/infobar_delegate.h"
7 #include "chrome/browser/google/google_url_tracker.h"
8 #include "chrome/browser/google/google_url_tracker_factory.h" 12 #include "chrome/browser/google/google_url_tracker_factory.h"
9 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
14 #include "content/public/common/url_fetcher.h" 18 #include "content/public/common/url_fetcher.h"
15 #include "content/test/test_browser_thread.h" 19 #include "content/test/test_browser_thread.h"
16 #include "content/test/test_url_fetcher_factory.h" 20 #include "content/test/test_url_fetcher_factory.h"
17 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // test_url_fetcher_factory.h). 146 // test_url_fetcher_factory.h).
143 MessageLoop message_loop_; 147 MessageLoop message_loop_;
144 content::TestBrowserThread io_thread_; 148 content::TestBrowserThread io_thread_;
145 // Creating this allows us to call 149 // Creating this allows us to call
146 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). 150 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests().
147 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 151 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
148 TestURLFetcherFactory fetcher_factory_; 152 TestURLFetcherFactory fetcher_factory_;
149 content::NotificationRegistrar registrar_; 153 content::NotificationRegistrar registrar_;
150 TestingProfile profile_; 154 TestingProfile profile_;
151 scoped_ptr<GoogleURLTracker> google_url_tracker_; 155 scoped_ptr<GoogleURLTracker> google_url_tracker_;
156 // This tracks the different "tabs" a test has "opened", so we can close them
157 // properly before shutting down |google_url_tracker_|, which expects that.
158 std::set<int> unique_ids_seen_;
152 }; 159 };
153 160
154 GoogleURLTrackerTest::GoogleURLTrackerTest() 161 GoogleURLTrackerTest::GoogleURLTrackerTest()
155 : observer_(new TestNotificationObserver), 162 : observer_(new TestNotificationObserver),
156 message_loop_(MessageLoop::TYPE_IO), 163 message_loop_(MessageLoop::TYPE_IO),
157 io_thread_(content::BrowserThread::IO, &message_loop_) { 164 io_thread_(content::BrowserThread::IO, &message_loop_) {
158 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); 165 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_);
159 } 166 }
160 167
161 GoogleURLTrackerTest::~GoogleURLTrackerTest() { 168 GoogleURLTrackerTest::~GoogleURLTrackerTest() {
162 } 169 }
163 170
164 void GoogleURLTrackerTest::SetUp() { 171 void GoogleURLTrackerTest::SetUp() {
165 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); 172 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
166 google_url_tracker_.reset( 173 google_url_tracker_.reset(
167 new GoogleURLTracker(&profile_, GoogleURLTracker::UNIT_TEST_MODE)); 174 new GoogleURLTracker(&profile_, GoogleURLTracker::UNIT_TEST_MODE));
168 google_url_tracker_->infobar_creator_ = &CreateTestInfobar; 175 google_url_tracker_->infobar_creator_ = &CreateTestInfobar;
169 } 176 }
170 177
171 void GoogleURLTrackerTest::TearDown() { 178 void GoogleURLTrackerTest::TearDown() {
179 while (!unique_ids_seen_.empty())
180 CloseTab(*unique_ids_seen_.begin());
181
172 google_url_tracker_.reset(); 182 google_url_tracker_.reset();
173 network_change_notifier_.reset(); 183 network_change_notifier_.reset();
174 } 184 }
175 185
176 TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { 186 TestURLFetcher* GoogleURLTrackerTest::GetFetcher() {
177 // This will return the last fetcher created. If no fetchers have been 187 // This will return the last fetcher created. If no fetchers have been
178 // created, we'll pass GetFetcherByID() "-1", and it will return NULL. 188 // created, we'll pass GetFetcherByID() "-1", and it will return NULL.
179 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1); 189 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1);
180 } 190 }
181 191
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { 226 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) {
217 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); 227 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec());
218 } 228 }
219 229
220 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { 230 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() {
221 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); 231 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL));
222 } 232 }
223 233
224 void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url, 234 void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url,
225 int unique_id) { 235 int unique_id) {
236 unique_ids_seen_.insert(unique_id);
226 google_url_tracker_->SearchCommitted(); 237 google_url_tracker_->SearchCommitted();
227 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), 238 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(),
228 content::NOTIFICATION_NAV_ENTRY_PENDING, 239 content::NOTIFICATION_NAV_ENTRY_PENDING,
229 content::NotificationService::AllBrowserContextsAndSources())) { 240 content::NotificationService::AllBrowserContextsAndSources())) {
230 google_url_tracker_->OnNavigationPending( 241 google_url_tracker_->OnNavigationPending(
231 content::Source<content::NavigationController>( 242 content::Source<content::NavigationController>(
232 reinterpret_cast<content::NavigationController*>(unique_id)), 243 reinterpret_cast<content::NavigationController*>(unique_id)),
233 content::Source<content::WebContents>( 244 content::Source<content::WebContents>(
234 reinterpret_cast<content::WebContents*>(unique_id)), 245 reinterpret_cast<content::WebContents*>(unique_id)),
235 reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url); 246 reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url);
236 } 247 }
237 } 248 }
238 249
239 void GoogleURLTrackerTest::CommitSearch(int unique_id) { 250 void GoogleURLTrackerTest::CommitSearch(int unique_id) {
240 content::Source<content::NavigationController> source( 251 content::Source<content::NavigationController> source(
241 reinterpret_cast<content::NavigationController*>(unique_id)); 252 reinterpret_cast<content::NavigationController*>(unique_id));
242 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), 253 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(),
243 content::NOTIFICATION_NAV_ENTRY_COMMITTED, source)) { 254 content::NOTIFICATION_NAV_ENTRY_COMMITTED, source)) {
244 google_url_tracker_->OnNavigationCommittedOrTabClosed(source, 255 google_url_tracker_->OnNavigationCommittedOrTabClosed(source,
245 content::Source<content::WebContents>( 256 content::Source<content::WebContents>(
246 reinterpret_cast<content::WebContents*>(unique_id)), 257 reinterpret_cast<content::WebContents*>(unique_id)),
247 reinterpret_cast<InfoBarTabHelper*>(unique_id), true); 258 reinterpret_cast<InfoBarTabHelper*>(unique_id), true);
248 } 259 }
249 } 260 }
250 261
251 void GoogleURLTrackerTest::CloseTab(int unique_id) { 262 void GoogleURLTrackerTest::CloseTab(int unique_id) {
263 unique_ids_seen_.erase(unique_id);
252 content::Source<content::WebContents> source( 264 content::Source<content::WebContents> source(
253 reinterpret_cast<content::WebContents*>(unique_id)); 265 reinterpret_cast<content::WebContents*>(unique_id));
254 InfoBarTabHelper* infobar_helper = 266 InfoBarTabHelper* infobar_helper =
255 reinterpret_cast<InfoBarTabHelper*>(unique_id); 267 reinterpret_cast<InfoBarTabHelper*>(unique_id);
256 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), 268 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(),
257 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, source)) { 269 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, source)) {
258 google_url_tracker_->OnNavigationCommittedOrTabClosed( 270 google_url_tracker_->OnNavigationCommittedOrTabClosed(
259 content::Source<content::NavigationController>( 271 content::Source<content::NavigationController>(
260 reinterpret_cast<content::NavigationController*>(unique_id)), 272 reinterpret_cast<content::NavigationController*>(unique_id)),
261 source, infobar_helper, false); 273 source, infobar_helper, false);
(...skipping 26 matching lines...) Expand all
288 } 300 }
289 301
290 302
291 // Tests ---------------------------------------------------------------------- 303 // Tests ----------------------------------------------------------------------
292 304
293 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { 305 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) {
294 ExpectDefaultURLs(); 306 ExpectDefaultURLs();
295 FinishSleep(); 307 FinishSleep();
296 // No one called RequestServerCheck() so nothing should have happened. 308 // No one called RequestServerCheck() so nothing should have happened.
297 EXPECT_FALSE(GetFetcher()); 309 EXPECT_FALSE(GetFetcher());
298 MockSearchDomainCheckResponse(".google.co.uk"); 310 MockSearchDomainCheckResponse("http://www.google.co.uk/");
299 ExpectDefaultURLs(); 311 ExpectDefaultURLs();
300 EXPECT_FALSE(observer_->notified()); 312 EXPECT_FALSE(observer_->notified());
301 } 313 }
302 314
303 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { 315 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) {
304 RequestServerCheck(); 316 RequestServerCheck();
305 EXPECT_FALSE(GetFetcher()); 317 EXPECT_FALSE(GetFetcher());
306 ExpectDefaultURLs(); 318 ExpectDefaultURLs();
307 EXPECT_FALSE(observer_->notified()); 319 EXPECT_FALSE(observer_->notified());
308 320
309 FinishSleep(); 321 FinishSleep();
310 MockSearchDomainCheckResponse(".google.co.uk"); 322 MockSearchDomainCheckResponse("http://www.google.co.uk/");
311 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 323 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
312 // GoogleURL should be updated, becase there was no last prompted URL. 324 // GoogleURL should be updated, becase there was no last prompted URL.
313 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 325 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
314 EXPECT_TRUE(observer_->notified()); 326 EXPECT_TRUE(observer_->notified());
315 } 327 }
316 328
317 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { 329 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) {
318 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 330 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
319 331
320 RequestServerCheck(); 332 RequestServerCheck();
321 EXPECT_FALSE(GetFetcher()); 333 EXPECT_FALSE(GetFetcher());
322 ExpectDefaultURLs(); 334 ExpectDefaultURLs();
323 EXPECT_FALSE(observer_->notified()); 335 EXPECT_FALSE(observer_->notified());
324 336
325 FinishSleep(); 337 FinishSleep();
326 MockSearchDomainCheckResponse(".google.co.uk"); 338 MockSearchDomainCheckResponse("http://www.google.co.uk/");
327 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 339 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
328 // GoogleURL should not be updated, because the fetched and prompted URLs 340 // GoogleURL should not be updated, because the fetched and prompted URLs
329 // match. 341 // match.
330 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 342 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
331 EXPECT_FALSE(observer_->notified()); 343 EXPECT_FALSE(observer_->notified());
332 } 344 }
333 345
346 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) {
347 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
348
349 RequestServerCheck();
350 EXPECT_FALSE(GetFetcher());
351 ExpectDefaultURLs();
352 EXPECT_FALSE(observer_->notified());
353
354 // Old-style domain string.
355 FinishSleep();
356 MockSearchDomainCheckResponse(".google.co.in");
357 EXPECT_EQ(GURL(), fetched_google_url());
358 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
359 EXPECT_FALSE(observer_->notified());
360 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
361 CommitSearch(1);
362 EXPECT_TRUE(GetInfoBar(1) == NULL);
363
364 // Bad subdomain.
365 NotifyIPAddressChanged();
366 MockSearchDomainCheckResponse("http://mail.google.com/");
367 EXPECT_EQ(GURL(), fetched_google_url());
368 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
369 EXPECT_FALSE(observer_->notified());
370 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
371 CommitSearch(1);
372 EXPECT_TRUE(GetInfoBar(1) == NULL);
373
374 // Non-empty path/query.
Ilya Sherman 2012/05/09 22:14:44 nit: Please also test the case where the path is n
Peter Kasting 2012/05/09 23:24:18 OK, separated into distinct path/query/ref cases.
375 NotifyIPAddressChanged();
376 MockSearchDomainCheckResponse("http://www.google.com/search?q=foo");
377 EXPECT_EQ(GURL(), fetched_google_url());
378 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
379 EXPECT_FALSE(observer_->notified());
380 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
381 CommitSearch(1);
382 EXPECT_TRUE(GetInfoBar(1) == NULL);
383
384 // Complete garbage.
385 NotifyIPAddressChanged();
386 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1");
387 EXPECT_EQ(GURL(), fetched_google_url());
388 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
389 EXPECT_FALSE(observer_->notified());
390 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
391 CommitSearch(1);
392 EXPECT_TRUE(GetInfoBar(1) == NULL);
393 }
394
334 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { 395 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) {
335 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); 396 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/"));
336 set_google_url(GURL("http://www.google.co.uk/")); 397 set_google_url(GURL("http://www.google.co.uk/"));
337 RequestServerCheck(); 398 RequestServerCheck();
338 FinishSleep(); 399 FinishSleep();
339 MockSearchDomainCheckResponse(".google.co.uk"); 400 MockSearchDomainCheckResponse("http://www.google.co.uk/");
340 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 401 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
341 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 402 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
342 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 403 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
343 EXPECT_FALSE(observer_->notified()); 404 EXPECT_FALSE(observer_->notified());
344 } 405 }
345 406
407 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) {
408 // We should auto-accept changes to the current Google URL that merely change
409 // the scheme, regardless of what the last prompted URL was.
410 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/"));
411 set_google_url(GURL("http://www.google.co.uk/"));
412 RequestServerCheck();
413 FinishSleep();
414 MockSearchDomainCheckResponse("https://www.google.co.uk/");
415 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url());
416 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url());
417 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL());
418 EXPECT_TRUE(observer_->notified());
419
420 NotifyIPAddressChanged();
421 MockSearchDomainCheckResponse("http://www.google.co.uk/");
422 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
423 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
424 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
425 EXPECT_TRUE(observer_->notified());
426 }
427
346 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { 428 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) {
347 RequestServerCheck(); 429 RequestServerCheck();
348 FinishSleep(); 430 FinishSleep();
349 MockSearchDomainCheckResponse(".google.co.uk"); 431 MockSearchDomainCheckResponse("http://www.google.co.uk/");
350 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 432 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
351 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 433 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
352 EXPECT_TRUE(observer_->notified()); 434 EXPECT_TRUE(observer_->notified());
353 observer_->clear_notified(); 435 observer_->clear_notified();
354 436
355 NotifyIPAddressChanged(); 437 NotifyIPAddressChanged();
356 MockSearchDomainCheckResponse(".google.co.in"); 438 MockSearchDomainCheckResponse("http://www.google.co.in/");
357 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); 439 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url());
358 // Just fetching a new URL shouldn't reset things without a prompt. 440 // Just fetching a new URL shouldn't reset things without a prompt.
359 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 441 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
360 EXPECT_FALSE(observer_->notified()); 442 EXPECT_FALSE(observer_->notified());
361 } 443 }
362 444
363 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { 445 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) {
364 FinishSleep(); 446 FinishSleep();
365 NotifyIPAddressChanged(); 447 NotifyIPAddressChanged();
366 // No one called RequestServerCheck() so nothing should have happened. 448 // No one called RequestServerCheck() so nothing should have happened.
367 EXPECT_FALSE(GetFetcher()); 449 EXPECT_FALSE(GetFetcher());
368 MockSearchDomainCheckResponse(".google.co.uk"); 450 MockSearchDomainCheckResponse("http://www.google.co.uk/");
369 ExpectDefaultURLs(); 451 ExpectDefaultURLs();
370 EXPECT_FALSE(observer_->notified()); 452 EXPECT_FALSE(observer_->notified());
371 } 453 }
372 454
373 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { 455 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) {
374 FinishSleep(); 456 FinishSleep();
375 NotifyIPAddressChanged(); 457 NotifyIPAddressChanged();
376 MockSearchDomainCheckResponse(".google.co.jp"); 458 MockSearchDomainCheckResponse("http://www.google.co.jp/");
377 459
378 RequestServerCheck(); 460 RequestServerCheck();
379 // The first request for a check should trigger a fetch if it hasn't happened 461 // The first request for a check should trigger a fetch if it hasn't happened
380 // already. 462 // already.
381 MockSearchDomainCheckResponse(".google.co.uk"); 463 MockSearchDomainCheckResponse("http://www.google.co.uk/");
382 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 464 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
383 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 465 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
384 EXPECT_TRUE(observer_->notified()); 466 EXPECT_TRUE(observer_->notified());
385 } 467 }
386 468
387 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { 469 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) {
388 FinishSleep(); 470 FinishSleep();
389 NotifyIPAddressChanged(); 471 NotifyIPAddressChanged();
390 MockSearchDomainCheckResponse(".google.co.jp"); 472 MockSearchDomainCheckResponse("http://www.google.co.jp/");
391 473
392 RequestServerCheck(); 474 RequestServerCheck();
393 // The first request for a check should trigger a fetch if it hasn't happened 475 // The first request for a check should trigger a fetch if it hasn't happened
394 // already. 476 // already.
395 MockSearchDomainCheckResponse(".google.co.uk"); 477 MockSearchDomainCheckResponse("http://www.google.co.uk/");
396 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 478 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
397 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 479 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
398 EXPECT_TRUE(observer_->notified()); 480 EXPECT_TRUE(observer_->notified());
399 observer_->clear_notified(); 481 observer_->clear_notified();
400 482
401 RequestServerCheck(); 483 RequestServerCheck();
402 // The second request should be ignored. 484 // The second request should be ignored.
403 EXPECT_FALSE(GetFetcher()); 485 EXPECT_FALSE(GetFetcher());
404 MockSearchDomainCheckResponse(".google.co.in"); 486 MockSearchDomainCheckResponse("http://www.google.co.in/");
405 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 487 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
406 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 488 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
407 EXPECT_FALSE(observer_->notified()); 489 EXPECT_FALSE(observer_->notified());
408 } 490 }
409 491
410 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { 492 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) {
411 RequestServerCheck(); 493 RequestServerCheck();
412 FinishSleep(); 494 FinishSleep();
413 MockSearchDomainCheckResponse(".google.co.uk"); 495 MockSearchDomainCheckResponse("http://www.google.co.uk/");
414 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 496 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
415 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 497 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
416 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 498 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
417 EXPECT_TRUE(observer_->notified()); 499 EXPECT_TRUE(observer_->notified());
418 observer_->clear_notified(); 500 observer_->clear_notified();
419 501
420 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); 502 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
421 CommitSearch(1); 503 CommitSearch(1);
422 TestInfoBarDelegate* infobar = GetInfoBar(1); 504 TestInfoBarDelegate* infobar = GetInfoBar(1);
423 ASSERT_TRUE(infobar == NULL); 505 EXPECT_TRUE(infobar == NULL);
424 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 506 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
425 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 507 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
426 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 508 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
427 EXPECT_FALSE(observer_->notified()); 509 EXPECT_FALSE(observer_->notified());
428 } 510 }
429 511
430 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { 512 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) {
431 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 513 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
432 RequestServerCheck(); 514 RequestServerCheck();
433 FinishSleep(); 515 FinishSleep();
434 MockSearchDomainCheckResponse(".google.co.jp"); 516 MockSearchDomainCheckResponse("http://www.google.co.jp/");
435 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 517 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
436 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); 518 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url());
437 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 519 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
438 EXPECT_FALSE(observer_->notified()); 520 EXPECT_FALSE(observer_->notified());
439 521
440 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); 522 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
441 TestInfoBarDelegate* infobar = GetInfoBar(1); 523 TestInfoBarDelegate* infobar = GetInfoBar(1);
442 ASSERT_FALSE(infobar == NULL); 524 ASSERT_FALSE(infobar == NULL);
443 EXPECT_FALSE(infobar->showing()); 525 EXPECT_FALSE(infobar->showing());
444 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 526 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
445 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), 527 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"),
446 infobar->search_url()); 528 infobar->search_url());
447 EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url()); 529 EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url());
448 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 530 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
449 EXPECT_FALSE(observer_->notified()); 531 EXPECT_FALSE(observer_->notified());
450 532
451 CloseTab(1); 533 CloseTab(1);
452 EXPECT_TRUE(GetInfoBar(1) == NULL); 534 EXPECT_TRUE(GetInfoBar(1) == NULL);
453 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 535 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
454 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 536 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
455 EXPECT_FALSE(observer_->notified()); 537 EXPECT_FALSE(observer_->notified());
456 } 538 }
457 539
458 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { 540 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) {
459 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 541 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
460 RequestServerCheck(); 542 RequestServerCheck();
461 FinishSleep(); 543 FinishSleep();
462 MockSearchDomainCheckResponse(".google.co.jp"); 544 MockSearchDomainCheckResponse("http://www.google.co.jp/");
463 545
464 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); 546 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
465 CommitSearch(1); 547 CommitSearch(1);
466 TestInfoBarDelegate* infobar = GetInfoBar(1); 548 TestInfoBarDelegate* infobar = GetInfoBar(1);
467 ASSERT_FALSE(infobar == NULL); 549 ASSERT_FALSE(infobar == NULL);
468 EXPECT_TRUE(infobar->showing()); 550 EXPECT_TRUE(infobar->showing());
469 551
470 CloseTab(1); 552 CloseTab(1);
471 EXPECT_TRUE(GetInfoBar(1) == NULL); 553 EXPECT_TRUE(GetInfoBar(1) == NULL);
472 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 554 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
473 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 555 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
474 EXPECT_FALSE(observer_->notified()); 556 EXPECT_FALSE(observer_->notified());
475 } 557 }
476 558
477 TEST_F(GoogleURLTrackerTest, InfobarClosed) { 559 TEST_F(GoogleURLTrackerTest, InfobarClosed) {
478 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 560 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
479 RequestServerCheck(); 561 RequestServerCheck();
480 FinishSleep(); 562 FinishSleep();
481 MockSearchDomainCheckResponse(".google.co.jp"); 563 MockSearchDomainCheckResponse("http://www.google.co.jp/");
482 564
483 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); 565 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
484 CommitSearch(1); 566 CommitSearch(1);
485 TestInfoBarDelegate* infobar = GetInfoBar(1); 567 TestInfoBarDelegate* infobar = GetInfoBar(1);
486 ASSERT_FALSE(infobar == NULL); 568 ASSERT_FALSE(infobar == NULL);
487 569
488 infobar->InfoBarClosed(); 570 infobar->InfoBarClosed();
489 EXPECT_TRUE(GetInfoBar(1) == NULL); 571 EXPECT_TRUE(GetInfoBar(1) == NULL);
490 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 572 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
491 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 573 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
492 EXPECT_FALSE(observer_->notified()); 574 EXPECT_FALSE(observer_->notified());
493 } 575 }
494 576
495 TEST_F(GoogleURLTrackerTest, InfobarRefused) { 577 TEST_F(GoogleURLTrackerTest, InfobarRefused) {
496 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 578 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
497 RequestServerCheck(); 579 RequestServerCheck();
498 FinishSleep(); 580 FinishSleep();
499 MockSearchDomainCheckResponse(".google.co.jp"); 581 MockSearchDomainCheckResponse("http://www.google.co.jp/");
500 582
501 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); 583 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
502 CommitSearch(1); 584 CommitSearch(1);
503 TestInfoBarDelegate* infobar = GetInfoBar(1); 585 TestInfoBarDelegate* infobar = GetInfoBar(1);
504 ASSERT_FALSE(infobar == NULL); 586 ASSERT_FALSE(infobar == NULL);
505 587
506 infobar->Cancel(); 588 infobar->Cancel();
507 EXPECT_TRUE(GetInfoBar(1) == NULL); 589 EXPECT_TRUE(GetInfoBar(1) == NULL);
508 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 590 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
509 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); 591 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
510 EXPECT_FALSE(observer_->notified()); 592 EXPECT_FALSE(observer_->notified());
511 } 593 }
512 594
513 TEST_F(GoogleURLTrackerTest, InfobarAccepted) { 595 TEST_F(GoogleURLTrackerTest, InfobarAccepted) {
514 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 596 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
515 RequestServerCheck(); 597 RequestServerCheck();
516 FinishSleep(); 598 FinishSleep();
517 MockSearchDomainCheckResponse(".google.co.jp"); 599 MockSearchDomainCheckResponse("http://www.google.co.jp/");
518 600
519 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); 601 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
520 CommitSearch(1); 602 CommitSearch(1);
521 TestInfoBarDelegate* infobar = GetInfoBar(1); 603 TestInfoBarDelegate* infobar = GetInfoBar(1);
522 ASSERT_FALSE(infobar == NULL); 604 ASSERT_FALSE(infobar == NULL);
523 605
524 infobar->Accept(); 606 infobar->Accept();
525 EXPECT_TRUE(GetInfoBar(1) == NULL); 607 EXPECT_TRUE(GetInfoBar(1) == NULL);
526 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); 608 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url());
527 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); 609 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
528 EXPECT_TRUE(observer_->notified()); 610 EXPECT_TRUE(observer_->notified());
529 } 611 }
530 612
613 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfobars) {
614 RequestServerCheck();
615 FinishSleep();
616 MockSearchDomainCheckResponse(google_url().spec());
617
618 // Re-fetching the accepted URL after showing an infobar for another URL
619 // should close the infobar.
620 NotifyIPAddressChanged();
621 MockSearchDomainCheckResponse("http://www.google.co.uk/");
622 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1);
623 CommitSearch(1);
624 EXPECT_FALSE(GetInfoBar(1) == NULL);
625 NotifyIPAddressChanged();
626 MockSearchDomainCheckResponse(google_url().spec());
627 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL());
628 EXPECT_TRUE(GetInfoBar(1) == NULL);
629
630 // As should fetching a URL that differs from the accepted only by the scheme.
631 NotifyIPAddressChanged();
632 MockSearchDomainCheckResponse("http://www.google.co.uk/");
633 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1);
634 CommitSearch(1);
635 EXPECT_FALSE(GetInfoBar(1) == NULL);
636 NotifyIPAddressChanged();
637 url_canon::Replacements<char> replacements;
638 const std::string& scheme("https");
639 replacements.SetScheme(scheme.data(),
640 url_parse::Component(0, scheme.length()));
641 GURL new_google_url(google_url().ReplaceComponents(replacements));
642 MockSearchDomainCheckResponse(new_google_url.spec());
643 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL());
644 EXPECT_TRUE(GetInfoBar(1) == NULL);
645
646 // As should re-fetching the last prompted URL.
647 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
648 NotifyIPAddressChanged();
649 MockSearchDomainCheckResponse("http://www.google.co.jp/");
650 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1);
651 CommitSearch(1);
652 EXPECT_FALSE(GetInfoBar(1) == NULL);
653 NotifyIPAddressChanged();
654 MockSearchDomainCheckResponse("http://www.google.co.uk/");
655 EXPECT_EQ(new_google_url, google_url());
656 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
657 EXPECT_TRUE(GetInfoBar(1) == NULL);
658
659 // And one that differs from the last prompted URL only by the scheme.
660 NotifyIPAddressChanged();
661 MockSearchDomainCheckResponse("http://www.google.co.jp/");
662 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1);
663 CommitSearch(1);
664 EXPECT_FALSE(GetInfoBar(1) == NULL);
665 NotifyIPAddressChanged();
666 MockSearchDomainCheckResponse("https://www.google.co.uk/");
667 EXPECT_EQ(new_google_url, google_url());
668 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL());
669 EXPECT_TRUE(GetInfoBar(1) == NULL);
670
671 // And fetching a different URL entirely.
672 NotifyIPAddressChanged();
673 MockSearchDomainCheckResponse("http://www.google.co.jp/");
674 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1);
675 CommitSearch(1);
676 EXPECT_FALSE(GetInfoBar(1) == NULL);
677 NotifyIPAddressChanged();
678 MockSearchDomainCheckResponse("https://www.google.co.in/");
679 EXPECT_EQ(new_google_url, google_url());
680 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL());
681 EXPECT_TRUE(GetInfoBar(1) == NULL);
682 }
683
684 TEST_F(GoogleURLTrackerTest, ResetInfobarGoogleURLs) {
685 RequestServerCheck();
686 FinishSleep();
687 MockSearchDomainCheckResponse(google_url().spec());
688
689 NotifyIPAddressChanged();
690 MockSearchDomainCheckResponse("http://www.google.co.uk/");
691 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1);
692 CommitSearch(1);
693 TestInfoBarDelegate* infobar = GetInfoBar(1);
694 ASSERT_FALSE(infobar == NULL);
695 EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url());
696
697 // If while an infobar is showing we fetch a new URL that differs from the
698 // infobar's only by scheme, the infobar should stay open but have its Google
699 // URL reset.
700 NotifyIPAddressChanged();
701 MockSearchDomainCheckResponse("https://www.google.co.uk/");
702 TestInfoBarDelegate* new_infobar = GetInfoBar(1);
703 ASSERT_FALSE(new_infobar == NULL);
704 EXPECT_EQ(infobar, new_infobar);
705 EXPECT_EQ(GURL("https://www.google.co.uk/"), new_infobar->new_google_url());
706 }
707
531 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterPendingSearch) { 708 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterPendingSearch) {
532 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 709 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
533 RequestServerCheck(); 710 RequestServerCheck();
534 FinishSleep(); 711 FinishSleep();
535 MockSearchDomainCheckResponse(".google.co.jp"); 712 MockSearchDomainCheckResponse("http://www.google.co.jp/");
536 713
537 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); 714 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
538 TestInfoBarDelegate* infobar = GetInfoBar(1); 715 TestInfoBarDelegate* infobar = GetInfoBar(1);
539 ASSERT_FALSE(infobar == NULL); 716 ASSERT_FALSE(infobar == NULL);
540 EXPECT_FALSE(infobar->showing()); 717 EXPECT_FALSE(infobar->showing());
541 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), 718 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"),
542 infobar->search_url()); 719 infobar->search_url());
543 720
544 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); 721 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1);
545 TestInfoBarDelegate* infobar2 = GetInfoBar(1); 722 TestInfoBarDelegate* infobar2 = GetInfoBar(1);
546 ASSERT_FALSE(infobar2 == NULL); 723 ASSERT_FALSE(infobar2 == NULL);
547 EXPECT_FALSE(infobar2->showing()); 724 EXPECT_FALSE(infobar2->showing());
548 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), 725 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"),
549 infobar2->search_url()); 726 infobar2->search_url());
550 727
551 CommitSearch(1); 728 CommitSearch(1);
552 EXPECT_TRUE(infobar2->showing()); 729 EXPECT_TRUE(infobar2->showing());
553 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 730 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
554 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 731 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
555 EXPECT_FALSE(observer_->notified()); 732 EXPECT_FALSE(observer_->notified());
556
557 CloseTab(1);
558 } 733 }
559 734
560 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterCommittedSearch) { 735 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterCommittedSearch) {
561 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 736 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
562 RequestServerCheck(); 737 RequestServerCheck();
563 FinishSleep(); 738 FinishSleep();
564 MockSearchDomainCheckResponse(".google.co.jp"); 739 MockSearchDomainCheckResponse("http://www.google.co.jp/");
565 740
566 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); 741 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
567 CommitSearch(1); 742 CommitSearch(1);
568 TestInfoBarDelegate* infobar = GetInfoBar(1); 743 TestInfoBarDelegate* infobar = GetInfoBar(1);
569 ASSERT_FALSE(infobar == NULL); 744 ASSERT_FALSE(infobar == NULL);
570 EXPECT_TRUE(infobar->showing()); 745 EXPECT_TRUE(infobar->showing());
571 746
572 // In real usage, the upcoming pending navigation for "test2" would close 747 // In real usage, the upcoming pending navigation for "test2" would close
573 // |infobar|. Since we're not actually doing navigations, we need to clean it 748 // |infobar|. Since we're not actually doing navigations, we need to clean it
574 // up manually to prevent leaks. 749 // up manually to prevent leaks.
575 delete infobar; 750 delete infobar;
576 751
577 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); 752 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1);
578 TestInfoBarDelegate* infobar2 = GetInfoBar(1); 753 TestInfoBarDelegate* infobar2 = GetInfoBar(1);
579 ASSERT_FALSE(infobar2 == NULL); 754 ASSERT_FALSE(infobar2 == NULL);
580 EXPECT_FALSE(infobar2->showing()); 755 EXPECT_FALSE(infobar2->showing());
581 756
582 CommitSearch(1); 757 CommitSearch(1);
583 EXPECT_TRUE(infobar2->showing()); 758 EXPECT_TRUE(infobar2->showing());
584 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 759 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
585 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 760 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
586 EXPECT_FALSE(observer_->notified()); 761 EXPECT_FALSE(observer_->notified());
587
588 CloseTab(1);
589 } 762 }
590 763
591 TEST_F(GoogleURLTrackerTest, MultipleInfobars) { 764 TEST_F(GoogleURLTrackerTest, MultipleInfobars) {
592 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 765 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
593 RequestServerCheck(); 766 RequestServerCheck();
594 FinishSleep(); 767 FinishSleep();
595 MockSearchDomainCheckResponse(".google.co.jp"); 768 MockSearchDomainCheckResponse("http://www.google.co.jp/");
596 769
597 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); 770 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
598 TestInfoBarDelegate* infobar = GetInfoBar(1); 771 TestInfoBarDelegate* infobar = GetInfoBar(1);
599 ASSERT_FALSE(infobar == NULL); 772 ASSERT_FALSE(infobar == NULL);
600 EXPECT_FALSE(infobar->showing()); 773 EXPECT_FALSE(infobar->showing());
601 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), 774 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"),
602 infobar->search_url()); 775 infobar->search_url());
603 776
604 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 2); 777 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 2);
605 CommitSearch(2); 778 CommitSearch(2);
(...skipping 26 matching lines...) Expand all
632 EXPECT_FALSE(observer_->notified()); 805 EXPECT_FALSE(observer_->notified());
633 806
634 infobar4->Accept(); 807 infobar4->Accept();
635 EXPECT_TRUE(GetInfoBar(1) == NULL); 808 EXPECT_TRUE(GetInfoBar(1) == NULL);
636 EXPECT_TRUE(GetInfoBar(3) == NULL); 809 EXPECT_TRUE(GetInfoBar(3) == NULL);
637 EXPECT_TRUE(GetInfoBar(4) == NULL); 810 EXPECT_TRUE(GetInfoBar(4) == NULL);
638 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); 811 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url());
639 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); 812 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
640 EXPECT_TRUE(observer_->notified()); 813 EXPECT_TRUE(observer_->notified());
641 } 814 }
OLDNEW
« chrome/browser/google/google_url_tracker.cc ('K') | « chrome/browser/google/google_url_tracker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698