Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / ios / chrome / browser / experimental_flags_unittest.mm
blob53b59ec3a40b2ca5e8c4c915dd73f88779675206
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 "ios/chrome/browser/experimental_flags.h"
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"
14 namespace {
16 class ExperimentalFlagsTest : public ::testing::Test {
17  protected:
18   ExperimentalFlagsTest() {}
20   void SetUp() override {
21     // Store the command line arguments to restore them at TearDown.
22     argv_ = base::CommandLine::ForCurrentProcess()->argv();
23   }
25   void TearDown() override {
26     // Reset command line.
27     base::CommandLine::Reset();
28     base::CommandLine::Init(0, NULL);
29     base::CommandLine::ForCurrentProcess()->InitFromArgv(argv_);
31     // Reset Finch.
32     variations::testing::ClearAllVariationParams();
33   }
35  private:
36   base::CommandLine::StringVector argv_;
38   DISALLOW_COPY_AND_ASSIGN(ExperimentalFlagsTest);
41 TEST_F(ExperimentalFlagsTest, MemoryWedgeSwitchNoFinch) {
42   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
43   command_line->AppendSwitchASCII(switches::kIOSMemoryWedgeSize, "10");
45   EXPECT_EQ(10u, experimental_flags::MemoryWedgeSizeInMB());
48 TEST_F(ExperimentalFlagsTest, MemoryWedgeNoSwitchFinchNoParam) {
49   base::FieldTrialList field_trial_list(nullptr);
50   base::FieldTrialList::CreateFieldTrial("MemoryWedge", "Default");
52   EXPECT_EQ(0u, experimental_flags::MemoryWedgeSizeInMB());
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));
63   EXPECT_EQ(20u, experimental_flags::MemoryWedgeSizeInMB());
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));
74   EXPECT_EQ(0u, experimental_flags::MemoryWedgeSizeInMB());
77 TEST_F(ExperimentalFlagsTest, MemoryWedgeSwitchFinch) {
78   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
79   command_line->AppendSwitchASCII(switches::kIOSMemoryWedgeSize, "10");
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));
88   EXPECT_EQ(10u, experimental_flags::MemoryWedgeSizeInMB());
91 TEST_F(ExperimentalFlagsTest, MemoryWedgeNoSwitchNoFinch) {
92   EXPECT_EQ(0u, experimental_flags::MemoryWedgeSizeInMB());
95 }  // namespace