| 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/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_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_constants.h" | 17 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 18 #include "chrome/browser/policy/mock_cloud_policy_client.h" |
| 18 #include "chrome/browser/policy/policy_map.h" | 19 #include "chrome/browser/policy/policy_map.h" |
| 19 #include "chrome/browser/policy/policy_service.h" | 20 #include "chrome/browser/policy/policy_service.h" |
| 20 #include "chrome/browser/policy/proto/chrome_settings.pb.h" | 21 #include "chrome/browser/policy/proto/chrome_settings.pb.h" |
| 21 #include "chrome/browser/policy/proto/cloud_policy.pb.h" | 22 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
| 23 #include "chrome/browser/policy/test_utils.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 28 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
| 30 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
| 31 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 47 using testing::InvokeWithoutArgs; | 49 using testing::InvokeWithoutArgs; |
| 48 using testing::Mock; | 50 using testing::Mock; |
| 49 using testing::_; | 51 using testing::_; |
| 50 | 52 |
| 51 namespace em = enterprise_management; | 53 namespace em = enterprise_management; |
| 52 | 54 |
| 53 namespace policy { | 55 namespace policy { |
| 54 | 56 |
| 55 namespace { | 57 namespace { |
| 56 | 58 |
| 57 class MockCloudPolicyClientObserver : public CloudPolicyClient::Observer { | |
| 58 public: | |
| 59 MockCloudPolicyClientObserver() {} | |
| 60 virtual ~MockCloudPolicyClientObserver() {} | |
| 61 | |
| 62 MOCK_METHOD1(OnPolicyFetched, void(CloudPolicyClient*)); | |
| 63 MOCK_METHOD1(OnRegistrationStateChanged, void(CloudPolicyClient*)); | |
| 64 MOCK_METHOD1(OnClientError, void(CloudPolicyClient*)); | |
| 65 }; | |
| 66 | |
| 67 const char* GetTestUser() { | 59 const char* GetTestUser() { |
| 68 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
| 69 return chromeos::UserManager::kStubUser; | 61 return chromeos::UserManager::kStubUser; |
| 70 #else | 62 #else |
| 71 return "user@example.com"; | 63 return "user@example.com"; |
| 72 #endif | 64 #endif |
| 73 } | 65 } |
| 74 | 66 |
| 75 std::string GetEmptyPolicy() { | 67 std::string GetEmptyPolicy() { |
| 76 const char kEmptyPolicy[] = | 68 const char kEmptyPolicy[] = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 temp_dir_.path().BaseName())); | 122 temp_dir_.path().BaseName())); |
| 131 ASSERT_TRUE(test_server_->Start()); | 123 ASSERT_TRUE(test_server_->Start()); |
| 132 | 124 |
| 133 std::string url = test_server_->GetURL("device_management").spec(); | 125 std::string url = test_server_->GetURL("device_management").spec(); |
| 134 | 126 |
| 135 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 127 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 136 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); | 128 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); |
| 137 } | 129 } |
| 138 | 130 |
| 139 virtual void SetUpOnMainThread() OVERRIDE { | 131 virtual void SetUpOnMainThread() OVERRIDE { |
| 140 // Checks that no policies have been loaded by the other providers before | 132 ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service())) |
| 141 // setting up the cloud connection. Other policies configured in the test | 133 << "Pre-existing policies in this machine will make this test fail."; |
| 142 // machine will interfere with these tests. | |
| 143 const PolicyMap& map = g_browser_process->policy_service()->GetPolicies( | |
| 144 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | |
| 145 if (!map.empty()) { | |
| 146 base::DictionaryValue dict; | |
| 147 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); ++it) | |
| 148 dict.SetWithoutPathExpansion(it->first, it->second.value->DeepCopy()); | |
| 149 ADD_FAILURE() | |
| 150 << "There are pre-existing policies in this machine that will " | |
| 151 << "interfere with these tests. Policies found: " << dict; | |
| 152 } | |
| 153 | 134 |
| 154 BrowserPolicyConnector* connector = | 135 BrowserPolicyConnector* connector = |
| 155 g_browser_process->browser_policy_connector(); | 136 g_browser_process->browser_policy_connector(); |
| 156 connector->ScheduleServiceInitialization(0); | 137 connector->ScheduleServiceInitialization(0); |
| 157 | 138 |
| 158 #if defined(OS_CHROMEOS) | 139 #if defined(OS_CHROMEOS) |
| 159 UserCloudPolicyManagerChromeOS* policy_manager = | 140 UserCloudPolicyManagerChromeOS* policy_manager = |
| 160 connector->GetUserCloudPolicyManager(); | 141 connector->GetUserCloudPolicyManager(); |
| 161 ASSERT_TRUE(policy_manager); | 142 ASSERT_TRUE(policy_manager); |
| 162 #else | 143 #else |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 261 |
| 281 // They should now serialize to the same bytes. | 262 // They should now serialize to the same bytes. |
| 282 std::string chrome_settings_serialized; | 263 std::string chrome_settings_serialized; |
| 283 std::string cloud_policy_serialized; | 264 std::string cloud_policy_serialized; |
| 284 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); | 265 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); |
| 285 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); | 266 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); |
| 286 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); | 267 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); |
| 287 } | 268 } |
| 288 | 269 |
| 289 } // namespace policy | 270 } // namespace policy |
| OLD | NEW |