Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / chrome / common / variations / variations_util_unittest.cc
blob6b4f9ec6db706aecd33faaebdd2b27f9b0165ecb
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/common/variations/variations_util.h"
7 #include "base/metrics/field_trial.h"
8 #include "components/variations/variations_associated_data.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace chrome_variations {
13 class VariationsUtilTest : public ::testing::Test {
14 public:
15 VariationsUtilTest() : field_trial_list_(NULL) {}
17 ~VariationsUtilTest() override {
18 // Ensure that the maps are cleared between tests, since they are stored as
19 // process singletons.
20 variations::testing::ClearAllVariationIDs();
21 variations::testing::ClearAllVariationParams();
24 private:
25 base::FieldTrialList field_trial_list_;
27 DISALLOW_COPY_AND_ASSIGN(VariationsUtilTest);
30 TEST_F(VariationsUtilTest, AssociateParamsFromString) {
31 const std::string kTrialName = "AssociateVariationParams";
32 const std::string kVariationsString =
33 "AssociateVariationParams.A:a/10/b/test,AssociateVariationParams.B:a/%2F";
34 ASSERT_TRUE(AssociateParamsFromString(kVariationsString));
36 base::FieldTrialList::CreateFieldTrial(kTrialName, "B");
37 EXPECT_EQ("/", variations::GetVariationParamValue(kTrialName, "a"));
38 EXPECT_EQ(std::string(), variations::GetVariationParamValue(kTrialName, "b"));
39 EXPECT_EQ(std::string(), variations::GetVariationParamValue(kTrialName, "x"));
41 std::map<std::string, std::string> params;
42 EXPECT_TRUE(variations::GetVariationParams(kTrialName, &params));
43 EXPECT_EQ(1U, params.size());
44 EXPECT_EQ("/", params["a"]);
47 } // namespace chrome_variations