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