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

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

Issue 12226007: base: Convert the remaining uses of MessageLoop::RunUntilIdle to RunLoop variant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « base/message_pump_glib_unittest.cc ('k') | base/observer_list_unittest.cc » ('j') | 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/metrics/field_trial.h"
6
5 #include "base/message_loop.h" 7 #include "base/message_loop.h"
6 #include "base/metrics/field_trial.h"
7 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/run_loop.h"
8 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
9 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 namespace base { 14 namespace base {
13 15
14 namespace { 16 namespace {
15 17
16 // Default group name used by several tests. 18 // Default group name used by several tests.
17 const char kDefaultGroupName[] = "DefaultGroup"; 19 const char kDefaultGroupName[] = "DefaultGroup";
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 EXPECT_EQ("Xyz", active_groups[1].trial_name); 445 EXPECT_EQ("Xyz", active_groups[1].trial_name);
444 EXPECT_EQ("zyx", active_groups[1].group_name); 446 EXPECT_EQ("zyx", active_groups[1].group_name);
445 } 447 }
446 448
447 TEST_F(FieldTrialTest, CreateTrialsFromStringObserver) { 449 TEST_F(FieldTrialTest, CreateTrialsFromStringObserver) {
448 ASSERT_FALSE(FieldTrialList::TrialExists("Abc")); 450 ASSERT_FALSE(FieldTrialList::TrialExists("Abc"));
449 451
450 TestFieldTrialObserver observer; 452 TestFieldTrialObserver observer;
451 ASSERT_TRUE(FieldTrialList::CreateTrialsFromString("Abc/def/")); 453 ASSERT_TRUE(FieldTrialList::CreateTrialsFromString("Abc/def/"));
452 454
453 message_loop_.RunUntilIdle(); 455 RunLoop().RunUntilIdle();
454 EXPECT_EQ("Abc", observer.trial_name()); 456 EXPECT_EQ("Abc", observer.trial_name());
455 EXPECT_EQ("def", observer.group_name()); 457 EXPECT_EQ("def", observer.group_name());
456 } 458 }
457 459
458 TEST_F(FieldTrialTest, CreateFieldTrial) { 460 TEST_F(FieldTrialTest, CreateFieldTrial) {
459 ASSERT_FALSE(FieldTrialList::TrialExists("Some_name")); 461 ASSERT_FALSE(FieldTrialList::TrialExists("Some_name"));
460 462
461 FieldTrialList::CreateFieldTrial("Some_name", "Winner"); 463 FieldTrialList::CreateFieldTrial("Some_name", "Winner");
462 464
463 FieldTrial* trial = FieldTrialList::Find("Some_name"); 465 FieldTrial* trial = FieldTrialList::Find("Some_name");
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 632
631 TestFieldTrialObserver observer; 633 TestFieldTrialObserver observer;
632 int default_group = -1; 634 int default_group = -1;
633 FieldTrial* trial = 635 FieldTrial* trial =
634 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName, 636 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
635 next_year_, 12, 31, &default_group); 637 next_year_, 12, 31, &default_group);
636 const int secondary_group = trial->AppendGroup(kSecondaryGroupName, 50); 638 const int secondary_group = trial->AppendGroup(kSecondaryGroupName, 50);
637 const int chosen_group = trial->group(); 639 const int chosen_group = trial->group();
638 EXPECT_TRUE(chosen_group == default_group || chosen_group == secondary_group); 640 EXPECT_TRUE(chosen_group == default_group || chosen_group == secondary_group);
639 641
640 message_loop_.RunUntilIdle(); 642 RunLoop().RunUntilIdle();
641 EXPECT_EQ(kTrialName, observer.trial_name()); 643 EXPECT_EQ(kTrialName, observer.trial_name());
642 if (chosen_group == default_group) 644 if (chosen_group == default_group)
643 EXPECT_EQ(kDefaultGroupName, observer.group_name()); 645 EXPECT_EQ(kDefaultGroupName, observer.group_name());
644 else 646 else
645 EXPECT_EQ(kSecondaryGroupName, observer.group_name()); 647 EXPECT_EQ(kSecondaryGroupName, observer.group_name());
646 } 648 }
647 649
648 TEST_F(FieldTrialTest, ObserveDisabled) { 650 TEST_F(FieldTrialTest, ObserveDisabled) {
649 const char kTrialName[] = "TrialToObserve2"; 651 const char kTrialName[] = "TrialToObserve2";
650 652
651 TestFieldTrialObserver observer; 653 TestFieldTrialObserver observer;
652 int default_group = -1; 654 int default_group = -1;
653 FieldTrial* trial = 655 FieldTrial* trial =
654 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName, 656 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
655 next_year_, 12, 31, &default_group); 657 next_year_, 12, 31, &default_group);
656 trial->AppendGroup("A", 25); 658 trial->AppendGroup("A", 25);
657 trial->AppendGroup("B", 25); 659 trial->AppendGroup("B", 25);
658 trial->AppendGroup("C", 25); 660 trial->AppendGroup("C", 25);
659 trial->Disable(); 661 trial->Disable();
660 662
661 // Observer shouldn't be notified of a disabled trial. 663 // Observer shouldn't be notified of a disabled trial.
662 message_loop_.RunUntilIdle(); 664 RunLoop().RunUntilIdle();
663 EXPECT_TRUE(observer.trial_name().empty()); 665 EXPECT_TRUE(observer.trial_name().empty());
664 EXPECT_TRUE(observer.group_name().empty()); 666 EXPECT_TRUE(observer.group_name().empty());
665 667
666 // Observer shouldn't be notified even after a |group()| call. 668 // Observer shouldn't be notified even after a |group()| call.
667 EXPECT_EQ(default_group, trial->group()); 669 EXPECT_EQ(default_group, trial->group());
668 message_loop_.RunUntilIdle(); 670 RunLoop().RunUntilIdle();
669 EXPECT_TRUE(observer.trial_name().empty()); 671 EXPECT_TRUE(observer.trial_name().empty());
670 EXPECT_TRUE(observer.group_name().empty()); 672 EXPECT_TRUE(observer.group_name().empty());
671 } 673 }
672 674
673 TEST_F(FieldTrialTest, ObserveForcedDisabled) { 675 TEST_F(FieldTrialTest, ObserveForcedDisabled) {
674 const char kTrialName[] = "TrialToObserve3"; 676 const char kTrialName[] = "TrialToObserve3";
675 677
676 TestFieldTrialObserver observer; 678 TestFieldTrialObserver observer;
677 int default_group = -1; 679 int default_group = -1;
678 FieldTrial* trial = 680 FieldTrial* trial =
679 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName, 681 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
680 next_year_, 12, 31, &default_group); 682 next_year_, 12, 31, &default_group);
681 trial->AppendGroup("A", 25); 683 trial->AppendGroup("A", 25);
682 trial->AppendGroup("B", 25); 684 trial->AppendGroup("B", 25);
683 trial->AppendGroup("C", 25); 685 trial->AppendGroup("C", 25);
684 trial->SetForced(); 686 trial->SetForced();
685 trial->Disable(); 687 trial->Disable();
686 688
687 // Observer shouldn't be notified of a disabled trial, even when forced. 689 // Observer shouldn't be notified of a disabled trial, even when forced.
688 message_loop_.RunUntilIdle(); 690 RunLoop().RunUntilIdle();
689 EXPECT_TRUE(observer.trial_name().empty()); 691 EXPECT_TRUE(observer.trial_name().empty());
690 EXPECT_TRUE(observer.group_name().empty()); 692 EXPECT_TRUE(observer.group_name().empty());
691 693
692 // Observer shouldn't be notified even after a |group()| call. 694 // Observer shouldn't be notified even after a |group()| call.
693 EXPECT_EQ(default_group, trial->group()); 695 EXPECT_EQ(default_group, trial->group());
694 message_loop_.RunUntilIdle(); 696 RunLoop().RunUntilIdle();
695 EXPECT_TRUE(observer.trial_name().empty()); 697 EXPECT_TRUE(observer.trial_name().empty());
696 EXPECT_TRUE(observer.group_name().empty()); 698 EXPECT_TRUE(observer.group_name().empty());
697 } 699 }
698 700
699 TEST_F(FieldTrialTest, DisabledTrialNotActive) { 701 TEST_F(FieldTrialTest, DisabledTrialNotActive) {
700 const char kTrialName[] = "DisabledTrial"; 702 const char kTrialName[] = "DisabledTrial";
701 ASSERT_FALSE(FieldTrialList::TrialExists(kTrialName)); 703 ASSERT_FALSE(FieldTrialList::TrialExists(kTrialName));
702 704
703 FieldTrial* trial = 705 FieldTrial* trial =
704 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName, 706 FieldTrialList::FactoryGetFieldTrial(kTrialName, 100, kDefaultGroupName,
(...skipping 20 matching lines...) Expand all
725 727
726 FieldTrial* trial = 728 FieldTrial* trial =
727 FieldTrialList::FactoryGetFieldTrial( 729 FieldTrialList::FactoryGetFieldTrial(
728 kTrialName, kProbability, kDefaultGroupName, 730 kTrialName, kProbability, kDefaultGroupName,
729 FieldTrialList::kNoExpirationYear, 1, 1, NULL); 731 FieldTrialList::kNoExpirationYear, 1, 1, NULL);
730 trial->AppendGroup(kGroupName, kProbability); 732 trial->AppendGroup(kGroupName, kProbability);
731 EXPECT_EQ(kGroupName, trial->group_name()); 733 EXPECT_EQ(kGroupName, trial->group_name());
732 } 734 }
733 735
734 } // namespace base 736 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_glib_unittest.cc ('k') | base/observer_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698