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

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc

Issue 2954293002: Chromad: Prevent session from starting without policy (Closed)
Patch Set: Move MockAuthPolicyClient into unittest Created 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const char kOAuth2AccessTokenData[] = 81 const char kOAuth2AccessTokenData[] =
82 "{" 82 "{"
83 " \"access_token\": \"5678\"," 83 " \"access_token\": \"5678\","
84 " \"expires_in\": 3600" 84 " \"expires_in\": 3600"
85 "}"; 85 "}";
86 86
87 class UserCloudPolicyManagerChromeOSTest : public testing::Test { 87 class UserCloudPolicyManagerChromeOSTest : public testing::Test {
88 public: 88 public:
89 // Note: This method has to be public, so that a pointer to it may be obtained 89 // Note: This method has to be public, so that a pointer to it may be obtained
90 // in the test. 90 // in the test.
91 void MakeManagerWithPreloadedStore(bool wait_for_fetch, 91 void MakeManagerWithPreloadedStore(int fetch_timeout_seconds) {
92 int fetch_timeout_seconds) {
93 std::unique_ptr<MockCloudPolicyStore> store = 92 std::unique_ptr<MockCloudPolicyStore> store =
94 base::MakeUnique<MockCloudPolicyStore>(); 93 base::MakeUnique<MockCloudPolicyStore>();
95 store->policy_.reset(new em::PolicyData(policy_data_)); 94 store->policy_.reset(new em::PolicyData(policy_data_));
96 store->policy_map_.CopyFrom(policy_map_); 95 store->policy_map_.CopyFrom(policy_map_);
97 store->NotifyStoreLoaded(); 96 store->NotifyStoreLoaded();
98 CreateManager(std::move(store), wait_for_fetch, fetch_timeout_seconds); 97 CreateManager(std::move(store), fetch_timeout_seconds);
99 // The manager gets already initialized by this point if the store is 98 // The manager gets already initialized by this point if the store is
100 // initialized and there is no blocking for policy fetch. 99 // initialized and there is no blocking for policy fetch.
101 EXPECT_NE(wait_for_fetch, 100 EXPECT_NE(fetch_timeout_seconds != 0,
102 manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 101 manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
103 InitAndConnectManager(); 102 InitAndConnectManager();
104 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 103 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
105 } 104 }
106 105
107 protected: 106 protected:
108 UserCloudPolicyManagerChromeOSTest() 107 UserCloudPolicyManagerChromeOSTest()
109 : store_(NULL), 108 : store_(NULL),
110 external_data_manager_(NULL), 109 external_data_manager_(NULL),
111 task_runner_(new base::TestSimpleTaskRunner()), 110 task_runner_(new base::TestSimpleTaskRunner()),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 token_forwarder_->Shutdown(); 171 token_forwarder_->Shutdown();
173 if (manager_) { 172 if (manager_) {
174 manager_->RemoveObserver(&observer_); 173 manager_->RemoveObserver(&observer_);
175 manager_->Shutdown(); 174 manager_->Shutdown();
176 } 175 }
177 signin_profile_ = NULL; 176 signin_profile_ = NULL;
178 profile_ = NULL; 177 profile_ = NULL;
179 profile_manager_->DeleteTestingProfile(chrome::kInitialProfile); 178 profile_manager_->DeleteTestingProfile(chrome::kInitialProfile);
180 } 179 }
181 180
182 void MakeManagerWithEmptyStore(bool wait_for_fetch, int fetch_timeout) { 181 void MakeManagerWithEmptyStore(int fetch_timeout) {
183 std::unique_ptr<MockCloudPolicyStore> store = 182 std::unique_ptr<MockCloudPolicyStore> store =
184 base::MakeUnique<MockCloudPolicyStore>(); 183 base::MakeUnique<MockCloudPolicyStore>();
185 EXPECT_CALL(*store, Load()); 184 EXPECT_CALL(*store, Load());
186 CreateManager(std::move(store), wait_for_fetch, fetch_timeout); 185 CreateManager(std::move(store), fetch_timeout);
187 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 186 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
188 InitAndConnectManager(); 187 InitAndConnectManager();
189 Mock::VerifyAndClearExpectations(store_); 188 Mock::VerifyAndClearExpectations(store_);
190 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 189 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
191 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 190 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
192 } 191 }
193 192
194 // Expects a pending URLFetcher for the |expected_url|, and returns it with 193 // Expects a pending URLFetcher for the |expected_url|, and returns it with
195 // prepared to deliver a response to its delegate. 194 // prepared to deliver a response to its delegate.
196 net::TestURLFetcher* PrepareOAuthFetcher(const GURL& expected_url) { 195 net::TestURLFetcher* PrepareOAuthFetcher(const GURL& expected_url) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // Required by ProfileHelper to get the signin Profile context. 331 // Required by ProfileHelper to get the signin Profile context.
333 std::unique_ptr<TestingProfileManager> profile_manager_; 332 std::unique_ptr<TestingProfileManager> profile_manager_;
334 TestingProfile* profile_; 333 TestingProfile* profile_;
335 TestingProfile* signin_profile_; 334 TestingProfile* signin_profile_;
336 335
337 chromeos::FakeChromeUserManager* user_manager_; 336 chromeos::FakeChromeUserManager* user_manager_;
338 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 337 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
339 338
340 private: 339 private:
341 void CreateManager(std::unique_ptr<MockCloudPolicyStore> store, 340 void CreateManager(std::unique_ptr<MockCloudPolicyStore> store,
342 bool wait_for_fetch,
343 int fetch_timeout_seconds) { 341 int fetch_timeout_seconds) {
344 store_ = store.get(); 342 store_ = store.get();
345 external_data_manager_ = new MockCloudExternalDataManager; 343 external_data_manager_ = new MockCloudExternalDataManager;
346 external_data_manager_->SetPolicyStore(store_); 344 external_data_manager_->SetPolicyStore(store_);
347 manager_.reset(new UserCloudPolicyManagerChromeOS( 345 manager_.reset(new UserCloudPolicyManagerChromeOS(
348 std::move(store), 346 std::move(store),
349 base::WrapUnique<MockCloudExternalDataManager>(external_data_manager_), 347 base::WrapUnique<MockCloudExternalDataManager>(external_data_manager_),
350 base::FilePath(), wait_for_fetch, 348 base::FilePath(), base::TimeDelta::FromSeconds(fetch_timeout_seconds),
351 base::TimeDelta::FromSeconds(fetch_timeout_seconds), task_runner_, 349 task_runner_, task_runner_, task_runner_));
352 task_runner_, task_runner_));
353 manager_->AddObserver(&observer_); 350 manager_->AddObserver(&observer_);
354 should_create_token_forwarder_ = !wait_for_fetch; 351 should_create_token_forwarder_ = (fetch_timeout_seconds == 0);
355 } 352 }
356 353
357 void InitAndConnectManager() { 354 void InitAndConnectManager() {
358 manager_->Init(&schema_registry_); 355 manager_->Init(&schema_registry_);
359 manager_->Connect(&prefs_, &device_management_service_, NULL); 356 manager_->Connect(&prefs_, &device_management_service_, NULL);
360 if (should_create_token_forwarder_) { 357 if (should_create_token_forwarder_) {
361 // Create the UserCloudPolicyTokenForwarder, which fetches the access 358 // Create the UserCloudPolicyTokenForwarder, which fetches the access
362 // token using the OAuth2PolicyFetcher and forwards it to the 359 // token using the OAuth2PolicyFetcher and forwards it to the
363 // UserCloudPolicyManagerChromeOS. This service is automatically created 360 // UserCloudPolicyManagerChromeOS. This service is automatically created
364 // for regular Profiles but not for testing Profiles. 361 // for regular Profiles but not for testing Profiles.
365 ProfileOAuth2TokenService* token_service = 362 ProfileOAuth2TokenService* token_service =
366 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 363 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
367 ASSERT_TRUE(token_service); 364 ASSERT_TRUE(token_service);
368 SigninManagerBase* signin_manager = 365 SigninManagerBase* signin_manager =
369 SigninManagerFactory::GetForProfile(profile_); 366 SigninManagerFactory::GetForProfile(profile_);
370 ASSERT_TRUE(signin_manager); 367 ASSERT_TRUE(signin_manager);
371 token_forwarder_.reset(new UserCloudPolicyTokenForwarder( 368 token_forwarder_.reset(new UserCloudPolicyTokenForwarder(
372 manager_.get(), token_service, signin_manager)); 369 manager_.get(), token_service, signin_manager));
373 } 370 }
374 } 371 }
375 372
376 bool should_create_token_forwarder_ = false; 373 bool should_create_token_forwarder_ = false;
377 374
378 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest); 375 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest);
379 }; 376 };
380 377
381 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFirstFetch) { 378 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFirstFetch) {
382 // Tests the initialization of a manager whose Profile is waiting for the 379 // Tests the initialization of a manager whose Profile is waiting for the
383 // initial fetch, when the policy cache is empty. 380 // initial fetch, when the policy cache is empty.
384 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(true, 1000)); 381 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(1000));
385 382
386 // Initialize the CloudPolicyService without any stored data. 383 // Initialize the CloudPolicyService without any stored data.
387 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 384 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
388 store_->NotifyStoreLoaded(); 385 store_->NotifyStoreLoaded();
389 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 386 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
390 EXPECT_FALSE(manager_->core()->client()->is_registered()); 387 EXPECT_FALSE(manager_->core()->client()->is_registered());
391 388
392 // This starts the OAuth2 policy token fetcher using the signin Profile. 389 // This starts the OAuth2 policy token fetcher using the signin Profile.
393 // The manager will then issue the registration request. 390 // The manager will then issue the registration request.
394 MockDeviceManagementJob* register_request = IssueOAuthToken(false); 391 MockDeviceManagementJob* register_request = IssueOAuthToken(false);
395 ASSERT_TRUE(register_request); 392 ASSERT_TRUE(register_request);
396 393
397 // Reply with a valid registration response. This triggers the initial policy 394 // Reply with a valid registration response. This triggers the initial policy
398 // fetch. 395 // fetch.
399 FetchPolicy(base::Bind(&MockDeviceManagementJob::SendResponse, 396 FetchPolicy(base::Bind(&MockDeviceManagementJob::SendResponse,
400 base::Unretained(register_request), 397 base::Unretained(register_request),
401 DM_STATUS_SUCCESS, register_blob_)); 398 DM_STATUS_SUCCESS, register_blob_));
402 } 399 }
403 400
404 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingRefreshFetch) { 401 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingRefreshFetch) {
405 // Tests the initialization of a manager whose Profile is waiting for the 402 // Tests the initialization of a manager whose Profile is waiting for the
406 // initial fetch, when a previously cached policy and DMToken already exist. 403 // initial fetch, when a previously cached policy and DMToken already exist.
407 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(true, 1000)); 404 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(1000));
408 405
409 // Set the initially cached data and initialize the CloudPolicyService. 406 // Set the initially cached data and initialize the CloudPolicyService.
410 // The initial policy fetch is issued using the cached DMToken. 407 // The initial policy fetch is issued using the cached DMToken.
411 store_->policy_.reset(new em::PolicyData(policy_data_)); 408 store_->policy_.reset(new em::PolicyData(policy_data_));
412 FetchPolicy(base::Bind(&MockCloudPolicyStore::NotifyStoreLoaded, 409 FetchPolicy(base::Bind(&MockCloudPolicyStore::NotifyStoreLoaded,
413 base::Unretained(store_))); 410 base::Unretained(store_)));
414 } 411 }
415 412
416 TEST_F(UserCloudPolicyManagerChromeOSTest, 413 TEST_F(UserCloudPolicyManagerChromeOSTest,
417 BlockingRefreshFetchWithPreloadedStore) { 414 BlockingRefreshFetchWithPreloadedStore) {
418 // Tests the initialization of a manager whose Profile is waiting for the 415 // Tests the initialization of a manager whose Profile is waiting for the
419 // initial fetch, when a previously cached policy and DMToken are already 416 // initial fetch, when a previously cached policy and DMToken are already
420 // loaded before the manager is constructed. The manager is still 417 // loaded before the manager is constructed. The manager is still
421 // uninitialized after the Init() call, despite that the store is already 418 // uninitialized after the Init() call, despite that the store is already
422 // initialized. The manager becomes initialized only after the policy is 419 // initialized. The manager becomes initialized only after the policy is
423 // fetched, and this is triggered from Connect() with the client registration 420 // fetched, and this is triggered from Connect() with the client registration
424 // performed by cloud policy service (as opposed to the registration normally 421 // performed by cloud policy service (as opposed to the registration normally
425 // performed by the manager). 422 // performed by the manager).
426 FetchPolicy(base::Bind( 423 FetchPolicy(base::Bind(
427 &UserCloudPolicyManagerChromeOSTest::MakeManagerWithPreloadedStore, 424 &UserCloudPolicyManagerChromeOSTest::MakeManagerWithPreloadedStore,
428 base::Unretained(this), true, 1000)); 425 base::Unretained(this), 1000));
429 } 426 }
430 427
431 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchStoreError) { 428 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchStoreError) {
432 // Tests the initialization of a manager whose Profile is waiting for the 429 // Tests the initialization of a manager whose Profile is waiting for the
433 // initial fetch, when the initial store load fails. 430 // initial fetch, when the initial store load fails.
434 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(true, 1000)); 431 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(1000));
435 432
436 // Initialize the CloudPolicyService without any stored data. 433 // Initialize the CloudPolicyService without any stored data.
437 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 434 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
438 store_->NotifyStoreError(); 435 store_->NotifyStoreError();
439 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 436 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
440 EXPECT_FALSE(manager_->core()->client()->is_registered()); 437 EXPECT_FALSE(manager_->core()->client()->is_registered());
441 438
442 // This starts the OAuth2 policy token fetcher using the signin Profile. 439 // This starts the OAuth2 policy token fetcher using the signin Profile.
443 // The manager will then issue the registration request. 440 // The manager will then issue the registration request.
444 MockDeviceManagementJob* register_request = IssueOAuthToken(false); 441 MockDeviceManagementJob* register_request = IssueOAuthToken(false);
445 ASSERT_TRUE(register_request); 442 ASSERT_TRUE(register_request);
446 443
447 // Reply with a valid registration response. This triggers the initial policy 444 // Reply with a valid registration response. This triggers the initial policy
448 // fetch. 445 // fetch.
449 FetchPolicy(base::Bind(&MockDeviceManagementJob::SendResponse, 446 FetchPolicy(base::Bind(&MockDeviceManagementJob::SendResponse,
450 base::Unretained(register_request), 447 base::Unretained(register_request),
451 DM_STATUS_SUCCESS, register_blob_)); 448 DM_STATUS_SUCCESS, register_blob_));
452 } 449 }
453 450
454 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchOAuthError) { 451 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchOAuthError) {
455 // Tests the initialization of a manager whose Profile is waiting for the 452 // Tests the initialization of a manager whose Profile is waiting for the
456 // initial fetch, when the OAuth2 token fetch fails. 453 // initial fetch, when the OAuth2 token fetch fails.
457 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(true, 1000)); 454 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(1000));
458 455
459 // Initialize the CloudPolicyService without any stored data. 456 // Initialize the CloudPolicyService without any stored data.
460 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 457 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
461 store_->NotifyStoreLoaded(); 458 store_->NotifyStoreLoaded();
462 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 459 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
463 EXPECT_FALSE(manager_->core()->client()->is_registered()); 460 EXPECT_FALSE(manager_->core()->client()->is_registered());
464 461
465 // This starts the OAuth2 policy token fetcher using the signin Profile. 462 // This starts the OAuth2 policy token fetcher using the signin Profile.
466 // The manager will initialize with no policy after the token fetcher fails. 463 // The manager will initialize with no policy after the token fetcher fails.
467 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 464 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
468 465
469 // The PolicyOAuth2TokenFetcher posts delayed retries on some errors. This 466 // The PolicyOAuth2TokenFetcher posts delayed retries on some errors. This
470 // data will make it fail immediately. 467 // data will make it fail immediately.
471 net::TestURLFetcher* fetcher = PrepareOAuthFetcher( 468 net::TestURLFetcher* fetcher = PrepareOAuthFetcher(
472 GaiaUrls::GetInstance()->client_login_to_oauth2_url()); 469 GaiaUrls::GetInstance()->client_login_to_oauth2_url());
473 ASSERT_TRUE(fetcher); 470 ASSERT_TRUE(fetcher);
474 fetcher->set_response_code(400); 471 fetcher->set_response_code(400);
475 fetcher->SetResponseString("Error=BadAuthentication"); 472 fetcher->SetResponseString("Error=BadAuthentication");
476 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 473 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
477 fetcher->delegate()->OnURLFetchComplete(fetcher); 474 fetcher->delegate()->OnURLFetchComplete(fetcher);
478 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 475 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
479 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies())); 476 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies()));
480 Mock::VerifyAndClearExpectations(&observer_); 477 Mock::VerifyAndClearExpectations(&observer_);
481 } 478 }
482 479
483 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchRegisterError) { 480 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchRegisterError) {
484 // Tests the initialization of a manager whose Profile is waiting for the 481 // Tests the initialization of a manager whose Profile is waiting for the
485 // initial fetch, when the device management registration fails. 482 // initial fetch, when the device management registration fails.
486 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(true, 1000)); 483 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(1000));
487 484
488 // Initialize the CloudPolicyService without any stored data. 485 // Initialize the CloudPolicyService without any stored data.
489 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 486 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
490 store_->NotifyStoreError(); 487 store_->NotifyStoreError();
491 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 488 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
492 EXPECT_FALSE(manager_->core()->client()->is_registered()); 489 EXPECT_FALSE(manager_->core()->client()->is_registered());
493 490
494 // This starts the OAuth2 policy token fetcher using the signin Profile. 491 // This starts the OAuth2 policy token fetcher using the signin Profile.
495 // The manager will then issue the registration request. 492 // The manager will then issue the registration request.
496 MockDeviceManagementJob* register_request = IssueOAuthToken(false); 493 MockDeviceManagementJob* register_request = IssueOAuthToken(false);
497 ASSERT_TRUE(register_request); 494 ASSERT_TRUE(register_request);
498 495
499 // Now make it fail. 496 // Now make it fail.
500 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 497 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
501 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 498 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
502 register_request->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE, 499 register_request->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE,
503 em::DeviceManagementResponse()); 500 em::DeviceManagementResponse());
504 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 501 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
505 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies())); 502 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies()));
506 Mock::VerifyAndClearExpectations(&observer_); 503 Mock::VerifyAndClearExpectations(&observer_);
507 } 504 }
508 505
509 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchPolicyFetchError) { 506 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchPolicyFetchError) {
510 // Tests the initialization of a manager whose Profile is waiting for the 507 // Tests the initialization of a manager whose Profile is waiting for the
511 // initial fetch, when the policy fetch request fails. 508 // initial fetch, when the policy fetch request fails.
512 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(true, 1000)); 509 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(1000));
513 510
514 // Initialize the CloudPolicyService without any stored data. 511 // Initialize the CloudPolicyService without any stored data.
515 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 512 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
516 store_->NotifyStoreLoaded(); 513 store_->NotifyStoreLoaded();
517 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 514 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
518 EXPECT_FALSE(manager_->core()->client()->is_registered()); 515 EXPECT_FALSE(manager_->core()->client()->is_registered());
519 516
520 // This starts the OAuth2 policy token fetcher using the signin Profile. 517 // This starts the OAuth2 policy token fetcher using the signin Profile.
521 // The manager will then issue the registration request. 518 // The manager will then issue the registration request.
522 MockDeviceManagementJob* register_request = IssueOAuthToken(false); 519 MockDeviceManagementJob* register_request = IssueOAuthToken(false);
(...skipping 18 matching lines...) Expand all
541 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())).Times(AtLeast(1)); 538 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())).Times(AtLeast(1));
542 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 539 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
543 policy_request->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE, 540 policy_request->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE,
544 em::DeviceManagementResponse()); 541 em::DeviceManagementResponse());
545 Mock::VerifyAndClearExpectations(&observer_); 542 Mock::VerifyAndClearExpectations(&observer_);
546 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 543 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
547 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies())); 544 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies()));
548 } 545 }
549 546
550 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchTimeout) { 547 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchTimeout) {
551 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(true, 1000)); 548 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(1000));
552 549
553 // Initialize the CloudPolicyService without any stored data. 550 // Initialize the CloudPolicyService without any stored data.
554 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 551 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
555 store_->NotifyStoreLoaded(); 552 store_->NotifyStoreLoaded();
556 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 553 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
557 EXPECT_FALSE(manager_->core()->client()->is_registered()); 554 EXPECT_FALSE(manager_->core()->client()->is_registered());
558 555
559 // Triggering the timeout should invoke our callback. 556 // Triggering the timeout should invoke our callback.
560 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())).Times(AtLeast(1)); 557 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())).Times(AtLeast(1));
561 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 558 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
562 manager_->ForceTimeoutForTest(); 559 manager_->ForceTimeoutForTest();
563 Mock::VerifyAndClearExpectations(&observer_); 560 Mock::VerifyAndClearExpectations(&observer_);
564 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 561 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
565 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies())); 562 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies()));
566 } 563 }
567 564
568 TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingFirstFetch) { 565 TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingFirstFetch) {
569 // Tests the first policy fetch request by a Profile that isn't managed. 566 // Tests the first policy fetch request by a Profile that isn't managed.
570 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(false, 0)); 567 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(0));
571 568
572 // Initialize the CloudPolicyService without any stored data. Since the 569 // Initialize the CloudPolicyService without any stored data. Since the
573 // manager is not waiting for the initial fetch, it will become initialized 570 // manager is not waiting for the initial fetch, it will become initialized
574 // once the store is ready. 571 // once the store is ready.
575 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 572 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
576 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 573 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
577 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 574 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
578 store_->NotifyStoreLoaded(); 575 store_->NotifyStoreLoaded();
579 Mock::VerifyAndClearExpectations(&observer_); 576 Mock::VerifyAndClearExpectations(&observer_);
580 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 577 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
(...skipping 25 matching lines...) Expand all
606 603
607 // The refresh scheduler takes care of the initial fetch for unmanaged users. 604 // The refresh scheduler takes care of the initial fetch for unmanaged users.
608 // Running the task runner issues the initial fetch. 605 // Running the task runner issues the initial fetch.
609 FetchPolicy( 606 FetchPolicy(
610 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_)); 607 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_));
611 } 608 }
612 609
613 TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingRefreshFetch) { 610 TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingRefreshFetch) {
614 // Tests a non-blocking initial policy fetch for a Profile that already has 611 // Tests a non-blocking initial policy fetch for a Profile that already has
615 // a cached DMToken. 612 // a cached DMToken.
616 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(false, 0)); 613 ASSERT_NO_FATAL_FAILURE(MakeManagerWithEmptyStore(0));
617 614
618 // Set the initially cached data and initialize the CloudPolicyService. 615 // Set the initially cached data and initialize the CloudPolicyService.
619 // The initial policy fetch is issued using the cached DMToken. 616 // The initial policy fetch is issued using the cached DMToken.
620 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 617 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
621 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 618 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
622 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 619 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
623 store_->policy_.reset(new em::PolicyData(policy_data_)); 620 store_->policy_.reset(new em::PolicyData(policy_data_));
624 store_->NotifyStoreLoaded(); 621 store_->NotifyStoreLoaded();
625 Mock::VerifyAndClearExpectations(&observer_); 622 Mock::VerifyAndClearExpectations(&observer_);
626 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 623 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
627 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 624 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
628 EXPECT_TRUE(manager_->core()->client()->is_registered()); 625 EXPECT_TRUE(manager_->core()->client()->is_registered());
629 626
630 // The refresh scheduler takes care of the initial fetch for unmanaged users. 627 // The refresh scheduler takes care of the initial fetch for unmanaged users.
631 // Running the task runner issues the initial fetch. 628 // Running the task runner issues the initial fetch.
632 FetchPolicy( 629 FetchPolicy(
633 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_)); 630 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_));
634 } 631 }
635 632
636 TEST_F(UserCloudPolicyManagerChromeOSTest, 633 TEST_F(UserCloudPolicyManagerChromeOSTest,
637 NonBlockingRefreshFetchWithPreloadedStore) { 634 NonBlockingRefreshFetchWithPreloadedStore) {
638 // Tests the initialization of a manager with non-blocking initial policy 635 // Tests the initialization of a manager with non-blocking initial policy
639 // fetch, when a previously cached policy and DMToken are already loaded 636 // fetch, when a previously cached policy and DMToken are already loaded
640 // before the manager is constructed. The manager gets initialized straight 637 // before the manager is constructed. The manager gets initialized straight
641 // away after the construction. 638 // away after the construction.
642 MakeManagerWithPreloadedStore(false, 0); 639 MakeManagerWithPreloadedStore(0);
643 EXPECT_TRUE(manager_->policies().Equals(expected_bundle_)); 640 EXPECT_TRUE(manager_->policies().Equals(expected_bundle_));
644 } 641 }
645 642
646 } // namespace policy 643 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698