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

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

Issue 298063006: Make SdchManager per-profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments and changed test name. 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') | net/filter/filter.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 "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 scoped_ptr<SdchManager> sdch_manager_; // A singleton database. 30 SdchManager* sdch_manager() { return sdch_manager_.get(); }
31
32 private:
33 scoped_ptr<SdchManager> sdch_manager_;
31 }; 34 };
32 35
33 //------------------------------------------------------------------------------ 36 //------------------------------------------------------------------------------
34 static std::string NewSdchDictionary(const std::string& domain) { 37 static std::string NewSdchDictionary(const std::string& domain) {
35 std::string dictionary; 38 std::string dictionary;
36 if (!domain.empty()) { 39 if (!domain.empty()) {
37 dictionary.append("Domain: "); 40 dictionary.append("Domain: ");
38 dictionary.append(domain); 41 dictionary.append(domain);
39 dictionary.append("\n"); 42 dictionary.append("\n");
40 } 43 }
41 dictionary.append("\n"); 44 dictionary.append("\n");
42 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); 45 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1);
43 return dictionary; 46 return dictionary;
44 } 47 }
45 48
46 TEST_F(SdchManagerTest, DomainSupported) { 49 TEST_F(SdchManagerTest, DomainSupported) {
47 GURL google_url("http://www.google.com"); 50 GURL google_url("http://www.google.com");
48 51
49 net::SdchManager::EnableSdchSupport(false); 52 net::SdchManager::EnableSdchSupport(false);
50 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(google_url)); 53 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url));
51 net::SdchManager::EnableSdchSupport(true); 54 net::SdchManager::EnableSdchSupport(true);
52 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url)); 55 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url));
53 } 56 }
54 57
55 TEST_F(SdchManagerTest, DomainBlacklisting) { 58 TEST_F(SdchManagerTest, DomainBlacklisting) {
56 GURL test_url("http://www.test.com"); 59 GURL test_url("http://www.test.com");
57 GURL google_url("http://www.google.com"); 60 GURL google_url("http://www.google.com");
58 61
59 SdchManager::BlacklistDomain(test_url); 62 sdch_manager()->BlacklistDomain(test_url);
60 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); 63 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url));
61 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url)); 64 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url));
62 65
63 SdchManager::BlacklistDomain(google_url); 66 sdch_manager()->BlacklistDomain(google_url);
64 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(google_url)); 67 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url));
65 } 68 }
66 69
67 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { 70 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) {
68 GURL test_url("http://www.TesT.com"); 71 GURL test_url("http://www.TesT.com");
69 GURL test2_url("http://www.tEst.com"); 72 GURL test2_url("http://www.tEst.com");
70 73
71 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(test_url)); 74 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url));
72 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(test2_url)); 75 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url));
73 SdchManager::BlacklistDomain(test_url); 76 sdch_manager()->BlacklistDomain(test_url);
74 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test2_url)); 77 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url));
75 } 78 }
76 79
77 TEST_F(SdchManagerTest, BlacklistingReset) { 80 TEST_F(SdchManagerTest, BlacklistingReset) {
78 GURL gurl("http://mytest.DoMain.com"); 81 GURL gurl("http://mytest.DoMain.com");
79 std::string domain(gurl.host()); 82 std::string domain(gurl.host());
80 83
81 SdchManager::ClearBlacklistings(); 84 sdch_manager()->ClearBlacklistings();
82 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 0); 85 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
83 EXPECT_EQ(SdchManager::BlacklistDomainExponential(domain), 0); 86 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0);
84 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(gurl)); 87 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl));
85 } 88 }
86 89
87 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { 90 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) {
88 GURL gurl("http://mytest.DoMain.com"); 91 GURL gurl("http://mytest.DoMain.com");
89 std::string domain(gurl.host()); 92 std::string domain(gurl.host());
90 SdchManager::ClearBlacklistings(); 93 sdch_manager()->ClearBlacklistings();
91 94
92 SdchManager::Global()->BlacklistDomain(gurl); 95 sdch_manager()->BlacklistDomain(gurl);
93 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 1); 96 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1);
94 EXPECT_EQ(SdchManager::BlacklistDomainExponential(domain), 1); 97 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1);
95 98
96 // Check that any domain lookup reduces the blacklist counter. 99 // Check that any domain lookup reduces the blacklist counter.
97 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(gurl)); 100 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl));
98 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 0); 101 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
99 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(gurl)); 102 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl));
100 } 103 }
101 104
102 TEST_F(SdchManagerTest, BlacklistingExponential) { 105 TEST_F(SdchManagerTest, BlacklistingExponential) {
103 GURL gurl("http://mytest.DoMain.com"); 106 GURL gurl("http://mytest.DoMain.com");
104 std::string domain(gurl.host()); 107 std::string domain(gurl.host());
105 SdchManager::ClearBlacklistings(); 108 sdch_manager()->ClearBlacklistings();
106 109
107 int exponential = 1; 110 int exponential = 1;
108 for (int i = 1; i < 100; ++i) { 111 for (int i = 1; i < 100; ++i) {
109 SdchManager::Global()->BlacklistDomain(gurl); 112 sdch_manager()->BlacklistDomain(gurl);
110 EXPECT_EQ(SdchManager::BlacklistDomainExponential(domain), exponential); 113 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential);
111 114
112 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), exponential); 115 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential);
113 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(gurl)); 116 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl));
114 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), exponential - 1); 117 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1);
115 118
116 // Simulate a large number of domain checks (which eventually remove the 119 // Simulate a large number of domain checks (which eventually remove the
117 // blacklisting). 120 // blacklisting).
118 SdchManager::ClearDomainBlacklisting(domain); 121 sdch_manager()->ClearDomainBlacklisting(domain);
119 EXPECT_EQ(SdchManager::BlackListDomainCount(domain), 0); 122 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
120 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(gurl)); 123 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl));
121 124
122 // Predict what exponential backoff will be. 125 // Predict what exponential backoff will be.
123 exponential = 1 + 2 * exponential; 126 exponential = 1 + 2 * exponential;
124 if (exponential < 0) 127 if (exponential < 0)
125 exponential = INT_MAX; // We don't wrap. 128 exponential = INT_MAX; // We don't wrap.
126 } 129 }
127 } 130 }
128 131
129 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { 132 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) {
130 std::string dictionary_domain("x.y.z.google.com"); 133 std::string dictionary_domain("x.y.z.google.com");
131 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 134 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
132 135
133 // Perfect match should work. 136 // Perfect match should work.
134 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 137 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
135 GURL("http://" + dictionary_domain))); 138 GURL("http://" + dictionary_domain)));
136 } 139 }
137 140
138 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { 141 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) {
139 std::string dictionary_domain("x.y.z.google.com"); 142 std::string dictionary_domain("x.y.z.google.com");
140 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 143 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
141 144
142 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 145 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
143 GURL("http://" + dictionary_domain))); 146 GURL("http://" + dictionary_domain)));
144 147
145 std::string dictionary_list; 148 std::string dictionary_list;
146 // HTTP target URL can advertise dictionary. 149 // HTTP target URL can advertise dictionary.
147 sdch_manager_->GetAvailDictionaryList( 150 sdch_manager()->GetAvailDictionaryList(
148 GURL("http://" + dictionary_domain + "/test"), 151 GURL("http://" + dictionary_domain + "/test"),
149 &dictionary_list); 152 &dictionary_list);
150 EXPECT_FALSE(dictionary_list.empty()); 153 EXPECT_FALSE(dictionary_list.empty());
151 } 154 }
152 155
153 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { 156 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) {
154 std::string dictionary_domain("x.y.z.google.com"); 157 std::string dictionary_domain("x.y.z.google.com");
155 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 158 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
156 159
157 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 160 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
158 GURL("http://" + dictionary_domain))); 161 GURL("http://" + dictionary_domain)));
159 162
160 std::string dictionary_list; 163 std::string dictionary_list;
161 // HTTPS target URL should NOT advertise dictionary. 164 // HTTPS target URL should NOT advertise dictionary.
162 sdch_manager_->GetAvailDictionaryList( 165 sdch_manager()->GetAvailDictionaryList(
163 GURL("https://" + dictionary_domain + "/test"), 166 GURL("https://" + dictionary_domain + "/test"),
164 &dictionary_list); 167 &dictionary_list);
165 EXPECT_TRUE(dictionary_list.empty()); 168 EXPECT_TRUE(dictionary_list.empty());
166 } 169 }
167 170
168 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { 171 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) {
169 std::string dictionary_domain("x.y.z.google.com"); 172 std::string dictionary_domain("x.y.z.google.com");
170 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 173 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
171 174
172 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 175 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
173 GURL("https://" + dictionary_domain))); 176 GURL("https://" + dictionary_domain)));
174 177
175 GURL target_url("https://" + dictionary_domain + "/test"); 178 GURL target_url("https://" + dictionary_domain + "/test");
176 std::string dictionary_list; 179 std::string dictionary_list;
177 // HTTPS target URL should advertise dictionary if secure scheme support is 180 // HTTPS target URL should advertise dictionary if secure scheme support is
178 // enabled. 181 // enabled.
179 sdch_manager_->EnableSecureSchemeSupport(true); 182 sdch_manager()->EnableSecureSchemeSupport(true);
180 sdch_manager_->GetAvailDictionaryList(target_url, &dictionary_list); 183 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
181 EXPECT_FALSE(dictionary_list.empty()); 184 EXPECT_FALSE(dictionary_list.empty());
182 185
183 // Dictionary should be available. 186 // Dictionary should be available.
184 SdchManager::Dictionary* dictionary = NULL; 187 SdchManager::Dictionary* dictionary = NULL;
185 std::string client_hash; 188 std::string client_hash;
186 std::string server_hash; 189 std::string server_hash;
187 sdch_manager_->GenerateHash(dictionary_text, &client_hash, &server_hash); 190 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
188 sdch_manager_->GetVcdiffDictionary(server_hash, target_url, &dictionary); 191 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
189 EXPECT_TRUE(dictionary != NULL); 192 EXPECT_TRUE(dictionary != NULL);
190 } 193 }
191 194
192 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { 195 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) {
193 std::string dictionary_domain("x.y.z.google.com"); 196 std::string dictionary_domain("x.y.z.google.com");
194 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 197 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
195 198
196 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 199 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
197 GURL("http://" + dictionary_domain))); 200 GURL("http://" + dictionary_domain)));
198 201
199 GURL target_url("https://" + dictionary_domain + "/test"); 202 GURL target_url("https://" + dictionary_domain + "/test");
200 std::string dictionary_list; 203 std::string dictionary_list;
201 // HTTPS target URL should not advertise dictionary acquired over HTTP even if 204 // HTTPS target URL should not advertise dictionary acquired over HTTP even if
202 // secure scheme support is enabled. 205 // secure scheme support is enabled.
203 sdch_manager_->EnableSecureSchemeSupport(true); 206 sdch_manager()->EnableSecureSchemeSupport(true);
204 sdch_manager_->GetAvailDictionaryList(target_url, &dictionary_list); 207 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
205 EXPECT_TRUE(dictionary_list.empty()); 208 EXPECT_TRUE(dictionary_list.empty());
206 209
207 SdchManager::Dictionary* dictionary = NULL; 210 SdchManager::Dictionary* dictionary = NULL;
208 std::string client_hash; 211 std::string client_hash;
209 std::string server_hash; 212 std::string server_hash;
210 sdch_manager_->GenerateHash(dictionary_text, &client_hash, &server_hash); 213 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
211 sdch_manager_->GetVcdiffDictionary(server_hash, target_url, &dictionary); 214 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
212 EXPECT_TRUE(dictionary == NULL); 215 EXPECT_TRUE(dictionary == NULL);
213 } 216 }
214 217
215 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { 218 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) {
216 std::string dictionary_domain("x.y.z.google.com"); 219 std::string dictionary_domain("x.y.z.google.com");
217 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 220 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
218 221
219 // Fail the "domain match" requirement. 222 // Fail the "domain match" requirement.
220 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, 223 EXPECT_FALSE(sdch_manager()->AddSdchDictionary(dictionary_text,
221 GURL("http://y.z.google.com"))); 224 GURL("http://y.z.google.com")));
222 } 225 }
223 226
224 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) { 227 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) {
225 std::string dictionary_domain("x.y.z.google.com"); 228 std::string dictionary_domain("x.y.z.google.com");
226 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 229 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
227 230
228 // Fail the HD with D being the domain and H having a dot requirement. 231 // Fail the HD with D being the domain and H having a dot requirement.
229 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, 232 EXPECT_FALSE(sdch_manager()->AddSdchDictionary(dictionary_text,
230 GURL("http://w.x.y.z.google.com"))); 233 GURL("http://w.x.y.z.google.com")));
231 } 234 }
232 235
233 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) { 236 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) {
234 // Make sure that a prefix that matches the domain postfix won't confuse 237 // Make sure that a prefix that matches the domain postfix won't confuse
235 // the validation checks. 238 // the validation checks.
236 std::string dictionary_domain("www.google.com"); 239 std::string dictionary_domain("www.google.com");
237 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 240 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
238 241
239 // Fail the HD with D being the domain and H having a dot requirement. 242 // Fail the HD with D being the domain and H having a dot requirement.
240 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, 243 EXPECT_FALSE(sdch_manager()->AddSdchDictionary(dictionary_text,
241 GURL("http://www.google.com.www.google.com"))); 244 GURL("http://www.google.com.www.google.com")));
242 } 245 }
243 246
244 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) { 247 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) {
245 // Make sure that a prefix that matches the domain postfix won't confuse 248 // Make sure that a prefix that matches the domain postfix won't confuse
246 // the validation checks. 249 // the validation checks.
247 std::string dictionary_domain(".google.com"); 250 std::string dictionary_domain(".google.com");
248 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 251 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
249 252
250 // Verify that a leading dot in the domain is acceptable, as long as the host 253 // Verify that a leading dot in the domain is acceptable, as long as the host
251 // name does not contain any dots preceding the matched domain name. 254 // name does not contain any dots preceding the matched domain name.
252 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 255 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
253 GURL("http://www.google.com"))); 256 GURL("http://www.google.com")));
254 } 257 }
255 258
256 // Make sure the order of the tests is not helping us or confusing things. 259 // Make sure the order of the tests is not helping us or confusing things.
257 // See test CanSetExactMatchDictionary above for first try. 260 // See test CanSetExactMatchDictionary above for first try.
258 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) { 261 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) {
259 std::string dictionary_domain("x.y.z.google.com"); 262 std::string dictionary_domain("x.y.z.google.com");
260 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 263 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
261 264
262 // Perfect match should *STILL* work. 265 // Perfect match should *STILL* work.
263 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 266 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
264 GURL("http://" + dictionary_domain))); 267 GURL("http://" + dictionary_domain)));
265 } 268 }
266 269
267 // Make sure the DOS protection precludes the addition of too many dictionaries. 270 // Make sure the DOS protection precludes the addition of too many dictionaries.
268 TEST_F(SdchManagerTest, TooManyDictionaries) { 271 TEST_F(SdchManagerTest, TooManyDictionaries) {
269 std::string dictionary_domain(".google.com"); 272 std::string dictionary_domain(".google.com");
270 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 273 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
271 274
272 size_t count = 0; 275 size_t count = 0;
273 while (count <= SdchManager::kMaxDictionaryCount + 1) { 276 while (count <= SdchManager::kMaxDictionaryCount + 1) {
274 if (!sdch_manager_->AddSdchDictionary(dictionary_text, 277 if (!sdch_manager()->AddSdchDictionary(dictionary_text,
275 GURL("http://www.google.com"))) 278 GURL("http://www.google.com")))
276 break; 279 break;
277 280
278 dictionary_text += " "; // Create dictionary with different SHA signature. 281 dictionary_text += " "; // Create dictionary with different SHA signature.
279 ++count; 282 ++count;
280 } 283 }
281 EXPECT_EQ(SdchManager::kMaxDictionaryCount, count); 284 EXPECT_EQ(SdchManager::kMaxDictionaryCount, count);
282 } 285 }
283 286
284 TEST_F(SdchManagerTest, DictionaryNotTooLarge) { 287 TEST_F(SdchManagerTest, DictionaryNotTooLarge) {
285 std::string dictionary_domain(".google.com"); 288 std::string dictionary_domain(".google.com");
286 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 289 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
287 290
288 dictionary_text.append( 291 dictionary_text.append(
289 SdchManager::kMaxDictionarySize - dictionary_text.size(), ' '); 292 SdchManager::kMaxDictionarySize - dictionary_text.size(), ' ');
290 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, 293 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
291 GURL("http://" + dictionary_domain))); 294 GURL("http://" + dictionary_domain)));
292 } 295 }
293 296
294 TEST_F(SdchManagerTest, DictionaryTooLarge) { 297 TEST_F(SdchManagerTest, DictionaryTooLarge) {
295 std::string dictionary_domain(".google.com"); 298 std::string dictionary_domain(".google.com");
296 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 299 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
297 300
298 dictionary_text.append( 301 dictionary_text.append(
299 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' '); 302 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' ');
300 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, 303 EXPECT_FALSE(sdch_manager()->AddSdchDictionary(dictionary_text,
301 GURL("http://" + dictionary_domain))); 304 GURL("http://" + dictionary_domain)));
302 } 305 }
303 306
304 TEST_F(SdchManagerTest, PathMatch) { 307 TEST_F(SdchManagerTest, PathMatch) {
305 bool (*PathMatch)(const std::string& path, const std::string& restriction) = 308 bool (*PathMatch)(const std::string& path, const std::string& restriction) =
306 SdchManager::Dictionary::PathMatch; 309 SdchManager::Dictionary::PathMatch;
307 // Perfect match is supported. 310 // Perfect match is supported.
308 EXPECT_TRUE(PathMatch("/search", "/search")); 311 EXPECT_TRUE(PathMatch("/search", "/search"));
309 EXPECT_TRUE(PathMatch("/search/", "/search/")); 312 EXPECT_TRUE(PathMatch("/search/", "/search/"));
310 313
(...skipping 30 matching lines...) Expand all
341 EXPECT_FALSE(PathMatch("/abc", "/ABC")); 344 EXPECT_FALSE(PathMatch("/abc", "/ABC"));
342 } 345 }
343 346
344 // The following are only applicable while we have a latency test in the code, 347 // The following are only applicable while we have a latency test in the code,
345 // and can be removed when that functionality is stripped. 348 // and can be removed when that functionality is stripped.
346 TEST_F(SdchManagerTest, LatencyTestControls) { 349 TEST_F(SdchManagerTest, LatencyTestControls) {
347 GURL url("http://www.google.com"); 350 GURL url("http://www.google.com");
348 GURL url2("http://www.google2.com"); 351 GURL url2("http://www.google2.com");
349 352
350 // First make sure we default to false. 353 // First make sure we default to false.
351 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); 354 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url));
352 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); 355 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url2));
353 356
354 // That we can set each to true. 357 // That we can set each to true.
355 sdch_manager_->SetAllowLatencyExperiment(url, true); 358 sdch_manager()->SetAllowLatencyExperiment(url, true);
356 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url)); 359 EXPECT_TRUE(sdch_manager()->AllowLatencyExperiment(url));
357 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); 360 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url2));
358 361
359 sdch_manager_->SetAllowLatencyExperiment(url2, true); 362 sdch_manager()->SetAllowLatencyExperiment(url2, true);
360 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url)); 363 EXPECT_TRUE(sdch_manager()->AllowLatencyExperiment(url));
361 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); 364 EXPECT_TRUE(sdch_manager()->AllowLatencyExperiment(url2));
362 365
363 // And can reset them to false. 366 // And can reset them to false.
364 sdch_manager_->SetAllowLatencyExperiment(url, false); 367 sdch_manager()->SetAllowLatencyExperiment(url, false);
365 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); 368 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url));
366 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); 369 EXPECT_TRUE(sdch_manager()->AllowLatencyExperiment(url2));
367 370
368 sdch_manager_->SetAllowLatencyExperiment(url2, false); 371 sdch_manager()->SetAllowLatencyExperiment(url2, false);
369 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); 372 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url));
370 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); 373 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url2));
374 }
375
376 TEST_F(SdchManagerTest, CanUseMultipleManagers) {
377 SdchManager second_manager;
378
379 std::string dictionary_domain_1("x.y.z.google.com");
380 std::string dictionary_domain_2("x.y.z.chromium.org");
381
382 std::string dictionary_text_1(NewSdchDictionary(dictionary_domain_1));
383 std::string dictionary_text_2(NewSdchDictionary(dictionary_domain_2));
384
385 std::string tmp_hash;
386 std::string server_hash_1;
387 std::string server_hash_2;
388
389 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1);
390 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2);
391
392 // Confirm that if you add directories to one manager, you
393 // can't get them from the other.
394 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(
395 dictionary_text_1, GURL("http://" + dictionary_domain_1)));
396 SdchManager::Dictionary* dictionary = NULL;
397 sdch_manager()->GetVcdiffDictionary(
398 server_hash_1,
399 GURL("http://" + dictionary_domain_1 + "/random_url"),
400 &dictionary);
401 EXPECT_TRUE(dictionary);
402
403 EXPECT_TRUE(second_manager.AddSdchDictionary(
404 dictionary_text_2, GURL("http://" + dictionary_domain_2)));
405 second_manager.GetVcdiffDictionary(
406 server_hash_2,
407 GURL("http://" + dictionary_domain_2 + "/random_url"),
408 &dictionary);
409 EXPECT_TRUE(dictionary);
410
411 sdch_manager()->GetVcdiffDictionary(
412 server_hash_2,
413 GURL("http://" + dictionary_domain_2 + "/random_url"),
414 &dictionary);
415 EXPECT_FALSE(dictionary);
416
417 second_manager.GetVcdiffDictionary(
418 server_hash_1,
419 GURL("http://" + dictionary_domain_1 + "/random_url"),
420 &dictionary);
421 EXPECT_FALSE(dictionary);
371 } 422 }
372 423
373 } // namespace net 424 } // namespace net
374 425
OLDNEW
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/filter/filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698