Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: components/arc/arc_util_unittest.cc

Issue 2885933003: arc: Consolidate IsArcAllowedForUser logic (Closed)
Patch Set: fix typo Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« components/arc/arc_util.cc ('K') | « components/arc/arc_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/arc/arc_util.h" 5 #include "components/arc/arc_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/test/scoped_feature_list.h" 13 #include "base/test/scoped_feature_list.h"
14 #include "components/signin/core/account_id/account_id.h"
15 #include "components/user_manager/user.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 namespace arc { 18 namespace arc {
17 namespace { 19 namespace {
18 20
19 // If an instance is created, based on the value passed to the consturctor, 21 // If an instance is created, based on the value passed to the consturctor,
20 // EnableARC feature is enabled/disabled in the scope. 22 // EnableARC feature is enabled/disabled in the scope.
21 class ScopedArcFeature { 23 class ScopedArcFeature {
22 public: 24 public:
23 explicit ScopedArcFeature(bool enabled) { 25 explicit ScopedArcFeature(bool enabled) {
24 constexpr char kArcFeatureName[] = "EnableARC"; 26 constexpr char kArcFeatureName[] = "EnableARC";
25 if (enabled) { 27 if (enabled) {
26 feature_list.InitFromCommandLine(kArcFeatureName, std::string()); 28 feature_list.InitFromCommandLine(kArcFeatureName, std::string());
27 } else { 29 } else {
28 feature_list.InitFromCommandLine(std::string(), kArcFeatureName); 30 feature_list.InitFromCommandLine(std::string(), kArcFeatureName);
29 } 31 }
30 } 32 }
31 ~ScopedArcFeature() = default; 33 ~ScopedArcFeature() = default;
32 34
33 private: 35 private:
34 base::test::ScopedFeatureList feature_list; 36 base::test::ScopedFeatureList feature_list;
35 DISALLOW_COPY_AND_ASSIGN(ScopedArcFeature); 37 DISALLOW_COPY_AND_ASSIGN(ScopedArcFeature);
36 }; 38 };
37 39
40 // Fake user that can be created with a specified type.
41 class FakeUser : public user_manager::User {
42 public:
43 explicit FakeUser(user_manager::UserType user_type)
44 : User(AccountId::FromUserEmail("user@test.com")),
45 user_type_(user_type) {}
46 ~FakeUser() override = default;
47
48 // user_manager::User:
49 user_manager::UserType GetType() const override { return user_type_; }
50
51 private:
52 const user_manager::UserType user_type_;
53
54 DISALLOW_COPY_AND_ASSIGN(FakeUser);
55 };
56
38 using ArcUtilTest = testing::Test; 57 using ArcUtilTest = testing::Test;
39 58
40 TEST_F(ArcUtilTest, IsArcAvailable_None) { 59 TEST_F(ArcUtilTest, IsArcAvailable_None) {
41 auto* command_line = base::CommandLine::ForCurrentProcess(); 60 auto* command_line = base::CommandLine::ForCurrentProcess();
42 61
43 command_line->InitFromArgv({"", "--arc-availability=none"}); 62 command_line->InitFromArgv({"", "--arc-availability=none"});
44 EXPECT_FALSE(IsArcAvailable()); 63 EXPECT_FALSE(IsArcAvailable());
45 64
46 // If --arc-availability flag is set to "none", even if Finch experiment is 65 // If --arc-availability flag is set to "none", even if Finch experiment is
47 // turned on, ARC cannot be used. 66 // turned on, ARC cannot be used.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 175
157 TEST_F(ArcUtilTest, IsArcOptInVerificationDisabled) { 176 TEST_F(ArcUtilTest, IsArcOptInVerificationDisabled) {
158 auto* command_line = base::CommandLine::ForCurrentProcess(); 177 auto* command_line = base::CommandLine::ForCurrentProcess();
159 command_line->InitFromArgv({""}); 178 command_line->InitFromArgv({""});
160 EXPECT_FALSE(IsArcOptInVerificationDisabled()); 179 EXPECT_FALSE(IsArcOptInVerificationDisabled());
161 180
162 command_line->InitFromArgv({"", "--disable-arc-opt-in-verification"}); 181 command_line->InitFromArgv({"", "--disable-arc-opt-in-verification"});
163 EXPECT_TRUE(IsArcOptInVerificationDisabled()); 182 EXPECT_TRUE(IsArcOptInVerificationDisabled());
164 } 183 }
165 184
185 TEST_F(ArcUtilTest, IsArcAllowedForUser) {
186 struct {
187 user_manager::UserType user_type;
188 bool expected_allowed;
189 } const kTestCases[] = {
190 {user_manager::USER_TYPE_REGULAR, true},
191 {user_manager::USER_TYPE_GUEST, false},
192 {user_manager::USER_TYPE_PUBLIC_ACCOUNT, false},
193 {user_manager::USER_TYPE_SUPERVISED, false},
194 {user_manager::USER_TYPE_KIOSK_APP, false},
195 {user_manager::USER_TYPE_CHILD, true},
196 {user_manager::USER_TYPE_ARC_KIOSK_APP, false},
197 {user_manager::USER_TYPE_ACTIVE_DIRECTORY, false},
198 };
199 for (const auto& test_case : kTestCases) {
200 const FakeUser user(test_case.user_type);
201 EXPECT_EQ(test_case.expected_allowed, IsArcAllowedForUser(&user))
202 << "User type=" << test_case.user_type;
203 }
204
205 // Active directory users are allowed when ARC is supported for active
206 // directory managed devices.
207 auto* command_line = base::CommandLine::ForCurrentProcess();
208 command_line->InitFromArgv(
209 {"", "--arc-availability=officially-supported-with-active-directory"});
210 const FakeUser active_directory_user(
211 user_manager::USER_TYPE_ACTIVE_DIRECTORY);
212 EXPECT_TRUE(IsArcAllowedForUser(&active_directory_user));
213 }
214
166 } // namespace 215 } // namespace
167 } // namespace arc 216 } // namespace arc
OLDNEW
« components/arc/arc_util.cc ('K') | « components/arc/arc_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698