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

Side by Side Diff: chrome/browser/net/sdch_browsertest.cc

Issue 1133763003: SdchObserver: add OnDictionary{Added,Removed} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove manager parameter from SdchObserver Created 5 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
« no previous file with comments | « no previous file | net/base/sdch_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/base64.h" 8 #include "base/base64.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 bool cache_sdch_response_; 254 bool cache_sdch_response_;
255 std::string encoded_data_; 255 std::string encoded_data_;
256 std::string sdch_dictionary_contents_; 256 std::string sdch_dictionary_contents_;
257 std::string dictionary_client_hash_; 257 std::string dictionary_client_hash_;
258 std::string dictionary_server_hash_; 258 std::string dictionary_server_hash_;
259 RequestVector request_vector_; 259 RequestVector request_vector_;
260 std::vector<base::Closure> callback_vector_; 260 std::vector<base::Closure> callback_vector_;
261 base::WeakPtrFactory<SdchResponseHandler> weak_ptr_factory_; 261 base::WeakPtrFactory<SdchResponseHandler> weak_ptr_factory_;
262 }; 262 };
263 263
264 class TestSdchObserver : public net::SdchObserver {
265 public:
266 TestSdchObserver() : manager_(nullptr), fetch_count_(0) {}
267 ~TestSdchObserver() override {
268 if (manager_) {
269 manager_->RemoveObserver(this);
270 }
271 }
272
273 void Observe(net::SdchManager* manager) {
274 DCHECK(!manager_);
275 manager_ = manager;
276 manager_->AddObserver(this);
277 }
278
279 // SdchObserver
280 void OnDictionaryAdded(const GURL& /* dictionary_url */,
281 const std::string& /* server_hash */) override {}
282 void OnDictionaryRemoved(const std::string& /* server_hash */) override {}
283 void OnGetDictionary(const GURL& /* request_url */,
284 const GURL& /* dictionary_url */) override {
285 fetch_count_++;
286 }
287 void OnDictionaryUsed(const std::string& /* server_hash */) override {}
288 void OnClearDictionaries() override {}
289
290 int fetch_count() const { return fetch_count_; }
291
292 private:
293 net::SdchManager* manager_;
294 int fetch_count_;
mmenke 2015/05/14 19:20:24 nit: DISALLOW_COPY_AND_ASSIGN
Elly Fong-Jones 2015/05/14 19:29:28 This won't work, since this class is used as a val
295 };
296
264 class SdchBrowserTest : public InProcessBrowserTest, 297 class SdchBrowserTest : public InProcessBrowserTest,
265 public net::URLFetcherDelegate, 298 public net::URLFetcherDelegate {
266 public net::SdchObserver {
267 public: 299 public:
268 static const char kTestHost[]; 300 static const char kTestHost[];
269 301
270 SdchBrowserTest() 302 SdchBrowserTest()
271 : response_handler_(kTestHost), 303 : response_handler_(kTestHost),
272 url_request_context_getter_(NULL), 304 url_request_context_getter_(NULL),
273 url_fetch_complete_(false), 305 url_fetch_complete_(false),
274 waiting_(false) {} 306 waiting_(false) {}
275 307
276 // Helper functions for fetching data. 308 // Helper functions for fetching data.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 sdch_manager->ClearData(); 573 sdch_manager->ClearData();
542 } 574 }
543 575
544 void GetNumberOfDictionaryFetchesOnIOThread( 576 void GetNumberOfDictionaryFetchesOnIOThread(
545 net::URLRequestContextGetter* context_getter, 577 net::URLRequestContextGetter* context_getter,
546 int* result) { 578 int* result) {
547 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 579 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
548 580
549 net::SdchManager* manager( 581 net::SdchManager* manager(
550 context_getter->GetURLRequestContext()->sdch_manager()); 582 context_getter->GetURLRequestContext()->sdch_manager());
551 DCHECK(fetch_counts_.end() != fetch_counts_.find(manager)); 583 DCHECK(observers_.end() != observers_.find(manager));
552 584
553 *result = fetch_counts_[manager]; 585 *result = observers_[manager].fetch_count();
554 } 586 }
555 587
556 // InProcessBrowserTest 588 // InProcessBrowserTest
557 void SetUpCommandLine(base::CommandLine* command_line) override { 589 void SetUpCommandLine(base::CommandLine* command_line) override {
558 command_line->AppendSwitchASCII( 590 command_line->AppendSwitchASCII(
559 switches::kHostResolverRules, 591 switches::kHostResolverRules,
560 "MAP " + std::string(kTestHost) + " 127.0.0.1"); 592 "MAP " + std::string(kTestHost) + " 127.0.0.1");
561 #if defined(OS_CHROMEOS) 593 #if defined(OS_CHROMEOS)
562 command_line->AppendSwitch( 594 command_line->AppendSwitch(
563 chromeos::switches::kIgnoreUserProfileMappingForTests); 595 chromeos::switches::kIgnoreUserProfileMappingForTests);
(...skipping 24 matching lines...) Expand all
588 base::Bind(&SdchBrowserTest::UnsubscribeFromAllSdchNotifications, 620 base::Bind(&SdchBrowserTest::UnsubscribeFromAllSdchNotifications,
589 base::Unretained(this))); 621 base::Unretained(this)));
590 } 622 }
591 623
592 void SubscribeToSdchNotifications( 624 void SubscribeToSdchNotifications(
593 net::URLRequestContextGetter* context_getter) { 625 net::URLRequestContextGetter* context_getter) {
594 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 626 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
595 627
596 net::SdchManager* manager = 628 net::SdchManager* manager =
597 context_getter->GetURLRequestContext()->sdch_manager(); 629 context_getter->GetURLRequestContext()->sdch_manager();
598 DCHECK(fetch_counts_.end() == fetch_counts_.find(manager)); 630 DCHECK(observers_.end() == observers_.find(manager));
599 631
600 fetch_counts_[manager] = 0; 632 observers_[manager].Observe(manager);
601 manager->AddObserver(this);
602 } 633 }
603 634
604 void UnsubscribeFromAllSdchNotifications() { 635 void UnsubscribeFromAllSdchNotifications() {
605 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 636 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
606 637 observers_.clear();
607 for (auto it = fetch_counts_.begin(); it != fetch_counts_.end(); ++it)
608 it->first->RemoveObserver(this);
609
610 fetch_counts_.clear();
611 } 638 }
612 639
613 // SdchObserver
614 void OnDictionaryUsed(net::SdchManager* manager,
615 const std::string& server_hash) override {}
616
617 void OnGetDictionary(net::SdchManager* manager,
618 const GURL& request_url,
619 const GURL& dictionary_url) override {
620 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
621 DLOG(ERROR) << "Retrieving count of notifications from manager " << manager;
622 DCHECK(fetch_counts_.end() != fetch_counts_.find(manager));
623 ++fetch_counts_[manager];
624 }
625
626 void OnClearDictionaries(net::SdchManager* manager) override {}
627
628 // URLFetcherDelegate 640 // URLFetcherDelegate
629 void OnURLFetchComplete(const net::URLFetcher* source) override { 641 void OnURLFetchComplete(const net::URLFetcher* source) override {
630 url_fetch_complete_ = true; 642 url_fetch_complete_ = true;
631 if (waiting_) 643 if (waiting_)
632 base::MessageLoopForUI::current()->Quit(); 644 base::MessageLoopForUI::current()->Quit();
633 } 645 }
634 646
635 SdchResponseHandler response_handler_; 647 SdchResponseHandler response_handler_;
636 net::test_server::EmbeddedTestServer test_server_; 648 net::test_server::EmbeddedTestServer test_server_;
637 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; 649 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
638 scoped_ptr<net::URLFetcher> fetcher_; 650 scoped_ptr<net::URLFetcher> fetcher_;
639 bool url_fetch_complete_; 651 bool url_fetch_complete_;
640 bool waiting_; 652 bool waiting_;
641 base::ScopedTempDir second_profile_data_dir_; 653 base::ScopedTempDir second_profile_data_dir_;
642 Profile* second_profile_; 654 Profile* second_profile_;
643 Browser* second_browser_; 655 Browser* second_browser_;
644 Browser* incognito_browser_; 656 Browser* incognito_browser_;
645 657
646 // IO Thread access only. 658 // IO Thread access only.
647 std::map<net::SdchManager*, int> fetch_counts_; 659 std::map<net::SdchManager*, TestSdchObserver> observers_;
648 }; 660 };
649 661
650 const char SdchBrowserTest::kTestHost[] = "our.test.host.com"; 662 const char SdchBrowserTest::kTestHost[] = "our.test.host.com";
651 663
652 // Confirm that after getting a dictionary, calling the browsing 664 // Confirm that after getting a dictionary, calling the browsing
653 // data remover renders it unusable. Also (in calling 665 // data remover renders it unusable. Also (in calling
654 // ForceSdchDictionaryLoad()) servers as a smoke test for SDCH. 666 // ForceSdchDictionaryLoad()) servers as a smoke test for SDCH.
655 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, BrowsingDataRemover) { 667 IN_PROC_BROWSER_TEST_F(SdchBrowserTest, BrowsingDataRemover) {
656 ASSERT_TRUE(ForceSdchDictionaryLoad(browser())); 668 ASSERT_TRUE(ForceSdchDictionaryLoad(browser()));
657 669
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 ASSERT_TRUE(SetupIncognitoBrowser()); 707 ASSERT_TRUE(SetupIncognitoBrowser());
696 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser())); 708 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser()));
697 709
698 // Data fetches on main browser should not be SDCH encoded. 710 // Data fetches on main browser should not be SDCH encoded.
699 bool sdch_encoding_used = true; 711 bool sdch_encoding_used = true;
700 ASSERT_TRUE(GetData(&sdch_encoding_used)); 712 ASSERT_TRUE(GetData(&sdch_encoding_used));
701 EXPECT_FALSE(sdch_encoding_used); 713 EXPECT_FALSE(sdch_encoding_used);
702 } 714 }
703 715
704 } // namespace 716 } // namespace
OLDNEW
« no previous file with comments | « no previous file | net/base/sdch_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698