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

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_service_unittest.cc

Issue 2201493002: [Merge to M53] arc: Implement safe access to ArcAuthService. (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@2785
Patch Set: Created 4 years, 4 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 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/command_line.h" 10 #include "base/command_line.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 PrefService* const prefs = profile()->GetPrefs(); 142 PrefService* const prefs = profile()->GetPrefs();
143 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 143 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
144 prefs->SetBoolean(prefs::kArcEnabled, true); 144 prefs->SetBoolean(prefs::kArcEnabled, true);
145 145
146 chromeos::FakeChromeUserManager* const fake_user_manager = 146 chromeos::FakeChromeUserManager* const fake_user_manager =
147 GetFakeUserManager(); 147 GetFakeUserManager();
148 148
149 fake_user_manager->AddUser(fake_user_manager->GetGuestAccountId()); 149 fake_user_manager->AddUser(fake_user_manager->GetGuestAccountId());
150 fake_user_manager->SwitchActiveUser(fake_user_manager->GetGuestAccountId()); 150 fake_user_manager->SwitchActiveUser(fake_user_manager->GetGuestAccountId());
151 auth_service()->OnPrimaryUserProfilePrepared(profile()); 151 auth_service()->OnPrimaryUserProfilePrepared(profile());
152 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); 152 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
153 153
154 fake_user_manager->AddUser(chromeos::login::DemoAccountId()); 154 fake_user_manager->AddUser(chromeos::login::DemoAccountId());
155 fake_user_manager->SwitchActiveUser(chromeos::login::DemoAccountId()); 155 fake_user_manager->SwitchActiveUser(chromeos::login::DemoAccountId());
156 auth_service()->Shutdown(); 156 auth_service()->Shutdown();
157 auth_service()->OnPrimaryUserProfilePrepared(profile()); 157 auth_service()->OnPrimaryUserProfilePrepared(profile());
158 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); 158 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
159 159
160 const AccountId public_account_id( 160 const AccountId public_account_id(
161 AccountId::FromUserEmail("public_user@gmail.com")); 161 AccountId::FromUserEmail("public_user@gmail.com"));
162 fake_user_manager->AddPublicAccountUser(public_account_id); 162 fake_user_manager->AddPublicAccountUser(public_account_id);
163 fake_user_manager->SwitchActiveUser(public_account_id); 163 fake_user_manager->SwitchActiveUser(public_account_id);
164 auth_service()->Shutdown(); 164 auth_service()->Shutdown();
165 auth_service()->OnPrimaryUserProfilePrepared(profile()); 165 auth_service()->OnPrimaryUserProfilePrepared(profile());
166 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); 166 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
167 167
168 const AccountId not_in_list_account_id( 168 const AccountId not_in_list_account_id(
169 AccountId::FromUserEmail("not_in_list_user@gmail.com")); 169 AccountId::FromUserEmail("not_in_list_user@gmail.com"));
170 fake_user_manager->set_ephemeral_users_enabled(true);
170 fake_user_manager->AddUser(not_in_list_account_id); 171 fake_user_manager->AddUser(not_in_list_account_id);
171 fake_user_manager->SwitchActiveUser(not_in_list_account_id); 172 fake_user_manager->SwitchActiveUser(not_in_list_account_id);
172 fake_user_manager->RemoveUserFromList(not_in_list_account_id); 173 fake_user_manager->RemoveUserFromList(not_in_list_account_id);
173 auth_service()->Shutdown(); 174 auth_service()->Shutdown();
174 auth_service()->OnPrimaryUserProfilePrepared(profile()); 175 auth_service()->OnPrimaryUserProfilePrepared(profile());
175 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); 176 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
176 177
177 // Correctly stop service. 178 // Correctly stop service.
178 auth_service()->Shutdown(); 179 auth_service()->Shutdown();
179 } 180 }
180 181
181 TEST_F(ArcAuthServiceTest, BaseWorkflow) { 182 TEST_F(ArcAuthServiceTest, BaseWorkflow) {
182 ASSERT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); 183 ASSERT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state());
183 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); 184 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
184 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); 185 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode());
185 186
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 GetFakeUserManager()->AddPublicAccountUser(account_id); 324 GetFakeUserManager()->AddPublicAccountUser(account_id);
324 325
325 // Remove |profile_| to set the device local account be the primary account. 326 // Remove |profile_| to set the device local account be the primary account.
326 GetFakeUserManager()->RemoveUserFromList( 327 GetFakeUserManager()->RemoveUserFromList(
327 multi_user_util::GetAccountIdFromProfile(profile())); 328 multi_user_util::GetAccountIdFromProfile(profile()));
328 GetFakeUserManager()->LoginUser(account_id); 329 GetFakeUserManager()->LoginUser(account_id);
329 330
330 // Check that user without GAIA account can't use ARC. 331 // Check that user without GAIA account can't use ARC.
331 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 332 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
332 auth_service()->OnPrimaryUserProfilePrepared(device_local_profile.get()); 333 auth_service()->OnPrimaryUserProfilePrepared(device_local_profile.get());
333 EXPECT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); 334 EXPECT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
334 335
335 // Correctly stop service. 336 // Correctly stop service.
336 auth_service()->Shutdown(); 337 auth_service()->Shutdown();
337 } 338 }
338 339
339 TEST_F(ArcAuthServiceTest, DisabledForNonPrimaryProfile) { 340 TEST_F(ArcAuthServiceTest, DisabledForNonPrimaryProfile) {
340 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 341 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
341 auth_service()->OnPrimaryUserProfilePrepared(profile()); 342 auth_service()->OnPrimaryUserProfilePrepared(profile());
342 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); 343 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode);
343 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); 344 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state());
344 345
345 // Create a second profile and set it as the active profile. 346 // Create a second profile and set it as the active profile.
346 const std::string email = "test@exmaple.com"; 347 const std::string email = "test@exmaple.com";
347 TestingProfile::Builder profile_builder; 348 TestingProfile::Builder profile_builder;
348 profile_builder.SetProfileName(email); 349 profile_builder.SetProfileName(email);
349 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build()); 350 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build());
350 const AccountId account_id(AccountId::FromUserEmail(email)); 351 const AccountId account_id(AccountId::FromUserEmail(email));
351 GetFakeUserManager()->AddUser(account_id); 352 GetFakeUserManager()->AddUser(account_id);
352 GetFakeUserManager()->SwitchActiveUser(account_id); 353 GetFakeUserManager()->SwitchActiveUser(account_id);
353 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 354 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
354 355
355 // Check that non-primary user can't use Arc. 356 // Check that non-primary user can't use Arc.
356 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); 357 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get()));
357 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); 358 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get()));
358 359
359 auth_service()->Shutdown(); 360 auth_service()->Shutdown();
360 } 361 }
361 362
362 } // namespace arc 363 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.cc ('k') | chrome/browser/chromeos/arc/arc_support_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698