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

Side by Side Diff: base/metrics/field_trial_unittest.cc

Issue 11359136: Make it so disabled field trials are not reported as active. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
« base/metrics/field_trial.cc ('K') | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/metrics/field_trial.h" 6 #include "base/metrics/field_trial.h"
7 #include "base/rand_util.h" 7 #include "base/rand_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 FieldTrial* trial3 = FieldTrialList::FactoryGetFieldTrial( 381 FieldTrial* trial3 = FieldTrialList::FactoryGetFieldTrial(
382 "zzz", 10, "default", next_year_, 12, 31, NULL); 382 "zzz", 10, "default", next_year_, 12, 31, NULL);
383 // Finalize the group selection by accessing the selected group. 383 // Finalize the group selection by accessing the selected group.
384 trial3->group(); 384 trial3->group();
385 385
386 FieldTrialList::StatesToString(&save_string); 386 FieldTrialList::StatesToString(&save_string);
387 EXPECT_EQ("Some name/Winner/xxx/yyyy/zzz/default/", save_string); 387 EXPECT_EQ("Some name/Winner/xxx/yyyy/zzz/default/", save_string);
388 } 388 }
389 389
390 TEST_F(FieldTrialTest, Restore) { 390 TEST_F(FieldTrialTest, Restore) {
391 EXPECT_TRUE(FieldTrialList::Find("Some_name") == NULL); 391 ASSERT_FALSE(FieldTrialList::TrialExists("Some_name"));
392 EXPECT_TRUE(FieldTrialList::Find("xxx") == NULL); 392 ASSERT_FALSE(FieldTrialList::TrialExists("xxx"));
Ilya Sherman 2012/11/09 22:45:59 Just curious, why did you change these from EXPECT
Alexei Svitkine (slow) 2012/11/09 23:42:39 It's a precondition, if that line fails, then the
393 393
394 FieldTrialList::CreateTrialsFromString("Some_name/Winner/xxx/yyyy/"); 394 FieldTrialList::CreateTrialsFromString("Some_name/Winner/xxx/yyyy/");
395 395
396 FieldTrial* trial = FieldTrialList::Find("Some_name"); 396 FieldTrial* trial = FieldTrialList::Find("Some_name");
397 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial); 397 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial);
398 EXPECT_EQ("Winner", trial->group_name()); 398 EXPECT_EQ("Winner", trial->group_name());
399 EXPECT_EQ("Some_name", trial->name()); 399 EXPECT_EQ("Some_name", trial->name());
400 400
401 trial = FieldTrialList::Find("xxx"); 401 trial = FieldTrialList::Find("xxx");
402 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial); 402 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial);
(...skipping 21 matching lines...) Expand all
424 EXPECT_EQ("Some name/Winner/", save_string); 424 EXPECT_EQ("Some name/Winner/", save_string);
425 425
426 // It is OK if we redundantly specify a winner. 426 // It is OK if we redundantly specify a winner.
427 EXPECT_TRUE(FieldTrialList::CreateTrialsFromString(save_string)); 427 EXPECT_TRUE(FieldTrialList::CreateTrialsFromString(save_string));
428 428
429 // But it is an error to try to change to a different winner. 429 // But it is an error to try to change to a different winner.
430 EXPECT_FALSE(FieldTrialList::CreateTrialsFromString("Some name/Loser/")); 430 EXPECT_FALSE(FieldTrialList::CreateTrialsFromString("Some name/Loser/"));
431 } 431 }
432 432
433 TEST_F(FieldTrialTest, CreateFieldTrial) { 433 TEST_F(FieldTrialTest, CreateFieldTrial) {
434 EXPECT_TRUE(FieldTrialList::Find("Some_name") == NULL); 434 ASSERT_FALSE(FieldTrialList::TrialExists("Some_name"));
435 435
436 FieldTrialList::CreateFieldTrial("Some_name", "Winner"); 436 FieldTrialList::CreateFieldTrial("Some_name", "Winner");
437 437
438 FieldTrial* trial = FieldTrialList::Find("Some_name"); 438 FieldTrial* trial = FieldTrialList::Find("Some_name");
439 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial); 439 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial);
440 EXPECT_EQ("Winner", trial->group_name()); 440 EXPECT_EQ("Winner", trial->group_name());
441 EXPECT_EQ("Some_name", trial->name()); 441 EXPECT_EQ("Some_name", trial->name());
442 } 442 }
443 443
444 TEST_F(FieldTrialTest, DuplicateFieldTrial) { 444 TEST_F(FieldTrialTest, DuplicateFieldTrial) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 if (chosen_group == default_group) 570 if (chosen_group == default_group)
571 EXPECT_EQ(kDefaultGroupName, observer.group_name()); 571 EXPECT_EQ(kDefaultGroupName, observer.group_name());
572 else 572 else
573 EXPECT_EQ(kSecondaryGroupName, observer.group_name()); 573 EXPECT_EQ(kSecondaryGroupName, observer.group_name());
574 } 574 }
575 575
576 TEST_F(FieldTrialTest, ObserveDisabled) { 576 TEST_F(FieldTrialTest, ObserveDisabled) {
577 const char kTrialName[] = "TrialToObserve2"; 577 const char kTrialName[] = "TrialToObserve2";
578 578
579 TestFieldTrialObserver observer; 579 TestFieldTrialObserver observer;
580 int default_group = -1;
580 FieldTrial* trial = 581 FieldTrial* trial =
581 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName, 582 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
582 next_year_, 12, 31, NULL); 583 next_year_, 12, 31, &default_group);
583 trial->AppendGroup("A", 25); 584 trial->AppendGroup("A", 25);
584 trial->AppendGroup("B", 25); 585 trial->AppendGroup("B", 25);
585 trial->AppendGroup("C", 25); 586 trial->AppendGroup("C", 25);
586 trial->Disable(); 587 trial->Disable();
587 588
588 // Observer shouldn't be notified until group() is called. 589 // Observer shouldn't be notified of a disabled trial.
589 message_loop_.RunAllPending(); 590 message_loop_.RunAllPending();
590 EXPECT_TRUE(observer.trial_name().empty()); 591 EXPECT_TRUE(observer.trial_name().empty());
591 EXPECT_TRUE(observer.group_name().empty()); 592 EXPECT_TRUE(observer.group_name().empty());
592 593
593 trial->group(); 594 // Observer shouldn't be notified even after a |group()| call.
595 EXPECT_EQ(default_group, trial->group());
594 message_loop_.RunAllPending(); 596 message_loop_.RunAllPending();
595 EXPECT_EQ(kTrialName, observer.trial_name()); 597 EXPECT_TRUE(observer.trial_name().empty());
596 EXPECT_EQ(kDefaultGroupName, observer.group_name()); 598 EXPECT_TRUE(observer.group_name().empty());
597 } 599 }
598 600
599 TEST_F(FieldTrialTest, ObserveForcedDisabled) { 601 TEST_F(FieldTrialTest, ObserveForcedDisabled) {
600 const char kTrialName[] = "TrialToObserve3"; 602 const char kTrialName[] = "TrialToObserve3";
601 603
602 TestFieldTrialObserver observer; 604 TestFieldTrialObserver observer;
605 int default_group = -1;
603 FieldTrial* trial = 606 FieldTrial* trial =
604 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName, 607 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
605 next_year_, 12, 31, NULL); 608 next_year_, 12, 31, &default_group);
606 trial->AppendGroup("A", 25); 609 trial->AppendGroup("A", 25);
607 trial->AppendGroup("B", 25); 610 trial->AppendGroup("B", 25);
608 trial->AppendGroup("C", 25); 611 trial->AppendGroup("C", 25);
609 trial->SetForced(); 612 trial->SetForced();
610 trial->Disable(); 613 trial->Disable();
611 614
612 // Observer shouldn't be notified until group() is called, even if SetForced() 615 // Observer shouldn't be notified of a disabled trial, even when forced.
613 // was called.
614 message_loop_.RunAllPending(); 616 message_loop_.RunAllPending();
615 EXPECT_TRUE(observer.trial_name().empty()); 617 EXPECT_TRUE(observer.trial_name().empty());
616 EXPECT_TRUE(observer.group_name().empty()); 618 EXPECT_TRUE(observer.group_name().empty());
617 619
618 trial->group(); 620 // Observer shouldn't be notified even after a |group()| call.
621 EXPECT_EQ(default_group, trial->group());
619 message_loop_.RunAllPending(); 622 message_loop_.RunAllPending();
620 EXPECT_EQ(kTrialName, observer.trial_name()); 623 EXPECT_TRUE(observer.trial_name().empty());
621 EXPECT_EQ(kDefaultGroupName, observer.group_name()); 624 EXPECT_TRUE(observer.group_name().empty());
622 } 625 }
623 626
627 TEST_F(FieldTrialTest, DisabledTrialNotActive) {
628 const char kTrialName[] = "DisabledTrial";
629 ASSERT_FALSE(FieldTrialList::TrialExists(kTrialName));
630
631 FieldTrial* trial =
632 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
633 next_year_, 12, 31, NULL);
634 trial->AppendGroup("X", 50);
635 trial->Disable();
636
637 // Ensure the trial is not listed as active.
638 FieldTrial::ActiveGroups active_groups;
639 FieldTrialList::GetActiveFieldTrialGroups(&active_groups);
640 EXPECT_TRUE(active_groups.empty());
641
642 // Ensure the trial is not listed in the |StatesToString()| result.
643 std::string states;
644 FieldTrialList::StatesToString(&states);
645 EXPECT_TRUE(states.empty());
646 }
647
648
624 } // namespace base 649 } // namespace base
OLDNEW
« base/metrics/field_trial.cc ('K') | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698