OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/privacy_blacklist/blacklist_io.h" | 5 #include "chrome/browser/privacy_blacklist/blacklist_io.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 TEST(BlacklistIOTest, Generic) { | 14 TEST(BlacklistIOTest, Generic) { |
15 // Testing data path. | 15 // Testing data path. |
16 FilePath data_dir; | 16 FilePath data_dir; |
17 PathService::Get(chrome::DIR_TEST_DATA, &data_dir); | 17 PathService::Get(chrome::DIR_TEST_DATA, &data_dir); |
18 | 18 |
19 FilePath input = | 19 FilePath input = data_dir.AppendASCII("blacklist_small.pbl"); |
20 data_dir.Append(FilePath::FromWStringHack(L"blacklist_small.pbl")); | |
21 | 20 |
22 FilePath expected = | 21 FilePath expected = data_dir.AppendASCII("blacklist_small.pbr"); |
23 data_dir.Append(FilePath::FromWStringHack(L"blacklist_small.pbr")); | |
24 | 22 |
25 BlacklistIO io; | 23 BlacklistIO io; |
26 EXPECT_TRUE(io.Read(input)); | 24 EXPECT_TRUE(io.Read(input)); |
27 const std::list<Blacklist::Entry*>& blacklist = io.blacklist(); | 25 const std::list<Blacklist::Entry*>& blacklist = io.blacklist(); |
28 EXPECT_EQ(5U, blacklist.size()); | 26 EXPECT_EQ(5U, blacklist.size()); |
29 | 27 |
30 std::list<Blacklist::Entry*>::const_iterator i = blacklist.begin(); | 28 std::list<Blacklist::Entry*>::const_iterator i = blacklist.begin(); |
31 EXPECT_EQ("@", (*i++)->pattern()); | 29 EXPECT_EQ("@", (*i++)->pattern()); |
32 EXPECT_EQ("@poor-security-site.com", (*i++)->pattern()); | 30 EXPECT_EQ("@poor-security-site.com", (*i++)->pattern()); |
33 EXPECT_EQ("@.ad-serving-place.com", (*i++)->pattern()); | 31 EXPECT_EQ("@.ad-serving-place.com", (*i++)->pattern()); |
34 EXPECT_EQ("www.site.com/anonymous/folder/@", (*i++)->pattern()); | 32 EXPECT_EQ("www.site.com/anonymous/folder/@", (*i++)->pattern()); |
35 EXPECT_EQ("www.site.com/bad/url", (*i++)->pattern()); | 33 EXPECT_EQ("www.site.com/bad/url", (*i++)->pattern()); |
36 | 34 |
37 EXPECT_EQ(1U, io.providers().size()); | 35 EXPECT_EQ(1U, io.providers().size()); |
38 EXPECT_EQ("Sample", io.providers().front()->name()); | 36 EXPECT_EQ("Sample", io.providers().front()->name()); |
39 EXPECT_EQ("http://www.google.com", io.providers().front()->url()); | 37 EXPECT_EQ("http://www.google.com", io.providers().front()->url()); |
40 | 38 |
41 FilePath output; | 39 FilePath output; |
42 PathService::Get(base::DIR_TEMP, &output); | 40 PathService::Get(base::DIR_TEMP, &output); |
43 output = output.Append(FilePath::FromWStringHack(L"blacklist_small.pbr")); | 41 output = output.AppendASCII("blacklist_small.pbr"); |
44 CHECK(io.Write(output)); | 42 CHECK(io.Write(output)); |
45 EXPECT_TRUE(file_util::ContentsEqual(output, expected)); | 43 EXPECT_TRUE(file_util::ContentsEqual(output, expected)); |
46 EXPECT_TRUE(file_util::Delete(output, false)); | 44 EXPECT_TRUE(file_util::Delete(output, false)); |
47 } | 45 } |
48 | 46 |
49 TEST(BlacklistIOTest, Combine) { | 47 TEST(BlacklistIOTest, Combine) { |
50 // Testing data path. | 48 // Testing data path. |
51 FilePath data_dir; | 49 FilePath data_dir; |
52 PathService::Get(chrome::DIR_TEST_DATA, &data_dir); | 50 PathService::Get(chrome::DIR_TEST_DATA, &data_dir); |
53 data_dir = data_dir.Append(FilePath::FromWStringHack(L"blacklist_samples")); | 51 data_dir = data_dir.AppendASCII("blacklist_samples"); |
54 | 52 |
55 FilePath input1 = | 53 FilePath input1 = data_dir.AppendASCII("annoying_ads.pbl"); |
56 data_dir.Append(FilePath::FromWStringHack(L"annoying_ads.pbl")); | |
57 | 54 |
58 FilePath input2 = | 55 FilePath input2 = data_dir.AppendASCII("block_flash.pbl"); |
59 data_dir.Append(FilePath::FromWStringHack(L"block_flash.pbl")); | |
60 | 56 |
61 FilePath input3 = | 57 FilePath input3 = data_dir.AppendASCII("session_cookies.pbl"); |
62 data_dir.Append(FilePath::FromWStringHack(L"session_cookies.pbl")); | |
63 | 58 |
64 BlacklistIO io; | 59 BlacklistIO io; |
65 EXPECT_TRUE(io.Read(input1)); | 60 EXPECT_TRUE(io.Read(input1)); |
66 EXPECT_TRUE(io.Read(input2)); | 61 EXPECT_TRUE(io.Read(input2)); |
67 EXPECT_TRUE(io.Read(input3)); | 62 EXPECT_TRUE(io.Read(input3)); |
68 | 63 |
69 const std::list<Blacklist::Entry*>& blacklist = io.blacklist(); | 64 const std::list<Blacklist::Entry*>& blacklist = io.blacklist(); |
70 EXPECT_EQ(5U, blacklist.size()); | 65 EXPECT_EQ(5U, blacklist.size()); |
71 | 66 |
72 std::list<Blacklist::Entry*>::const_iterator i = blacklist.begin(); | 67 std::list<Blacklist::Entry*>::const_iterator i = blacklist.begin(); |
(...skipping 14 matching lines...) Expand all Loading... |
87 std::list<Blacklist::Provider*>::const_iterator j = providers.begin(); | 82 std::list<Blacklist::Provider*>::const_iterator j = providers.begin(); |
88 EXPECT_EQ("AnnoyingAds", (*j)->name()); | 83 EXPECT_EQ("AnnoyingAds", (*j)->name()); |
89 EXPECT_EQ("http://www.ads.tv", (*j++)->url()); | 84 EXPECT_EQ("http://www.ads.tv", (*j++)->url()); |
90 EXPECT_EQ("BlockFlash", (*j)->name()); | 85 EXPECT_EQ("BlockFlash", (*j)->name()); |
91 EXPECT_EQ("http://www.google.com", (*j++)->url()); | 86 EXPECT_EQ("http://www.google.com", (*j++)->url()); |
92 EXPECT_EQ("SessionCookies", (*j)->name()); | 87 EXPECT_EQ("SessionCookies", (*j)->name()); |
93 EXPECT_EQ("http://www.google.com", (*j++)->url()); | 88 EXPECT_EQ("http://www.google.com", (*j++)->url()); |
94 | 89 |
95 FilePath output; | 90 FilePath output; |
96 PathService::Get(base::DIR_TEMP, &output); | 91 PathService::Get(base::DIR_TEMP, &output); |
97 output = output.Append(FilePath::FromWStringHack(L"combine3.pbr")); | 92 output = output.AppendASCII("combine3.pbr"); |
98 | 93 |
99 FilePath expected = | 94 FilePath expected = data_dir.AppendASCII("combine3.pbr"); |
100 data_dir.Append(FilePath::FromWStringHack(L"combine3.pbr")); | |
101 | 95 |
102 CHECK(io.Write(output)); | 96 CHECK(io.Write(output)); |
103 EXPECT_TRUE(file_util::ContentsEqual(output, expected)); | 97 EXPECT_TRUE(file_util::ContentsEqual(output, expected)); |
104 EXPECT_TRUE(file_util::Delete(output, false)); | 98 EXPECT_TRUE(file_util::Delete(output, false)); |
105 } | 99 } |
OLD | NEW |