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 "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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 // Scans in a case-insensitive way for |header| in |map|, | 102 // Scans in a case-insensitive way for |header| in |map|, |
103 // returning true if found and setting |*value| to the value | 103 // returning true if found and setting |*value| to the value |
104 // of that header. Does not handle multiple instances of the same | 104 // of that header. Does not handle multiple instances of the same |
105 // header. | 105 // header. |
106 bool GetRequestHeader(const HttpRequestHeaderMap& map, | 106 bool GetRequestHeader(const HttpRequestHeaderMap& map, |
107 const char* header, | 107 const char* header, |
108 std::string* value) { | 108 std::string* value) { |
109 for (HttpRequestHeaderMap::const_iterator it = map.begin(); | 109 for (HttpRequestHeaderMap::const_iterator it = map.begin(); |
110 it != map.end(); ++it) { | 110 it != map.end(); ++it) { |
111 if (!base::strcasecmp(it->first.c_str(), header)) { | 111 if (base::EqualsCaseInsensitiveASCII(it->first, header)) { |
112 *value = it->second; | 112 *value = it->second; |
113 return true; | 113 return true; |
114 } | 114 } |
115 } | 115 } |
116 return false; | 116 return false; |
117 } | 117 } |
118 | 118 |
119 // Do a URL-safe base64 encoding. See the SDCH spec "Dictionary Identifier" | 119 // Do a URL-safe base64 encoding. See the SDCH spec "Dictionary Identifier" |
120 // section, and RFC 3548 section 4. | 120 // section, and RFC 3548 section 4. |
121 void SafeBase64Encode(const std::string& input_value, std::string* output) { | 121 void SafeBase64Encode(const std::string& input_value, std::string* output) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 result = encoder.FinishEncoding(&encoded_data_); | 163 result = encoder.FinishEncoding(&encoded_data_); |
164 DCHECK(result); | 164 DCHECK(result); |
165 } | 165 } |
166 | 166 |
167 static bool ClientIsAdvertisingSdchEncoding(const HttpRequestHeaderMap& map) { | 167 static bool ClientIsAdvertisingSdchEncoding(const HttpRequestHeaderMap& map) { |
168 std::string value; | 168 std::string value; |
169 if (!GetRequestHeader(map, "accept-encoding", &value)) | 169 if (!GetRequestHeader(map, "accept-encoding", &value)) |
170 return false; | 170 return false; |
171 base::StringTokenizer tokenizer(value, " ,"); | 171 base::StringTokenizer tokenizer(value, " ,"); |
172 while (tokenizer.GetNext()) { | 172 while (tokenizer.GetNext()) { |
173 if (base::strcasecmp(tokenizer.token().c_str(), "sdch")) | 173 if (base::EqualsCaseInsensitiveASCII(tokenizer.token(), "sdch")) |
174 return true; | 174 return true; |
175 } | 175 } |
176 return false; | 176 return false; |
177 } | 177 } |
178 | 178 |
179 bool ShouldRespondWithSdchEncoding(const HttpRequestHeaderMap& map) { | 179 bool ShouldRespondWithSdchEncoding(const HttpRequestHeaderMap& map) { |
180 std::string value; | 180 std::string value; |
181 if (!GetRequestHeader(map, "avail-dictionary", &value)) | 181 if (!GetRequestHeader(map, "avail-dictionary", &value)) |
182 return false; | 182 return false; |
183 return value == dictionary_client_hash_; | 183 return value == dictionary_client_hash_; |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 ASSERT_TRUE(SetupIncognitoBrowser()); | 707 ASSERT_TRUE(SetupIncognitoBrowser()); |
708 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser())); | 708 ASSERT_TRUE(ForceSdchDictionaryLoad(incognito_browser())); |
709 | 709 |
710 // Data fetches on main browser should not be SDCH encoded. | 710 // Data fetches on main browser should not be SDCH encoded. |
711 bool sdch_encoding_used = true; | 711 bool sdch_encoding_used = true; |
712 ASSERT_TRUE(GetData(&sdch_encoding_used)); | 712 ASSERT_TRUE(GetData(&sdch_encoding_used)); |
713 EXPECT_FALSE(sdch_encoding_used); | 713 EXPECT_FALSE(sdch_encoding_used); |
714 } | 714 } |
715 | 715 |
716 } // namespace | 716 } // namespace |
OLD | NEW |