OLD | NEW |
---|---|
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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/browser/policy/browser_policy_connector.h" | 10 #include "chrome/browser/policy/browser_policy_connector.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 " \"access_token\": \"at1\"," | 53 " \"access_token\": \"at1\"," |
54 " \"expires_in\": 3600," | 54 " \"expires_in\": 3600," |
55 " \"token_type\": \"Bearer\"" | 55 " \"token_type\": \"Bearer\"" |
56 "}"; | 56 "}"; |
57 | 57 |
58 static const char kHostedDomainResponse[] = | 58 static const char kHostedDomainResponse[] = |
59 "{" | 59 "{" |
60 " \"hd\": \"test.com\"" | 60 " \"hd\": \"test.com\"" |
61 "}"; | 61 "}"; |
62 | 62 |
63 namespace { | |
64 class SigninManagerFake : public FakeSigninManager { | |
65 public: | |
66 explicit SigninManagerFake(Profile* profile) | |
67 : FakeSigninManager(profile) { | |
68 } | |
69 | |
70 void ForceSignOut() { | |
71 // Allow signing out now. | |
72 prohibit_signout_ = false; | |
73 SignOut(); | |
74 } | |
75 | |
76 static ProfileKeyedService* Build(Profile* profile) { | |
77 return new SigninManagerFake(profile); | |
78 } | |
Andrew T Wilson (Slow)
2013/04/09 15:39:25
Wrong indent.
tim (not reviewing)
2013/04/16 03:28:29
Done.
| |
79 }; | |
80 } // namespace | |
81 | |
63 class UserPolicySigninServiceTest : public testing::Test { | 82 class UserPolicySigninServiceTest : public testing::Test { |
64 public: | 83 public: |
65 UserPolicySigninServiceTest() | 84 UserPolicySigninServiceTest() |
66 : loop_(MessageLoop::TYPE_IO), | 85 : loop_(MessageLoop::TYPE_IO), |
67 ui_thread_(content::BrowserThread::UI, &loop_), | 86 ui_thread_(content::BrowserThread::UI, &loop_), |
68 file_thread_(content::BrowserThread::FILE, &loop_), | 87 file_thread_(content::BrowserThread::FILE, &loop_), |
69 io_thread_(content::BrowserThread::IO, &loop_), | 88 io_thread_(content::BrowserThread::IO, &loop_), |
70 register_completed_(false) {} | 89 register_completed_(false) {} |
71 | 90 |
72 MOCK_METHOD1(OnPolicyRefresh, void(bool)); | 91 MOCK_METHOD1(OnPolicyRefresh, void(bool)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 chrome::RegisterUserPrefs(prefs->registry()); | 125 chrome::RegisterUserPrefs(prefs->registry()); |
107 TestingProfile::Builder builder; | 126 TestingProfile::Builder builder; |
108 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass())); | 127 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass())); |
109 profile_ = builder.Build().Pass(); | 128 profile_ = builder.Build().Pass(); |
110 profile_->CreateRequestContext(); | 129 profile_->CreateRequestContext(); |
111 | 130 |
112 mock_store_ = new MockUserCloudPolicyStore(); | 131 mock_store_ = new MockUserCloudPolicyStore(); |
113 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber()); | 132 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber()); |
114 manager_.reset(new UserCloudPolicyManager( | 133 manager_.reset(new UserCloudPolicyManager( |
115 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_))); | 134 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_))); |
116 signin_manager_ = static_cast<FakeSigninManager*>( | 135 signin_manager_ = static_cast<SigninManagerFake*>( |
117 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 136 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
118 profile_.get(), FakeSigninManager::Build)); | 137 profile_.get(), SigninManagerFake::Build)); |
119 | 138 |
120 // Make sure the UserPolicySigninService is created. | 139 // Make sure the UserPolicySigninService is created. |
121 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); | 140 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); |
122 Mock::VerifyAndClearExpectations(mock_store_); | 141 Mock::VerifyAndClearExpectations(mock_store_); |
123 url_factory_.set_remove_fetcher_on_delete(true); | 142 url_factory_.set_remove_fetcher_on_delete(true); |
124 } | 143 } |
125 | 144 |
126 virtual void TearDown() OVERRIDE { | 145 virtual void TearDown() OVERRIDE { |
127 // Free the profile before we clear out the browser prefs. | 146 // Free the profile before we clear out the browser prefs. |
128 profile_.reset(); | 147 profile_.reset(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 | 263 |
245 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free | 264 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free |
246 // various components asynchronously via tasks, so create fake threads here. | 265 // various components asynchronously via tasks, so create fake threads here. |
247 MessageLoop loop_; | 266 MessageLoop loop_; |
248 content::TestBrowserThread ui_thread_; | 267 content::TestBrowserThread ui_thread_; |
249 content::TestBrowserThread file_thread_; | 268 content::TestBrowserThread file_thread_; |
250 content::TestBrowserThread io_thread_; | 269 content::TestBrowserThread io_thread_; |
251 | 270 |
252 net::TestURLFetcherFactory url_factory_; | 271 net::TestURLFetcherFactory url_factory_; |
253 | 272 |
254 FakeSigninManager* signin_manager_; | 273 SigninManagerFake* signin_manager_; |
255 | 274 |
256 // Used in conjunction with OnRegisterCompleted() to test client registration | 275 // Used in conjunction with OnRegisterCompleted() to test client registration |
257 // callbacks. | 276 // callbacks. |
258 scoped_ptr<CloudPolicyClient> created_client_; | 277 scoped_ptr<CloudPolicyClient> created_client_; |
259 | 278 |
260 // True if OnRegisterCompleted() was called. | 279 // True if OnRegisterCompleted() was called. |
261 bool register_completed_; | 280 bool register_completed_; |
262 | 281 |
263 // Weak ptr to the MockDeviceManagementService (object is owned by the | 282 // Weak ptr to the MockDeviceManagementService (object is owned by the |
264 // BrowserPolicyConnector). | 283 // BrowserPolicyConnector). |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 signin_manager_->ForceSignOut(); | 651 signin_manager_->ForceSignOut(); |
633 ASSERT_FALSE(manager_->core()->service()); | 652 ASSERT_FALSE(manager_->core()->service()); |
634 | 653 |
635 // Now sign in again. | 654 // Now sign in again. |
636 TestSuccessfulSignin(); | 655 TestSuccessfulSignin(); |
637 } | 656 } |
638 | 657 |
639 } // namespace | 658 } // namespace |
640 | 659 |
641 } // namespace policy | 660 } // namespace policy |
OLD | NEW |