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

Side by Side Diff: net/base/sdch_manager_unittest.cc

Issue 664263002: Restructure SDCH layering to allow more separation (observer/1->[0,n] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync'd to 303035. Created 6 years, 1 month 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 | « net/base/sdch_manager.cc ('k') | net/base/sdch_observer.h » ('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 #include <limits.h> 5 #include <limits.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/sdch_manager.h" 11 #include "net/base/sdch_manager.h"
12 #include "net/base/sdch_observer.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "url/gurl.h"
13 15
14 namespace net { 16 namespace net {
15 17
16 //------------------------------------------------------------------------------ 18 //------------------------------------------------------------------------------
17 // Provide sample data and compression results with a sample VCDIFF dictionary. 19 // Provide sample data and compression results with a sample VCDIFF dictionary.
18 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. 20 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary.
19 static const char kTestVcdiffDictionary[] = "DictionaryFor" 21 static const char kTestVcdiffDictionary[] = "DictionaryFor"
20 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; 22 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n";
21 23
22 //------------------------------------------------------------------------------ 24 //------------------------------------------------------------------------------
23 25
26 class MockSdchObserver : public SdchObserver {
27 public:
28 MockSdchObserver() : get_dictionary_notifications_(0) {}
29
30 const GURL& last_dictionary_request_url() {
31 return last_dictionary_request_url_;
32 }
33 const GURL& last_dictionary_url() { return last_dictionary_url_; }
34 int get_dictionary_notifications() { return get_dictionary_notifications_; }
35
36 // SdchObserver implementation
37 void OnGetDictionary(SdchManager* manager,
38 const GURL& request_url,
39 const GURL& dictionary_url) override {
40 ++get_dictionary_notifications_;
41 last_dictionary_request_url_ = request_url;
42 last_dictionary_url_ = dictionary_url;
43 }
44 void OnClearDictionaries(SdchManager* manager) override {}
45
46 private:
47 int get_dictionary_notifications_;
48 GURL last_dictionary_request_url_;
49 GURL last_dictionary_url_;
50 };
51
24 class SdchManagerTest : public testing::Test { 52 class SdchManagerTest : public testing::Test {
25 protected: 53 protected:
26 SdchManagerTest() 54 SdchManagerTest()
27 : sdch_manager_(new SdchManager), 55 : sdch_manager_(new SdchManager),
28 default_support_(false), 56 default_support_(false),
29 default_https_support_(false) { 57 default_https_support_(false) {
30 default_support_ = sdch_manager_->sdch_enabled(); 58 default_support_ = sdch_manager_->sdch_enabled();
31 default_https_support_ = sdch_manager_->secure_scheme_supported(); 59 default_https_support_ = sdch_manager_->secure_scheme_supported();
32 } 60 }
33 61
62 virtual ~SdchManagerTest() {}
63
34 SdchManager* sdch_manager() { return sdch_manager_.get(); } 64 SdchManager* sdch_manager() { return sdch_manager_.get(); }
35 65
36 // Reset globals back to default state. 66 // Reset globals back to default state.
37 void TearDown() override { 67 void TearDown() override {
38 SdchManager::EnableSdchSupport(default_support_); 68 SdchManager::EnableSdchSupport(default_support_);
39 SdchManager::EnableSecureSchemeSupport(default_https_support_); 69 SdchManager::EnableSecureSchemeSupport(default_https_support_);
40 } 70 }
41 71
42 // Attempt to add a dictionary to the manager and probe for success or 72 // Attempt to add a dictionary to the manager and probe for success or
43 // failure. 73 // failure.
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 586
557 dictionary = NULL; 587 dictionary = NULL;
558 sdch_manager()->GetVcdiffDictionary( 588 sdch_manager()->GetVcdiffDictionary(
559 server_hash, 589 server_hash,
560 GURL("http://" + dictionary_domain + "/random_url"), 590 GURL("http://" + dictionary_domain + "/random_url"),
561 &dictionary); 591 &dictionary);
562 EXPECT_FALSE(dictionary.get()); 592 EXPECT_FALSE(dictionary.get());
563 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); 593 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url));
564 } 594 }
565 595
596 TEST_F(SdchManagerTest, GetDictionaryNotification) {
597 GURL test_request_gurl(GURL("http://www.example.com/data"));
598 GURL test_dictionary_gurl(GURL("http://www.example.com/dict"));
599 MockSdchObserver observer;
600 sdch_manager()->AddObserver(&observer);
601
602 EXPECT_EQ(0, observer.get_dictionary_notifications());
603 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl);
604 EXPECT_EQ(1, observer.get_dictionary_notifications());
605 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url());
606 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url());
607
608 sdch_manager()->RemoveObserver(&observer);
609 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl);
610 EXPECT_EQ(1, observer.get_dictionary_notifications());
611 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url());
612 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url());
613 }
614
566 } // namespace net 615 } // namespace net
OLDNEW
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/base/sdch_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698