| 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_manager.h" | 5 #include "chrome/browser/privacy_blacklist/blacklist_manager.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/thread.h" | 10 #include "base/thread.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 Blacklist::Match* match = blacklist->findMatch(GURL(url)); | 142 Blacklist::Match* match = blacklist->findMatch(GURL(url)); |
| 143 | 143 |
| 144 if (!match) | 144 if (!match) |
| 145 return false; | 145 return false; |
| 146 | 146 |
| 147 delete match; | 147 delete match; |
| 148 return true; | 148 return true; |
| 149 } | 149 } |
| 150 | 150 |
| 151 TEST_F(BlacklistManagerTest, Basic) { | 151 TEST_F(BlacklistManagerTest, Basic) { |
| 152 scoped_refptr<BlacklistManager> manager( | 152 scoped_refptr<BlacklistManager> manager(new BlacklistManager()); |
| 153 new BlacklistManager(&profile_, &path_provider_)); | 153 manager->Initialize(&profile_, &path_provider_); |
| 154 WaitForBlacklistUpdate(); | 154 WaitForBlacklistUpdate(); |
| 155 | 155 |
| 156 const Blacklist* blacklist = manager->GetCompiledBlacklist(); | 156 const Blacklist* blacklist = manager->GetCompiledBlacklist(); |
| 157 EXPECT_TRUE(blacklist); | 157 EXPECT_TRUE(blacklist); |
| 158 | 158 |
| 159 // Repeated invocations of GetCompiledBlacklist should return the same object. | 159 // Repeated invocations of GetCompiledBlacklist should return the same object. |
| 160 EXPECT_EQ(blacklist, manager->GetCompiledBlacklist()); | 160 EXPECT_EQ(blacklist, manager->GetCompiledBlacklist()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(BlacklistManagerTest, BlacklistPathProvider) { | 163 TEST_F(BlacklistManagerTest, BlacklistPathProvider) { |
| 164 scoped_refptr<BlacklistManager> manager( | 164 scoped_refptr<BlacklistManager> manager(new BlacklistManager()); |
| 165 new BlacklistManager(&profile_, &path_provider_)); | 165 manager->Initialize(&profile_, &path_provider_); |
| 166 WaitForBlacklistUpdate(); | 166 WaitForBlacklistUpdate(); |
| 167 | 167 |
| 168 const Blacklist* blacklist1 = manager->GetCompiledBlacklist(); | 168 const Blacklist* blacklist1 = manager->GetCompiledBlacklist(); |
| 169 EXPECT_FALSE(BlacklistHasMatch(blacklist1, | 169 EXPECT_FALSE(BlacklistHasMatch(blacklist1, |
| 170 "http://host/annoying_ads/ad.jpg")); | 170 "http://host/annoying_ads/ad.jpg")); |
| 171 | 171 |
| 172 path_provider_.AddPersistentPath( | 172 path_provider_.AddPersistentPath( |
| 173 test_data_dir_.AppendASCII("annoying_ads.pbl")); | 173 test_data_dir_.AppendASCII("annoying_ads.pbl")); |
| 174 WaitForBlacklistUpdate(); | 174 WaitForBlacklistUpdate(); |
| 175 | 175 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 189 // not checking for inequality. | 189 // not checking for inequality. |
| 190 EXPECT_TRUE(BlacklistHasMatch(blacklist3, "http://host/annoying_ads/ad.jpg")); | 190 EXPECT_TRUE(BlacklistHasMatch(blacklist3, "http://host/annoying_ads/ad.jpg")); |
| 191 EXPECT_TRUE(BlacklistHasMatch(blacklist3, "http://host/other_ads/ad.jpg")); | 191 EXPECT_TRUE(BlacklistHasMatch(blacklist3, "http://host/other_ads/ad.jpg")); |
| 192 | 192 |
| 193 // Now make sure that transient blacklists don't survive after re-creating | 193 // Now make sure that transient blacklists don't survive after re-creating |
| 194 // the BlacklistManager. | 194 // the BlacklistManager. |
| 195 manager = NULL; | 195 manager = NULL; |
| 196 path_provider_.clear(); | 196 path_provider_.clear(); |
| 197 path_provider_.AddPersistentPath( | 197 path_provider_.AddPersistentPath( |
| 198 test_data_dir_.AppendASCII("annoying_ads.pbl")); | 198 test_data_dir_.AppendASCII("annoying_ads.pbl")); |
| 199 manager = new BlacklistManager(&profile_, &path_provider_); | 199 manager = new BlacklistManager(); |
| 200 manager->Initialize(&profile_, &path_provider_); |
| 200 WaitForBlacklistUpdate(); | 201 WaitForBlacklistUpdate(); |
| 201 | 202 |
| 202 const Blacklist* blacklist4 = manager->GetCompiledBlacklist(); | 203 const Blacklist* blacklist4 = manager->GetCompiledBlacklist(); |
| 203 | 204 |
| 204 EXPECT_TRUE(BlacklistHasMatch(blacklist4, "http://host/annoying_ads/ad.jpg")); | 205 EXPECT_TRUE(BlacklistHasMatch(blacklist4, "http://host/annoying_ads/ad.jpg")); |
| 205 EXPECT_FALSE(BlacklistHasMatch(blacklist4, "http://host/other_ads/ad.jpg")); | 206 EXPECT_FALSE(BlacklistHasMatch(blacklist4, "http://host/other_ads/ad.jpg")); |
| 206 } | 207 } |
| 207 | 208 |
| 208 TEST_F(BlacklistManagerTest, BlacklistPathReadError) { | 209 TEST_F(BlacklistManagerTest, BlacklistPathReadError) { |
| 209 scoped_refptr<BlacklistManager> manager( | 210 scoped_refptr<BlacklistManager> manager(new BlacklistManager()); |
| 210 new BlacklistManager(&profile_, &path_provider_)); | 211 manager->Initialize(&profile_, &path_provider_); |
| 211 WaitForBlacklistUpdate(); | 212 WaitForBlacklistUpdate(); |
| 212 | 213 |
| 213 FilePath bogus_path(test_data_dir_.AppendASCII("does_not_exist_randomness")); | 214 FilePath bogus_path(test_data_dir_.AppendASCII("does_not_exist_randomness")); |
| 214 ASSERT_FALSE(file_util::PathExists(bogus_path)); | 215 ASSERT_FALSE(file_util::PathExists(bogus_path)); |
| 215 path_provider_.AddPersistentPath(bogus_path); | 216 path_provider_.AddPersistentPath(bogus_path); |
| 216 WaitForBlacklistError(); | 217 WaitForBlacklistError(); |
| 217 | 218 |
| 218 const Blacklist* blacklist = manager->GetCompiledBlacklist(); | 219 const Blacklist* blacklist = manager->GetCompiledBlacklist(); |
| 219 EXPECT_TRUE(blacklist); | 220 EXPECT_TRUE(blacklist); |
| 220 } | 221 } |
| 221 | 222 |
| 222 TEST_F(BlacklistManagerTest, CompiledBlacklistReadError) { | 223 TEST_F(BlacklistManagerTest, CompiledBlacklistReadError) { |
| 223 FilePath compiled_blacklist_path; | 224 FilePath compiled_blacklist_path; |
| 224 | 225 |
| 225 { | 226 { |
| 226 scoped_refptr<BlacklistManager> manager( | 227 scoped_refptr<BlacklistManager> manager(new BlacklistManager()); |
| 227 new BlacklistManager(&profile_, &path_provider_)); | 228 manager->Initialize(&profile_, &path_provider_); |
| 228 WaitForBlacklistUpdate(); | 229 WaitForBlacklistUpdate(); |
| 229 | 230 |
| 230 path_provider_.AddPersistentPath( | 231 path_provider_.AddPersistentPath( |
| 231 test_data_dir_.AppendASCII("annoying_ads.pbl")); | 232 test_data_dir_.AppendASCII("annoying_ads.pbl")); |
| 232 WaitForBlacklistUpdate(); | 233 WaitForBlacklistUpdate(); |
| 233 const Blacklist* blacklist = manager->GetCompiledBlacklist(); | 234 const Blacklist* blacklist = manager->GetCompiledBlacklist(); |
| 234 EXPECT_TRUE(BlacklistHasMatch(blacklist, | 235 EXPECT_TRUE(BlacklistHasMatch(blacklist, |
| 235 "http://host/annoying_ads/ad.jpg")); | 236 "http://host/annoying_ads/ad.jpg")); |
| 236 | 237 |
| 237 compiled_blacklist_path = manager->compiled_blacklist_path(); | 238 compiled_blacklist_path = manager->compiled_blacklist_path(); |
| 238 } | 239 } |
| 239 | 240 |
| 240 ASSERT_TRUE(file_util::PathExists(compiled_blacklist_path)); | 241 ASSERT_TRUE(file_util::PathExists(compiled_blacklist_path)); |
| 241 ASSERT_TRUE(file_util::Delete(compiled_blacklist_path, false)); | 242 ASSERT_TRUE(file_util::Delete(compiled_blacklist_path, false)); |
| 242 | 243 |
| 243 { | 244 { |
| 244 scoped_refptr<BlacklistManager> manager( | 245 scoped_refptr<BlacklistManager> manager(new BlacklistManager()); |
| 245 new BlacklistManager(&profile_, &path_provider_)); | 246 manager->Initialize(&profile_, &path_provider_); |
| 246 WaitForBlacklistUpdate(); | 247 WaitForBlacklistUpdate(); |
| 247 | 248 |
| 248 // The manager should recompile the blacklist. | 249 // The manager should recompile the blacklist. |
| 249 const Blacklist* blacklist = manager->GetCompiledBlacklist(); | 250 const Blacklist* blacklist = manager->GetCompiledBlacklist(); |
| 250 EXPECT_TRUE(BlacklistHasMatch(blacklist, | 251 EXPECT_TRUE(BlacklistHasMatch(blacklist, |
| 251 "http://host/annoying_ads/ad.jpg")); | 252 "http://host/annoying_ads/ad.jpg")); |
| 252 } | 253 } |
| 253 } | 254 } |
| 254 | 255 |
| 255 } // namespace | 256 } // namespace |
| OLD | NEW |