OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/previews/core/previews_black_list.h" | 5 #include "components/previews/core/previews_black_list.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 namespace { | 27 namespace { |
28 | 28 |
29 using PreviewsBlackListTest = testing::Test; | 29 using PreviewsBlackListTest = testing::Test; |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 namespace previews { | 33 namespace previews { |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 void RunLoadCallback(LoadBlackListCallback callback, | 37 void RunLoadCallback( |
38 std::unique_ptr<BlackListItemMap> black_list_item_map) { | 38 LoadBlackListCallback callback, |
39 callback.Run(std::move(black_list_item_map)); | 39 std::unique_ptr<BlackListItemMap> black_list_item_map, |
| 40 std::unique_ptr<PreviewsBlackListItem> general_black_list_item) { |
| 41 callback.Run(std::move(black_list_item_map), |
| 42 std::move(general_black_list_item)); |
40 } | 43 } |
41 | 44 |
42 class TestPreviewsOptOutStore : public PreviewsOptOutStore { | 45 class TestPreviewsOptOutStore : public PreviewsOptOutStore { |
43 public: | 46 public: |
44 TestPreviewsOptOutStore() : clear_blacklist_count_(0) {} | 47 TestPreviewsOptOutStore() : clear_blacklist_count_(0) {} |
45 ~TestPreviewsOptOutStore() override {} | 48 ~TestPreviewsOptOutStore() override {} |
46 | 49 |
47 int clear_blacklist_count() { return clear_blacklist_count_; } | 50 int clear_blacklist_count() { return clear_blacklist_count_; } |
48 | 51 |
49 private: | 52 private: |
50 // PreviewsOptOutStore implementation: | 53 // PreviewsOptOutStore implementation: |
51 void AddPreviewNavigation(bool opt_out, | 54 void AddPreviewNavigation(bool opt_out, |
52 const std::string& host_name, | 55 const std::string& host_name, |
53 PreviewsType type, | 56 PreviewsType type, |
54 base::Time now) override {} | 57 base::Time now) override {} |
55 | 58 |
56 void LoadBlackList(LoadBlackListCallback callback) override { | 59 void LoadBlackList(LoadBlackListCallback callback) override { |
57 std::unique_ptr<BlackListItemMap> black_list_item_map( | 60 std::unique_ptr<BlackListItemMap> black_list_item_map( |
58 new BlackListItemMap()); | 61 new BlackListItemMap()); |
| 62 std::unique_ptr<PreviewsBlackListItem> general_black_list_item = |
| 63 PreviewsBlackList::CreateGeneralBlackListItem(); |
59 base::ThreadTaskRunnerHandle::Get()->PostTask( | 64 base::ThreadTaskRunnerHandle::Get()->PostTask( |
60 FROM_HERE, base::Bind(&RunLoadCallback, callback, | 65 FROM_HERE, base::Bind(&RunLoadCallback, callback, |
61 base::Passed(&black_list_item_map))); | 66 base::Passed(&black_list_item_map), |
| 67 base::Passed(&general_black_list_item))); |
62 } | 68 } |
63 | 69 |
64 void ClearBlackList(base::Time begin_time, base::Time end_time) override { | 70 void ClearBlackList(base::Time begin_time, base::Time end_time) override { |
65 ++clear_blacklist_count_; | 71 ++clear_blacklist_count_; |
66 } | 72 } |
67 | 73 |
68 int clear_blacklist_count_; | 74 int clear_blacklist_count_; |
69 }; | 75 }; |
70 | 76 |
71 } // namespace | 77 } // namespace |
72 | 78 |
73 TEST_F(PreviewsBlackListTest, BlackListNoStore) { | 79 TEST_F(PreviewsBlackListTest, PerHostBlackListNoStore) { |
74 // Tests the black list behavior when a null OptOutSture is passed in. | 80 // Tests the black list behavior when a null OptOutSture is passed in. |
75 const GURL url_a("http://www.url_a.com"); | 81 const GURL url_a("http://www.url_a.com"); |
76 const GURL url_b("http://www.url_b.com"); | 82 const GURL url_b("http://www.url_b.com"); |
77 const size_t history = 4; | 83 const size_t per_host_history = 4; |
78 const int threshold = 2; | 84 const int per_host_threshold = 2; |
| 85 // General blacklisting should have no effect with the following params. |
| 86 const size_t general_history = 1; |
| 87 const int general_threshold = 2; |
79 const int duration_in_days = 365; | 88 const int duration_in_days = 365; |
80 base::FieldTrialList field_trial_list(nullptr); | 89 base::FieldTrialList field_trial_list(nullptr); |
81 std::map<std::string, std::string> params; | 90 std::map<std::string, std::string> params; |
82 params["stored_history_length"] = base::SizeTToString(history); | 91 params["per_host_max_stored_history_length"] = |
83 params["opt_out_threshold"] = base::IntToString(threshold); | 92 base::SizeTToString(per_host_history); |
84 params["black_list_duration_in_days"] = base::IntToString(duration_in_days); | 93 params["general_max_stored_history_length"] = |
| 94 base::SizeTToString(general_history); |
| 95 params["per_host_opt_out_threshold"] = base::IntToString(per_host_threshold); |
| 96 params["general_opt_out_threshold"] = base::IntToString(general_threshold); |
| 97 params["per_host_black_list_duration_in_days"] = |
| 98 base::IntToString(duration_in_days); |
85 ASSERT_TRUE( | 99 ASSERT_TRUE( |
86 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", | 100 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", |
87 params) && | 101 params) && |
88 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); | 102 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); |
89 | 103 |
90 base::SimpleTestClock* test_clock = new base::SimpleTestClock(); | 104 base::SimpleTestClock* test_clock = new base::SimpleTestClock(); |
91 base::Time start = test_clock->Now(); | 105 base::Time start = test_clock->Now(); |
92 test_clock->Advance(base::TimeDelta::FromSeconds(1)); | 106 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
93 | 107 |
94 std::unique_ptr<PreviewsBlackList> black_list( | 108 std::unique_ptr<PreviewsBlackList> black_list( |
(...skipping 23 matching lines...) Expand all Loading... |
118 | 132 |
119 test_clock->Advance(base::TimeDelta::FromSeconds(1)); | 133 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
120 black_list->ClearBlackList(start, test_clock->Now()); | 134 black_list->ClearBlackList(start, test_clock->Now()); |
121 | 135 |
122 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); | 136 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
123 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); | 137 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
124 | 138 |
125 variations::testing::ClearAllVariationParams(); | 139 variations::testing::ClearAllVariationParams(); |
126 } | 140 } |
127 | 141 |
128 TEST_F(PreviewsBlackListTest, BlackListWithStore) { | 142 TEST_F(PreviewsBlackListTest, PerHostBlackListWithStore) { |
129 // Tests the black list behavior when a non-null OptOutSture is passed in. | 143 // Tests the black list behavior when a non-null OptOutSture is passed in. |
130 const GURL url_a1("http://www.url_a.com/a1"); | 144 const GURL url_a1("http://www.url_a.com/a1"); |
131 const GURL url_a2("http://www.url_a.com/a2"); | 145 const GURL url_a2("http://www.url_a.com/a2"); |
132 const GURL url_b("http://www.url_b.com"); | 146 const GURL url_b("http://www.url_b.com"); |
133 const size_t history = 4; | 147 const size_t per_host_history = 4; |
134 const int threshold = 2; | 148 const int per_host_threshold = 2; |
| 149 // General blacklisting should have no effect with the following params. |
| 150 const size_t general_history = 1; |
| 151 const int general_threshold = 2; |
135 const int duration_in_days = 365; | 152 const int duration_in_days = 365; |
136 base::FieldTrialList field_trial_list(nullptr); | 153 base::FieldTrialList field_trial_list(nullptr); |
137 std::map<std::string, std::string> params; | 154 std::map<std::string, std::string> params; |
138 params["stored_history_length"] = base::SizeTToString(history); | 155 params["per_host_max_stored_history_length"] = |
139 params["opt_out_threshold"] = base::IntToString(threshold); | 156 base::SizeTToString(per_host_history); |
140 params["black_list_duration_in_days"] = base::IntToString(duration_in_days); | 157 params["general_max_stored_history_length"] = |
| 158 base::SizeTToString(general_history); |
| 159 params["per_host_opt_out_threshold"] = base::IntToString(per_host_threshold); |
| 160 params["general_opt_out_threshold"] = base::IntToString(general_threshold); |
| 161 params["per_host_black_list_duration_in_days"] = |
| 162 base::IntToString(duration_in_days); |
141 ASSERT_TRUE( | 163 ASSERT_TRUE( |
142 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", | 164 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", |
143 params) && | 165 params) && |
144 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); | 166 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); |
145 | 167 |
146 base::MessageLoop loop; | 168 base::MessageLoop loop; |
147 | 169 |
148 base::SimpleTestClock* test_clock = new base::SimpleTestClock(); | 170 base::SimpleTestClock* test_clock = new base::SimpleTestClock(); |
149 base::Time start = test_clock->Now(); | 171 base::Time start = test_clock->Now(); |
150 test_clock->Advance(base::TimeDelta::FromSeconds(1)); | 172 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 base::RunLoop().RunUntilIdle(); | 220 base::RunLoop().RunUntilIdle(); |
199 EXPECT_EQ(1, opt_out_store->clear_blacklist_count()); | 221 EXPECT_EQ(1, opt_out_store->clear_blacklist_count()); |
200 | 222 |
201 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); | 223 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); |
202 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); | 224 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); |
203 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); | 225 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
204 | 226 |
205 variations::testing::ClearAllVariationParams(); | 227 variations::testing::ClearAllVariationParams(); |
206 } | 228 } |
207 | 229 |
| 230 TEST_F(PreviewsBlackListTest, GeneralBlackListNoStore) { |
| 231 // Tests the black list behavior when a null OptOutSture is passed in. |
| 232 const GURL url_a("http://www.url_a.com"); |
| 233 const GURL url_b("http://www.url_b.com"); |
| 234 const GURL url_c("http://www.url_c.com"); |
| 235 const GURL url_d("http://www.url_d.com"); |
| 236 // Per host blacklisting should have no effect with the following params. |
| 237 const size_t per_host_history = 1; |
| 238 const int per_host_threshold = 2; |
| 239 const size_t general_history = 4; |
| 240 const int general_threshold = 4; |
| 241 const int duration_in_days = 365; |
| 242 base::FieldTrialList field_trial_list(nullptr); |
| 243 std::map<std::string, std::string> params; |
| 244 params["per_host_max_stored_history_length"] = |
| 245 base::SizeTToString(per_host_history); |
| 246 params["general_max_stored_history_length"] = |
| 247 base::SizeTToString(general_history); |
| 248 params["per_host_opt_out_threshold"] = base::IntToString(per_host_threshold); |
| 249 params["general_opt_out_threshold"] = base::IntToString(general_threshold); |
| 250 params["per_host_black_list_duration_in_days"] = |
| 251 base::IntToString(duration_in_days); |
| 252 ASSERT_TRUE( |
| 253 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", |
| 254 params) && |
| 255 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); |
| 256 |
| 257 base::SimpleTestClock* test_clock = new base::SimpleTestClock(); |
| 258 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 259 |
| 260 std::unique_ptr<PreviewsBlackList> black_list( |
| 261 new PreviewsBlackList(nullptr, base::WrapUnique(test_clock))); |
| 262 |
| 263 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 264 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| 265 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| 266 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| 267 |
| 268 black_list->AddPreviewNavigation(url_a, true, PreviewsType::OFFLINE); |
| 269 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 270 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 271 |
| 272 black_list->AddPreviewNavigation(url_b, true, PreviewsType::OFFLINE); |
| 273 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 274 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 275 |
| 276 black_list->AddPreviewNavigation(url_c, true, PreviewsType::OFFLINE); |
| 277 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 278 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 279 |
| 280 black_list->AddPreviewNavigation(url_d, true, PreviewsType::OFFLINE); |
| 281 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 282 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 283 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| 284 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| 285 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| 286 |
| 287 black_list->AddPreviewNavigation(url_d, false, PreviewsType::OFFLINE); |
| 288 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 289 |
| 290 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 291 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| 292 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| 293 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| 294 |
| 295 variations::testing::ClearAllVariationParams(); |
| 296 } |
| 297 |
| 298 TEST_F(PreviewsBlackListTest, GeneralBlackListWithStore) { |
| 299 // Tests the black list behavior when a non-null OptOutSture is passed in. |
| 300 const GURL url_a("http://www.url_a.com"); |
| 301 const GURL url_b("http://www.url_b.com"); |
| 302 const GURL url_c("http://www.url_c.com"); |
| 303 const GURL url_d("http://www.url_d.com"); |
| 304 // Per host blacklisting should have no effect with the following params. |
| 305 const size_t per_host_history = 1; |
| 306 const int per_host_threshold = 2; |
| 307 const size_t general_history = 4; |
| 308 const int general_threshold = 4; |
| 309 const int duration_in_days = 365; |
| 310 base::FieldTrialList field_trial_list(nullptr); |
| 311 std::map<std::string, std::string> params; |
| 312 params["per_host_max_stored_history_length"] = |
| 313 base::SizeTToString(per_host_history); |
| 314 params["general_max_stored_history_length"] = |
| 315 base::SizeTToString(general_history); |
| 316 params["per_host_opt_out_threshold"] = base::IntToString(per_host_threshold); |
| 317 params["general_opt_out_threshold"] = base::IntToString(general_threshold); |
| 318 params["per_host_black_list_duration_in_days"] = |
| 319 base::IntToString(duration_in_days); |
| 320 ASSERT_TRUE( |
| 321 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", |
| 322 params) && |
| 323 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); |
| 324 |
| 325 base::MessageLoop loop; |
| 326 |
| 327 base::SimpleTestClock* test_clock = new base::SimpleTestClock(); |
| 328 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 329 |
| 330 TestPreviewsOptOutStore* opt_out_store = new TestPreviewsOptOutStore(); |
| 331 |
| 332 std::unique_ptr<PreviewsBlackList> black_list(new PreviewsBlackList( |
| 333 base::WrapUnique(opt_out_store), base::WrapUnique(test_clock))); |
| 334 |
| 335 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 336 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| 337 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| 338 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| 339 |
| 340 base::RunLoop().RunUntilIdle(); |
| 341 |
| 342 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 343 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| 344 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| 345 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| 346 |
| 347 black_list->AddPreviewNavigation(url_a, true, PreviewsType::OFFLINE); |
| 348 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 349 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 350 |
| 351 black_list->AddPreviewNavigation(url_b, true, PreviewsType::OFFLINE); |
| 352 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 353 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 354 |
| 355 black_list->AddPreviewNavigation(url_c, true, PreviewsType::OFFLINE); |
| 356 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 357 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 358 |
| 359 black_list->AddPreviewNavigation(url_d, true, PreviewsType::OFFLINE); |
| 360 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 361 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 362 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| 363 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| 364 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| 365 |
| 366 black_list->AddPreviewNavigation(url_d, false, PreviewsType::OFFLINE); |
| 367 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 368 |
| 369 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| 370 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| 371 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| 372 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| 373 |
| 374 variations::testing::ClearAllVariationParams(); |
| 375 } |
| 376 |
208 TEST_F(PreviewsBlackListTest, QueueBehavior) { | 377 TEST_F(PreviewsBlackListTest, QueueBehavior) { |
209 // Tests the black list asynchronous queue behavior. Methods called while | 378 // Tests the black list asynchronous queue behavior. Methods called while |
210 // loading are queued and should run in the order they were queued. | 379 // loading are queued and should run in the order they were queued. |
211 const GURL url("http://www.url.com"); | 380 const GURL url("http://www.url.com"); |
212 const GURL url2("http://www.url2.com"); | 381 const GURL url2("http://www.url2.com"); |
| 382 // General blacklisting should have no effect with the following params. |
| 383 const size_t general_history = 1; |
| 384 const int general_threshold = 2; |
213 const int duration_in_days = 365; | 385 const int duration_in_days = 365; |
214 base::FieldTrialList field_trial_list(nullptr); | 386 base::FieldTrialList field_trial_list(nullptr); |
215 std::map<std::string, std::string> params; | 387 std::map<std::string, std::string> params; |
216 params["black_list_duration_in_days"] = base::IntToString(duration_in_days); | 388 params["per_host_black_list_duration_in_days"] = |
| 389 base::IntToString(duration_in_days); |
| 390 params["general_max_stored_history_length"] = |
| 391 base::SizeTToString(general_history); |
| 392 params["general_opt_out_threshold"] = base::IntToString(general_threshold); |
217 ASSERT_TRUE( | 393 ASSERT_TRUE( |
218 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", | 394 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", |
219 params) && | 395 params) && |
220 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); | 396 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); |
221 | 397 |
222 base::MessageLoop loop; | 398 base::MessageLoop loop; |
223 | 399 |
224 std::vector<bool> test_opt_out{true, false}; | 400 std::vector<bool> test_opt_out{true, false}; |
225 | 401 |
226 for (auto opt_out : test_opt_out) { | 402 for (auto opt_out : test_opt_out) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // hosts. | 442 // hosts. |
267 const GURL url_a("http://www.url_a.com"); | 443 const GURL url_a("http://www.url_a.com"); |
268 const GURL url_b("http://www.url_b.com"); | 444 const GURL url_b("http://www.url_b.com"); |
269 const GURL url_c("http://www.url_c.com"); | 445 const GURL url_c("http://www.url_c.com"); |
270 const GURL url_d("http://www.url_d.com"); | 446 const GURL url_d("http://www.url_d.com"); |
271 const GURL url_e("http://www.url_e.com"); | 447 const GURL url_e("http://www.url_e.com"); |
272 const size_t stored_history_length = 1; | 448 const size_t stored_history_length = 1; |
273 const int opt_out_threshold = 1; | 449 const int opt_out_threshold = 1; |
274 const int black_list_duration_in_days = 365; | 450 const int black_list_duration_in_days = 365; |
275 const size_t max_hosts_in_blacklist = 2; | 451 const size_t max_hosts_in_blacklist = 2; |
| 452 // General blacklisting should have no effect with the following params. |
| 453 const size_t general_history = 1; |
| 454 const int general_threshold = 2; |
276 base::FieldTrialList field_trial_list(nullptr); | 455 base::FieldTrialList field_trial_list(nullptr); |
277 std::map<std::string, std::string> params; | 456 std::map<std::string, std::string> params; |
278 params["stored_history_length"] = base::SizeTToString(stored_history_length); | 457 params["per_host_stored_history_length"] = |
279 params["opt_out_threshold"] = base::IntToString(opt_out_threshold); | 458 base::SizeTToString(stored_history_length); |
280 params["black_list_duration_in_days"] = | 459 params["per_host_opt_out_threshold"] = base::IntToString(opt_out_threshold); |
| 460 params["per_host_black_list_duration_in_days"] = |
281 base::IntToString(black_list_duration_in_days); | 461 base::IntToString(black_list_duration_in_days); |
282 params["max_hosts_in_blacklist"] = | 462 params["max_hosts_in_blacklist"] = |
283 base::SizeTToString(max_hosts_in_blacklist); | 463 base::SizeTToString(max_hosts_in_blacklist); |
| 464 params["general_max_stored_history_length"] = |
| 465 base::SizeTToString(general_history); |
| 466 params["general_opt_out_threshold"] = base::IntToString(general_threshold); |
284 ASSERT_TRUE( | 467 ASSERT_TRUE( |
285 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", | 468 variations::AssociateVariationParams("ClientSidePreviews", "Enabled", |
286 params) && | 469 params) && |
287 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); | 470 base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); |
288 | 471 |
289 base::MessageLoop loop; | 472 base::MessageLoop loop; |
290 | 473 |
291 base::SimpleTestClock* test_clock = new base::SimpleTestClock(); | 474 base::SimpleTestClock* test_clock = new base::SimpleTestClock(); |
292 | 475 |
293 std::unique_ptr<PreviewsBlackList> black_list( | 476 std::unique_ptr<PreviewsBlackList> black_list( |
(...skipping 15 matching lines...) Expand all Loading... |
309 black_list->AddPreviewNavigation(url_e, true, PreviewsType::OFFLINE); | 492 black_list->AddPreviewNavigation(url_e, true, PreviewsType::OFFLINE); |
310 // url_d and url_e should remain in the map, but url_a should be evicted. | 493 // url_d and url_e should remain in the map, but url_a should be evicted. |
311 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); | 494 EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
312 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); | 495 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
313 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_e, PreviewsType::OFFLINE)); | 496 EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_e, PreviewsType::OFFLINE)); |
314 | 497 |
315 variations::testing::ClearAllVariationParams(); | 498 variations::testing::ClearAllVariationParams(); |
316 } | 499 } |
317 | 500 |
318 } // namespace previews | 501 } // namespace previews |
OLD | NEW |