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

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

Issue 2885933003: arc: Consolidate IsArcAllowedForUser logic (Closed)
Patch Set: rebase 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
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 "ash/shared/app_types.h" 10 #include "ash/shared/app_types.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/test/scoped_feature_list.h" 14 #include "base/test/scoped_feature_list.h"
15 #include "components/signin/core/account_id/account_id.h"
16 #include "components/user_manager/fake_user_manager.h"
17 #include "components/user_manager/user.h"
15 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/aura/client/aura_constants.h" 19 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/test/test_windows.h" 20 #include "ui/aura/test/test_windows.h"
18 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
19 22
20 namespace arc { 23 namespace arc {
21 namespace { 24 namespace {
22 25
23 // If an instance is created, based on the value passed to the consturctor, 26 // If an instance is created, based on the value passed to the consturctor,
24 // EnableARC feature is enabled/disabled in the scope. 27 // EnableARC feature is enabled/disabled in the scope.
25 class ScopedArcFeature { 28 class ScopedArcFeature {
26 public: 29 public:
27 explicit ScopedArcFeature(bool enabled) { 30 explicit ScopedArcFeature(bool enabled) {
28 constexpr char kArcFeatureName[] = "EnableARC"; 31 constexpr char kArcFeatureName[] = "EnableARC";
29 if (enabled) { 32 if (enabled) {
30 feature_list.InitFromCommandLine(kArcFeatureName, std::string()); 33 feature_list.InitFromCommandLine(kArcFeatureName, std::string());
31 } else { 34 } else {
32 feature_list.InitFromCommandLine(std::string(), kArcFeatureName); 35 feature_list.InitFromCommandLine(std::string(), kArcFeatureName);
33 } 36 }
34 } 37 }
35 ~ScopedArcFeature() = default; 38 ~ScopedArcFeature() = default;
36 39
37 private: 40 private:
38 base::test::ScopedFeatureList feature_list; 41 base::test::ScopedFeatureList feature_list;
39 DISALLOW_COPY_AND_ASSIGN(ScopedArcFeature); 42 DISALLOW_COPY_AND_ASSIGN(ScopedArcFeature);
40 }; 43 };
41 44
45 // Helper to enable user_manager::FakeUserManager while it is in scope.
46 // TODO(xiyuan): Remove after ScopedUserManagerEnabler is moved to user_manager.
47 class ScopedUserManager {
48 public:
49 explicit ScopedUserManager(user_manager::UserManager* user_manager)
50 : user_manager_(user_manager) {
51 DCHECK(!user_manager::UserManager::IsInitialized());
52 user_manager->Initialize();
53 }
54 ~ScopedUserManager() {
55 DCHECK_EQ(user_manager::UserManager::Get(), user_manager_);
56 user_manager_->Shutdown();
57 user_manager_->Destroy();
58 }
59
60 private:
61 user_manager::UserManager* const user_manager_;
62
63 DISALLOW_COPY_AND_ASSIGN(ScopedUserManager);
64 };
65
66 // Fake user that can be created with a specified type.
67 class FakeUser : public user_manager::User {
68 public:
69 explicit FakeUser(user_manager::UserType user_type)
70 : User(AccountId::FromUserEmail("user@test.com")),
71 user_type_(user_type) {}
72 ~FakeUser() override = default;
73
74 // user_manager::User:
75 user_manager::UserType GetType() const override { return user_type_; }
76
77 private:
78 const user_manager::UserType user_type_;
79
80 DISALLOW_COPY_AND_ASSIGN(FakeUser);
81 };
82
42 using ArcUtilTest = testing::Test; 83 using ArcUtilTest = testing::Test;
43 84
44 TEST_F(ArcUtilTest, IsArcAvailable_None) { 85 TEST_F(ArcUtilTest, IsArcAvailable_None) {
45 auto* command_line = base::CommandLine::ForCurrentProcess(); 86 auto* command_line = base::CommandLine::ForCurrentProcess();
46 87
47 command_line->InitFromArgv({"", "--arc-availability=none"}); 88 command_line->InitFromArgv({"", "--arc-availability=none"});
48 EXPECT_FALSE(IsArcAvailable()); 89 EXPECT_FALSE(IsArcAvailable());
49 90
50 // If --arc-availability flag is set to "none", even if Finch experiment is 91 // If --arc-availability flag is set to "none", even if Finch experiment is
51 // turned on, ARC cannot be used. 92 // turned on, ARC cannot be used.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 window->SetProperty(aura::client::kAppType, 216 window->SetProperty(aura::client::kAppType,
176 static_cast<int>(ash::AppType::CHROME_APP)); 217 static_cast<int>(ash::AppType::CHROME_APP));
177 EXPECT_FALSE(IsArcAppWindow(window.get())); 218 EXPECT_FALSE(IsArcAppWindow(window.get()));
178 window->SetProperty(aura::client::kAppType, 219 window->SetProperty(aura::client::kAppType,
179 static_cast<int>(ash::AppType::ARC_APP)); 220 static_cast<int>(ash::AppType::ARC_APP));
180 EXPECT_TRUE(IsArcAppWindow(window.get())); 221 EXPECT_TRUE(IsArcAppWindow(window.get()));
181 222
182 EXPECT_FALSE(IsArcAppWindow(nullptr)); 223 EXPECT_FALSE(IsArcAppWindow(nullptr));
183 } 224 }
184 225
226 TEST_F(ArcUtilTest, IsArcAllowedForUser) {
227 user_manager::FakeUserManager fake_user_manager;
228 ScopedUserManager scoped_user_manager(&fake_user_manager);
229
230 struct {
231 user_manager::UserType user_type;
232 bool expected_allowed;
233 } const kTestCases[] = {
234 {user_manager::USER_TYPE_REGULAR, true},
235 {user_manager::USER_TYPE_GUEST, false},
236 {user_manager::USER_TYPE_PUBLIC_ACCOUNT, false},
237 {user_manager::USER_TYPE_SUPERVISED, false},
238 {user_manager::USER_TYPE_KIOSK_APP, false},
239 {user_manager::USER_TYPE_CHILD, true},
240 {user_manager::USER_TYPE_ARC_KIOSK_APP, false},
241 {user_manager::USER_TYPE_ACTIVE_DIRECTORY, false},
242 };
243 for (const auto& test_case : kTestCases) {
244 const FakeUser user(test_case.user_type);
245 EXPECT_EQ(test_case.expected_allowed, IsArcAllowedForUser(&user))
246 << "User type=" << test_case.user_type;
247 }
248
249 // Active directory users are allowed when ARC is supported for active
250 // directory managed devices.
251 auto* command_line = base::CommandLine::ForCurrentProcess();
252 command_line->InitFromArgv(
253 {"", "--arc-availability=officially-supported-with-active-directory"});
hidehiko 2017/05/18 18:52:50 This is flag is being deprecated (as you looks reb
xiyuan 2017/05/22 20:58:18 Removed after rebase.
254 const FakeUser active_directory_user(
255 user_manager::USER_TYPE_ACTIVE_DIRECTORY);
256 EXPECT_TRUE(IsArcAllowedForUser(&active_directory_user));
257
258 // An ephemeral user is a logged in user but unknown to UserManager when
259 // ephemeral policy is set.
260 fake_user_manager.SetEphemeralUsersEnabled(true);
261 fake_user_manager.UserLoggedIn(AccountId::FromUserEmail("test@test.com"),
262 "test@test.com-hash", false);
263 const user_manager::User* ephemeral_user = fake_user_manager.GetActiveUser();
264 ASSERT_TRUE(ephemeral_user && fake_user_manager.IsUserCryptohomeDataEphemeral(
hidehiko 2017/05/18 18:52:50 nit/style: How about splitting two ASSERT_TRUEs? S
xiyuan 2017/05/22 20:58:18 Done.
265 ephemeral_user->GetAccountId()));
266
267 // Ephemeral user is not allowed for ARC.
268 EXPECT_FALSE(IsArcAllowedForUser(ephemeral_user));
269 }
270
185 } // namespace 271 } // namespace
186 } // namespace arc 272 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698