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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 private: | 299 private: |
300 net::SdchManager* manager_; | 300 net::SdchManager* manager_; |
301 int fetch_count_; | 301 int fetch_count_; |
302 }; | 302 }; |
303 | 303 |
304 class SdchBrowserTest : public InProcessBrowserTest, | 304 class SdchBrowserTest : public InProcessBrowserTest, |
305 public net::URLFetcherDelegate { | 305 public net::URLFetcherDelegate { |
306 public: | 306 public: |
307 static const char kTestHost[]; | 307 static const char kTestHost[]; |
308 | 308 |
309 SdchBrowserTest() | 309 SdchBrowserTest() : response_handler_(kTestHost) {} |
310 : response_handler_(kTestHost), | |
311 url_request_context_getter_(NULL), | |
312 url_fetch_complete_(false), | |
313 waiting_(false) {} | |
314 | 310 |
315 // Helper functions for fetching data. | 311 // Helper functions for fetching data. |
316 | 312 |
317 void FetchUrlDetailed(GURL url, net::URLRequestContextGetter* getter) { | 313 void FetchUrlDetailed(GURL url, net::URLRequestContextGetter* getter) { |
318 url_fetch_complete_ = false; | 314 url_fetch_complete_ = false; |
319 fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this); | 315 fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this); |
320 fetcher_->SetRequestContext(getter); | 316 fetcher_->SetRequestContext(getter); |
321 fetcher_->Start(); | 317 fetcher_->Start(); |
322 if (!url_fetch_complete_) { | 318 if (!url_fetch_complete_) { |
323 waiting_ = true; | 319 waiting_ = true; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 second_browser_ = new Browser(Browser::CreateParams(second_profile_, true)); | 444 second_browser_ = new Browser(Browser::CreateParams(second_profile_, true)); |
449 if (!second_browser_) return false; | 445 if (!second_browser_) return false; |
450 | 446 |
451 chrome::AddSelectedTabWithURL(second_browser_, | 447 chrome::AddSelectedTabWithURL(second_browser_, |
452 GURL(url::kAboutBlankURL), | 448 GURL(url::kAboutBlankURL), |
453 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | 449 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
454 content::WaitForLoadStop( | 450 content::WaitForLoadStop( |
455 second_browser_->tab_strip_model()->GetActiveWebContents()); | 451 second_browser_->tab_strip_model()->GetActiveWebContents()); |
456 second_browser_->window()->Show(); | 452 second_browser_->window()->Show(); |
457 | 453 |
458 content::BrowserThread::PostTask( | 454 bool sdch_enabled = false; |
| 455 base::RunLoop run_loop; |
| 456 content::BrowserThread::PostTaskAndReply( |
459 content::BrowserThread::IO, FROM_HERE, | 457 content::BrowserThread::IO, FROM_HERE, |
460 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, | 458 base::Bind( |
461 base::Unretained(this), | 459 &SdchBrowserTest::SubscribeToSdchNotifications, |
462 base::RetainedRef( | 460 base::Unretained(this), |
463 second_browser_->profile()->GetRequestContext()))); | 461 base::RetainedRef(second_browser_->profile()->GetRequestContext()), |
| 462 &sdch_enabled_), |
| 463 run_loop.QuitClosure()); |
| 464 run_loop.Run(); |
| 465 DCHECK(sdch_enabled); |
464 | 466 |
465 return true; | 467 return true; |
466 } | 468 } |
467 | 469 |
468 bool SetupIncognitoBrowser() { | 470 bool SetupIncognitoBrowser() { |
469 incognito_browser_ = CreateIncognitoBrowser(); | 471 incognito_browser_ = CreateIncognitoBrowser(); |
470 | 472 |
471 if (!incognito_browser_) | 473 if (!incognito_browser_) |
472 return false; | 474 return false; |
473 | 475 |
474 content::BrowserThread::PostTask( | 476 bool sdch_enabled = false; |
| 477 base::RunLoop run_loop; |
| 478 content::BrowserThread::PostTaskAndReply( |
475 content::BrowserThread::IO, FROM_HERE, | 479 content::BrowserThread::IO, FROM_HERE, |
476 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, | 480 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, |
477 base::Unretained(this), | 481 base::Unretained(this), |
478 base::RetainedRef( | 482 base::RetainedRef( |
479 incognito_browser_->profile()->GetRequestContext()))); | 483 incognito_browser_->profile()->GetRequestContext()), |
| 484 &sdch_enabled), |
| 485 run_loop.QuitClosure()); |
| 486 run_loop.Run(); |
| 487 DCHECK(sdch_enabled); |
480 | 488 |
481 return true; | 489 return true; |
482 } | 490 } |
483 | 491 |
484 Browser* second_browser() { return second_browser_; } | 492 Browser* second_browser() { return second_browser_; } |
485 Browser* incognito_browser() { return incognito_browser_; } | 493 Browser* incognito_browser() { return incognito_browser_; } |
486 | 494 |
487 // Server information and control. | 495 // Server information and control. |
488 | 496 |
489 void WaitAndGetTestVector(int num_requests, RequestVector* result) { | 497 void WaitAndGetTestVector(int num_requests, RequestVector* result) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 // Confirm the request vector looks at this point as expected. | 574 // Confirm the request vector looks at this point as expected. |
567 WaitAndGetTestVector(4, &request_vector); | 575 WaitAndGetTestVector(4, &request_vector); |
568 EXPECT_EQ(4u, request_vector.size()); | 576 EXPECT_EQ(4u, request_vector.size()); |
569 EXPECT_EQ(request_vector[2].relative_url, kDataURLPath); | 577 EXPECT_EQ(request_vector[2].relative_url, kDataURLPath); |
570 EXPECT_EQ(request_vector[3].relative_url, kDataURLPath); | 578 EXPECT_EQ(request_vector[3].relative_url, kDataURLPath); |
571 return (4u == request_vector.size() && | 579 return (4u == request_vector.size() && |
572 request_vector[2].relative_url == kDataURLPath && | 580 request_vector[2].relative_url == kDataURLPath && |
573 request_vector[3].relative_url == kDataURLPath); | 581 request_vector[3].relative_url == kDataURLPath); |
574 } | 582 } |
575 | 583 |
| 584 bool sdch_enabled() const { return sdch_enabled_; } |
| 585 |
576 private: | 586 private: |
577 static void NukeSdchDictionariesOnIOThread( | 587 static void NukeSdchDictionariesOnIOThread( |
578 net::URLRequestContextGetter* context_getter) { | 588 net::URLRequestContextGetter* context_getter) { |
579 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 589 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
580 net::SdchManager* sdch_manager = | 590 net::SdchManager* sdch_manager = |
581 context_getter->GetURLRequestContext()->sdch_manager(); | 591 context_getter->GetURLRequestContext()->sdch_manager(); |
582 DCHECK(sdch_manager); | 592 DCHECK(sdch_manager); |
583 sdch_manager->ClearData(); | 593 sdch_manager->ClearData(); |
584 } | 594 } |
585 | 595 |
(...skipping 20 matching lines...) Expand all Loading... |
606 #endif | 616 #endif |
607 } | 617 } |
608 | 618 |
609 void SetUpOnMainThread() override { | 619 void SetUpOnMainThread() override { |
610 test_server_.RegisterRequestHandler( | 620 test_server_.RegisterRequestHandler( |
611 base::Bind(&SdchResponseHandler::HandleRequest, | 621 base::Bind(&SdchResponseHandler::HandleRequest, |
612 base::Unretained(&response_handler_))); | 622 base::Unretained(&response_handler_))); |
613 CHECK(test_server_.Start()); | 623 CHECK(test_server_.Start()); |
614 url_request_context_getter_ = browser()->profile()->GetRequestContext(); | 624 url_request_context_getter_ = browser()->profile()->GetRequestContext(); |
615 | 625 |
616 content::BrowserThread::PostTask( | 626 base::RunLoop run_loop; |
| 627 content::BrowserThread::PostTaskAndReply( |
617 content::BrowserThread::IO, FROM_HERE, | 628 content::BrowserThread::IO, FROM_HERE, |
618 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, | 629 base::Bind(&SdchBrowserTest::SubscribeToSdchNotifications, |
619 base::Unretained(this), | 630 base::Unretained(this), |
620 base::RetainedRef(url_request_context_getter_))); | 631 base::RetainedRef(url_request_context_getter_), |
| 632 &sdch_enabled_), |
| 633 run_loop.QuitClosure()); |
| 634 run_loop.Run(); |
621 } | 635 } |
622 | 636 |
623 void TearDownOnMainThread() override { | 637 void TearDownOnMainThread() override { |
624 CHECK(test_server_.ShutdownAndWaitUntilComplete()); | 638 CHECK(test_server_.ShutdownAndWaitUntilComplete()); |
625 | 639 |
626 content::BrowserThread::PostTask( | 640 content::BrowserThread::PostTask( |
627 content::BrowserThread::IO, | 641 content::BrowserThread::IO, |
628 FROM_HERE, | 642 FROM_HERE, |
629 base::Bind(&SdchBrowserTest::UnsubscribeFromAllSdchNotifications, | 643 base::Bind(&SdchBrowserTest::UnsubscribeFromAllSdchNotifications, |
630 base::Unretained(this))); | 644 base::Unretained(this))); |
631 } | 645 } |
632 | 646 |
| 647 // Check if SDCH is enabled, and if so subscribe an observer to the |
| 648 // SDCH manager on the URLRequestContext that was passed in. |
633 void SubscribeToSdchNotifications( | 649 void SubscribeToSdchNotifications( |
634 net::URLRequestContextGetter* context_getter) { | 650 net::URLRequestContextGetter* context_getter, |
| 651 bool* sdch_enabled) { |
635 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 652 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
636 | 653 |
637 net::SdchManager* manager = | 654 net::SdchManager* manager = |
638 context_getter->GetURLRequestContext()->sdch_manager(); | 655 context_getter->GetURLRequestContext()->sdch_manager(); |
| 656 *sdch_enabled = !!manager; |
| 657 if (!*sdch_enabled) |
| 658 return; |
| 659 |
639 DCHECK(observers_.end() == observers_.find(manager)); | 660 DCHECK(observers_.end() == observers_.find(manager)); |
640 | 661 |
641 observers_[manager].Observe(manager); | 662 observers_[manager].Observe(manager); |
642 } | 663 } |
643 | 664 |
644 void UnsubscribeFromAllSdchNotifications() { | 665 void UnsubscribeFromAllSdchNotifications() { |
645 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 666 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
646 observers_.clear(); | 667 observers_.clear(); |
647 } | 668 } |
648 | 669 |
649 // URLFetcherDelegate | 670 // URLFetcherDelegate |
650 void OnURLFetchComplete(const net::URLFetcher* source) override { | 671 void OnURLFetchComplete(const net::URLFetcher* source) override { |
651 url_fetch_complete_ = true; | 672 url_fetch_complete_ = true; |
652 if (waiting_) | 673 if (waiting_) |
653 base::MessageLoopForUI::current()->QuitWhenIdle(); | 674 base::MessageLoopForUI::current()->QuitWhenIdle(); |
654 } | 675 } |
655 | 676 |
| 677 bool sdch_enabled_ = false; |
656 SdchResponseHandler response_handler_; | 678 SdchResponseHandler response_handler_; |
657 net::EmbeddedTestServer test_server_; | 679 net::EmbeddedTestServer test_server_; |
658 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 680 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_ = |
| 681 nullptr; |
659 std::unique_ptr<net::URLFetcher> fetcher_; | 682 std::unique_ptr<net::URLFetcher> fetcher_; |
660 bool url_fetch_complete_; | 683 bool url_fetch_complete_ = false; |
661 bool waiting_; | 684 bool waiting_ = false; |
662 base::ScopedTempDir second_profile_data_dir_; | 685 base::ScopedTempDir second_profile_data_dir_; |
663 Profile* second_profile_; | 686 Profile* second_profile_; |
664 Browser* second_browser_; | 687 Browser* second_browser_; |
665 Browser* incognito_browser_; | 688 Browser* incognito_browser_; |
666 | 689 |
667 // IO Thread access only. | 690 // IO Thread access only. |
668 std::map<net::SdchManager*, TestSdchObserver> observers_; | 691 std::map<net::SdchManager*, TestSdchObserver> observers_; |
669 }; | 692 }; |
670 | 693 |
671 const char SdchBrowserTest::kTestHost[] = "our.test.host.com"; | 694 const char SdchBrowserTest::kTestHost[] = "our.test.host.com"; |
672 | 695 |
673 // Confirm that after getting a dictionary, calling the browsing | 696 // Confirm that after getting a dictionary, calling the browsing |
674 // data remover renders it unusable. Also (in calling | 697 // data remover renders it unusable. Also (in calling |
675 // ForceSdchDictionaryLoad()) servers as a smoke test for SDCH. | 698 // ForceSdchDictionaryLoad()) servers as a smoke test for SDCH. |
676 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, BrowsingDataRemover) { | 699 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, BrowsingDataRemover) { |
| 700 if (!sdch_enabled()) { |
| 701 LOG(ERROR) << "SDCH disabled; not running test."; |
| 702 return; |
| 703 } |
| 704 |
677 ASSERT_TRUE(ForceSdchDictionaryLoad(browser())); | 705 ASSERT_TRUE(ForceSdchDictionaryLoad(browser())); |
678 | 706 |
679 // Confirm browsing data remover without removing the cache leaves | 707 // Confirm browsing data remover without removing the cache leaves |
680 // SDCH alone. | 708 // SDCH alone. |
681 BrowsingDataRemoveAndWait(ChromeBrowsingDataRemoverDelegate::ALL_DATA_TYPES & | 709 BrowsingDataRemoveAndWait(ChromeBrowsingDataRemoverDelegate::ALL_DATA_TYPES & |
682 ~BrowsingDataRemover::DATA_TYPE_CACHE); | 710 ~BrowsingDataRemover::DATA_TYPE_CACHE); |
683 bool sdch_encoding_used = false; | 711 bool sdch_encoding_used = false; |
684 ASSERT_TRUE(GetData(&sdch_encoding_used)); | 712 ASSERT_TRUE(GetData(&sdch_encoding_used)); |
685 EXPECT_TRUE(sdch_encoding_used); | 713 EXPECT_TRUE(sdch_encoding_used); |
686 | 714 |
687 // Confirm browsing data remover removing the cache clears SDCH state. | 715 // Confirm browsing data remover removing the cache clears SDCH state. |
688 BrowsingDataRemoveAndWait(BrowsingDataRemover::DATA_TYPE_CACHE); | 716 BrowsingDataRemoveAndWait(BrowsingDataRemover::DATA_TYPE_CACHE); |
689 sdch_encoding_used = false; | 717 sdch_encoding_used = false; |
690 ASSERT_TRUE(GetData(&sdch_encoding_used)); | 718 ASSERT_TRUE(GetData(&sdch_encoding_used)); |
691 EXPECT_FALSE(sdch_encoding_used); | 719 EXPECT_FALSE(sdch_encoding_used); |
692 } | 720 } |
693 | 721 |
694 // Confirm dictionaries not visible in other profiles. | 722 // Confirm dictionaries not visible in other profiles. |
695 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, Isolation) { | 723 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, Isolation) { |
| 724 if (!sdch_enabled()) { |
| 725 LOG(ERROR) << "SDCH disabled; not running test."; |
| 726 return; |
| 727 } |
| 728 |
696 ASSERT_TRUE(ForceSdchDictionaryLoad(browser())); | 729 ASSERT_TRUE(ForceSdchDictionaryLoad(browser())); |
697 ASSERT_TRUE(SetupSecondBrowser()); | 730 ASSERT_TRUE(SetupSecondBrowser()); |
698 ASSERT_TRUE(SetupIncognitoBrowser()); | 731 ASSERT_TRUE(SetupIncognitoBrowser()); |
699 | 732 |
700 // Data fetches from incognito or separate profiles should not be SDCH | 733 // Data fetches from incognito or separate profiles should not be SDCH |
701 // encoded. | 734 // encoded. |
702 bool sdch_encoding_used = true; | 735 bool sdch_encoding_used = true; |
703 EXPECT_TRUE( | 736 EXPECT_TRUE( |
704 GetDataDetailed(incognito_browser()->profile()->GetRequestContext(), | 737 GetDataDetailed(incognito_browser()->profile()->GetRequestContext(), |
705 &sdch_encoding_used)); | 738 &sdch_encoding_used)); |
706 EXPECT_FALSE(sdch_encoding_used); | 739 EXPECT_FALSE(sdch_encoding_used); |
707 | 740 |
708 sdch_encoding_used = true; | 741 sdch_encoding_used = true; |
709 EXPECT_TRUE(GetDataDetailed( | 742 EXPECT_TRUE(GetDataDetailed( |
710 second_browser()->profile()->GetRequestContext(), &sdch_encoding_used)); | 743 second_browser()->profile()->GetRequestContext(), &sdch_encoding_used)); |
711 EXPECT_FALSE(sdch_encoding_used); | 744 EXPECT_FALSE(sdch_encoding_used); |
712 } | 745 } |
713 | 746 |
714 // Confirm a dictionary loaded in incognito isn't visible in the main profile. | 747 // Confirm a dictionary loaded in incognito isn't visible in the main profile. |
715 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, ReverseIsolation) { | 748 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, ReverseIsolation) { |
| 749 if (!sdch_enabled()) { |
| 750 LOG(ERROR) << "SDCH disabled; not running test."; |
| 751 return; |
| 752 } |
| 753 |
716 ASSERT_TRUE(SetupIncognitoBrowser()); | 754 ASSERT_TRUE(SetupIncognitoBrowser()); |
717 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser())); | 755 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser())); |
718 | 756 |
719 // Data fetches on main browser should not be SDCH encoded. | 757 // Data fetches on main browser should not be SDCH encoded. |
720 bool sdch_encoding_used = true; | 758 bool sdch_encoding_used = true; |
721 ASSERT_TRUE(GetData(&sdch_encoding_used)); | 759 ASSERT_TRUE(GetData(&sdch_encoding_used)); |
722 EXPECT_FALSE(sdch_encoding_used); | 760 EXPECT_FALSE(sdch_encoding_used); |
723 } | 761 } |
724 | 762 |
725 } // namespace | 763 } // namespace |
OLD | NEW |