| 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "chrome/browser/policy/cloud_policy_constants.h" | 8 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 9 #include "chrome/browser/policy/device_management_service.h" | 9 #include "chrome/browser/policy/device_management_service.h" |
| 10 #include "chrome/browser/policy/test/local_policy_test_server.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 12 #include "net/base/upload_bytes_element_reader.h" | 13 #include "net/base/upload_bytes_element_reader.h" |
| 13 #include "net/base/upload_data_stream.h" | 14 #include "net/base/upload_data_stream.h" |
| 14 #include "net/test/test_server.h" | |
| 15 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 17 #include "net/url_request/url_request_filter.h" | 17 #include "net/url_request/url_request_filter.h" |
| 18 #include "net/url_request/url_request_job_factory.h" | 18 #include "net/url_request/url_request_job_factory.h" |
| 19 #include "net/url_request/url_request_test_job.h" | 19 #include "net/url_request/url_request_test_job.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 using testing::DoAll; | 24 using testing::DoAll; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 const em::DeviceManagementResponse&)); | 131 const em::DeviceManagementResponse&)); |
| 132 | 132 |
| 133 std::string InitCannedResponse() { | 133 std::string InitCannedResponse() { |
| 134 net::URLFetcher::SetEnableInterceptionForTests(true); | 134 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 135 interceptor_.reset(new CannedResponseInterceptor(GURL(kServiceUrl))); | 135 interceptor_.reset(new CannedResponseInterceptor(GURL(kServiceUrl))); |
| 136 return kServiceUrl; | 136 return kServiceUrl; |
| 137 } | 137 } |
| 138 | 138 |
| 139 std::string InitTestServer() { | 139 std::string InitTestServer() { |
| 140 StartTestServer(); | 140 StartTestServer(); |
| 141 return test_server_->GetURL("device_management").spec(); | 141 return test_server_->GetServiceURL().spec(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 protected: | 144 protected: |
| 145 void PerformRegistration() { | 145 void PerformRegistration() { |
| 146 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) | 146 EXPECT_CALL(*this, OnJobDone(DM_STATUS_SUCCESS, _)) |
| 147 .WillOnce( | 147 .WillOnce( |
| 148 DoAll(Invoke(this, | 148 DoAll(Invoke(this, |
| 149 &DeviceManagementServiceIntegrationTest::RecordToken), | 149 &DeviceManagementServiceIntegrationTest::RecordToken), |
| 150 InvokeWithoutArgs(MessageLoop::current(), | 150 InvokeWithoutArgs(MessageLoop::current(), |
| 151 &MessageLoop::Quit))); | 151 &MessageLoop::Quit))); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 167 } | 167 } |
| 168 | 168 |
| 169 virtual void CleanUpOnMainThread() OVERRIDE { | 169 virtual void CleanUpOnMainThread() OVERRIDE { |
| 170 service_.reset(); | 170 service_.reset(); |
| 171 test_server_.reset(); | 171 test_server_.reset(); |
| 172 interceptor_.reset(); | 172 interceptor_.reset(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void StartTestServer() { | 175 void StartTestServer() { |
| 176 test_server_.reset( | 176 test_server_.reset( |
| 177 new net::TestServer( | 177 new LocalPolicyTestServer("device_management_service_browsertest")); |
| 178 net::TestServer::TYPE_HTTP, | |
| 179 net::TestServer::kLocalhost, | |
| 180 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/policy")))); | |
| 181 ASSERT_TRUE(test_server_->Start()); | 178 ASSERT_TRUE(test_server_->Start()); |
| 182 } | 179 } |
| 183 | 180 |
| 184 void RecordToken(DeviceManagementStatus status, | 181 void RecordToken(DeviceManagementStatus status, |
| 185 const em::DeviceManagementResponse& response) { | 182 const em::DeviceManagementResponse& response) { |
| 186 token_ = response.register_response().device_management_token(); | 183 token_ = response.register_response().device_management_token(); |
| 187 } | 184 } |
| 188 | 185 |
| 189 std::string token_; | 186 std::string token_; |
| 190 scoped_ptr<DeviceManagementService> service_; | 187 scoped_ptr<DeviceManagementService> service_; |
| 191 scoped_ptr<net::TestServer> test_server_; | 188 scoped_ptr<LocalPolicyTestServer> test_server_; |
| 192 scoped_ptr<CannedResponseInterceptor> interceptor_; | 189 scoped_ptr<CannedResponseInterceptor> interceptor_; |
| 193 }; | 190 }; |
| 194 | 191 |
| 195 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Registration) { | 192 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Registration) { |
| 196 PerformRegistration(); | 193 PerformRegistration(); |
| 197 EXPECT_FALSE(token_.empty()); | 194 EXPECT_FALSE(token_.empty()); |
| 198 } | 195 } |
| 199 | 196 |
| 200 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) { | 197 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) { |
| 201 PerformRegistration(); | 198 PerformRegistration(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 MessageLoop::current()->Run(); | 240 MessageLoop::current()->Run(); |
| 244 } | 241 } |
| 245 | 242 |
| 246 INSTANTIATE_TEST_CASE_P( | 243 INSTANTIATE_TEST_CASE_P( |
| 247 DeviceManagementServiceIntegrationTestInstance, | 244 DeviceManagementServiceIntegrationTestInstance, |
| 248 DeviceManagementServiceIntegrationTest, | 245 DeviceManagementServiceIntegrationTest, |
| 249 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse, | 246 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse, |
| 250 &DeviceManagementServiceIntegrationTest::InitTestServer)); | 247 &DeviceManagementServiceIntegrationTest::InitTestServer)); |
| 251 | 248 |
| 252 } // namespace policy | 249 } // namespace policy |
| OLD | NEW |