OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 15 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
16 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 16 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
18 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | |
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
19 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 20 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
22 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
24 #include "chromeos/login/user_names.h" | |
23 #include "components/arc/arc_bridge_service.h" | 25 #include "components/arc/arc_bridge_service.h" |
24 #include "components/arc/test/fake_arc_bridge_service.h" | 26 #include "components/arc/test/fake_arc_bridge_service.h" |
25 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
26 #include "components/signin/core/account_id/account_id.h" | 28 #include "components/signin/core/account_id/account_id.h" |
27 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 29 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
28 #include "components/user_manager/user_manager.h" | 30 #include "components/user_manager/user_manager.h" |
29 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/test/test_browser_thread_bundle.h" | 32 #include "content/public/test/test_browser_thread_bundle.h" |
31 #include "google_apis/gaia/gaia_constants.h" | 33 #include "google_apis/gaia/gaia_constants.h" |
32 #include "google_apis/gaia/gaia_urls.h" | 34 #include "google_apis/gaia/gaia_urls.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 // Check initial conditions. | 69 // Check initial conditions. |
68 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); | 70 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); |
69 EXPECT_EQ(true, !ArcBridgeService::Get()->available()); | 71 EXPECT_EQ(true, !ArcBridgeService::Get()->available()); |
70 EXPECT_EQ(ArcBridgeService::State::STOPPED, | 72 EXPECT_EQ(ArcBridgeService::State::STOPPED, |
71 ArcBridgeService::Get()->state()); | 73 ArcBridgeService::Get()->state()); |
72 | 74 |
73 const AccountId account_id( | 75 const AccountId account_id( |
74 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890")); | 76 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890")); |
75 GetFakeUserManager()->AddUser(account_id); | 77 GetFakeUserManager()->AddUser(account_id); |
76 GetFakeUserManager()->LoginUser(account_id); | 78 GetFakeUserManager()->LoginUser(account_id); |
79 | |
80 chromeos::WallpaperManager::Initialize(); | |
77 } | 81 } |
78 | 82 |
79 void TearDown() override {} | 83 void TearDown() override {} |
80 | 84 |
81 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 85 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
82 return static_cast<chromeos::FakeChromeUserManager*>( | 86 return static_cast<chromeos::FakeChromeUserManager*>( |
83 user_manager::UserManager::Get()); | 87 user_manager::UserManager::Get()); |
84 } | 88 } |
85 | 89 |
86 protected: | 90 protected: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 pref->SetBoolean(prefs::kArcEnabled, true); | 125 pref->SetBoolean(prefs::kArcEnabled, true); |
122 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 126 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
123 | 127 |
124 pref->SetBoolean(prefs::kArcEnabled, false); | 128 pref->SetBoolean(prefs::kArcEnabled, false); |
125 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 129 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
126 | 130 |
127 // Correctly stop service. | 131 // Correctly stop service. |
128 auth_service()->Shutdown(); | 132 auth_service()->Shutdown(); |
129 } | 133 } |
130 | 134 |
135 TEST_F(ArcAuthServiceTest, DisabledForEphemeralDataUsers) { | |
136 PrefService* prefs = profile()->GetPrefs(); | |
peletskyi
2016/04/28 12:00:55
nit: PrefService* const
Roman Sorokin (ftl)
2016/04/28 13:27:58
Done.
| |
137 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | |
138 prefs->SetBoolean(prefs::kArcEnabled, true); | |
139 | |
140 chromeos::FakeChromeUserManager* fake_user_manager = GetFakeUserManager(); | |
peletskyi
2016/04/28 12:00:55
FakeChromeUserManager* const
Roman Sorokin (ftl)
2016/04/28 13:27:58
Done.
| |
141 | |
142 fake_user_manager->AddUser(fake_user_manager->GetGuestAccountId()); | |
143 fake_user_manager->SwitchActiveUser(fake_user_manager->GetGuestAccountId()); | |
144 auth_service()->OnPrimaryUserProfilePrepared(profile()); | |
145 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | |
146 | |
147 fake_user_manager->AddUser(chromeos::login::DemoAccountId()); | |
148 fake_user_manager->SwitchActiveUser(chromeos::login::DemoAccountId()); | |
149 auth_service()->OnPrimaryUserProfilePrepared(profile()); | |
150 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | |
151 | |
152 const AccountId public_account_id( | |
153 AccountId::FromUserEmail("public_user@gmail.com")); | |
154 fake_user_manager->AddPublicAccountUser(public_account_id); | |
155 fake_user_manager->SwitchActiveUser(public_account_id); | |
156 auth_service()->OnPrimaryUserProfilePrepared(profile()); | |
157 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | |
158 | |
159 const AccountId not_in_list_account_id( | |
160 AccountId::FromUserEmail("not_in_list_user@gmail.com")); | |
161 fake_user_manager->AddUser(not_in_list_account_id); | |
162 fake_user_manager->SwitchActiveUser(not_in_list_account_id); | |
163 fake_user_manager->RemoveUserFromList(not_in_list_account_id); | |
164 auth_service()->OnPrimaryUserProfilePrepared(profile()); | |
165 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | |
166 | |
167 // Correctly stop service. | |
168 auth_service()->Shutdown(); | |
169 } | |
170 | |
131 TEST_F(ArcAuthServiceTest, BaseWorkflow) { | 171 TEST_F(ArcAuthServiceTest, BaseWorkflow) { |
132 ASSERT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); | 172 ASSERT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); |
133 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 173 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
134 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); | 174 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
135 | 175 |
136 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 176 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
137 | 177 |
138 // By default ARC is not enabled. | 178 // By default ARC is not enabled. |
139 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 179 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
140 | 180 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 | 312 |
273 // Check that user without GAIA account can't use ARC. | 313 // Check that user without GAIA account can't use ARC. |
274 auth_service()->OnPrimaryUserProfilePrepared(device_local_profile.get()); | 314 auth_service()->OnPrimaryUserProfilePrepared(device_local_profile.get()); |
275 EXPECT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 315 EXPECT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
276 | 316 |
277 // Correctly stop service. | 317 // Correctly stop service. |
278 auth_service()->Shutdown(); | 318 auth_service()->Shutdown(); |
279 } | 319 } |
280 | 320 |
281 } // namespace arc | 321 } // namespace arc |
OLD | NEW |