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

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

Issue 2614443002: Supporting study definitions without default groups and end_date filtering. (Closed)
Patch Set: rkaplow's comments 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 { now, true }, 231 // Note, the proto start_date is truncated to seconds, but the reference
232 { now + delta, false }, 232 // date isn't.
233 {now, true},
234 {now + delta, false},
233 }; 235 };
234 236
235 Study_Filter filter; 237 Study_Filter filter;
236 238
237 // Start date not set should result in true. 239 // Start date not set should result in true.
238 EXPECT_TRUE(internal::CheckStudyStartDate(filter, now)); 240 EXPECT_TRUE(internal::CheckStudyStartDate(filter, now));
239 241
240 for (size_t i = 0; i < arraysize(start_test_cases); ++i) { 242 for (size_t i = 0; i < arraysize(start_test_cases); ++i) {
241 filter.set_start_date(TimeToProtoTime(start_test_cases[i].start_date)); 243 filter.set_start_date(TimeToProtoTime(start_test_cases[i].start_date));
242 const bool result = internal::CheckStudyStartDate(filter, now); 244 const bool result = internal::CheckStudyStartDate(filter, now);
243 EXPECT_EQ(start_test_cases[i].expected_result, result) 245 EXPECT_EQ(start_test_cases[i].expected_result, result)
244 << "Case " << i << " failed!"; 246 << "Case " << i << " failed!";
245 } 247 }
246 } 248 }
247 249
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
248 TEST(VariationsStudyFilteringTest, CheckStudyVersion) { 273 TEST(VariationsStudyFilteringTest, CheckStudyVersion) {
249 const struct { 274 const struct {
250 const char* min_version; 275 const char* min_version;
251 const char* version; 276 const char* version;
252 bool expected_result; 277 bool expected_result;
253 } min_test_cases[] = { 278 } min_test_cases[] = {
254 { "1.2.2", "1.2.3", true }, 279 { "1.2.2", "1.2.3", true },
255 { "1.2.3", "1.2.3", true }, 280 { "1.2.3", "1.2.3", true },
256 { "1.2.4", "1.2.3", false }, 281 { "1.2.4", "1.2.3", false },
257 { "1.3.2", "1.2.3", false }, 282 { "1.3.2", "1.2.3", false },
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 EXPECT_TRUE(processed_study.Init(&study, false)); 591 EXPECT_TRUE(processed_study.Init(&study, false));
567 592
568 // Max version checks. 593 // Max version checks.
569 study.mutable_filter()->set_max_version("2.3.4.*"); 594 study.mutable_filter()->set_max_version("2.3.4.*");
570 EXPECT_TRUE(processed_study.Init(&study, false)); 595 EXPECT_TRUE(processed_study.Init(&study, false));
571 study.mutable_filter()->set_max_version("*.3"); 596 study.mutable_filter()->set_max_version("*.3");
572 EXPECT_FALSE(processed_study.Init(&study, false)); 597 EXPECT_FALSE(processed_study.Init(&study, false));
573 study.mutable_filter()->set_max_version("2.3.4"); 598 study.mutable_filter()->set_max_version("2.3.4");
574 EXPECT_TRUE(processed_study.Init(&study, false)); 599 EXPECT_TRUE(processed_study.Init(&study, false));
575 600
601 // A blank default study is allowed.
576 study.clear_default_experiment_name(); 602 study.clear_default_experiment_name();
577 EXPECT_FALSE(processed_study.Init(&study, false)); 603 EXPECT_TRUE(processed_study.Init(&study, false));
578 604
579 study.set_default_experiment_name("xyz"); 605 study.set_default_experiment_name("xyz");
580 EXPECT_FALSE(processed_study.Init(&study, false)); 606 EXPECT_FALSE(processed_study.Init(&study, false));
581 607
582 study.set_default_experiment_name("def"); 608 study.set_default_experiment_name("def");
583 default_group->clear_name(); 609 default_group->clear_name();
584 EXPECT_FALSE(processed_study.Init(&study, false)); 610 EXPECT_FALSE(processed_study.Init(&study, false));
585 611
586 default_group->set_name("def"); 612 default_group->set_name("def");
587 EXPECT_TRUE(processed_study.Init(&study, false)); 613 EXPECT_TRUE(processed_study.Init(&study, false));
588 Study_Experiment* repeated_group = study.add_experiment(); 614 Study_Experiment* repeated_group = study.add_experiment();
589 repeated_group->set_name("abc"); 615 repeated_group->set_name("abc");
590 repeated_group->set_probability_weight(1); 616 repeated_group->set_probability_weight(1);
591 EXPECT_FALSE(processed_study.Init(&study, false)); 617 EXPECT_FALSE(processed_study.Init(&study, false));
592 } 618 }
593 619
594 } // namespace variations 620 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698