| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/policy/cloud/test_request_interceptor.h" | 9 #include "chrome/browser/policy/cloud/test_request_interceptor.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 namespace policy { | 43 namespace policy { |
| 44 | 44 |
| 45 // Tests the cloud policy stack using a URLRequestJobFactory::ProtocolHandler | 45 // Tests the cloud policy stack using a URLRequestJobFactory::ProtocolHandler |
| 46 // to intercept requests and produce canned responses. | 46 // to intercept requests and produce canned responses. |
| 47 class CloudPolicyManagerTest : public InProcessBrowserTest { | 47 class CloudPolicyManagerTest : public InProcessBrowserTest { |
| 48 protected: | 48 protected: |
| 49 CloudPolicyManagerTest() {} | 49 CloudPolicyManagerTest() {} |
| 50 virtual ~CloudPolicyManagerTest() {} | 50 virtual ~CloudPolicyManagerTest() {} |
| 51 | 51 |
| 52 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 52 virtual void SetUpInProcessBrowserTestFixture() override { |
| 53 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 53 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 54 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, | 54 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, |
| 55 "http://localhost"); | 55 "http://localhost"); |
| 56 } | 56 } |
| 57 | 57 |
| 58 virtual void SetUpOnMainThread() OVERRIDE { | 58 virtual void SetUpOnMainThread() override { |
| 59 ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service())) | 59 ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service())) |
| 60 << "Pre-existing policies in this machine will make this test fail."; | 60 << "Pre-existing policies in this machine will make this test fail."; |
| 61 | 61 |
| 62 interceptor_.reset(new TestRequestInterceptor( | 62 interceptor_.reset(new TestRequestInterceptor( |
| 63 "localhost", | 63 "localhost", |
| 64 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 64 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
| 65 | 65 |
| 66 BrowserPolicyConnector* connector = | 66 BrowserPolicyConnector* connector = |
| 67 g_browser_process->browser_policy_connector(); | 67 g_browser_process->browser_policy_connector(); |
| 68 connector->ScheduleServiceInitialization(0); | 68 connector->ScheduleServiceInitialization(0); |
| 69 | 69 |
| 70 #if !defined(OS_CHROMEOS) | 70 #if !defined(OS_CHROMEOS) |
| 71 // Mock a signed-in user. This is used by the UserCloudPolicyStore to pass | 71 // Mock a signed-in user. This is used by the UserCloudPolicyStore to pass |
| 72 // the username to the UserCloudPolicyValidator. | 72 // the username to the UserCloudPolicyValidator. |
| 73 SigninManager* signin_manager = | 73 SigninManager* signin_manager = |
| 74 SigninManagerFactory::GetForProfile(browser()->profile()); | 74 SigninManagerFactory::GetForProfile(browser()->profile()); |
| 75 ASSERT_TRUE(signin_manager); | 75 ASSERT_TRUE(signin_manager); |
| 76 signin_manager->SetAuthenticatedUsername("user@example.com"); | 76 signin_manager->SetAuthenticatedUsername("user@example.com"); |
| 77 | 77 |
| 78 ASSERT_TRUE(policy_manager()); | 78 ASSERT_TRUE(policy_manager()); |
| 79 policy_manager()->Connect( | 79 policy_manager()->Connect( |
| 80 g_browser_process->local_state(), | 80 g_browser_process->local_state(), |
| 81 g_browser_process->system_request_context(), | 81 g_browser_process->system_request_context(), |
| 82 UserCloudPolicyManager::CreateCloudPolicyClient( | 82 UserCloudPolicyManager::CreateCloudPolicyClient( |
| 83 connector->device_management_service(), | 83 connector->device_management_service(), |
| 84 g_browser_process->system_request_context()).Pass()); | 84 g_browser_process->system_request_context()).Pass()); |
| 85 #endif | 85 #endif |
| 86 } | 86 } |
| 87 | 87 |
| 88 virtual void TearDownOnMainThread() OVERRIDE { | 88 virtual void TearDownOnMainThread() override { |
| 89 // Verify that all the expected requests were handled. | 89 // Verify that all the expected requests were handled. |
| 90 EXPECT_EQ(0u, interceptor_->GetPendingSize()); | 90 EXPECT_EQ(0u, interceptor_->GetPendingSize()); |
| 91 | 91 |
| 92 interceptor_.reset(); | 92 interceptor_.reset(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 #if defined(OS_CHROMEOS) | 95 #if defined(OS_CHROMEOS) |
| 96 UserCloudPolicyManagerChromeOS* policy_manager() { | 96 UserCloudPolicyManagerChromeOS* policy_manager() { |
| 97 return UserCloudPolicyManagerFactoryChromeOS::GetForProfile( | 97 return UserCloudPolicyManagerFactoryChromeOS::GetForProfile( |
| 98 browser()->profile()); | 98 browser()->profile()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 const bool expect_reregister = true; | 193 const bool expect_reregister = true; |
| 194 interceptor_->PushJobCallback( | 194 interceptor_->PushJobCallback( |
| 195 TestRequestInterceptor::RegisterJob(expected_type, expect_reregister)); | 195 TestRequestInterceptor::RegisterJob(expected_type, expect_reregister)); |
| 196 | 196 |
| 197 EXPECT_FALSE(policy_manager()->core()->client()->is_registered()); | 197 EXPECT_FALSE(policy_manager()->core()->client()->is_registered()); |
| 198 ASSERT_NO_FATAL_FAILURE(Register()); | 198 ASSERT_NO_FATAL_FAILURE(Register()); |
| 199 EXPECT_TRUE(policy_manager()->core()->client()->is_registered()); | 199 EXPECT_TRUE(policy_manager()->core()->client()->is_registered()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 } // namespace policy | 202 } // namespace policy |
| OLD | NEW |