OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "components/arc/arc_util.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/test/scoped_feature_list.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace arc { |
| 16 namespace { |
| 17 |
| 18 // If an instance is created, based on the value passed to the consturctor, |
| 19 // EnableARC feature is enabled/disabled in the scope. |
| 20 class ScopedArcFeature { |
| 21 public: |
| 22 explicit ScopedArcFeature(bool enabled) { |
| 23 constexpr char kArcFeatureName[] = "EnableARC"; |
| 24 if (enabled) { |
| 25 feature_list.InitFromCommandLine(kArcFeatureName, std::string()); |
| 26 } else { |
| 27 feature_list.InitFromCommandLine(std::string(), kArcFeatureName); |
| 28 } |
| 29 } |
| 30 ~ScopedArcFeature() = default; |
| 31 |
| 32 private: |
| 33 base::test::ScopedFeatureList feature_list; |
| 34 DISALLOW_COPY_AND_ASSIGN(ScopedArcFeature); |
| 35 }; |
| 36 |
| 37 using ArcUtilTest = testing::Test; |
| 38 |
| 39 // Test --arc-available with EnableARC feature combination. |
| 40 TEST_F(ArcUtilTest, IsArcAvailable_Installed) { |
| 41 auto* command_line = base::CommandLine::ForCurrentProcess(); |
| 42 |
| 43 // If ARC is not installed, IsArcAvailable() should return false, |
| 44 // regardless of EnableARC feature. |
| 45 command_line->InitFromArgv({""}); |
| 46 |
| 47 // Not available, by-default. |
| 48 EXPECT_FALSE(IsArcAvailable()); |
| 49 |
| 50 { |
| 51 ScopedArcFeature feature(true); |
| 52 EXPECT_FALSE(IsArcAvailable()); |
| 53 } |
| 54 { |
| 55 ScopedArcFeature feature(false); |
| 56 EXPECT_FALSE(IsArcAvailable()); |
| 57 } |
| 58 |
| 59 // If ARC is installed, IsArcAvailable() should return true when EnableARC |
| 60 // feature is set. |
| 61 command_line->InitFromArgv({"", "--arc-available"}); |
| 62 |
| 63 // Not available, by-default, too. |
| 64 EXPECT_FALSE(IsArcAvailable()); |
| 65 |
| 66 { |
| 67 ScopedArcFeature feature(true); |
| 68 EXPECT_TRUE(IsArcAvailable()); |
| 69 } |
| 70 { |
| 71 ScopedArcFeature feature(false); |
| 72 EXPECT_FALSE(IsArcAvailable()); |
| 73 } |
| 74 } |
| 75 |
| 76 TEST_F(ArcUtilTest, IsArcAvailable_OfficialSupport) { |
| 77 // Regardless of FeatureList, IsArcAvailable() should return true. |
| 78 auto* command_line = base::CommandLine::ForCurrentProcess(); |
| 79 command_line->InitFromArgv({"", "--enable-arc"}); |
| 80 EXPECT_TRUE(IsArcAvailable()); |
| 81 } |
| 82 |
| 83 } // namespace |
| 84 } // namespace arc |
OLD | NEW |