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

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

Issue 593863002: Enable SDCH over HTTPS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Correct test default assumptions. Created 6 years, 2 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 | « net/base/sdch_manager.cc ('k') | no next file » | 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 "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 //------------------------------------------------------------------------------ 16 //------------------------------------------------------------------------------
17 // Provide sample data and compression results with a sample VCDIFF dictionary. 17 // Provide sample data and compression results with a sample VCDIFF dictionary.
18 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. 18 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary.
19 static const char kTestVcdiffDictionary[] = "DictionaryFor" 19 static const char kTestVcdiffDictionary[] = "DictionaryFor"
20 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; 20 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n";
21 21
22 //------------------------------------------------------------------------------ 22 //------------------------------------------------------------------------------
23 23
24 class SdchManagerTest : public testing::Test { 24 class SdchManagerTest : public testing::Test {
25 protected: 25 protected:
26 SdchManagerTest() 26 SdchManagerTest()
27 : sdch_manager_(new SdchManager) { 27 : sdch_manager_(new SdchManager),
28 default_support_(false),
29 default_https_support_(false) {
30 default_support_ = sdch_manager_->sdch_enabled();
31 default_https_support_ = sdch_manager_->secure_scheme_supported();
28 } 32 }
29 33
30 SdchManager* sdch_manager() { return sdch_manager_.get(); } 34 SdchManager* sdch_manager() { return sdch_manager_.get(); }
31 35
32 // Reset globals back to default state. 36 // Reset globals back to default state.
33 virtual void TearDown() { 37 virtual void TearDown() {
34 SdchManager::EnableSdchSupport(true); 38 SdchManager::EnableSdchSupport(default_support_);
35 SdchManager::EnableSecureSchemeSupport(false); 39 SdchManager::EnableSecureSchemeSupport(default_https_support_);
36 } 40 }
37 41
38 // Attempt to add a dictionary to the manager and probe for success or 42 // Attempt to add a dictionary to the manager and probe for success or
39 // failure. 43 // failure.
40 bool AddSdchDictionary(const std::string& dictionary_text, 44 bool AddSdchDictionary(const std::string& dictionary_text,
41 const GURL& gurl) { 45 const GURL& gurl) {
42 std::string list; 46 std::string list;
43 sdch_manager_->GetAvailDictionaryList(gurl, &list); 47 sdch_manager_->GetAvailDictionaryList(gurl, &list);
44 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); 48 sdch_manager_->AddSdchDictionary(dictionary_text, gurl);
45 std::string list2; 49 std::string list2;
46 sdch_manager_->GetAvailDictionaryList(gurl, &list2); 50 sdch_manager_->GetAvailDictionaryList(gurl, &list2);
47 51
48 // The list of hashes should change iff the addition succeeds. 52 // The list of hashes should change iff the addition succeeds.
49 return (list != list2); 53 return (list != list2);
50 } 54 }
51 55
52 private: 56 private:
53 scoped_ptr<SdchManager> sdch_manager_; 57 scoped_ptr<SdchManager> sdch_manager_;
58 bool default_support_;
59 bool default_https_support_;
54 }; 60 };
55 61
56 //------------------------------------------------------------------------------ 62 //------------------------------------------------------------------------------
57 static std::string NewSdchDictionary(const std::string& domain) { 63 static std::string NewSdchDictionary(const std::string& domain) {
58 std::string dictionary; 64 std::string dictionary;
59 if (!domain.empty()) { 65 if (!domain.empty()) {
60 dictionary.append("Domain: "); 66 dictionary.append("Domain: ");
61 dictionary.append(domain); 67 dictionary.append(domain);
62 dictionary.append("\n"); 68 dictionary.append("\n");
63 } 69 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 sdch_manager()->GetAvailDictionaryList( 191 sdch_manager()->GetAvailDictionaryList(
186 GURL("https://" + dictionary_domain + "/test"), 192 GURL("https://" + dictionary_domain + "/test"),
187 &dictionary_list); 193 &dictionary_list);
188 EXPECT_TRUE(dictionary_list.empty()); 194 EXPECT_TRUE(dictionary_list.empty());
189 } 195 }
190 196
191 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { 197 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) {
192 std::string dictionary_domain("x.y.z.google.com"); 198 std::string dictionary_domain("x.y.z.google.com");
193 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 199 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
194 200
201 SdchManager::EnableSecureSchemeSupport(false);
195 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 202 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
196 GURL("https://" + dictionary_domain))); 203 GURL("https://" + dictionary_domain)));
197 SdchManager::EnableSecureSchemeSupport(true); 204 SdchManager::EnableSecureSchemeSupport(true);
198 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 205 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
199 GURL("https://" + dictionary_domain))); 206 GURL("https://" + dictionary_domain)));
200 207
201 GURL target_url("https://" + dictionary_domain + "/test"); 208 GURL target_url("https://" + dictionary_domain + "/test");
202 std::string dictionary_list; 209 std::string dictionary_list;
203 // HTTPS target URL should advertise dictionary if secure scheme support is 210 // HTTPS target URL should advertise dictionary if secure scheme support is
204 // enabled. 211 // enabled.
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 GURL("http://" + dictionary_domain_1 + "/random_url"), 467 GURL("http://" + dictionary_domain_1 + "/random_url"),
461 &dictionary); 468 &dictionary);
462 EXPECT_FALSE(dictionary.get()); 469 EXPECT_FALSE(dictionary.get());
463 } 470 }
464 471
465 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { 472 TEST_F(SdchManagerTest, HttpsCorrectlySupported) {
466 GURL url("http://www.google.com"); 473 GURL url("http://www.google.com");
467 GURL secure_url("https://www.google.com"); 474 GURL secure_url("https://www.google.com");
468 475
469 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); 476 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
477 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(secure_url));
478
479 SdchManager::EnableSecureSchemeSupport(false);
480 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
470 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(secure_url)); 481 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(secure_url));
471
472 SdchManager::EnableSecureSchemeSupport(true);
473 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
474 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(secure_url));
475 } 482 }
476 483
477 TEST_F(SdchManagerTest, ClearDictionaryData) { 484 TEST_F(SdchManagerTest, ClearDictionaryData) {
478 std::string dictionary_domain("x.y.z.google.com"); 485 std::string dictionary_domain("x.y.z.google.com");
479 GURL blacklist_url("http://bad.chromium.org"); 486 GURL blacklist_url("http://bad.chromium.org");
480 487
481 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 488 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
482 std::string tmp_hash; 489 std::string tmp_hash;
483 std::string server_hash; 490 std::string server_hash;
484 491
(...skipping 17 matching lines...) Expand all
502 dictionary = NULL; 509 dictionary = NULL;
503 sdch_manager()->GetVcdiffDictionary( 510 sdch_manager()->GetVcdiffDictionary(
504 server_hash, 511 server_hash,
505 GURL("http://" + dictionary_domain + "/random_url"), 512 GURL("http://" + dictionary_domain + "/random_url"),
506 &dictionary); 513 &dictionary);
507 EXPECT_FALSE(dictionary.get()); 514 EXPECT_FALSE(dictionary.get());
508 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); 515 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url));
509 } 516 }
510 517
511 } // namespace net 518 } // namespace net
512
OLDNEW
« no previous file with comments | « net/base/sdch_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698