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

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

Issue 1108983002: Fetch policy with refresh token. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix user_cloud_policy_manager_chromeos_unittest Created 5 years, 7 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/testing_pref_service.h" 12 #include "base/prefs/testing_pref_service.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/test/test_simple_task_runner.h" 17 #include "base/test/test_simple_task_runner.h"
18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
18 #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h" 19 #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h"
19 #include "chrome/browser/chromeos/profiles/profile_helper.h" 20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
20 #include "chrome/browser/prefs/browser_prefs.h" 21 #include "chrome/browser/prefs/browser_prefs.h"
21 #include "chrome/browser/prefs/pref_service_syncable.h" 22 #include "chrome/browser/prefs/pref_service_syncable.h"
22 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 23 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
23 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 24 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
25 #include "chrome/browser/signin/signin_manager_factory.h" 26 #include "chrome/browser/signin/signin_manager_factory.h"
26 #include "chrome/common/chrome_constants.h" 27 #include "chrome/common/chrome_constants.h"
27 #include "chrome/test/base/testing_browser_process.h" 28 #include "chrome/test/base/testing_browser_process.h"
28 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
29 #include "chrome/test/base/testing_profile_manager.h" 30 #include "chrome/test/base/testing_profile_manager.h"
30 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" 31 #include "components/policy/core/common/cloud/cloud_external_data_manager.h"
31 #include "components/policy/core/common/cloud/mock_cloud_external_data_manager.h " 32 #include "components/policy/core/common/cloud/mock_cloud_external_data_manager.h "
32 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" 33 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
33 #include "components/policy/core/common/cloud/mock_device_management_service.h" 34 #include "components/policy/core/common/cloud/mock_device_management_service.h"
34 #include "components/policy/core/common/external_data_fetcher.h" 35 #include "components/policy/core/common/external_data_fetcher.h"
35 #include "components/policy/core/common/mock_configuration_policy_provider.h" 36 #include "components/policy/core/common/mock_configuration_policy_provider.h"
36 #include "components/policy/core/common/schema_registry.h" 37 #include "components/policy/core/common/schema_registry.h"
37 #include "components/signin/core/browser/profile_oauth2_token_service.h" 38 #include "components/signin/core/browser/profile_oauth2_token_service.h"
38 #include "components/signin/core/browser/signin_manager.h" 39 #include "components/signin/core/browser/signin_manager.h"
40 #include "components/user_manager/fake_user_manager.h"
39 #include "content/public/test/test_browser_thread_bundle.h" 41 #include "content/public/test/test_browser_thread_bundle.h"
40 #include "google_apis/gaia/gaia_auth_consumer.h" 42 #include "google_apis/gaia/gaia_auth_consumer.h"
41 #include "google_apis/gaia/gaia_constants.h" 43 #include "google_apis/gaia/gaia_constants.h"
42 #include "google_apis/gaia/gaia_urls.h" 44 #include "google_apis/gaia/gaia_urls.h"
43 #include "net/url_request/test_url_fetcher_factory.h" 45 #include "net/url_request/test_url_fetcher_factory.h"
44 #include "net/url_request/url_fetcher_delegate.h" 46 #include "net/url_request/url_fetcher_delegate.h"
45 #include "net/url_request/url_request_context_getter.h" 47 #include "net/url_request/url_request_context_getter.h"
46 #include "net/url_request/url_request_status.h" 48 #include "net/url_request/url_request_status.h"
47 #include "policy/policy_constants.h" 49 #include "policy/policy_constants.h"
48 #include "policy/proto/device_management_backend.pb.h" 50 #include "policy/proto/device_management_backend.pb.h"
(...skipping 24 matching lines...) Expand all
73 " \"expires_in\": 3600" 75 " \"expires_in\": 3600"
74 "}"; 76 "}";
75 77
76 class UserCloudPolicyManagerChromeOSTest : public testing::Test { 78 class UserCloudPolicyManagerChromeOSTest : public testing::Test {
77 protected: 79 protected:
78 UserCloudPolicyManagerChromeOSTest() 80 UserCloudPolicyManagerChromeOSTest()
79 : store_(NULL), 81 : store_(NULL),
80 external_data_manager_(NULL), 82 external_data_manager_(NULL),
81 task_runner_(new base::TestSimpleTaskRunner()), 83 task_runner_(new base::TestSimpleTaskRunner()),
82 profile_(NULL), 84 profile_(NULL),
83 signin_profile_(NULL) {} 85 signin_profile_(NULL),
86 user_manager_(new user_manager::FakeUserManager()),
87 user_manager_enabler_(user_manager_) {}
84 88
85 void SetUp() override { 89 void SetUp() override {
86 // The initialization path that blocks on the initial policy fetch requires 90 // The initialization path that blocks on the initial policy fetch requires
87 // a signin Profile to use its URLRequestContext. 91 // a signin Profile to use its URLRequestContext.
88 profile_manager_.reset( 92 profile_manager_.reset(
89 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 93 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
90 ASSERT_TRUE(profile_manager_->SetUp()); 94 ASSERT_TRUE(profile_manager_->SetUp());
91 TestingProfile::TestingFactories factories; 95 TestingProfile::TestingFactories factories;
92 factories.push_back( 96 factories.push_back(
93 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), 97 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(),
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 339 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
336 SchemaRegistry schema_registry_; 340 SchemaRegistry schema_registry_;
337 scoped_ptr<UserCloudPolicyManagerChromeOS> manager_; 341 scoped_ptr<UserCloudPolicyManagerChromeOS> manager_;
338 scoped_ptr<UserCloudPolicyTokenForwarder> token_forwarder_; 342 scoped_ptr<UserCloudPolicyTokenForwarder> token_forwarder_;
339 343
340 // Required by ProfileHelper to get the signin Profile context. 344 // Required by ProfileHelper to get the signin Profile context.
341 scoped_ptr<TestingProfileManager> profile_manager_; 345 scoped_ptr<TestingProfileManager> profile_manager_;
342 TestingProfile* profile_; 346 TestingProfile* profile_;
343 TestingProfile* signin_profile_; 347 TestingProfile* signin_profile_;
344 348
349 user_manager::FakeUserManager* user_manager_;
350 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
351
345 private: 352 private:
346 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest); 353 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest);
347 }; 354 };
348 355
349 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFirstFetch) { 356 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFirstFetch) {
350 // Tests the initialization of a manager whose Profile is waiting for the 357 // Tests the initialization of a manager whose Profile is waiting for the
351 // initial fetch, when the policy cache is empty. 358 // initial fetch, when the policy cache is empty.
352 ASSERT_NO_FATAL_FAILURE(CreateManager(true, 1000)); 359 ASSERT_NO_FATAL_FAILURE(CreateManager(true, 1000));
353 360
354 // Initialize the CloudPolicyService without any stored data. 361 // Initialize the CloudPolicyService without any stored data.
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 589 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
583 EXPECT_TRUE(manager_->core()->client()->is_registered()); 590 EXPECT_TRUE(manager_->core()->client()->is_registered());
584 591
585 // The refresh scheduler takes care of the initial fetch for unmanaged users. 592 // The refresh scheduler takes care of the initial fetch for unmanaged users.
586 // Running the task runner issues the initial fetch. 593 // Running the task runner issues the initial fetch.
587 FetchPolicy( 594 FetchPolicy(
588 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_)); 595 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_));
589 } 596 }
590 597
591 } // namespace policy 598 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698