OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h" |
| 6 #include "chrome/browser/garbled_text_url_tracker.h" |
| 7 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/common/pref_names.h" |
| 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "googleurl/src/gurl.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 class GarbledTextURLTrackerTest : public testing::Test { |
| 14 public: |
| 15 typedef GarbledTextURLTracker::Blacklist Blacklist; |
| 16 typedef GarbledTextURLTracker::GarbledURLs GarbledURLs; |
| 17 GarbledTextURLTrackerTest() {} |
| 18 |
| 19 protected: |
| 20 virtual void SetUp() OVERRIDE { |
| 21 enabled_.Init(prefs::kEnableAutoGarbledTextFix, |
| 22 profile_.GetPrefs(), NULL); |
| 23 } |
| 24 |
| 25 virtual void TearDown() OVERRIDE { |
| 26 } |
| 27 |
| 28 const BooleanPrefMember& enabled() { |
| 29 return enabled_; |
| 30 } |
| 31 |
| 32 void set_enabled(bool enabled) { |
| 33 enabled_.SetValue(enabled); |
| 34 } |
| 35 |
| 36 private: |
| 37 TestingProfile profile_; |
| 38 BooleanPrefMember enabled_; |
| 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(GarbledTextURLTrackerTest); |
| 41 }; |
| 42 |
| 43 TEST_F(GarbledTextURLTrackerTest, QueryAndAddTest) { |
| 44 std::string kBlacklist[] = { |
| 45 "foo.example.com", |
| 46 "bar.example.com", |
| 47 "baz.example.com", |
| 48 }; |
| 49 GarbledTextURLTracker tracker( |
| 50 enabled(), |
| 51 Blacklist(kBlacklist, kBlacklist + arraysize(kBlacklist))); |
| 52 |
| 53 EXPECT_TRUE(tracker.NeedsEncodingDetection( |
| 54 GURL("https://foo.example.com/apple/banana/cherry.csv"))); |
| 55 EXPECT_FALSE(tracker.NeedsEncodingDetection( |
| 56 GURL("ftp://fizz.example.com/cat/dog.png"))); |
| 57 |
| 58 GURL kGarbledURLs[] = { |
| 59 GURL("http://fizz.example.com/hoge/fuga/piyo.html"), |
| 60 GURL("file://buzz.example.com/fuga.txt"), |
| 61 GURL("http://fizz.example.com/piyo.css"), |
| 62 }; |
| 63 Blacklist delta; |
| 64 tracker.UpdateBlacklist( |
| 65 GarbledURLs(kGarbledURLs, kGarbledURLs + arraysize(kGarbledURLs)), |
| 66 &delta); |
| 67 EXPECT_EQ(2u, delta.size()); |
| 68 EXPECT_TRUE(delta.find("fizz.example.com") != delta.end()); |
| 69 EXPECT_TRUE(delta.find("buzz.example.com") != delta.end()); |
| 70 |
| 71 EXPECT_TRUE(tracker.NeedsEncodingDetection( |
| 72 GURL("gopher://fizz.example.com/pakeratta.dat"))); |
| 73 EXPECT_FALSE(tracker.NeedsEncodingDetection( |
| 74 GURL("wss://puyo.example.com/fire/ice.xml"))); |
| 75 } |
| 76 |
| 77 TEST_F(GarbledTextURLTrackerTest, DisablingTest) { |
| 78 std::string kBlacklist[] = { |
| 79 "coffee.example.com", |
| 80 "tea.example.com", |
| 81 }; |
| 82 GarbledTextURLTracker tracker( |
| 83 enabled(), |
| 84 Blacklist(kBlacklist, kBlacklist + arraysize(kBlacklist))); |
| 85 |
| 86 set_enabled(false); |
| 87 EXPECT_FALSE(tracker.NeedsEncodingDetection( |
| 88 GURL("http://coffee.example.com/cup.txt"))); |
| 89 EXPECT_FALSE(tracker.NeedsEncodingDetection( |
| 90 GURL("http://vodka.example.com/barrel.bat"))); |
| 91 |
| 92 GURL kGarbledURLs[] = { |
| 93 GURL("http://tabasco.example.com/stein.tar"), |
| 94 }; |
| 95 Blacklist delta; |
| 96 tracker.UpdateBlacklist( |
| 97 GarbledURLs(kGarbledURLs, kGarbledURLs + arraysize(kGarbledURLs)), |
| 98 &delta); |
| 99 EXPECT_TRUE(delta.empty()); |
| 100 |
| 101 set_enabled(true); |
| 102 EXPECT_TRUE(tracker.NeedsEncodingDetection( |
| 103 GURL("http://coffee.example.com/milk.js"))); |
| 104 EXPECT_FALSE(tracker.NeedsEncodingDetection( |
| 105 GURL("http://tabasco.example.com/"))); |
| 106 } |
OLD | NEW |