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

Side by Side Diff: chrome/browser/policy/cloud_policy_browsertest.cc

Issue 11415094: Split UserCloudPolicyManager implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Crazy ProfileKeyedService hackery. Created 8 years 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 | Annotate | Revision Log
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 "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/policy/browser_policy_connector.h" 15 #include "chrome/browser/policy/browser_policy_connector.h"
16 #include "chrome/browser/policy/cloud_policy_client.h" 16 #include "chrome/browser/policy/cloud_policy_client.h"
17 #include "chrome/browser/policy/cloud_policy_data_store.h" 17 #include "chrome/browser/policy/cloud_policy_data_store.h"
18 #include "chrome/browser/policy/policy_map.h" 18 #include "chrome/browser/policy/policy_map.h"
19 #include "chrome/browser/policy/policy_service.h" 19 #include "chrome/browser/policy/policy_service.h"
20 #include "chrome/browser/policy/user_cloud_policy_manager.h"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
23 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
25 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
26 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
29 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
30 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
31 #include "net/test/test_server.h" 30 #include "net/test/test_server.h"
32 #include "policy/policy_constants.h" 31 #include "policy/policy_constants.h"
33 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
35 34
36 #if defined(OS_CHROMEOS) 35 #if defined(OS_CHROMEOS)
37 #include "chrome/browser/chromeos/login/user_manager.h" 36 #include "chrome/browser/chromeos/login/user_manager.h"
37 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h"
38 #else 38 #else
39 #include "chrome/browser/policy/user_cloud_policy_manager.h"
40 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h"
39 #include "chrome/browser/signin/signin_manager.h" 41 #include "chrome/browser/signin/signin_manager.h"
40 #include "chrome/browser/signin/signin_manager_factory.h" 42 #include "chrome/browser/signin/signin_manager_factory.h"
41 #endif 43 #endif
42 44
43 using testing::InvokeWithoutArgs; 45 using testing::InvokeWithoutArgs;
44 using testing::Mock; 46 using testing::Mock;
45 using testing::_; 47 using testing::_;
46 48
47 namespace policy { 49 namespace policy {
48 50
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 116 }
115 #endif 117 #endif
116 118
117 void SetUpNewStackBeforeCreatingBrowser() { 119 void SetUpNewStackBeforeCreatingBrowser() {
118 CommandLine* command_line = CommandLine::ForCurrentProcess(); 120 CommandLine* command_line = CommandLine::ForCurrentProcess();
119 command_line->AppendSwitch(switches::kEnableCloudPolicyService); 121 command_line->AppendSwitch(switches::kEnableCloudPolicyService);
120 command_line->AppendSwitch(switches::kLoadCloudPolicyOnSignin); 122 command_line->AppendSwitch(switches::kLoadCloudPolicyOnSignin);
121 } 123 }
122 124
123 void SetUpNewStackAfterCreatingBrowser(Browser* browser) { 125 void SetUpNewStackAfterCreatingBrowser(Browser* browser) {
124 #if !defined(OS_CHROMEOS) 126 BrowserPolicyConnector* connector =
127 g_browser_process->browser_policy_connector();
128 connector->ScheduleServiceInitialization(0);
129
130 #if defined(OS_CHROMEOS)
131 connector->InitializeUserPolicy(GetTestUser(), true);
132 UserCloudPolicyManagerChromeOS* policy_manager =
133 connector->GetUserCloudPolicyManager();
134 ASSERT_TRUE(policy_manager);
135 #else
125 // Mock a signed-in user. This is used by the UserCloudPolicyStore to pass the 136 // Mock a signed-in user. This is used by the UserCloudPolicyStore to pass the
126 // username to the UserCloudPolicyValidator. 137 // username to the UserCloudPolicyValidator.
127 SigninManager* signin_manager = 138 SigninManager* signin_manager =
128 SigninManagerFactory::GetForProfile(browser->profile()); 139 SigninManagerFactory::GetForProfile(browser->profile());
129 ASSERT_TRUE(signin_manager); 140 ASSERT_TRUE(signin_manager);
130 signin_manager->SetAuthenticatedUsername(GetTestUser()); 141 signin_manager->SetAuthenticatedUsername(GetTestUser());
131 #endif
132
133 BrowserPolicyConnector* connector =
134 g_browser_process->browser_policy_connector();
135 connector->ScheduleServiceInitialization(0);
136 142
137 UserCloudPolicyManager* policy_manager = 143 UserCloudPolicyManager* policy_manager =
138 browser->profile()->GetUserCloudPolicyManager(); 144 UserCloudPolicyManagerFactory::GetForProfile(browser->profile());
139 ASSERT_TRUE(policy_manager); 145 ASSERT_TRUE(policy_manager);
140 policy_manager->Initialize(g_browser_process->local_state(), 146 policy_manager->Initialize(g_browser_process->local_state(),
141 connector->device_management_service(), 147 connector->device_management_service());
142 policy::USER_AFFILIATION_MANAGED); 148 #endif // defined(OS_CHROMEOS)
143 149
144 ASSERT_TRUE(policy_manager->cloud_policy_client()); 150 ASSERT_TRUE(policy_manager->cloud_policy_client());
145 base::RunLoop run_loop; 151 base::RunLoop run_loop;
146 MockCloudPolicyClientObserver observer; 152 MockCloudPolicyClientObserver observer;
147 EXPECT_CALL(observer, OnRegistrationStateChanged(_)).WillOnce( 153 EXPECT_CALL(observer, OnRegistrationStateChanged(_)).WillOnce(
148 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 154 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
149 policy_manager->cloud_policy_client()->AddObserver(&observer); 155 policy_manager->cloud_policy_client()->AddObserver(&observer);
150 156
151 // Give a bogus OAuth token to the |policy_manager|. This should make its 157 // Give a bogus OAuth token to the |policy_manager|. This should make its
152 // CloudPolicyClient fetch the DMToken. 158 // CloudPolicyClient fetch the DMToken.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 #endif 263 #endif
258 264
259 INSTANTIATE_TEST_CASE_P( 265 INSTANTIATE_TEST_CASE_P(
260 NewStackCloudPolicyTest, 266 NewStackCloudPolicyTest,
261 CloudPolicyTest, 267 CloudPolicyTest,
262 testing::Values( 268 testing::Values(
263 TestSetup(SetUpNewStackBeforeCreatingBrowser, 269 TestSetup(SetUpNewStackBeforeCreatingBrowser,
264 SetUpNewStackAfterCreatingBrowser))); 270 SetUpNewStackAfterCreatingBrowser)));
265 271
266 } // namespace policy 272 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698