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

Side by Side Diff: chrome/browser/privacy_blacklist/blacklist_io_unittest.cc

Issue 159199: Load Multiple Blacklists... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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
OLDNEW
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 std::wstring 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 std::wstring input(data_dir); 19 FilePath input =
20 file_util::AppendToPath(&input, L"blacklist_small.pbl"); 20 data_dir.Append(FilePath::FromWStringHack(L"blacklist_small.pbl"));
21 21
22 std::wstring expected(data_dir); 22 FilePath expected =
23 file_util::AppendToPath(&expected, L"blacklist_small.pbr"); 23 data_dir.Append(FilePath::FromWStringHack(L"blacklist_small.pbr"));
24 24
25 BlacklistIO io; 25 BlacklistIO io;
26 EXPECT_TRUE(io.Read(FilePath::FromWStringHack(input))); 26 EXPECT_TRUE(io.Read(input));
27 const std::list<Blacklist::Entry*>& blacklist = io.blacklist(); 27 const std::list<Blacklist::Entry*>& blacklist = io.blacklist();
28 EXPECT_EQ(5U, blacklist.size()); 28 EXPECT_EQ(5U, blacklist.size());
29 29
30 std::list<Blacklist::Entry*>::const_iterator i = blacklist.begin(); 30 std::list<Blacklist::Entry*>::const_iterator i = blacklist.begin();
31 EXPECT_EQ("@", (*i++)->pattern()); 31 EXPECT_EQ("@", (*i++)->pattern());
32 EXPECT_EQ("@poor-security-site.com", (*i++)->pattern()); 32 EXPECT_EQ("@poor-security-site.com", (*i++)->pattern());
33 EXPECT_EQ("@.ad-serving-place.com", (*i++)->pattern()); 33 EXPECT_EQ("@.ad-serving-place.com", (*i++)->pattern());
34 EXPECT_EQ("www.site.com/anonymous/folder/@", (*i++)->pattern()); 34 EXPECT_EQ("www.site.com/anonymous/folder/@", (*i++)->pattern());
35 EXPECT_EQ("www.site.com/bad/url", (*i++)->pattern()); 35 EXPECT_EQ("www.site.com/bad/url", (*i++)->pattern());
36 36
37 EXPECT_EQ(1U, io.providers().size()); 37 EXPECT_EQ(1U, io.providers().size());
38 EXPECT_EQ("Sample", io.providers().front()->name()); 38 EXPECT_EQ("Sample", io.providers().front()->name());
39 EXPECT_EQ("http://www.google.com", io.providers().front()->url()); 39 EXPECT_EQ("http://www.google.com", io.providers().front()->url());
40 40
41 std::wstring output; 41 FilePath output;
42 PathService::Get(base::DIR_TEMP, &output); 42 PathService::Get(base::DIR_TEMP, &output);
43 file_util::AppendToPath(&output, L"blacklist_small.pbr"); 43 output = output.Append(FilePath::FromWStringHack(L"blacklist_small.pbr"));
44 CHECK(io.Write(FilePath::FromWStringHack(output))); 44 CHECK(io.Write(output));
45 EXPECT_TRUE(file_util::ContentsEqual(output, expected)); 45 EXPECT_TRUE(file_util::ContentsEqual(output, expected));
46 EXPECT_TRUE(file_util::Delete(output, false)); 46 EXPECT_TRUE(file_util::Delete(output, false));
47 } 47 }
48
49 TEST(BlacklistIOTest, Combine) {
50 // Testing data path.
51 FilePath data_dir;
52 PathService::Get(chrome::DIR_TEST_DATA, &data_dir);
53 data_dir = data_dir.Append(FilePath::FromWStringHack(L"blacklist_samples"));
54
55 FilePath input1 =
56 data_dir.Append(FilePath::FromWStringHack(L"annoying_ads.pbl"));
57
58 FilePath input2 =
59 data_dir.Append(FilePath::FromWStringHack(L"block_flash.pbl"));
60
61 FilePath input3 =
62 data_dir.Append(FilePath::FromWStringHack(L"session_cookies.pbl"));
63
64 BlacklistIO io;
65 EXPECT_TRUE(io.Read(input1));
66 EXPECT_TRUE(io.Read(input2));
67 EXPECT_TRUE(io.Read(input3));
68
69 const std::list<Blacklist::Entry*>& blacklist = io.blacklist();
70 EXPECT_EQ(5U, blacklist.size());
71
72 std::list<Blacklist::Entry*>::const_iterator i = blacklist.begin();
73 EXPECT_EQ(Blacklist::kBlockAll, (*i)->attributes());
74 EXPECT_EQ("annoying.ads.tv/@", (*i++)->pattern());
75 EXPECT_EQ(Blacklist::kBlockAll, (*i)->attributes());
76 EXPECT_EQ("@/annoying/120x600.jpg", (*i++)->pattern());
77 EXPECT_EQ(Blacklist::kBlockAll, (*i)->attributes());
78 EXPECT_EQ("@/annoying_ads/@", (*i++)->pattern());
79 EXPECT_EQ(Blacklist::kBlockByType, (*i)->attributes());
80 EXPECT_EQ("@", (*i++)->pattern());
81 EXPECT_EQ(Blacklist::kDontPersistCookies, (*i)->attributes());
82 EXPECT_EQ("@", (*i++)->pattern());
83
84 const std::list<Blacklist::Provider*>& providers = io.providers();
85 EXPECT_EQ(3U, providers.size());
86
87 std::list<Blacklist::Provider*>::const_iterator j = providers.begin();
88 EXPECT_EQ("AnnoyingAds", (*j)->name());
89 EXPECT_EQ("http://www.ads.tv", (*j++)->url());
90 EXPECT_EQ("BlockFlash", (*j)->name());
91 EXPECT_EQ("http://www.google.com", (*j++)->url());
92 EXPECT_EQ("SessionCookies", (*j)->name());
93 EXPECT_EQ("http://www.google.com", (*j++)->url());
94
95 FilePath output;
96 PathService::Get(base::DIR_TEMP, &output);
97 output = output.Append(FilePath::FromWStringHack(L"combine3.pbr"));
98
99 FilePath expected =
100 data_dir.Append(FilePath::FromWStringHack(L"combine3.pbr"));
101
102 CHECK(io.Write(output));
103 EXPECT_TRUE(file_util::ContentsEqual(output, expected));
104 EXPECT_TRUE(file_util::Delete(output, false));
105 }
OLDNEW
« no previous file with comments | « chrome/browser/privacy_blacklist/blacklist_io.h ('k') | chrome/test/data/blacklist_samples/annoying_ads.pbl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698