| 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/proto/chrome_settings.pb.h" | 20 #include "chrome/browser/policy/proto/chrome_settings.pb.h" |
| 21 #include "chrome/browser/policy/proto/cloud_policy.pb.h" | 21 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
| 22 #include "chrome/browser/policy/user_cloud_policy_manager.h" | |
| 23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
| 28 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 31 #include "content/public/test/test_utils.h" | 30 #include "content/public/test/test_utils.h" |
| 32 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
| 33 #include "net/test/test_server.h" | 32 #include "net/test/test_server.h" |
| 34 #include "policy/policy_constants.h" | 33 #include "policy/policy_constants.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 36 |
| 38 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
| 39 #include "chrome/browser/chromeos/login/user_manager.h" | 38 #include "chrome/browser/chromeos/login/user_manager.h" |
| 39 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h" |
| 40 #else | 40 #else |
| 41 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
| 42 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h" |
| 41 #include "chrome/browser/signin/signin_manager.h" | 43 #include "chrome/browser/signin/signin_manager.h" |
| 42 #include "chrome/browser/signin/signin_manager_factory.h" | 44 #include "chrome/browser/signin/signin_manager_factory.h" |
| 43 #endif | 45 #endif |
| 44 | 46 |
| 45 using testing::InvokeWithoutArgs; | 47 using testing::InvokeWithoutArgs; |
| 46 using testing::Mock; | 48 using testing::Mock; |
| 47 using testing::_; | 49 using testing::_; |
| 48 | 50 |
| 49 namespace em = enterprise_management; | 51 namespace em = enterprise_management; |
| 50 | 52 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 120 } |
| 119 #endif | 121 #endif |
| 120 | 122 |
| 121 void SetUpNewStackBeforeCreatingBrowser() { | 123 void SetUpNewStackBeforeCreatingBrowser() { |
| 122 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 124 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 123 command_line->AppendSwitch(switches::kEnableCloudPolicyService); | 125 command_line->AppendSwitch(switches::kEnableCloudPolicyService); |
| 124 command_line->AppendSwitch(switches::kLoadCloudPolicyOnSignin); | 126 command_line->AppendSwitch(switches::kLoadCloudPolicyOnSignin); |
| 125 } | 127 } |
| 126 | 128 |
| 127 void SetUpNewStackAfterCreatingBrowser(Browser* browser) { | 129 void SetUpNewStackAfterCreatingBrowser(Browser* browser) { |
| 128 #if !defined(OS_CHROMEOS) | 130 BrowserPolicyConnector* connector = |
| 131 g_browser_process->browser_policy_connector(); |
| 132 connector->ScheduleServiceInitialization(0); |
| 133 |
| 134 #if defined(OS_CHROMEOS) |
| 135 connector->InitializeUserPolicy(GetTestUser(), true); |
| 136 UserCloudPolicyManagerChromeOS* policy_manager = |
| 137 connector->GetUserCloudPolicyManager(); |
| 138 ASSERT_TRUE(policy_manager); |
| 139 #else |
| 129 // Mock a signed-in user. This is used by the UserCloudPolicyStore to pass the | 140 // Mock a signed-in user. This is used by the UserCloudPolicyStore to pass the |
| 130 // username to the UserCloudPolicyValidator. | 141 // username to the UserCloudPolicyValidator. |
| 131 SigninManager* signin_manager = | 142 SigninManager* signin_manager = |
| 132 SigninManagerFactory::GetForProfile(browser->profile()); | 143 SigninManagerFactory::GetForProfile(browser->profile()); |
| 133 ASSERT_TRUE(signin_manager); | 144 ASSERT_TRUE(signin_manager); |
| 134 signin_manager->SetAuthenticatedUsername(GetTestUser()); | 145 signin_manager->SetAuthenticatedUsername(GetTestUser()); |
| 135 #endif | |
| 136 | |
| 137 BrowserPolicyConnector* connector = | |
| 138 g_browser_process->browser_policy_connector(); | |
| 139 connector->ScheduleServiceInitialization(0); | |
| 140 | 146 |
| 141 UserCloudPolicyManager* policy_manager = | 147 UserCloudPolicyManager* policy_manager = |
| 142 browser->profile()->GetUserCloudPolicyManager(); | 148 UserCloudPolicyManagerFactory::GetForProfile(browser->profile()); |
| 143 ASSERT_TRUE(policy_manager); | 149 ASSERT_TRUE(policy_manager); |
| 144 policy_manager->Initialize(g_browser_process->local_state(), | 150 policy_manager->Initialize(g_browser_process->local_state(), |
| 145 connector->device_management_service(), | 151 connector->device_management_service()); |
| 146 policy::USER_AFFILIATION_MANAGED); | 152 #endif // defined(OS_CHROMEOS) |
| 147 | 153 |
| 148 ASSERT_TRUE(policy_manager->cloud_policy_client()); | 154 ASSERT_TRUE(policy_manager->cloud_policy_client()); |
| 149 base::RunLoop run_loop; | 155 base::RunLoop run_loop; |
| 150 MockCloudPolicyClientObserver observer; | 156 MockCloudPolicyClientObserver observer; |
| 151 EXPECT_CALL(observer, OnRegistrationStateChanged(_)).WillOnce( | 157 EXPECT_CALL(observer, OnRegistrationStateChanged(_)).WillOnce( |
| 152 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 158 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 153 policy_manager->cloud_policy_client()->AddObserver(&observer); | 159 policy_manager->cloud_policy_client()->AddObserver(&observer); |
| 154 | 160 |
| 155 // Give a bogus OAuth token to the |policy_manager|. This should make its | 161 // Give a bogus OAuth token to the |policy_manager|. This should make its |
| 156 // CloudPolicyClient fetch the DMToken. | 162 // CloudPolicyClient fetch the DMToken. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 316 |
| 311 // They should now serialize to the same bytes. | 317 // They should now serialize to the same bytes. |
| 312 std::string chrome_settings_serialized; | 318 std::string chrome_settings_serialized; |
| 313 std::string cloud_policy_serialized; | 319 std::string cloud_policy_serialized; |
| 314 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); | 320 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); |
| 315 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); | 321 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); |
| 316 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); | 322 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); |
| 317 } | 323 } |
| 318 | 324 |
| 319 } // namespace policy | 325 } // namespace policy |
| OLD | NEW |