| 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/browser/privacy_blacklist/blacklist.h" | 11 #include "chrome/browser/privacy_blacklist/blacklist.h" |
| 12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 TEST(BlacklistIOTest, Generic) { | 15 TEST(BlacklistIOTest, Generic) { |
| 16 // Testing data path. | 16 // Testing data path. |
| 17 FilePath data_dir; | 17 FilePath data_dir; |
| 18 PathService::Get(chrome::DIR_TEST_DATA, &data_dir); | 18 PathService::Get(chrome::DIR_TEST_DATA, &data_dir); |
| 19 | 19 |
| 20 FilePath input = data_dir.AppendASCII("blacklist_small.pbl"); | 20 FilePath input = data_dir.AppendASCII("blacklist_small.pbl"); |
| 21 | 21 |
| 22 FilePath expected = data_dir.AppendASCII("blacklist_small.pbr"); | 22 FilePath expected = data_dir.AppendASCII("blacklist_small.pbr"); |
| 23 | 23 |
| 24 Blacklist blacklist; | 24 Blacklist blacklist; |
| 25 std::string error_string; | 25 std::string error_string; |
| 26 ASSERT_TRUE(BlacklistIO::ReadText(&blacklist, input, &error_string)); | 26 ASSERT_TRUE(BlacklistIO::ReadText(&blacklist, input, &error_string)); |
| 27 EXPECT_TRUE(error_string.empty()); | 27 EXPECT_TRUE(error_string.empty()); |
| 28 | 28 |
| 29 const Blacklist::EntryList entries(blacklist.entries_begin(), | 29 const Blacklist::EntryList entries(blacklist.entries_begin(), |
| 30 blacklist.entries_end()); | 30 blacklist.entries_end()); |
| 31 ASSERT_EQ(5U, entries.size()); | 31 ASSERT_EQ(7U, entries.size()); |
| 32 | 32 |
| 33 EXPECT_EQ("@", entries[0]->pattern()); | 33 EXPECT_EQ("@", entries[0]->pattern()); |
| 34 EXPECT_EQ("@poor-security-site.com", entries[1]->pattern()); | 34 EXPECT_EQ("@poor-security-site.com", entries[1]->pattern()); |
| 35 EXPECT_EQ("@.ad-serving-place.com", entries[2]->pattern()); | 35 EXPECT_EQ("@.ad-serving-place.com", entries[2]->pattern()); |
| 36 EXPECT_EQ("www.site.com/anonymous/folder/@", entries[3]->pattern()); | 36 EXPECT_EQ("www.site.com/anonymous/folder/@", entries[3]->pattern()); |
| 37 EXPECT_EQ("www.site.com/bad/url", entries[4]->pattern()); | 37 EXPECT_EQ("www.site.com/bad/url", entries[4]->pattern()); |
| 38 | 38 EXPECT_EQ("@/script?@", entries[5]->pattern()); |
| 39 EXPECT_EQ("@?badparam@", entries[6]->pattern()); |
| 40 |
| 39 const Blacklist::ProviderList providers(blacklist.providers_begin(), | 41 const Blacklist::ProviderList providers(blacklist.providers_begin(), |
| 40 blacklist.providers_end()); | 42 blacklist.providers_end()); |
| 41 | 43 |
| 42 ASSERT_EQ(1U, providers.size()); | 44 ASSERT_EQ(1U, providers.size()); |
| 43 EXPECT_EQ("Sample", providers[0]->name()); | 45 EXPECT_EQ("Sample", providers[0]->name()); |
| 44 EXPECT_EQ("http://www.google.com", providers[0]->url()); | 46 EXPECT_EQ("http://www.google.com", providers[0]->url()); |
| 45 | 47 |
| 46 FilePath output; | 48 FilePath output; |
| 47 PathService::Get(base::DIR_TEMP, &output); | 49 PathService::Get(base::DIR_TEMP, &output); |
| 48 output = output.AppendASCII("blacklist_small.pbr"); | 50 output = output.AppendASCII("blacklist_small.pbr"); |
| 49 ASSERT_TRUE(BlacklistIO::WriteBinary(&blacklist, output)); | 51 ASSERT_TRUE(BlacklistIO::WriteBinary(&blacklist, output)); |
| 50 EXPECT_TRUE(file_util::ContentsEqual(output, expected)); | 52 EXPECT_TRUE(file_util::ContentsEqual(output, expected)); |
| 51 EXPECT_TRUE(file_util::Delete(output, false)); | 53 EXPECT_TRUE(file_util::Delete(output, false)); |
| 52 } | 54 } |
| 53 | 55 |
| 54 | 56 |
| OLD | NEW |