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