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 #include <limits.h> | 5 #include <limits.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const GURL& gurl) { | 75 const GURL& gurl) { |
76 return sdch_manager_->AddSdchDictionary(dictionary_text, gurl, nullptr) == | 76 return sdch_manager_->AddSdchDictionary(dictionary_text, gurl, nullptr) == |
77 SDCH_OK; | 77 SDCH_OK; |
78 } | 78 } |
79 | 79 |
80 MockFilterContext* filter_context() { return filter_context_.get(); } | 80 MockFilterContext* filter_context() { return filter_context_.get(); } |
81 | 81 |
82 // Sets both the GURL and the SDCH response for a filter context. | 82 // Sets both the GURL and the SDCH response for a filter context. |
83 void SetupFilterContextWithGURL(GURL url) { | 83 void SetupFilterContextWithGURL(GURL url) { |
84 filter_context_->SetURL(url); | 84 filter_context_->SetURL(url); |
85 filter_context_->SetSdchResponse( | 85 filter_context_->SetSdchResponse(sdch_manager_->GetDictionarySet(url)); |
86 sdch_manager_->GetDictionarySet(url).Pass()); | |
87 } | 86 } |
88 | 87 |
89 std::string NewSdchCompressedData(const std::string& dictionary) { | 88 std::string NewSdchCompressedData(const std::string& dictionary) { |
90 std::string client_hash; | 89 std::string client_hash; |
91 std::string server_hash; | 90 std::string server_hash; |
92 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); | 91 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); |
93 | 92 |
94 // Build compressed data that refers to our dictionary. | 93 // Build compressed data that refers to our dictionary. |
95 std::string compressed(server_hash); | 94 std::string compressed(server_hash); |
96 compressed.append("\0", 1); | 95 compressed.append("\0", 1); |
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 // Don't use the Helper function since its insertion check is indeterminate | 1206 // Don't use the Helper function since its insertion check is indeterminate |
1208 // for a Max-Age: 0 dictionary. | 1207 // for a Max-Age: 0 dictionary. |
1209 sdch_manager_->AddSdchDictionary(expired_dictionary, url, nullptr); | 1208 sdch_manager_->AddSdchDictionary(expired_dictionary, url, nullptr); |
1210 | 1209 |
1211 std::string client_hash; | 1210 std::string client_hash; |
1212 std::string server_hash; | 1211 std::string server_hash; |
1213 SdchManager::GenerateHash(expired_dictionary, &client_hash, &server_hash); | 1212 SdchManager::GenerateHash(expired_dictionary, &client_hash, &server_hash); |
1214 | 1213 |
1215 SdchProblemCode problem_code; | 1214 SdchProblemCode problem_code; |
1216 scoped_ptr<SdchManager::DictionarySet> hash_set( | 1215 scoped_ptr<SdchManager::DictionarySet> hash_set( |
1217 sdch_manager_->GetDictionarySetByHash( | 1216 sdch_manager_->GetDictionarySetByHash(url, server_hash, &problem_code)); |
1218 url, server_hash, &problem_code).Pass()); | |
1219 ASSERT_TRUE(hash_set); | 1217 ASSERT_TRUE(hash_set); |
1220 ASSERT_EQ(SDCH_OK, problem_code); | 1218 ASSERT_EQ(SDCH_OK, problem_code); |
1221 | 1219 |
1222 // Encode output with the second dictionary. | 1220 // Encode output with the second dictionary. |
1223 std::string sdch_compressed(NewSdchCompressedData(expired_dictionary)); | 1221 std::string sdch_compressed(NewSdchCompressedData(expired_dictionary)); |
1224 | 1222 |
1225 // See if the filter decodes it. | 1223 // See if the filter decodes it. |
1226 std::string output; | 1224 std::string output; |
1227 EXPECT_TRUE(FilterTestData(sdch_compressed, 100, 100, filter.get(), &output)); | 1225 EXPECT_TRUE(FilterTestData(sdch_compressed, 100, 100, filter.get(), &output)); |
1228 EXPECT_EQ(expanded_, output); | 1226 EXPECT_EQ(expanded_, output); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 | 1291 |
1294 filter.reset(nullptr); | 1292 filter.reset(nullptr); |
1295 | 1293 |
1296 // Confirm that we got a "DictionaryUsed" signal from the SdchManager | 1294 // Confirm that we got a "DictionaryUsed" signal from the SdchManager |
1297 // for our dictionary. | 1295 // for our dictionary. |
1298 EXPECT_EQ(1, observer.dictionary_used_calls()); | 1296 EXPECT_EQ(1, observer.dictionary_used_calls()); |
1299 EXPECT_EQ(server_hash, observer.last_server_hash()); | 1297 EXPECT_EQ(server_hash, observer.last_server_hash()); |
1300 } | 1298 } |
1301 | 1299 |
1302 } // namespace net | 1300 } // namespace net |
OLD | NEW |