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/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" |
39 #include "chrome/browser/signin/signin_manager.h" | 40 #include "chrome/browser/signin/signin_manager.h" |
40 #include "chrome/browser/signin/signin_manager_factory.h" | 41 #include "chrome/browser/signin/signin_manager_factory.h" |
41 #endif | 42 #endif |
42 | 43 |
43 using testing::InvokeWithoutArgs; | 44 using testing::InvokeWithoutArgs; |
44 using testing::Mock; | 45 using testing::Mock; |
45 using testing::_; | 46 using testing::_; |
46 | 47 |
47 namespace policy { | 48 namespace policy { |
48 | 49 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 115 } |
115 #endif | 116 #endif |
116 | 117 |
117 void SetUpNewStackBeforeCreatingBrowser() { | 118 void SetUpNewStackBeforeCreatingBrowser() { |
118 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 119 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
119 command_line->AppendSwitch(switches::kEnableCloudPolicyService); | 120 command_line->AppendSwitch(switches::kEnableCloudPolicyService); |
120 command_line->AppendSwitch(switches::kLoadCloudPolicyOnSignin); | 121 command_line->AppendSwitch(switches::kLoadCloudPolicyOnSignin); |
121 } | 122 } |
122 | 123 |
123 void SetUpNewStackAfterCreatingBrowser(Browser* browser) { | 124 void SetUpNewStackAfterCreatingBrowser(Browser* browser) { |
124 #if !defined(OS_CHROMEOS) | 125 BrowserPolicyConnector* connector = |
| 126 g_browser_process->browser_policy_connector(); |
| 127 connector->ScheduleServiceInitialization(0); |
| 128 |
| 129 #if defined(OS_CHROMEOS) |
| 130 connector->InitializeUserPolicy(GetTestUser(), true); |
| 131 UserCloudPolicyManagerChromeOS* policy_manager = |
| 132 connector->GetUserCloudPolicyManager(); |
| 133 ASSERT_TRUE(policy_manager); |
| 134 #else |
125 // Mock a signed-in user. This is used by the UserCloudPolicyStore to pass the | 135 // Mock a signed-in user. This is used by the UserCloudPolicyStore to pass the |
126 // username to the UserCloudPolicyValidator. | 136 // username to the UserCloudPolicyValidator. |
127 SigninManager* signin_manager = | 137 SigninManager* signin_manager = |
128 SigninManagerFactory::GetForProfile(browser->profile()); | 138 SigninManagerFactory::GetForProfile(browser->profile()); |
129 ASSERT_TRUE(signin_manager); | 139 ASSERT_TRUE(signin_manager); |
130 signin_manager->SetAuthenticatedUsername(GetTestUser()); | 140 signin_manager->SetAuthenticatedUsername(GetTestUser()); |
131 #endif | |
132 | |
133 BrowserPolicyConnector* connector = | |
134 g_browser_process->browser_policy_connector(); | |
135 connector->ScheduleServiceInitialization(0); | |
136 | 141 |
137 UserCloudPolicyManager* policy_manager = | 142 UserCloudPolicyManager* policy_manager = |
138 browser->profile()->GetUserCloudPolicyManager(); | 143 browser->profile()->GetUserCloudPolicyManager(); |
139 ASSERT_TRUE(policy_manager); | 144 ASSERT_TRUE(policy_manager); |
140 policy_manager->Initialize(g_browser_process->local_state(), | 145 policy_manager->Initialize(g_browser_process->local_state(), |
141 connector->device_management_service(), | 146 connector->device_management_service()); |
142 policy::USER_AFFILIATION_MANAGED); | 147 #endif // defined(OS_CHROMEOS) |
143 | 148 |
144 ASSERT_TRUE(policy_manager->cloud_policy_client()); | 149 ASSERT_TRUE(policy_manager->cloud_policy_client()); |
145 base::RunLoop run_loop; | 150 base::RunLoop run_loop; |
146 MockCloudPolicyClientObserver observer; | 151 MockCloudPolicyClientObserver observer; |
147 EXPECT_CALL(observer, OnRegistrationStateChanged(_)).WillOnce( | 152 EXPECT_CALL(observer, OnRegistrationStateChanged(_)).WillOnce( |
148 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 153 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
149 policy_manager->cloud_policy_client()->AddObserver(&observer); | 154 policy_manager->cloud_policy_client()->AddObserver(&observer); |
150 | 155 |
151 // Give a bogus OAuth token to the |policy_manager|. This should make its | 156 // Give a bogus OAuth token to the |policy_manager|. This should make its |
152 // CloudPolicyClient fetch the DMToken. | 157 // CloudPolicyClient fetch the DMToken. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 #endif | 262 #endif |
258 | 263 |
259 INSTANTIATE_TEST_CASE_P( | 264 INSTANTIATE_TEST_CASE_P( |
260 NewStackCloudPolicyTest, | 265 NewStackCloudPolicyTest, |
261 CloudPolicyTest, | 266 CloudPolicyTest, |
262 testing::Values( | 267 testing::Values( |
263 TestSetup(SetUpNewStackBeforeCreatingBrowser, | 268 TestSetup(SetUpNewStackBeforeCreatingBrowser, |
264 SetUpNewStackAfterCreatingBrowser))); | 269 SetUpNewStackAfterCreatingBrowser))); |
265 | 270 |
266 } // namespace policy | 271 } // namespace policy |
OLD | NEW |