fixup! [M120 Migration] Notify media device state to webbrowser
[platform/framework/web/chromium-efl.git] / base / scoped_add_feature_flags_unittest.cc
1 // Copyright 2019 The Chromium Authors
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 "base/scoped_add_feature_flags.h"
6
7 #include <cstring>
8 #include <string>
9
10 #include "base/base_switches.h"
11 #include "base/command_line.h"
12 #include "base/feature_list.h"
13 #include "base/strings/string_util.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace base {
17
18 namespace {
19
20 // Converts a string to CommandLine::StringType, which is std::wstring on
21 // Windows and std::string on other platforms.
22 CommandLine::StringType ToCommandLineStringType(StringPiece s) {
23   return CommandLine::StringType(s.begin(), s.end());
24 }
25
26 }  // namespace
27
28 TEST(ScopedAddFeatureFlags, ConflictWithExistingFlags) {
29   CommandLine command_line(CommandLine::NO_PROGRAM);
30   command_line.AppendSwitchASCII(switches::kEnableFeatures,
31                                  "ExistingEnabledFoo,ExistingEnabledBar");
32   command_line.AppendSwitchASCII(switches::kDisableFeatures,
33                                  "ExistingDisabledFoo,ExistingDisabledBar");
34
35   static BASE_FEATURE(kExistingEnabledFoo, "ExistingEnabledFoo",
36                       FEATURE_DISABLED_BY_DEFAULT);
37   static BASE_FEATURE(kExistingDisabledFoo, "ExistingDisabledFoo",
38                       FEATURE_DISABLED_BY_DEFAULT);
39   static BASE_FEATURE(kEnabledBaz, "EnabledBaz", FEATURE_DISABLED_BY_DEFAULT);
40   static BASE_FEATURE(kDisabledBaz, "DisabledBaz", FEATURE_DISABLED_BY_DEFAULT);
41   {
42     ScopedAddFeatureFlags scoped_add(&command_line);
43     scoped_add.EnableIfNotSet(kExistingEnabledFoo);
44     scoped_add.EnableIfNotSet(kExistingDisabledFoo);
45     scoped_add.EnableIfNotSet(kEnabledBaz);
46     scoped_add.DisableIfNotSet(kExistingEnabledFoo);
47     scoped_add.DisableIfNotSet(kExistingDisabledFoo);
48     scoped_add.DisableIfNotSet(kDisabledBaz);
49   }
50
51   EXPECT_EQ(std::string("ExistingEnabledFoo,ExistingEnabledBar,EnabledBaz"),
52             command_line.GetSwitchValueASCII(switches::kEnableFeatures));
53   EXPECT_EQ(std::string("ExistingDisabledFoo,ExistingDisabledBar,DisabledBaz"),
54             command_line.GetSwitchValueASCII(switches::kDisableFeatures));
55
56   // There should not be duplicate --enable-features or --disable-features flags
57   EXPECT_EQ(
58       ToCommandLineStringType(
59           " --enable-features=ExistingEnabledFoo,ExistingEnabledBar,EnabledBaz"
60           " --disable-features=ExistingDisabledFoo,ExistingDisabledBar,"
61           "DisabledBaz"),
62       JoinString(command_line.argv(), ToCommandLineStringType(" ")));
63 }
64
65 TEST(ScopedAddFeatureFlags, FlagWithParameter) {
66   CommandLine command_line(CommandLine::NO_PROGRAM);
67   command_line.AppendSwitchASCII(switches::kEnableFeatures,
68                                  "ExistingEnabledFoo");
69   static BASE_FEATURE(kExistingEnabledFoo, "ExistingEnabledFoo",
70                       FEATURE_DISABLED_BY_DEFAULT);
71   static BASE_FEATURE(kFeatureWithParameter, "FeatureWithParam",
72                       FEATURE_DISABLED_BY_DEFAULT);
73
74   {
75     ScopedAddFeatureFlags scoped_add(&command_line);
76     scoped_add.EnableIfNotSet(kExistingEnabledFoo);
77     scoped_add.EnableIfNotSetWithParameter(kFeatureWithParameter, "name",
78                                            "value");
79     EXPECT_TRUE(scoped_add.IsEnabledWithParameter(kFeatureWithParameter, "name",
80                                                   "value"));
81   }
82
83   EXPECT_EQ(std::string("ExistingEnabledFoo,FeatureWithParam:name/value"),
84             command_line.GetSwitchValueASCII(switches::kEnableFeatures));
85 }
86
87 }  // namespace base