Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/policy/device_management_backend_impl.h" | 5 #include "chrome/browser/policy/device_management_backend_impl.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "chrome/browser/browser.h" | |
| 8 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
| 10 #include "chrome/browser/profile.h" | |
|
danno
2010/11/16 22:02:56
alphabetize
Mattias Nissler (ping if slow)
2010/11/19 17:21:53
Done.
| |
| 9 #include "chrome/browser/policy/device_management_backend_mock.h" | 11 #include "chrome/browser/policy/device_management_backend_mock.h" |
| 10 #include "chrome/test/in_process_browser_test.h" | 12 #include "chrome/test/in_process_browser_test.h" |
| 11 #include "net/test/test_server.h" | 13 #include "net/test/test_server.h" |
| 12 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 13 #include "net/url_request/url_request_test_job.h" | 15 #include "net/url_request/url_request_test_job.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 16 | 18 |
| 17 using testing::_; | 19 using testing::_; |
| 18 using testing::DoAll; | 20 using testing::DoAll; |
| 19 using testing::Invoke; | 21 using testing::Invoke; |
| 20 using testing::InvokeWithoutArgs; | 22 using testing::InvokeWithoutArgs; |
| 21 | 23 |
| 22 namespace policy { | 24 namespace policy { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 const char kServiceUrl[] = "http://example.com/service"; | 28 // Dummy service URL for testing with request interception enabled. |
| 29 const char kServiceURL[] = "http://example.com/device_management"; | |
|
markusheintz_
2010/11/18 12:40:36
s/URL/Url/
please do that in the reset of the CL
Mattias Nissler (ping if slow)
2010/11/19 17:21:53
I changed the constant names, but the class names
| |
| 27 | 30 |
| 28 // Binary representation of successful register response containing a token. | 31 // Binary representation of successful register response containing a token. |
| 29 const char kServiceResponseRegister[] = | 32 const char kServiceResponseRegister[] = |
| 30 "\x08\x00\x1a\x22\x0a\x20\x64\x64\x32\x63\x38\x63\x33\x65\x64\x61" | 33 "\x08\x00\x1a\x22\x0a\x20\x64\x64\x32\x63\x38\x63\x33\x65\x64\x61" |
| 31 "\x63\x63\x34\x61\x33\x32\x38\x31\x66\x33\x38\x62\x36\x35\x31\x31" | 34 "\x63\x63\x34\x61\x33\x32\x38\x31\x66\x33\x38\x62\x36\x35\x31\x31" |
| 32 "\x36\x64\x61\x62\x66\x63"; | 35 "\x36\x64\x61\x62\x66\x63"; |
| 33 // Contains a single policy setting, namely HomepageIsNewTabPage: false. | 36 // Contains a single policy setting, namely HomepageIsNewTabPage: false. |
| 34 const char kServiceResponsePolicy[] = | 37 const char kServiceResponsePolicy[] = |
| 35 "\x08\x00\x2a\x2a\x0a\x28\x0a\x06\x70\x6f\x6c\x69\x63\x79\x12\x1e" | 38 "\x08\x00\x2a\x2a\x0a\x28\x0a\x06\x70\x6f\x6c\x69\x63\x79\x12\x1e" |
| 36 "\x0a\x1c\x0a\x14\x48\x6f\x6d\x65\x70\x61\x67\x65\x49\x73\x4e\x65" | 39 "\x0a\x1c\x0a\x14\x48\x6f\x6d\x65\x70\x61\x67\x65\x49\x73\x4e\x65" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 std::string token_; | 88 std::string token_; |
| 86 }; | 89 }; |
| 87 | 90 |
| 88 static void QuitMessageLoop() { | 91 static void QuitMessageLoop() { |
| 89 MessageLoop::current()->Quit(); | 92 MessageLoop::current()->Quit(); |
| 90 } | 93 } |
| 91 | 94 |
| 92 IN_PROC_BROWSER_TEST_F(DeviceManagementBackendImplIntegrationTest, | 95 IN_PROC_BROWSER_TEST_F(DeviceManagementBackendImplIntegrationTest, |
| 93 CannedResponses) { | 96 CannedResponses) { |
| 94 URLFetcher::enable_interception_for_tests(true); | 97 URLFetcher::enable_interception_for_tests(true); |
| 95 DeviceManagementBackendImpl service(kServiceUrl); | 98 DeviceManagementBackendImpl backend( |
| 99 kServiceURL, | |
| 100 browser()->profile()->GetRequestContext()); | |
| 101 scoped_ptr<DeviceManagementBackend> service( | |
| 102 DeviceManagementBackendImpl::Get()); | |
| 96 | 103 |
| 97 { | 104 { |
| 98 CannedResponseInterceptor interceptor( | 105 CannedResponseInterceptor interceptor( |
| 99 GURL(kServiceUrl), PROTO_STRING(kServiceResponseRegister)); | 106 GURL(kServiceURL), PROTO_STRING(kServiceResponseRegister)); |
| 100 DeviceRegisterResponseDelegateMock delegate; | 107 DeviceRegisterResponseDelegateMock delegate; |
| 101 EXPECT_CALL(delegate, HandleRegisterResponse(_)) | 108 EXPECT_CALL(delegate, HandleRegisterResponse(_)) |
| 102 .WillOnce(DoAll(Invoke(this, &DeviceManagementBackendImplIntegrationTest | 109 .WillOnce(DoAll(Invoke(this, &DeviceManagementBackendImplIntegrationTest |
| 103 ::CaptureToken), | 110 ::CaptureToken), |
| 104 InvokeWithoutArgs(QuitMessageLoop))); | 111 InvokeWithoutArgs(QuitMessageLoop))); |
| 105 em::DeviceRegisterRequest request; | 112 em::DeviceRegisterRequest request; |
| 106 service.ProcessRegisterRequest("token", "device id", request, &delegate); | 113 service->ProcessRegisterRequest("token", "device id", request, &delegate); |
| 107 MessageLoop::current()->Run(); | 114 MessageLoop::current()->Run(); |
| 108 } | 115 } |
| 109 | 116 |
| 110 { | 117 { |
| 111 CannedResponseInterceptor interceptor( | 118 CannedResponseInterceptor interceptor( |
| 112 GURL(kServiceUrl), PROTO_STRING(kServiceResponsePolicy)); | 119 GURL(kServiceURL), PROTO_STRING(kServiceResponsePolicy)); |
| 113 DevicePolicyResponseDelegateMock delegate; | 120 DevicePolicyResponseDelegateMock delegate; |
| 114 EXPECT_CALL(delegate, HandlePolicyResponse(_)) | 121 EXPECT_CALL(delegate, HandlePolicyResponse(_)) |
| 115 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 122 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
| 116 em::DevicePolicyRequest request; | 123 em::DevicePolicyRequest request; |
| 117 request.set_policy_scope("chrome"); | 124 request.set_policy_scope("chrome"); |
| 118 em::DevicePolicySettingRequest* setting_request = | 125 em::DevicePolicySettingRequest* setting_request = |
| 119 request.add_setting_request(); | 126 request.add_setting_request(); |
| 120 setting_request->set_key("policy"); | 127 setting_request->set_key("policy"); |
| 121 service.ProcessPolicyRequest(token_, request, &delegate); | 128 service->ProcessPolicyRequest(token_, request, &delegate); |
| 122 | 129 |
| 123 MessageLoop::current()->Run(); | 130 MessageLoop::current()->Run(); |
| 124 } | 131 } |
| 125 | 132 |
| 126 { | 133 { |
| 127 CannedResponseInterceptor interceptor( | 134 CannedResponseInterceptor interceptor( |
| 128 GURL(kServiceUrl), PROTO_STRING(kServiceResponseUnregister)); | 135 GURL(kServiceURL), PROTO_STRING(kServiceResponseUnregister)); |
| 129 DeviceUnregisterResponseDelegateMock delegate; | 136 DeviceUnregisterResponseDelegateMock delegate; |
| 130 EXPECT_CALL(delegate, HandleUnregisterResponse(_)) | 137 EXPECT_CALL(delegate, HandleUnregisterResponse(_)) |
| 131 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 138 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
| 132 em::DeviceUnregisterRequest request; | 139 em::DeviceUnregisterRequest request; |
| 133 service.ProcessUnregisterRequest(token_, request, &delegate); | 140 service->ProcessUnregisterRequest(token_, request, &delegate); |
| 134 | 141 |
| 135 MessageLoop::current()->Run(); | 142 MessageLoop::current()->Run(); |
| 136 } | 143 } |
| 137 } | 144 } |
| 138 | 145 |
| 139 IN_PROC_BROWSER_TEST_F(DeviceManagementBackendImplIntegrationTest, | 146 IN_PROC_BROWSER_TEST_F(DeviceManagementBackendImplIntegrationTest, |
| 140 WithTestServer) { | 147 WithTestServer) { |
| 141 net::TestServer test_server( | 148 net::TestServer test_server_( |
| 142 net::TestServer::TYPE_HTTP, | 149 net::TestServer::TYPE_HTTP, |
| 143 FilePath(FILE_PATH_LITERAL("chrome/test/data/policy"))); | 150 FilePath(FILE_PATH_LITERAL("chrome/test/data/policy"))); |
| 144 ASSERT_TRUE(test_server.Start()); | 151 ASSERT_TRUE(test_server_.Start()); |
| 145 DeviceManagementBackendImpl service( | 152 DeviceManagementBackendImpl backend( |
| 146 test_server.GetURL("device_management").spec()); | 153 test_server_.GetURL("device_management").spec(), |
| 154 browser()->profile()->GetRequestContext()); | |
| 155 scoped_ptr<DeviceManagementBackend> service( | |
| 156 DeviceManagementBackendImpl::Get()); | |
| 147 | 157 |
| 148 { | 158 { |
| 149 DeviceRegisterResponseDelegateMock delegate; | 159 DeviceRegisterResponseDelegateMock delegate; |
| 150 EXPECT_CALL(delegate, HandleRegisterResponse(_)) | 160 EXPECT_CALL(delegate, HandleRegisterResponse(_)) |
| 151 .WillOnce(DoAll(Invoke(this, &DeviceManagementBackendImplIntegrationTest | 161 .WillOnce(DoAll(Invoke(this, &DeviceManagementBackendImplIntegrationTest |
| 152 ::CaptureToken), | 162 ::CaptureToken), |
| 153 InvokeWithoutArgs(QuitMessageLoop))); | 163 InvokeWithoutArgs(QuitMessageLoop))); |
| 154 em::DeviceRegisterRequest request; | 164 em::DeviceRegisterRequest request; |
| 155 service.ProcessRegisterRequest("token", "device id", request, &delegate); | 165 service->ProcessRegisterRequest("token", "device id", request, &delegate); |
| 156 MessageLoop::current()->Run(); | 166 MessageLoop::current()->Run(); |
| 157 } | 167 } |
| 158 | 168 |
| 159 { | 169 { |
| 160 em::DevicePolicyResponse expected_response; | 170 em::DevicePolicyResponse expected_response; |
| 161 | 171 |
| 162 DevicePolicyResponseDelegateMock delegate; | 172 DevicePolicyResponseDelegateMock delegate; |
| 163 EXPECT_CALL(delegate, HandlePolicyResponse(_)) | 173 EXPECT_CALL(delegate, HandlePolicyResponse(_)) |
| 164 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 174 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
| 165 em::DevicePolicyRequest request; | 175 em::DevicePolicyRequest request; |
| 166 request.set_policy_scope("chrome"); | 176 request.set_policy_scope("chrome"); |
| 167 em::DevicePolicySettingRequest* setting_request = | 177 em::DevicePolicySettingRequest* setting_request = |
| 168 request.add_setting_request(); | 178 request.add_setting_request(); |
| 169 setting_request->set_key("policy"); | 179 setting_request->set_key("policy"); |
| 170 service.ProcessPolicyRequest(token_, request, &delegate); | 180 service->ProcessPolicyRequest(token_, request, &delegate); |
| 171 | 181 |
| 172 MessageLoop::current()->Run(); | 182 MessageLoop::current()->Run(); |
| 173 } | 183 } |
| 174 | 184 |
| 175 { | 185 { |
| 176 DeviceUnregisterResponseDelegateMock delegate; | 186 DeviceUnregisterResponseDelegateMock delegate; |
| 177 EXPECT_CALL(delegate, HandleUnregisterResponse(_)) | 187 EXPECT_CALL(delegate, HandleUnregisterResponse(_)) |
| 178 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 188 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
| 179 em::DeviceUnregisterRequest request; | 189 em::DeviceUnregisterRequest request; |
| 180 service.ProcessUnregisterRequest(token_, request, &delegate); | 190 service->ProcessUnregisterRequest(token_, request, &delegate); |
| 181 | 191 |
| 182 MessageLoop::current()->Run(); | 192 MessageLoop::current()->Run(); |
| 183 } | 193 } |
| 184 } | 194 } |
| 185 | 195 |
| 186 } // namespace policy | 196 } // namespace policy |
| OLD | NEW |