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

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

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