Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/policy/device_management_service_browsertest.cc

Issue 12235003: Split out policy code from net/tools/testserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 80 chars. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/policy/cloud_policy_constants.h" 10 #include "chrome/browser/policy/cloud_policy_constants.h"
11 #include "chrome/browser/policy/device_management_service.h" 11 #include "chrome/browser/policy/device_management_service.h"
12 #include "chrome/browser/policy/test/local_policy_test_server.h"
12 #include "chrome/browser/policy/test_request_interceptor.h" 13 #include "chrome/browser/policy/test_request_interceptor.h"
13 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
14 #include "net/base/upload_bytes_element_reader.h" 15 #include "net/base/upload_bytes_element_reader.h"
15 #include "net/base/upload_data_stream.h" 16 #include "net/base/upload_data_stream.h"
16 #include "net/test/test_server.h" 17 #include "net/url_request/url_fetcher.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_test_job.h" 19 #include "net/url_request/url_request_test_job.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 using testing::DoAll; 23 using testing::DoAll;
23 using testing::Invoke; 24 using testing::Invoke;
24 using testing::InvokeWithoutArgs; 25 using testing::InvokeWithoutArgs;
25 using testing::_; 26 using testing::_;
26 27
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 MOCK_METHOD2(OnJobDone, void(DeviceManagementStatus, 89 MOCK_METHOD2(OnJobDone, void(DeviceManagementStatus,
89 const em::DeviceManagementResponse&)); 90 const em::DeviceManagementResponse&));
90 91
91 std::string InitCannedResponse() { 92 std::string InitCannedResponse() {
92 interceptor_.reset(new TestRequestInterceptor("localhost")); 93 interceptor_.reset(new TestRequestInterceptor("localhost"));
93 return "http://localhost"; 94 return "http://localhost";
94 } 95 }
95 96
96 std::string InitTestServer() { 97 std::string InitTestServer() {
97 StartTestServer(); 98 StartTestServer();
98 return test_server_->GetURL("device_management").spec(); 99 return test_server_->GetServiceURL().spec();
99 } 100 }
100 101
101 protected: 102 protected:
102 void ExpectRequest() { 103 void ExpectRequest() {
103 if (interceptor_) 104 if (interceptor_)
104 interceptor_->PushJobCallback(base::Bind(&ResponseJob)); 105 interceptor_->PushJobCallback(base::Bind(&ResponseJob));
105 } 106 }
106 107
107 void PerformRegistration() { 108 void PerformRegistration() {
108 ExpectRequest(); 109 ExpectRequest();
(...skipping 21 matching lines...) Expand all
130 } 131 }
131 132
132 virtual void CleanUpOnMainThread() OVERRIDE { 133 virtual void CleanUpOnMainThread() OVERRIDE {
133 service_.reset(); 134 service_.reset();
134 test_server_.reset(); 135 test_server_.reset();
135 interceptor_.reset(); 136 interceptor_.reset();
136 } 137 }
137 138
138 void StartTestServer() { 139 void StartTestServer() {
139 test_server_.reset( 140 test_server_.reset(
140 new net::TestServer( 141 new LocalPolicyTestServer("device_management_service_browsertest"));
141 net::TestServer::TYPE_HTTP,
142 net::TestServer::kLocalhost,
143 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/policy"))));
144 ASSERT_TRUE(test_server_->Start()); 142 ASSERT_TRUE(test_server_->Start());
145 } 143 }
146 144
147 void RecordToken(DeviceManagementStatus status, 145 void RecordToken(DeviceManagementStatus status,
148 const em::DeviceManagementResponse& response) { 146 const em::DeviceManagementResponse& response) {
149 token_ = response.register_response().device_management_token(); 147 token_ = response.register_response().device_management_token();
150 } 148 }
151 149
152 std::string token_; 150 std::string token_;
153 scoped_ptr<DeviceManagementService> service_; 151 scoped_ptr<DeviceManagementService> service_;
154 scoped_ptr<net::TestServer> test_server_; 152 scoped_ptr<LocalPolicyTestServer> test_server_;
155 scoped_ptr<TestRequestInterceptor> interceptor_; 153 scoped_ptr<TestRequestInterceptor> interceptor_;
156 }; 154 };
157 155
158 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Registration) { 156 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, Registration) {
159 PerformRegistration(); 157 PerformRegistration();
160 EXPECT_FALSE(token_.empty()); 158 EXPECT_FALSE(token_.empty());
161 } 159 }
162 160
163 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) { 161 IN_PROC_BROWSER_TEST_P(DeviceManagementServiceIntegrationTest, PolicyFetch) {
164 PerformRegistration(); 162 PerformRegistration();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 MessageLoop::current()->Run(); 207 MessageLoop::current()->Run();
210 } 208 }
211 209
212 INSTANTIATE_TEST_CASE_P( 210 INSTANTIATE_TEST_CASE_P(
213 DeviceManagementServiceIntegrationTestInstance, 211 DeviceManagementServiceIntegrationTestInstance,
214 DeviceManagementServiceIntegrationTest, 212 DeviceManagementServiceIntegrationTest,
215 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse, 213 testing::Values(&DeviceManagementServiceIntegrationTest::InitCannedResponse,
216 &DeviceManagementServiceIntegrationTest::InitTestServer)); 214 &DeviceManagementServiceIntegrationTest::InitTestServer));
217 215
218 } // namespace policy 216 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_browsertest.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698