Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / net / base / sdch_manager_unittest.cc
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
3 // found in the LICENSE file.
4
5 #include <limits.h>
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/sdch_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace net {
15
16 //------------------------------------------------------------------------------
17 // Workaround for http://crbug.com/418975; remove when fixed.
18 #if !defined(OS_IOS)
19
20 //------------------------------------------------------------------------------
21 // Provide sample data and compression results with a sample VCDIFF dictionary.
22 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary.
23 static const char kTestVcdiffDictionary[] = "DictionaryFor"
24     "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n";
25
26 //------------------------------------------------------------------------------
27
28 class SdchManagerTest : public testing::Test {
29  protected:
30   SdchManagerTest()
31       : sdch_manager_(new SdchManager),
32         default_support_(false),
33         default_https_support_(false) {
34     default_support_ = sdch_manager_->sdch_enabled();
35     default_https_support_ = sdch_manager_->secure_scheme_supported();
36   }
37
38   SdchManager* sdch_manager() { return sdch_manager_.get(); }
39
40   // Reset globals back to default state.
41   virtual void TearDown() {
42     SdchManager::EnableSdchSupport(default_support_);
43     SdchManager::EnableSecureSchemeSupport(default_https_support_);
44   }
45
46   // Attempt to add a dictionary to the manager and probe for success or
47   // failure.
48   bool AddSdchDictionary(const std::string& dictionary_text,
49                          const GURL& gurl) {
50     std::string list;
51     sdch_manager_->GetAvailDictionaryList(gurl, &list);
52     sdch_manager_->AddSdchDictionary(dictionary_text, gurl);
53     std::string list2;
54     sdch_manager_->GetAvailDictionaryList(gurl, &list2);
55
56     // The list of hashes should change iff the addition succeeds.
57     return (list != list2);
58   }
59
60  private:
61   scoped_ptr<SdchManager> sdch_manager_;
62   bool default_support_;
63   bool default_https_support_;
64 };
65
66 static std::string NewSdchDictionary(const std::string& domain) {
67   std::string dictionary;
68   if (!domain.empty()) {
69     dictionary.append("Domain: ");
70     dictionary.append(domain);
71     dictionary.append("\n");
72   }
73   dictionary.append("\n");
74   dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1);
75   return dictionary;
76 }
77
78 TEST_F(SdchManagerTest, DomainSupported) {
79   GURL google_url("http://www.google.com");
80
81   SdchManager::EnableSdchSupport(false);
82   EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url));
83   SdchManager::EnableSdchSupport(true);
84   EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url));
85 }
86
87 TEST_F(SdchManagerTest, DomainBlacklisting) {
88   GURL test_url("http://www.test.com");
89   GURL google_url("http://www.google.com");
90
91   sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE);
92   EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url));
93   EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url));
94
95   sdch_manager()->BlacklistDomain(google_url, SdchManager::MIN_PROBLEM_CODE);
96   EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url));
97 }
98
99 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) {
100   GURL test_url("http://www.TesT.com");
101   GURL test2_url("http://www.tEst.com");
102
103   EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url));
104   EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url));
105   sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE);
106   EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url));
107 }
108
109 TEST_F(SdchManagerTest, BlacklistingReset) {
110   GURL gurl("http://mytest.DoMain.com");
111   std::string domain(gurl.host());
112
113   sdch_manager()->ClearBlacklistings();
114   EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
115   EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0);
116   EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl));
117 }
118
119 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) {
120   GURL gurl("http://mytest.DoMain.com");
121   std::string domain(gurl.host());
122   sdch_manager()->ClearBlacklistings();
123
124   sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE);
125   EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1);
126   EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1);
127
128   // Check that any domain lookup reduces the blacklist counter.
129   EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl));
130   EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
131   EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl));
132 }
133
134 TEST_F(SdchManagerTest, BlacklistingExponential) {
135   GURL gurl("http://mytest.DoMain.com");
136   std::string domain(gurl.host());
137   sdch_manager()->ClearBlacklistings();
138
139   int exponential = 1;
140   for (int i = 1; i < 100; ++i) {
141     sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE);
142     EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential);
143
144     EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential);
145     EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl));
146     EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1);
147
148     // Simulate a large number of domain checks (which eventually remove the
149     // blacklisting).
150     sdch_manager()->ClearDomainBlacklisting(domain);
151     EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
152     EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl));
153
154     // Predict what exponential backoff will be.
155     exponential = 1 + 2 * exponential;
156     if (exponential < 0)
157       exponential = INT_MAX;  // We don't wrap.
158   }
159 }
160
161 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) {
162   std::string dictionary_domain("x.y.z.google.com");
163   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
164
165   // Perfect match should work.
166   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
167                                 GURL("http://" + dictionary_domain)));
168 }
169
170 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) {
171   std::string dictionary_domain("x.y.z.google.com");
172   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
173
174   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
175                                 GURL("http://" + dictionary_domain)));
176
177   std::string dictionary_list;
178   // HTTP target URL can advertise dictionary.
179   sdch_manager()->GetAvailDictionaryList(
180       GURL("http://" + dictionary_domain + "/test"),
181       &dictionary_list);
182   EXPECT_FALSE(dictionary_list.empty());
183 }
184
185 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) {
186   std::string dictionary_domain("x.y.z.google.com");
187   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
188
189   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
190                                 GURL("http://" + dictionary_domain)));
191
192   std::string dictionary_list;
193   // HTTPS target URL should NOT advertise dictionary.
194   sdch_manager()->GetAvailDictionaryList(
195       GURL("https://" + dictionary_domain + "/test"),
196       &dictionary_list);
197   EXPECT_TRUE(dictionary_list.empty());
198 }
199
200 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) {
201   std::string dictionary_domain("x.y.z.google.com");
202   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
203
204   SdchManager::EnableSecureSchemeSupport(false);
205   EXPECT_FALSE(AddSdchDictionary(dictionary_text,
206                                  GURL("https://" + dictionary_domain)));
207   SdchManager::EnableSecureSchemeSupport(true);
208   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
209                                 GURL("https://" + dictionary_domain)));
210
211   GURL target_url("https://" + dictionary_domain + "/test");
212   std::string dictionary_list;
213   // HTTPS target URL should advertise dictionary if secure scheme support is
214   // enabled.
215   sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
216   EXPECT_FALSE(dictionary_list.empty());
217
218   // Dictionary should be available.
219   scoped_refptr<SdchManager::Dictionary> dictionary;
220   std::string client_hash;
221   std::string server_hash;
222   sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
223   sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
224   EXPECT_TRUE(dictionary.get() != NULL);
225 }
226
227 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) {
228   std::string dictionary_domain("x.y.z.google.com");
229   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
230
231   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
232                                 GURL("http://" + dictionary_domain)));
233
234   GURL target_url("https://" + dictionary_domain + "/test");
235   std::string dictionary_list;
236   // HTTPS target URL should not advertise dictionary acquired over HTTP even if
237   // secure scheme support is enabled.
238   SdchManager::EnableSecureSchemeSupport(true);
239   sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
240   EXPECT_TRUE(dictionary_list.empty());
241
242   scoped_refptr<SdchManager::Dictionary> dictionary;
243   std::string client_hash;
244   std::string server_hash;
245   sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
246   sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
247   EXPECT_TRUE(dictionary.get() == NULL);
248 }
249
250 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) {
251   std::string dictionary_domain("x.y.z.google.com");
252   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
253
254   SdchManager::EnableSecureSchemeSupport(true);
255   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
256                                 GURL("https://" + dictionary_domain)));
257
258   GURL target_url("http://" + dictionary_domain + "/test");
259   std::string dictionary_list;
260   // HTTP target URL should not advertise dictionary acquired over HTTPS even if
261   // secure scheme support is enabled.
262   sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
263   EXPECT_TRUE(dictionary_list.empty());
264
265   scoped_refptr<SdchManager::Dictionary> dictionary;
266   std::string client_hash;
267   std::string server_hash;
268   sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
269   sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
270   EXPECT_TRUE(dictionary.get() == NULL);
271 }
272
273 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) {
274   std::string dictionary_domain("x.y.z.google.com");
275   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
276
277   // Fail the "domain match" requirement.
278   EXPECT_FALSE(AddSdchDictionary(dictionary_text,
279                                  GURL("http://y.z.google.com")));
280 }
281
282 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) {
283   std::string dictionary_domain("x.y.z.google.com");
284   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
285
286   // Fail the HD with D being the domain and H having a dot requirement.
287   EXPECT_FALSE(AddSdchDictionary(dictionary_text,
288                                  GURL("http://w.x.y.z.google.com")));
289 }
290
291 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionaryTrailingDot) {
292   std::string dictionary_domain("x.y.z.google.com");
293   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
294
295   // Fail the HD with D being the domain and H having a dot requirement.
296   EXPECT_FALSE(AddSdchDictionary(dictionary_text,
297                                  GURL("http://w.x.y.z.google.com.")));
298 }
299
300 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) {
301   // Make sure that a prefix that matches the domain postfix won't confuse
302   // the validation checks.
303   std::string dictionary_domain("www.google.com");
304   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
305
306   // Fail the HD with D being the domain and H having a dot requirement.
307   EXPECT_FALSE(AddSdchDictionary(dictionary_text,
308                                  GURL("http://www.google.com.www.google.com")));
309 }
310
311 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) {
312   // Make sure that a prefix that matches the domain postfix won't confuse
313   // the validation checks.
314   std::string dictionary_domain(".google.com");
315   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
316
317   // Verify that a leading dot in the domain is acceptable, as long as the host
318   // name does not contain any dots preceding the matched domain name.
319   EXPECT_TRUE(AddSdchDictionary(dictionary_text, GURL("http://www.google.com")));
320 }
321
322 TEST_F(SdchManagerTest,
323        CanSetLeadingDotDomainDictionaryFromURLWithTrailingDot) {
324   // Make sure that a prefix that matches the domain postfix won't confuse
325   // the validation checks.
326   std::string dictionary_domain(".google.com");
327   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
328
329   // Verify that a leading dot in the domain is acceptable, as long as the host
330   // name does not contain any dots preceding the matched domain name.
331   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
332                                 GURL("http://www.google.com.")));
333 }
334
335 TEST_F(SdchManagerTest, CannotSetLeadingDotDomainDictionary) {
336   // Make sure that a prefix that matches the domain postfix won't confuse
337   // the validation checks.
338   std::string dictionary_domain(".google.com");
339   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
340
341   // Verify that a leading dot in the domain does not affect the name containing
342   // dots failure.
343   EXPECT_FALSE(AddSdchDictionary(dictionary_text,
344                                  GURL("http://www.subdomain.google.com")));
345 }
346
347 TEST_F(SdchManagerTest, CannotSetLeadingDotDomainDictionaryTrailingDot) {
348   // Make sure that a prefix that matches the domain postfix won't confuse
349   // the validation checks.
350   std::string dictionary_domain(".google.com");
351   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
352
353   // Verify that a trailing period in the URL doesn't affect the check.
354   EXPECT_FALSE(AddSdchDictionary(dictionary_text,
355                                  GURL("http://www.subdomain.google.com.")));
356 }
357
358 // Make sure the order of the tests is not helping us or confusing things.
359 // See test CanSetExactMatchDictionary above for first try.
360 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) {
361   std::string dictionary_domain("x.y.z.google.com");
362   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
363
364   // Perfect match should *STILL* work.
365   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
366                                 GURL("http://" + dictionary_domain)));
367 }
368
369 // Make sure the DOS protection precludes the addition of too many dictionaries.
370 TEST_F(SdchManagerTest, TooManyDictionaries) {
371   std::string dictionary_domain(".google.com");
372   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
373
374   for (size_t count = 0; count < SdchManager::kMaxDictionaryCount; ++count) {
375     EXPECT_TRUE(AddSdchDictionary(dictionary_text,
376                                   GURL("http://www.google.com")));
377     dictionary_text += " ";  // Create dictionary with different SHA signature.
378   }
379   EXPECT_FALSE(
380       AddSdchDictionary(dictionary_text, GURL("http://www.google.com")));
381 }
382
383 TEST_F(SdchManagerTest, DictionaryNotTooLarge) {
384   std::string dictionary_domain(".google.com");
385   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
386
387   dictionary_text.append(
388       SdchManager::kMaxDictionarySize  - dictionary_text.size(), ' ');
389   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
390                                 GURL("http://" + dictionary_domain)));
391 }
392
393 TEST_F(SdchManagerTest, DictionaryTooLarge) {
394   std::string dictionary_domain(".google.com");
395   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
396
397   dictionary_text.append(
398       SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' ');
399   EXPECT_FALSE(AddSdchDictionary(dictionary_text,
400                                  GURL("http://" + dictionary_domain)));
401 }
402
403 TEST_F(SdchManagerTest, PathMatch) {
404   bool (*PathMatch)(const std::string& path, const std::string& restriction) =
405       SdchManager::Dictionary::PathMatch;
406   // Perfect match is supported.
407   EXPECT_TRUE(PathMatch("/search", "/search"));
408   EXPECT_TRUE(PathMatch("/search/", "/search/"));
409
410   // Prefix only works if last character of restriction is a slash, or first
411   // character in path after a match is a slash.  Validate each case separately.
412
413   // Rely on the slash in the path (not at the end of the restriction).
414   EXPECT_TRUE(PathMatch("/search/something", "/search"));
415   EXPECT_TRUE(PathMatch("/search/s", "/search"));
416   EXPECT_TRUE(PathMatch("/search/other", "/search"));
417   EXPECT_TRUE(PathMatch("/search/something", "/search"));
418
419   // Rely on the slash at the end of the restriction.
420   EXPECT_TRUE(PathMatch("/search/something", "/search/"));
421   EXPECT_TRUE(PathMatch("/search/s", "/search/"));
422   EXPECT_TRUE(PathMatch("/search/other", "/search/"));
423   EXPECT_TRUE(PathMatch("/search/something", "/search/"));
424
425   // Make sure less that sufficient prefix match is false.
426   EXPECT_FALSE(PathMatch("/sear", "/search"));
427   EXPECT_FALSE(PathMatch("/", "/search"));
428   EXPECT_FALSE(PathMatch(std::string(), "/search"));
429
430   // Add examples with several levels of direcories in the restriction.
431   EXPECT_FALSE(PathMatch("/search/something", "search/s"));
432   EXPECT_FALSE(PathMatch("/search/", "/search/s"));
433
434   // Make sure adding characters to path will also fail.
435   EXPECT_FALSE(PathMatch("/searching", "/search/"));
436   EXPECT_FALSE(PathMatch("/searching", "/search"));
437
438   // Make sure we're case sensitive.
439   EXPECT_FALSE(PathMatch("/ABC", "/abc"));
440   EXPECT_FALSE(PathMatch("/abc", "/ABC"));
441 }
442
443 // The following are only applicable while we have a latency test in the code,
444 // and can be removed when that functionality is stripped.
445 TEST_F(SdchManagerTest, LatencyTestControls) {
446   GURL url("http://www.google.com");
447   GURL url2("http://www.google2.com");
448
449   // First make sure we default to false.
450   EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url));
451   EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url2));
452
453   // That we can set each to true.
454   sdch_manager()->SetAllowLatencyExperiment(url, true);
455   EXPECT_TRUE(sdch_manager()->AllowLatencyExperiment(url));
456   EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url2));
457
458   sdch_manager()->SetAllowLatencyExperiment(url2, true);
459   EXPECT_TRUE(sdch_manager()->AllowLatencyExperiment(url));
460   EXPECT_TRUE(sdch_manager()->AllowLatencyExperiment(url2));
461
462   // And can reset them to false.
463   sdch_manager()->SetAllowLatencyExperiment(url, false);
464   EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url));
465   EXPECT_TRUE(sdch_manager()->AllowLatencyExperiment(url2));
466
467   sdch_manager()->SetAllowLatencyExperiment(url2, false);
468   EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url));
469   EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url2));
470 }
471
472 TEST_F(SdchManagerTest, CanUseMultipleManagers) {
473   SdchManager second_manager;
474
475   std::string dictionary_domain_1("x.y.z.google.com");
476   std::string dictionary_domain_2("x.y.z.chromium.org");
477
478   std::string dictionary_text_1(NewSdchDictionary(dictionary_domain_1));
479   std::string dictionary_text_2(NewSdchDictionary(dictionary_domain_2));
480
481   std::string tmp_hash;
482   std::string server_hash_1;
483   std::string server_hash_2;
484
485   SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1);
486   SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2);
487
488   // Confirm that if you add directories to one manager, you
489   // can't get them from the other.
490   EXPECT_TRUE(AddSdchDictionary(dictionary_text_1,
491                                 GURL("http://" + dictionary_domain_1)));
492   scoped_refptr<SdchManager::Dictionary> dictionary;
493   sdch_manager()->GetVcdiffDictionary(
494       server_hash_1,
495       GURL("http://" + dictionary_domain_1 + "/random_url"),
496       &dictionary);
497   EXPECT_TRUE(dictionary.get());
498
499   second_manager.AddSdchDictionary(
500       dictionary_text_2, GURL("http://" + dictionary_domain_2));
501   second_manager.GetVcdiffDictionary(
502       server_hash_2,
503       GURL("http://" + dictionary_domain_2 + "/random_url"),
504       &dictionary);
505   EXPECT_TRUE(dictionary.get());
506
507   sdch_manager()->GetVcdiffDictionary(
508       server_hash_2,
509       GURL("http://" + dictionary_domain_2 + "/random_url"),
510       &dictionary);
511   EXPECT_FALSE(dictionary.get());
512
513   second_manager.GetVcdiffDictionary(
514       server_hash_1,
515       GURL("http://" + dictionary_domain_1 + "/random_url"),
516       &dictionary);
517   EXPECT_FALSE(dictionary.get());
518 }
519
520 TEST_F(SdchManagerTest, HttpsCorrectlySupported) {
521   GURL url("http://www.google.com");
522   GURL secure_url("https://www.google.com");
523
524 #if !defined(OS_IOS)
525   // Workaround for http://crbug.com/418975; remove when fixed.
526   bool expect_https_support = true;
527 #else
528   bool expect_https_support = false;
529 #endif
530
531   EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
532   EXPECT_EQ(expect_https_support,
533             sdch_manager()->IsInSupportedDomain(secure_url));
534
535   SdchManager::EnableSecureSchemeSupport(!expect_https_support);
536   EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
537   EXPECT_NE(expect_https_support,
538             sdch_manager()->IsInSupportedDomain(secure_url));
539 }
540
541 TEST_F(SdchManagerTest, ClearDictionaryData) {
542   std::string dictionary_domain("x.y.z.google.com");
543   GURL blacklist_url("http://bad.chromium.org");
544
545   std::string dictionary_text(NewSdchDictionary(dictionary_domain));
546   std::string tmp_hash;
547   std::string server_hash;
548
549   SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash);
550
551   EXPECT_TRUE(AddSdchDictionary(dictionary_text,
552                                 GURL("http://" + dictionary_domain)));
553   scoped_refptr<SdchManager::Dictionary> dictionary;
554   sdch_manager()->GetVcdiffDictionary(
555       server_hash,
556       GURL("http://" + dictionary_domain + "/random_url"),
557       &dictionary);
558   EXPECT_TRUE(dictionary.get());
559
560   sdch_manager()->BlacklistDomain(GURL(blacklist_url),
561                                   SdchManager::MIN_PROBLEM_CODE);
562   EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url));
563
564   sdch_manager()->ClearData();
565
566   dictionary = NULL;
567   sdch_manager()->GetVcdiffDictionary(
568       server_hash,
569       GURL("http://" + dictionary_domain + "/random_url"),
570       &dictionary);
571   EXPECT_FALSE(dictionary.get());
572   EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url));
573 }
574
575 #else
576
577 TEST(SdchManagerTest, SdchOffByDefault) {
578   GURL google_url("http://www.google.com");
579   SdchManager* sdch_manager(new SdchManager);
580
581   EXPECT_FALSE(sdch_manager->IsInSupportedDomain(google_url));
582   SdchManager::EnableSdchSupport(true);
583   EXPECT_TRUE(sdch_manager->IsInSupportedDomain(google_url));
584 }
585
586 #endif  // !defined(OS_IOS)
587
588 }  // namespace net