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

Unified Diff: chrome/common/metrics/experiments_helper_unittest.cc

Issue 10151017: Remove the hash fields from FieldTrials. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: MAD comments. Reshuffled test methods. Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/metrics/experiments_helper_unittest.cc
diff --git a/chrome/common/metrics/experiments_helper_unittest.cc b/chrome/common/metrics/experiments_helper_unittest.cc
index 546cce86c3ebe5abd84c0a97743933e850876b08..7a93896c75de6229386471c0ff19f9f751769ac8 100644
--- a/chrome/common/metrics/experiments_helper_unittest.cc
+++ b/chrome/common/metrics/experiments_helper_unittest.cc
@@ -12,14 +12,15 @@
#include "content/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include <set>
+
namespace {
// Convenience helper to retrieve the GoogleExperimentID for a FieldTrial. Note
// that this will do the group assignment in |trial| if not already done.
experiments_helper::GoogleExperimentID GetIDForTrial(base::FieldTrial* trial) {
return experiments_helper::GetGoogleExperimentID(
- base::FieldTrial::MakeNameGroupId(trial->name(),
- trial->group_name()));
+ testing::TestMakeNameGroupId(trial->name(), trial->group_name()));
}
} // namespace
@@ -49,6 +50,63 @@ class ExperimentsHelperTest : public ::testing::Test {
scoped_ptr<content::TestBrowserThread> ui_thread_;
};
+TEST_F(ExperimentsHelperTest, HashName) {
+ // Make sure hashing is stable on all platforms.
+ struct {
+ const char* name;
+ uint32 hash_value;
+ } known_hashes[] = {
+ {"a", 937752454u},
+ {"1", 723085877u},
+ {"Trial Name", 2713117220u},
+ {"Group Name", 3201815843u},
+ {"My Favorite Experiment", 3722155194u},
+ {"My Awesome Group Name", 4109503236u},
+ {"abcdefghijklmonpqrstuvwxyz", 787728696u},
+ {"0123456789ABCDEF", 348858318U}
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(known_hashes); ++i) {
+ EXPECT_EQ(known_hashes[i].hash_value,
+ testing::TestHashName(known_hashes[i].name));
+ }
+}
+
+TEST_F(ExperimentsHelperTest, GetFieldTrialSelectedGroups) {
+ std::string trial_one("trial one");
+ std::string group_one("group one");
+ std::string trial_two("trial two");
+ std::string group_two("group two");
+
+ base::FieldTrial::SelectedGroups selected_groups;
+ base::FieldTrial::SelectedGroup selected_group;
+ selected_group.trial = trial_one;
+ selected_group.group = group_one;
+ selected_groups.push_back(selected_group);
+
+ selected_group.trial = trial_two;
+ selected_group.group = group_two;
+ selected_groups.push_back(selected_group);
+
+ // Create our expected groups of IDs.
+ std::set<experiments_helper::NameGroupId,
+ experiments_helper::NameGroupIdCompare> expected_groups;
+ expected_groups.insert(testing::TestMakeNameGroupId(trial_one, group_one));
+ expected_groups.insert(testing::TestMakeNameGroupId(trial_two, group_two));
+
+ std::vector<experiments_helper::NameGroupId> name_group_ids;
+ testing::TestGetFieldTrialNameGroupIdsForSelectedGroups(selected_groups,
+ &name_group_ids);
+ EXPECT_EQ(2U, name_group_ids.size());
+ for (size_t i = 0; i < name_group_ids.size(); ++i) {
+ std::set<experiments_helper::NameGroupId,
+ experiments_helper::NameGroupIdCompare>::iterator it =
+ expected_groups.find(name_group_ids[i]);
+ EXPECT_NE(it, expected_groups.end());
+ expected_groups.erase(it);
MAD 2012/04/26 19:40:13 I think it's dangerous for some container classes
SteveT 2012/04/26 21:06:03 Oops, maybe it's not clear, but there are actually
MAD 2012/04/27 17:33:22 OK, that's fine... The trick I propose would preve
SteveT 2012/04/27 17:59:33 Good point. I've renamed it to expected_group, whi
+ }
+ EXPECT_EQ(0U, expected_groups.size());
+}
+
// Test that if the trial is immediately disabled, GetGoogleExperimentID just
// returns the empty ID.
TEST_F(ExperimentsHelperTest, DisableImmediately) {
@@ -76,9 +134,9 @@ TEST_F(ExperimentsHelperTest, DisableAfterInitialization) {
next_year_, 12, 12, NULL));
trial->AppendGroup(non_default_name, 100);
experiments_helper::AssociateGoogleExperimentID(
- base::FieldTrial::MakeNameGroupId(trial->name(), default_name), 123);
+ testing::TestMakeNameGroupId(trial->name(), default_name), 123);
experiments_helper::AssociateGoogleExperimentID(
- base::FieldTrial::MakeNameGroupId(trial->name(), non_default_name), 456);
+ testing::TestMakeNameGroupId(trial->name(), non_default_name), 456);
ASSERT_EQ(non_default_name, trial->group_name());
ASSERT_EQ(456U, GetIDForTrial(trial.get()));
trial->Disable();
@@ -97,11 +155,9 @@ TEST_F(ExperimentsHelperTest, AssociateGoogleExperimentID) {
// Set GoogleExperimentIDs so we can verify that they were chosen correctly.
experiments_helper::AssociateGoogleExperimentID(
- base::FieldTrial::MakeNameGroupId(trial_true->name(), default_name1),
- 123);
+ testing::TestMakeNameGroupId(trial_true->name(), default_name1), 123);
experiments_helper::AssociateGoogleExperimentID(
- base::FieldTrial::MakeNameGroupId(trial_true->name(), winner),
- 456);
+ testing::TestMakeNameGroupId(trial_true->name(), winner), 456);
EXPECT_EQ(winner_group, trial_true->group());
EXPECT_EQ(winner, trial_true->group_name());
@@ -115,11 +171,9 @@ TEST_F(ExperimentsHelperTest, AssociateGoogleExperimentID) {
int loser_group = trial_false->AppendGroup(loser, 0);
experiments_helper::AssociateGoogleExperimentID(
- base::FieldTrial::MakeNameGroupId(trial_false->name(), default_name2),
- 123);
+ testing::TestMakeNameGroupId(trial_false->name(), default_name2), 123);
experiments_helper::AssociateGoogleExperimentID(
- base::FieldTrial::MakeNameGroupId(trial_false->name(), loser),
- 456);
+ testing::TestMakeNameGroupId(trial_false->name(), loser), 456);
EXPECT_NE(loser_group, trial_false->group());
EXPECT_EQ(123U, GetIDForTrial(trial_false.get()));
« chrome/common/metrics/experiments_helper.h ('K') | « chrome/common/metrics/experiments_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698