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

Side by Side Diff: components/variations/study_filtering_unittest.cc

Issue 2615763002: Revert of Supporting study definitions without default groups and end_date filtering. (Closed)
Patch Set: Created 3 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/variations/study_filtering.h" 5 #include "components/variations/study_filtering.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 220 }
221 } 221 }
222 222
223 TEST(VariationsStudyFilteringTest, CheckStudyStartDate) { 223 TEST(VariationsStudyFilteringTest, CheckStudyStartDate) {
224 const base::Time now = base::Time::Now(); 224 const base::Time now = base::Time::Now();
225 const base::TimeDelta delta = base::TimeDelta::FromHours(1); 225 const base::TimeDelta delta = base::TimeDelta::FromHours(1);
226 const struct { 226 const struct {
227 const base::Time start_date; 227 const base::Time start_date;
228 bool expected_result; 228 bool expected_result;
229 } start_test_cases[] = { 229 } start_test_cases[] = {
230 {now - delta, true}, 230 { now - delta, true },
231 // Note, the proto start_date is truncated to seconds, but the reference 231 { now, true },
232 // date isn't. 232 { now + delta, false },
233 {now, true},
234 {now + delta, false},
235 }; 233 };
236 234
237 Study_Filter filter; 235 Study_Filter filter;
238 236
239 // Start date not set should result in true. 237 // Start date not set should result in true.
240 EXPECT_TRUE(internal::CheckStudyStartDate(filter, now)); 238 EXPECT_TRUE(internal::CheckStudyStartDate(filter, now));
241 239
242 for (size_t i = 0; i < arraysize(start_test_cases); ++i) { 240 for (size_t i = 0; i < arraysize(start_test_cases); ++i) {
243 filter.set_start_date(TimeToProtoTime(start_test_cases[i].start_date)); 241 filter.set_start_date(TimeToProtoTime(start_test_cases[i].start_date));
244 const bool result = internal::CheckStudyStartDate(filter, now); 242 const bool result = internal::CheckStudyStartDate(filter, now);
245 EXPECT_EQ(start_test_cases[i].expected_result, result) 243 EXPECT_EQ(start_test_cases[i].expected_result, result)
246 << "Case " << i << " failed!"; 244 << "Case " << i << " failed!";
247 } 245 }
248 } 246 }
249 247
250 TEST(VariationsStudyFilteringTest, CheckStudyEndDate) {
251 const base::Time now = base::Time::Now();
252 const base::TimeDelta delta = base::TimeDelta::FromHours(1);
253 const struct {
254 const base::Time end_date;
255 bool expected_result;
256 } start_test_cases[] = {
257 {now - delta, false}, {now + delta, true},
258 };
259
260 Study_Filter filter;
261
262 // End date not set should result in true.
263 EXPECT_TRUE(internal::CheckStudyEndDate(filter, now));
264
265 for (size_t i = 0; i < arraysize(start_test_cases); ++i) {
266 filter.set_end_date(TimeToProtoTime(start_test_cases[i].end_date));
267 const bool result = internal::CheckStudyEndDate(filter, now);
268 EXPECT_EQ(start_test_cases[i].expected_result, result) << "Case " << i
269 << " failed!";
270 }
271 }
272
273 TEST(VariationsStudyFilteringTest, CheckStudyVersion) { 248 TEST(VariationsStudyFilteringTest, CheckStudyVersion) {
274 const struct { 249 const struct {
275 const char* min_version; 250 const char* min_version;
276 const char* version; 251 const char* version;
277 bool expected_result; 252 bool expected_result;
278 } min_test_cases[] = { 253 } min_test_cases[] = {
279 { "1.2.2", "1.2.3", true }, 254 { "1.2.2", "1.2.3", true },
280 { "1.2.3", "1.2.3", true }, 255 { "1.2.3", "1.2.3", true },
281 { "1.2.4", "1.2.3", false }, 256 { "1.2.4", "1.2.3", false },
282 { "1.3.2", "1.2.3", false }, 257 { "1.3.2", "1.2.3", false },
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 EXPECT_TRUE(processed_study.Init(&study, false)); 566 EXPECT_TRUE(processed_study.Init(&study, false));
592 567
593 // Max version checks. 568 // Max version checks.
594 study.mutable_filter()->set_max_version("2.3.4.*"); 569 study.mutable_filter()->set_max_version("2.3.4.*");
595 EXPECT_TRUE(processed_study.Init(&study, false)); 570 EXPECT_TRUE(processed_study.Init(&study, false));
596 study.mutable_filter()->set_max_version("*.3"); 571 study.mutable_filter()->set_max_version("*.3");
597 EXPECT_FALSE(processed_study.Init(&study, false)); 572 EXPECT_FALSE(processed_study.Init(&study, false));
598 study.mutable_filter()->set_max_version("2.3.4"); 573 study.mutable_filter()->set_max_version("2.3.4");
599 EXPECT_TRUE(processed_study.Init(&study, false)); 574 EXPECT_TRUE(processed_study.Init(&study, false));
600 575
601 // A blank default study is allowed.
602 study.clear_default_experiment_name(); 576 study.clear_default_experiment_name();
603 EXPECT_TRUE(processed_study.Init(&study, false)); 577 EXPECT_FALSE(processed_study.Init(&study, false));
604 578
605 study.set_default_experiment_name("xyz"); 579 study.set_default_experiment_name("xyz");
606 EXPECT_FALSE(processed_study.Init(&study, false)); 580 EXPECT_FALSE(processed_study.Init(&study, false));
607 581
608 study.set_default_experiment_name("def"); 582 study.set_default_experiment_name("def");
609 default_group->clear_name(); 583 default_group->clear_name();
610 EXPECT_FALSE(processed_study.Init(&study, false)); 584 EXPECT_FALSE(processed_study.Init(&study, false));
611 585
612 default_group->set_name("def"); 586 default_group->set_name("def");
613 EXPECT_TRUE(processed_study.Init(&study, false)); 587 EXPECT_TRUE(processed_study.Init(&study, false));
614 Study_Experiment* repeated_group = study.add_experiment(); 588 Study_Experiment* repeated_group = study.add_experiment();
615 repeated_group->set_name("abc"); 589 repeated_group->set_name("abc");
616 repeated_group->set_probability_weight(1); 590 repeated_group->set_probability_weight(1);
617 EXPECT_FALSE(processed_study.Init(&study, false)); 591 EXPECT_FALSE(processed_study.Init(&study, false));
618 } 592 }
619 593
620 } // namespace variations 594 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/study_filtering.cc ('k') | components/variations/variations_seed_processor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698