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

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

Issue 329373002: Avoid advertising SDCH over HTTPS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reset global variables between tests. Created 6 years, 6 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 | Annotate | Revision Log
« 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 } 28 }
29 29
30 // Reset globals back to default state.
31 virtual void TearDown() {
32 net::SdchManager::EnableSdchSupport(true);
33 net::SdchManager::EnableSecureSchemeSupport(false);
mmenke 2014/06/15 22:38:58 nit: net not needed.
Randy Smith (Not in Mondays) 2014/06/15 23:37:17 Done.
34 }
35
30 scoped_ptr<SdchManager> sdch_manager_; // A singleton database. 36 scoped_ptr<SdchManager> sdch_manager_; // A singleton database.
31 }; 37 };
32 38
33 //------------------------------------------------------------------------------ 39 //------------------------------------------------------------------------------
34 static std::string NewSdchDictionary(const std::string& domain) { 40 static std::string NewSdchDictionary(const std::string& domain) {
35 std::string dictionary; 41 std::string dictionary;
36 if (!domain.empty()) { 42 if (!domain.empty()) {
37 dictionary.append("Domain: "); 43 dictionary.append("Domain: ");
38 dictionary.append(domain); 44 dictionary.append(domain);
39 dictionary.append("\n"); 45 dictionary.append("\n");
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 sdch_manager_->GetAvailDictionaryList( 168 sdch_manager_->GetAvailDictionaryList(
163 GURL("https://" + dictionary_domain + "/test"), 169 GURL("https://" + dictionary_domain + "/test"),
164 &dictionary_list); 170 &dictionary_list);
165 EXPECT_TRUE(dictionary_list.empty()); 171 EXPECT_TRUE(dictionary_list.empty());
166 } 172 }
167 173
168 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { 174 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) {
169 std::string dictionary_domain("x.y.z.google.com"); 175 std::string dictionary_domain("x.y.z.google.com");
170 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 176 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
171 177
172 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 178 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(
173 GURL("https://" + dictionary_domain))); 179 dictionary_text, GURL("https://" + dictionary_domain)));
180 sdch_manager_->EnableSecureSchemeSupport(true);
mmenke 2014/06/15 22:38:58 Think it's clearer this is a static function if yo
Randy Smith (Not in Mondays) 2014/06/15 23:37:17 Good point. Done. (Did both of these throughout
181 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(
182 dictionary_text, GURL("https://" + dictionary_domain)));
174 183
175 GURL target_url("https://" + dictionary_domain + "/test"); 184 GURL target_url("https://" + dictionary_domain + "/test");
176 std::string dictionary_list; 185 std::string dictionary_list;
177 // HTTPS target URL should advertise dictionary if secure scheme support is 186 // HTTPS target URL should advertise dictionary if secure scheme support is
178 // enabled. 187 // enabled.
179 sdch_manager_->EnableSecureSchemeSupport(true);
180 sdch_manager_->GetAvailDictionaryList(target_url, &dictionary_list); 188 sdch_manager_->GetAvailDictionaryList(target_url, &dictionary_list);
181 EXPECT_FALSE(dictionary_list.empty()); 189 EXPECT_FALSE(dictionary_list.empty());
182 190
183 // Dictionary should be available. 191 // Dictionary should be available.
184 SdchManager::Dictionary* dictionary = NULL; 192 SdchManager::Dictionary* dictionary = NULL;
185 std::string client_hash; 193 std::string client_hash;
186 std::string server_hash; 194 std::string server_hash;
187 sdch_manager_->GenerateHash(dictionary_text, &client_hash, &server_hash); 195 sdch_manager_->GenerateHash(dictionary_text, &client_hash, &server_hash);
188 sdch_manager_->GetVcdiffDictionary(server_hash, target_url, &dictionary); 196 sdch_manager_->GetVcdiffDictionary(server_hash, target_url, &dictionary);
189 EXPECT_TRUE(dictionary != NULL); 197 EXPECT_TRUE(dictionary != NULL);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // And can reset them to false. 371 // And can reset them to false.
364 sdch_manager_->SetAllowLatencyExperiment(url, false); 372 sdch_manager_->SetAllowLatencyExperiment(url, false);
365 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); 373 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url));
366 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); 374 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2));
367 375
368 sdch_manager_->SetAllowLatencyExperiment(url2, false); 376 sdch_manager_->SetAllowLatencyExperiment(url2, false);
369 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); 377 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url));
370 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); 378 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2));
371 } 379 }
372 380
381 TEST_F(SdchManagerTest, HttpsCorrectlySupported) {
382 GURL url("http://www.google.com");
383 GURL secure_url("https://www.google.com");
384
385 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(url));
386 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(secure_url));
387
388 sdch_manager_->EnableSecureSchemeSupport(true);
389 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(url));
390 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(secure_url));
391 }
392
373 } // namespace net 393 } // namespace net
374 394
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