OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // End-to-end SDCH tests. Uses the embedded test server to return SDCH | 5 // End-to-end SDCH tests. Uses the embedded test server to return SDCH |
6 // results | 6 // results |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <utility> | 10 #include <utility> |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 completion_observer.BlockUntilCompletion(); | 413 completion_observer.BlockUntilCompletion(); |
414 } | 414 } |
415 | 415 |
416 // Something of a cheat; nuke the dictionaries off the SdchManager without | 416 // Something of a cheat; nuke the dictionaries off the SdchManager without |
417 // touching the cache (which browsing data remover would do). | 417 // touching the cache (which browsing data remover would do). |
418 void NukeSdchDictionaries() { | 418 void NukeSdchDictionaries() { |
419 base::RunLoop run_loop; | 419 base::RunLoop run_loop; |
420 content::BrowserThread::PostTaskAndReply( | 420 content::BrowserThread::PostTaskAndReply( |
421 content::BrowserThread::IO, FROM_HERE, | 421 content::BrowserThread::IO, FROM_HERE, |
422 base::Bind(&SdchBrowserTest::NukeSdchDictionariesOnIOThread, | 422 base::Bind(&SdchBrowserTest::NukeSdchDictionariesOnIOThread, |
423 url_request_context_getter_), | 423 base::RetainedRef(url_request_context_getter_)), |
424 run_loop.QuitClosure()); | 424 run_loop.QuitClosure()); |
425 run_loop.Run(); | 425 run_loop.Run(); |
426 } | 426 } |
427 | 427 |
428 // Create a second browser based on a second profile to work within | 428 // Create a second browser based on a second profile to work within |
429 // multi-profile. | 429 // multi-profile. |
430 bool SetupSecondBrowser() { | 430 bool SetupSecondBrowser() { |
431 base::FilePath user_data_dir; | 431 base::FilePath user_data_dir; |
432 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 432 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
433 | 433 |
434 if (!second_profile_data_dir_.CreateUniqueTempDirUnderPath(user_data_dir)) | 434 if (!second_profile_data_dir_.CreateUniqueTempDirUnderPath(user_data_dir)) |
435 return false; | 435 return false; |
436 | 436 |
437 second_profile_ = g_browser_process->profile_manager()->GetProfile( | 437 second_profile_ = g_browser_process->profile_manager()->GetProfile( |
438 second_profile_data_dir_.path()); | 438 second_profile_data_dir_.path()); |
439 if (!second_profile_) return false; | 439 if (!second_profile_) return false; |
440 | 440 |
441 second_browser_ = new Browser(Browser::CreateParams(second_profile_)); | 441 second_browser_ = new Browser(Browser::CreateParams(second_profile_)); |
442 if (!second_browser_) return false; | 442 if (!second_browser_) return false; |
443 | 443 |
444 chrome::AddSelectedTabWithURL(second_browser_, | 444 chrome::AddSelectedTabWithURL(second_browser_, |
445 GURL(url::kAboutBlankURL), | 445 GURL(url::kAboutBlankURL), |
446 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | 446 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
447 content::WaitForLoadStop( | 447 content::WaitForLoadStop( |
448 second_browser_->tab_strip_model()->GetActiveWebContents()); | 448 second_browser_->tab_strip_model()->GetActiveWebContents()); |
449 second_browser_->window()->Show(); | 449 second_browser_->window()->Show(); |
450 | 450 |
451 content::BrowserThread::PostTask( | 451 content::BrowserThread::PostTask( |
452 content::BrowserThread::IO, | 452 content::BrowserThread::IO, FROM_HERE, |
453 FROM_HERE, | |
454 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, | 453 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, |
455 base::Unretained(this), | 454 base::Unretained(this), |
456 make_scoped_refptr( | 455 base::RetainedRef( |
457 second_browser_->profile()->GetRequestContext()))); | 456 second_browser_->profile()->GetRequestContext()))); |
458 | 457 |
459 return true; | 458 return true; |
460 } | 459 } |
461 | 460 |
462 bool SetupIncognitoBrowser() { | 461 bool SetupIncognitoBrowser() { |
463 incognito_browser_ = CreateIncognitoBrowser(); | 462 incognito_browser_ = CreateIncognitoBrowser(); |
464 | 463 |
465 if (!incognito_browser_) | 464 if (!incognito_browser_) |
466 return false; | 465 return false; |
467 | 466 |
468 content::BrowserThread::PostTask( | 467 content::BrowserThread::PostTask( |
469 content::BrowserThread::IO, | 468 content::BrowserThread::IO, FROM_HERE, |
470 FROM_HERE, | |
471 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, | 469 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, |
472 base::Unretained(this), | 470 base::Unretained(this), |
473 make_scoped_refptr( | 471 base::RetainedRef( |
474 incognito_browser_->profile()->GetRequestContext()))); | 472 incognito_browser_->profile()->GetRequestContext()))); |
475 | 473 |
476 return true; | 474 return true; |
477 } | 475 } |
478 | 476 |
479 Browser* second_browser() { return second_browser_; } | 477 Browser* second_browser() { return second_browser_; } |
480 Browser* incognito_browser() { return incognito_browser_; } | 478 Browser* incognito_browser() { return incognito_browser_; } |
481 | 479 |
482 // Server information and control. | 480 // Server information and control. |
483 | 481 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 } | 600 } |
603 | 601 |
604 void SetUpOnMainThread() override { | 602 void SetUpOnMainThread() override { |
605 test_server_.RegisterRequestHandler( | 603 test_server_.RegisterRequestHandler( |
606 base::Bind(&SdchResponseHandler::HandleRequest, | 604 base::Bind(&SdchResponseHandler::HandleRequest, |
607 base::Unretained(&response_handler_))); | 605 base::Unretained(&response_handler_))); |
608 CHECK(test_server_.Start()); | 606 CHECK(test_server_.Start()); |
609 url_request_context_getter_ = browser()->profile()->GetRequestContext(); | 607 url_request_context_getter_ = browser()->profile()->GetRequestContext(); |
610 | 608 |
611 content::BrowserThread::PostTask( | 609 content::BrowserThread::PostTask( |
612 content::BrowserThread::IO, | 610 content::BrowserThread::IO, FROM_HERE, |
613 FROM_HERE, | |
614 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, | 611 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, |
615 base::Unretained(this), | 612 base::Unretained(this), |
616 url_request_context_getter_)); | 613 base::RetainedRef(url_request_context_getter_))); |
617 } | 614 } |
618 | 615 |
619 void TearDownOnMainThread() override { | 616 void TearDownOnMainThread() override { |
620 CHECK(test_server_.ShutdownAndWaitUntilComplete()); | 617 CHECK(test_server_.ShutdownAndWaitUntilComplete()); |
621 | 618 |
622 content::BrowserThread::PostTask( | 619 content::BrowserThread::PostTask( |
623 content::BrowserThread::IO, | 620 content::BrowserThread::IO, |
624 FROM_HERE, | 621 FROM_HERE, |
625 base::Bind(&SdchBrowserTest::UnsubscribeFromAllSdchNotifications, | 622 base::Bind(&SdchBrowserTest::UnsubscribeFromAllSdchNotifications, |
626 base::Unretained(this))); | 623 base::Unretained(this))); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 ASSERT_TRUE(SetupIncognitoBrowser()); | 709 ASSERT_TRUE(SetupIncognitoBrowser()); |
713 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser())); | 710 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser())); |
714 | 711 |
715 // Data fetches on main browser should not be SDCH encoded. | 712 // Data fetches on main browser should not be SDCH encoded. |
716 bool sdch_encoding_used = true; | 713 bool sdch_encoding_used = true; |
717 ASSERT_TRUE(GetData(&sdch_encoding_used)); | 714 ASSERT_TRUE(GetData(&sdch_encoding_used)); |
718 EXPECT_FALSE(sdch_encoding_used); | 715 EXPECT_FALSE(sdch_encoding_used); |
719 } | 716 } |
720 | 717 |
721 } // namespace | 718 } // namespace |
OLD | NEW |