OLD | NEW |
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" | 5 #include "base/metrics/field_trial.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial); | 392 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial); |
393 EXPECT_EQ("Winner", trial->group_name()); | 393 EXPECT_EQ("Winner", trial->group_name()); |
394 EXPECT_EQ("Some_name", trial->trial_name()); | 394 EXPECT_EQ("Some_name", trial->trial_name()); |
395 | 395 |
396 trial = FieldTrialList::Find("xxx"); | 396 trial = FieldTrialList::Find("xxx"); |
397 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial); | 397 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial); |
398 EXPECT_EQ("yyyy", trial->group_name()); | 398 EXPECT_EQ("yyyy", trial->group_name()); |
399 EXPECT_EQ("xxx", trial->trial_name()); | 399 EXPECT_EQ("xxx", trial->trial_name()); |
400 } | 400 } |
401 | 401 |
| 402 TEST_F(FieldTrialTest, RestoreNotEndingWithSlash) { |
| 403 EXPECT_TRUE(FieldTrialList::CreateTrialsFromString( |
| 404 "tname/gname", FieldTrialList::DONT_ACTIVATE_TRIALS, |
| 405 std::set<std::string>())); |
| 406 |
| 407 FieldTrial* trial = FieldTrialList::Find("tname"); |
| 408 ASSERT_NE(static_cast<FieldTrial*>(NULL), trial); |
| 409 EXPECT_EQ("gname", trial->group_name()); |
| 410 EXPECT_EQ("tname", trial->trial_name()); |
| 411 } |
| 412 |
402 TEST_F(FieldTrialTest, BogusRestore) { | 413 TEST_F(FieldTrialTest, BogusRestore) { |
403 EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( | 414 EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( |
404 "MissingSlash", FieldTrialList::DONT_ACTIVATE_TRIALS, | 415 "MissingSlash", FieldTrialList::DONT_ACTIVATE_TRIALS, |
405 std::set<std::string>())); | 416 std::set<std::string>())); |
406 EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( | 417 EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( |
407 "MissingGroupName/", FieldTrialList::DONT_ACTIVATE_TRIALS, | 418 "MissingGroupName/", FieldTrialList::DONT_ACTIVATE_TRIALS, |
408 std::set<std::string>())); | 419 std::set<std::string>())); |
409 EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( | 420 EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( |
410 "MissingFinalSlash/gname", FieldTrialList::DONT_ACTIVATE_TRIALS, | |
411 std::set<std::string>())); | |
412 EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( | |
413 "noname, only group/", FieldTrialList::DONT_ACTIVATE_TRIALS, | 421 "noname, only group/", FieldTrialList::DONT_ACTIVATE_TRIALS, |
414 std::set<std::string>())); | 422 std::set<std::string>())); |
415 } | 423 } |
416 | 424 |
417 TEST_F(FieldTrialTest, DuplicateRestore) { | 425 TEST_F(FieldTrialTest, DuplicateRestore) { |
418 FieldTrial* trial = CreateFieldTrial("Some name", 10, "Default", NULL); | 426 FieldTrial* trial = CreateFieldTrial("Some name", 10, "Default", NULL); |
419 trial->AppendGroup("Winner", 10); | 427 trial->AppendGroup("Winner", 10); |
420 // Finalize the group selection by accessing the selected group. | 428 // Finalize the group selection by accessing the selected group. |
421 trial->group(); | 429 trial->group(); |
422 std::string save_string; | 430 std::string save_string; |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 EXPECT_TRUE(active_groups.empty()); | 974 EXPECT_TRUE(active_groups.empty()); |
967 | 975 |
968 // The trial shouldn't be listed in the |StatesToString()| result. | 976 // The trial shouldn't be listed in the |StatesToString()| result. |
969 std::string states; | 977 std::string states; |
970 FieldTrialList::StatesToString(&states); | 978 FieldTrialList::StatesToString(&states); |
971 EXPECT_TRUE(states.empty()); | 979 EXPECT_TRUE(states.empty()); |
972 } | 980 } |
973 } | 981 } |
974 | 982 |
975 } // namespace base | 983 } // namespace base |
OLD | NEW |