OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "ios/chrome/browser/experimental_flags.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/metrics/field_trial.h" | |
9 #include "components/variations/variations_associated_data.h" | |
10 #include "ios/chrome/browser/chrome_switches.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace { | |
14 | |
15 class ExperimentalFlagsTest : public ::testing::Test { | |
16 protected: | |
17 void SetUp() override { | |
18 // Store the command line arguments to restore them at TearDown. | |
19 argv_ = base::CommandLine::ForCurrentProcess()->argv(); | |
20 } | |
21 | |
22 void TearDown() override { | |
23 // Reset command line. | |
24 base::CommandLine::Reset(); | |
25 base::CommandLine::Init(0, NULL); | |
26 base::CommandLine::ForCurrentProcess()->InitFromArgv(argv_); | |
27 | |
28 // Reset Finch. | |
29 variations::testing::ClearAllVariationParams(); | |
30 } | |
31 | |
32 private: | |
33 base::CommandLine::StringVector argv_; | |
34 }; | |
Alexei Svitkine (slow)
2015/04/28 16:52:58
DISALLOW_COPY_AND_ASSIGN()
lpromero
2015/04/28 18:12:46
Done.
| |
35 | |
36 TEST_F(ExperimentalFlagsTest, MemoryWedgeSwitchNoFinch) { | |
37 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
38 command_line->AppendSwitchASCII(switches::kIOSMemoryWedgeSize, "10"); | |
39 | |
40 EXPECT_EQ(10u, experimental_flags::MemoryWedgeSizeInMB()); | |
41 } | |
42 | |
43 TEST_F(ExperimentalFlagsTest, MemoryWedgeNoSwitchFinchNoParam) { | |
44 base::FieldTrialList field_trial_list(nullptr); | |
45 base::FieldTrialList::CreateFieldTrial("MemoryWedge", "Default"); | |
46 | |
47 EXPECT_EQ(0u, experimental_flags::MemoryWedgeSizeInMB()); | |
48 } | |
49 | |
50 TEST_F(ExperimentalFlagsTest, MemoryWedgeNoSwitchFinchParam) { | |
51 base::FieldTrialList field_trial_list(nullptr); | |
52 base::FieldTrialList::CreateFieldTrial("MemoryWedge", "Experiment2"); | |
53 std::map<std::string, std::string> params; | |
54 params[std::string("wedge_size")] = "20"; | |
55 ASSERT_TRUE(variations::AssociateVariationParams("MemoryWedge", "Experiment2", | |
56 params)); | |
57 | |
58 EXPECT_EQ(20u, experimental_flags::MemoryWedgeSizeInMB()); | |
59 } | |
60 | |
61 TEST_F(ExperimentalFlagsTest, MemoryWedgeNoSwitchFinchWrongParam) { | |
62 base::FieldTrialList field_trial_list(nullptr); | |
63 base::FieldTrialList::CreateFieldTrial("MemoryWedge", "Experiment2"); | |
64 std::map<std::string, std::string> params; | |
65 params[std::string("wedge_size")] = "twenty"; | |
66 ASSERT_TRUE(variations::AssociateVariationParams("MemoryWedge", "Experiment2", | |
67 params)); | |
68 | |
69 EXPECT_EQ(0u, experimental_flags::MemoryWedgeSizeInMB()); | |
70 } | |
71 | |
72 TEST_F(ExperimentalFlagsTest, MemoryWedgeSwitchFinch) { | |
73 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
74 command_line->AppendSwitchASCII(switches::kIOSMemoryWedgeSize, "10"); | |
75 | |
76 base::FieldTrialList field_trial_list(nullptr); | |
77 base::FieldTrialList::CreateFieldTrial("MemoryWedge", "Experiment2"); | |
78 std::map<std::string, std::string> params; | |
79 params[std::string("wedge_size")] = "20"; | |
80 ASSERT_TRUE(variations::AssociateVariationParams("MemoryWedge", "Experiment2", | |
81 params)); | |
82 | |
83 EXPECT_EQ(10u, experimental_flags::MemoryWedgeSizeInMB()); | |
84 } | |
85 | |
86 TEST_F(ExperimentalFlagsTest, MemoryWedgeNoSwitchNoFinch) { | |
87 EXPECT_EQ(0u, experimental_flags::MemoryWedgeSizeInMB()); | |
88 } | |
89 | |
90 } // namespace | |
OLD | NEW |