| 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/callback.h" | 5 #include "base/callback.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/file_path.h" | 8 #include "base/files/file_path.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/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/invalidation/fake_invalidation_service.h" | 18 #include "chrome/browser/invalidation/fake_invalidation_service.h" |
| 19 #include "chrome/browser/invalidation/invalidation_service_factory.h" | 19 #include "chrome/browser/invalidation/profile_invalidation_provider.h" |
| 20 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 20 #include "chrome/browser/policy/profile_policy_connector.h" | 21 #include "chrome/browser/policy/profile_policy_connector.h" |
| 21 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 22 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 22 #include "chrome/browser/policy/test/local_policy_test_server.h" | 23 #include "chrome/browser/policy/test/local_policy_test_server.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "components/invalidation/invalidation_service.h" |
| 28 #include "components/keyed_service/core/keyed_service.h" |
| 26 #include "components/policy/core/browser/browser_policy_connector.h" | 29 #include "components/policy/core/browser/browser_policy_connector.h" |
| 27 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 30 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 28 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 31 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 29 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" | 32 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" |
| 30 #include "components/policy/core/common/external_data_fetcher.h" | 33 #include "components/policy/core/common/external_data_fetcher.h" |
| 31 #include "components/policy/core/common/policy_map.h" | 34 #include "components/policy/core/common/policy_map.h" |
| 32 #include "components/policy/core/common/policy_service.h" | 35 #include "components/policy/core/common/policy_service.h" |
| 33 #include "components/policy/core/common/policy_switches.h" | 36 #include "components/policy/core/common/policy_switches.h" |
| 34 #include "components/policy/core/common/policy_test_utils.h" | 37 #include "components/policy/core/common/policy_test_utils.h" |
| 35 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 56 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 59 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
| 57 #include "components/signin/core/browser/signin_manager.h" | 60 #include "components/signin/core/browser/signin_manager.h" |
| 58 #endif | 61 #endif |
| 59 | 62 |
| 60 using testing::AnyNumber; | 63 using testing::AnyNumber; |
| 61 using testing::InvokeWithoutArgs; | 64 using testing::InvokeWithoutArgs; |
| 62 using testing::Mock; | 65 using testing::Mock; |
| 63 using testing::Return; | 66 using testing::Return; |
| 64 using testing::_; | 67 using testing::_; |
| 65 | 68 |
| 69 namespace content { |
| 70 class BrowserContext; |
| 71 } |
| 72 |
| 66 namespace em = enterprise_management; | 73 namespace em = enterprise_management; |
| 67 | 74 |
| 68 namespace policy { | 75 namespace policy { |
| 69 | 76 |
| 70 namespace { | 77 namespace { |
| 71 | 78 |
| 79 KeyedService* BuildFakeProfileInvalidationProvider( |
| 80 content::BrowserContext* context) { |
| 81 return new invalidation::ProfileInvalidationProvider( |
| 82 scoped_ptr<invalidation::InvalidationService>( |
| 83 new invalidation::FakeInvalidationService)); |
| 84 } |
| 85 |
| 72 const char* GetTestUser() { | 86 const char* GetTestUser() { |
| 73 #if defined(OS_CHROMEOS) | 87 #if defined(OS_CHROMEOS) |
| 74 return chromeos::UserManager::kStubUser; | 88 return chromeos::UserManager::kStubUser; |
| 75 #else | 89 #else |
| 76 return "user@example.com"; | 90 return "user@example.com"; |
| 77 #endif | 91 #endif |
| 78 } | 92 } |
| 79 | 93 |
| 80 std::string GetEmptyPolicy() { | 94 std::string GetEmptyPolicy() { |
| 81 const char kEmptyPolicy[] = | 95 const char kEmptyPolicy[] = |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetEmptyPolicy())); | 181 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetEmptyPolicy())); |
| 168 | 182 |
| 169 test_server_.reset(new LocalPolicyTestServer(policy_file_path())); | 183 test_server_.reset(new LocalPolicyTestServer(policy_file_path())); |
| 170 ASSERT_TRUE(test_server_->Start()); | 184 ASSERT_TRUE(test_server_->Start()); |
| 171 | 185 |
| 172 std::string url = test_server_->GetServiceURL().spec(); | 186 std::string url = test_server_->GetServiceURL().spec(); |
| 173 | 187 |
| 174 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 188 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 175 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); | 189 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); |
| 176 | 190 |
| 177 invalidation::InvalidationServiceFactory::GetInstance()-> | 191 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
| 178 RegisterTestingFactory(invalidation::FakeInvalidationService::Build); | 192 RegisterTestingFactory(BuildFakeProfileInvalidationProvider); |
| 179 } | 193 } |
| 180 | 194 |
| 181 virtual void SetUpOnMainThread() OVERRIDE { | 195 virtual void SetUpOnMainThread() OVERRIDE { |
| 182 ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service())) | 196 ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service())) |
| 183 << "Pre-existing policies in this machine will make this test fail."; | 197 << "Pre-existing policies in this machine will make this test fail."; |
| 184 | 198 |
| 185 BrowserPolicyConnector* connector = | 199 BrowserPolicyConnector* connector = |
| 186 g_browser_process->browser_policy_connector(); | 200 g_browser_process->browser_policy_connector(); |
| 187 connector->ScheduleServiceInitialization(0); | 201 connector->ScheduleServiceInitialization(0); |
| 188 | 202 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 } | 262 } |
| 249 | 263 |
| 250 PolicyService* GetPolicyService() { | 264 PolicyService* GetPolicyService() { |
| 251 ProfilePolicyConnector* profile_connector = | 265 ProfilePolicyConnector* profile_connector = |
| 252 ProfilePolicyConnectorFactory::GetForProfile(browser()->profile()); | 266 ProfilePolicyConnectorFactory::GetForProfile(browser()->profile()); |
| 253 return profile_connector->policy_service(); | 267 return profile_connector->policy_service(); |
| 254 } | 268 } |
| 255 | 269 |
| 256 invalidation::FakeInvalidationService* GetInvalidationService() { | 270 invalidation::FakeInvalidationService* GetInvalidationService() { |
| 257 return static_cast<invalidation::FakeInvalidationService*>( | 271 return static_cast<invalidation::FakeInvalidationService*>( |
| 258 invalidation::InvalidationServiceFactory::GetForProfile( | 272 static_cast<invalidation::ProfileInvalidationProvider*>( |
| 259 browser()->profile())); | 273 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
| 274 GetForProfile(browser()->profile()))->GetInvalidationService()); |
| 260 } | 275 } |
| 261 | 276 |
| 262 void SetServerPolicy(const std::string& policy) { | 277 void SetServerPolicy(const std::string& policy) { |
| 263 int result = base::WriteFile(policy_file_path(), policy.data(), | 278 int result = base::WriteFile(policy_file_path(), policy.data(), |
| 264 policy.size()); | 279 policy.size()); |
| 265 ASSERT_EQ(static_cast<int>(policy.size()), result); | 280 ASSERT_EQ(static_cast<int>(policy.size()), result); |
| 266 } | 281 } |
| 267 | 282 |
| 268 base::FilePath policy_file_path() const { | 283 base::FilePath policy_file_path() const { |
| 269 return temp_dir_.path().AppendASCII("policy.json"); | 284 return temp_dir_.path().AppendASCII("policy.json"); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 458 |
| 444 // They should now serialize to the same bytes. | 459 // They should now serialize to the same bytes. |
| 445 std::string chrome_settings_serialized; | 460 std::string chrome_settings_serialized; |
| 446 std::string cloud_policy_serialized; | 461 std::string cloud_policy_serialized; |
| 447 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); | 462 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); |
| 448 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); | 463 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); |
| 449 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); | 464 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); |
| 450 } | 465 } |
| 451 | 466 |
| 452 } // namespace policy | 467 } // namespace policy |
| OLD | NEW |