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

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

Issue 2490093002: Migrate opt-in auth flow to re-auth flow. (Closed)
Patch Set: rebase Created 4 years, 1 month 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
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.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 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 26 matching lines...) Expand all
37 #include "components/user_manager/user_names.h" 37 #include "components/user_manager/user_names.h"
38 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
39 #include "content/public/test/test_browser_thread_bundle.h" 39 #include "content/public/test/test_browser_thread_bundle.h"
40 #include "google_apis/gaia/gaia_constants.h" 40 #include "google_apis/gaia/gaia_constants.h"
41 #include "google_apis/gaia/gaia_urls.h" 41 #include "google_apis/gaia/gaia_urls.h"
42 #include "net/http/http_status_code.h" 42 #include "net/http/http_status_code.h"
43 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
44 44
45 namespace arc { 45 namespace arc {
46 46
47 namespace {
48
49 const char kTestAuthCode[] = "4/Qa3CPIhh-WcMfWSf9HZaYcGUhEeax-F9sQK9CNRhZWs";
50
51 } // namespace
52
53 class ArcAuthServiceTest : public testing::Test { 47 class ArcAuthServiceTest : public testing::Test {
54 public: 48 public:
55 ArcAuthServiceTest() 49 ArcAuthServiceTest()
56 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 50 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
57 user_manager_enabler_(new chromeos::FakeChromeUserManager) {} 51 user_manager_enabler_(new chromeos::FakeChromeUserManager) {}
58 ~ArcAuthServiceTest() override = default; 52 ~ArcAuthServiceTest() override = default;
59 53
60 void SetUp() override { 54 void SetUp() override {
61 chromeos::DBusThreadManager::Initialize(); 55 chromeos::DBusThreadManager::Initialize();
62 56
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 auth_service()->OnPrimaryUserProfilePrepared(profile()); 173 auth_service()->OnPrimaryUserProfilePrepared(profile());
180 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); 174 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
181 175
182 // Correctly stop service. 176 // Correctly stop service.
183 auth_service()->Shutdown(); 177 auth_service()->Shutdown();
184 } 178 }
185 179
186 TEST_F(ArcAuthServiceTest, BaseWorkflow) { 180 TEST_F(ArcAuthServiceTest, BaseWorkflow) {
187 ASSERT_FALSE(bridge_service()->ready()); 181 ASSERT_FALSE(bridge_service()->ready());
188 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); 182 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
189 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode());
190 183
191 auth_service()->OnPrimaryUserProfilePrepared(profile()); 184 auth_service()->OnPrimaryUserProfilePrepared(profile());
192 185
193 // By default ARC is not enabled. 186 // By default ARC is not enabled.
194 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); 187 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state());
195 188
196 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 189 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
197 190
198 // Setting profile and pref initiates a code fetching process. 191 // Setting profile and pref initiates a code fetching process.
199 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, 192 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE,
200 auth_service()->state()); 193 auth_service()->state());
201 194
202 // TODO(hidehiko): Verify state transition from SHOWINING_TERMS_OF_SERVICE -> 195 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE ->
203 // CHECKING_ANDROID_MANAGEMENT -> FETCHING_CODE, when we extract 196 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager.
204 // ArcSessionManager. 197 auth_service()->StartArc();
205 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode);
206 198
207 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); 199 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state());
208 ASSERT_TRUE(bridge_service()->ready()); 200 ASSERT_TRUE(bridge_service()->ready());
209 // Auth code valid only for one call.
210 ASSERT_EQ(kTestAuthCode, auth_service()->GetAndResetAuthCode());
211 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode());
212 201
213 auth_service()->Shutdown(); 202 auth_service()->Shutdown();
214 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); 203 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
215 ASSERT_FALSE(bridge_service()->ready()); 204 ASSERT_FALSE(bridge_service()->ready());
216 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode());
217 205
218 // Send profile and don't provide a code. 206 // Send profile and don't provide a code.
219 auth_service()->OnPrimaryUserProfilePrepared(profile()); 207 auth_service()->OnPrimaryUserProfilePrepared(profile());
220 208
221 // Setting profile initiates a code fetching process. 209 // Setting profile initiates a code fetching process.
222 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, 210 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE,
223 auth_service()->state()); 211 auth_service()->state());
224 212
225 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 213 content::BrowserThread::GetBlockingPool()->FlushForTesting();
226 base::RunLoop().RunUntilIdle(); 214 base::RunLoop().RunUntilIdle();
(...skipping 21 matching lines...) Expand all
248 // Correctly stop service. 236 // Correctly stop service.
249 auth_service()->Shutdown(); 237 auth_service()->Shutdown();
250 } 238 }
251 239
252 TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { 240 TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) {
253 PrefService* const pref = profile()->GetPrefs(); 241 PrefService* const pref = profile()->GetPrefs();
254 242
255 auth_service()->OnPrimaryUserProfilePrepared(profile()); 243 auth_service()->OnPrimaryUserProfilePrepared(profile());
256 pref->SetBoolean(prefs::kArcEnabled, true); 244 pref->SetBoolean(prefs::kArcEnabled, true);
257 245
258 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); 246 auth_service()->StartArc();
259 247
260 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); 248 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state());
261 249
262 auth_service()->CancelAuthCode(); 250 auth_service()->CancelAuthCode();
263 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); 251 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state());
264 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); 252 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled));
265 253
266 // Correctly stop service. 254 // Correctly stop service.
267 auth_service()->Shutdown(); 255 auth_service()->Shutdown();
268 } 256 }
(...skipping 14 matching lines...) Expand all
283 271
284 TEST_F(ArcAuthServiceTest, SignInStatus) { 272 TEST_F(ArcAuthServiceTest, SignInStatus) {
285 PrefService* const prefs = profile()->GetPrefs(); 273 PrefService* const prefs = profile()->GetPrefs();
286 274
287 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 275 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
288 prefs->SetBoolean(prefs::kArcEnabled, true); 276 prefs->SetBoolean(prefs::kArcEnabled, true);
289 277
290 auth_service()->OnPrimaryUserProfilePrepared(profile()); 278 auth_service()->OnPrimaryUserProfilePrepared(profile());
291 EXPECT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, 279 EXPECT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE,
292 auth_service()->state()); 280 auth_service()->state());
293 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); 281 auth_service()->StartArc();
294 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); 282 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state());
295 EXPECT_TRUE(bridge_service()->ready()); 283 EXPECT_TRUE(bridge_service()->ready());
296 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 284 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
297 auth_service()->OnSignInComplete(); 285 auth_service()->OnSignInComplete();
298 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); 286 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
299 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); 287 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state());
300 EXPECT_TRUE(bridge_service()->ready()); 288 EXPECT_TRUE(bridge_service()->ready());
301 289
302 // Second start, no fetching code is expected. 290 // Second start, no fetching code is expected.
303 auth_service()->Shutdown(); 291 auth_service()->Shutdown();
(...skipping 15 matching lines...) Expand all
319 307
320 // Correctly stop service. 308 // Correctly stop service.
321 auth_service()->Shutdown(); 309 auth_service()->Shutdown();
322 } 310 }
323 311
324 TEST_F(ArcAuthServiceTest, DisabledForDeviceLocalAccount) { 312 TEST_F(ArcAuthServiceTest, DisabledForDeviceLocalAccount) {
325 PrefService* const prefs = profile()->GetPrefs(); 313 PrefService* const prefs = profile()->GetPrefs();
326 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 314 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
327 prefs->SetBoolean(prefs::kArcEnabled, true); 315 prefs->SetBoolean(prefs::kArcEnabled, true);
328 auth_service()->OnPrimaryUserProfilePrepared(profile()); 316 auth_service()->OnPrimaryUserProfilePrepared(profile());
329 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); 317 auth_service()->StartArc();
330 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); 318 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state());
331 319
332 // Create device local account and set it as active. 320 // Create device local account and set it as active.
333 const std::string email = "device-local-account@fake-email.com"; 321 const std::string email = "device-local-account@fake-email.com";
334 TestingProfile::Builder profile_builder; 322 TestingProfile::Builder profile_builder;
335 profile_builder.SetProfileName(email); 323 profile_builder.SetProfileName(email);
336 std::unique_ptr<TestingProfile> device_local_profile(profile_builder.Build()); 324 std::unique_ptr<TestingProfile> device_local_profile(profile_builder.Build());
337 const AccountId account_id(AccountId::FromUserEmail(email)); 325 const AccountId account_id(AccountId::FromUserEmail(email));
338 GetFakeUserManager()->AddPublicAccountUser(account_id); 326 GetFakeUserManager()->AddPublicAccountUser(account_id);
339 327
340 // Remove |profile_| to set the device local account be the primary account. 328 // Remove |profile_| to set the device local account be the primary account.
341 GetFakeUserManager()->RemoveUserFromList( 329 GetFakeUserManager()->RemoveUserFromList(
342 multi_user_util::GetAccountIdFromProfile(profile())); 330 multi_user_util::GetAccountIdFromProfile(profile()));
343 GetFakeUserManager()->LoginUser(account_id); 331 GetFakeUserManager()->LoginUser(account_id);
344 332
345 // Check that user without GAIA account can't use ARC. 333 // Check that user without GAIA account can't use ARC.
346 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 334 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
347 auth_service()->OnPrimaryUserProfilePrepared(device_local_profile.get()); 335 auth_service()->OnPrimaryUserProfilePrepared(device_local_profile.get());
348 EXPECT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); 336 EXPECT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state());
349 337
350 // Correctly stop service. 338 // Correctly stop service.
351 auth_service()->Shutdown(); 339 auth_service()->Shutdown();
352 } 340 }
353 341
354 TEST_F(ArcAuthServiceTest, DisabledForNonPrimaryProfile) { 342 TEST_F(ArcAuthServiceTest, DisabledForNonPrimaryProfile) {
355 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 343 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
356 auth_service()->OnPrimaryUserProfilePrepared(profile()); 344 auth_service()->OnPrimaryUserProfilePrepared(profile());
357 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); 345 auth_service()->StartArc();
358 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); 346 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state());
359 347
360 // Create a second profile and set it as the active profile. 348 // Create a second profile and set it as the active profile.
361 const std::string email = "test@example.com"; 349 const std::string email = "test@example.com";
362 TestingProfile::Builder profile_builder; 350 TestingProfile::Builder profile_builder;
363 profile_builder.SetProfileName(email); 351 profile_builder.SetProfileName(email);
364 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build()); 352 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build());
365 const AccountId account_id(AccountId::FromUserEmail(email)); 353 const AccountId account_id(AccountId::FromUserEmail(email));
366 GetFakeUserManager()->AddUser(account_id); 354 GetFakeUserManager()->AddUser(account_id);
367 GetFakeUserManager()->SwitchActiveUser(account_id); 355 GetFakeUserManager()->SwitchActiveUser(account_id);
368 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 356 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
369 357
370 // Check that non-primary user can't use Arc. 358 // Check that non-primary user can't use Arc.
371 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); 359 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get()));
372 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); 360 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get()));
373 361
374 auth_service()->Shutdown(); 362 auth_service()->Shutdown();
375 } 363 }
376 364
377 } // namespace arc 365 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698