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

Side by Side Diff: components/policy/core/common/cloud/policy_header_service_unittest.cc

Issue 1548203002: Convert Pass()→std::move() in //components/[n-z]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bad headers Created 4 years, 12 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/policy/core/common/cloud/policy_header_service.h"
6
7 #include <utility>
8
5 #include "base/base64.h" 9 #include "base/base64.h"
6 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
7 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
8 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/test_simple_task_runner.h"
9 #include "base/values.h" 13 #include "base/values.h"
10 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 14 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
11 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" 15 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
12 #include "components/policy/core/common/cloud/policy_header_io_helper.h" 16 #include "components/policy/core/common/cloud/policy_header_io_helper.h"
13 #include "components/policy/core/common/cloud/policy_header_service.h"
14 #include "net/http/http_request_headers.h" 17 #include "net/http/http_request_headers.h"
15 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
16 #include "net/url_request/url_request_test_util.h" 19 #include "net/url_request/url_request_test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
18 21
19 namespace policy { 22 namespace policy {
20 using enterprise_management::PolicyData; 23 using enterprise_management::PolicyData;
21 24
22 namespace { 25 namespace {
23 const char kDMServerURL[] = "http://server_url"; 26 const char kDMServerURL[] = "http://server_url";
24 const char kPolicyHeaderName[] = "Chrome-Policy-Posture"; 27 const char kPolicyHeaderName[] = "Chrome-Policy-Posture";
25 28
26 class TestCloudPolicyStore : public MockCloudPolicyStore { 29 class TestCloudPolicyStore : public MockCloudPolicyStore {
27 public: 30 public:
28 void SetPolicy(scoped_ptr<PolicyData> policy) { 31 void SetPolicy(scoped_ptr<PolicyData> policy) {
29 policy_ = policy.Pass(); 32 policy_ = std::move(policy);
30 // Notify observers. 33 // Notify observers.
31 NotifyStoreLoaded(); 34 NotifyStoreLoaded();
32 } 35 }
33 }; 36 };
34 37
35 class PolicyHeaderServiceTest : public testing::Test { 38 class PolicyHeaderServiceTest : public testing::Test {
36 public: 39 public:
37 PolicyHeaderServiceTest() { 40 PolicyHeaderServiceTest() {
38 task_runner_ = make_scoped_refptr(new base::TestSimpleTaskRunner()); 41 task_runner_ = make_scoped_refptr(new base::TestSimpleTaskRunner());
39 } 42 }
40 ~PolicyHeaderServiceTest() override {} 43 ~PolicyHeaderServiceTest() override {}
41 44
42 void SetUp() override { 45 void SetUp() override {
43 service_.reset(new PolicyHeaderService(kDMServerURL, 46 service_.reset(new PolicyHeaderService(kDMServerURL,
44 kPolicyVerificationKeyHash, 47 kPolicyVerificationKeyHash,
45 &user_store_, 48 &user_store_,
46 &device_store_)); 49 &device_store_));
47 helper_ = service_->CreatePolicyHeaderIOHelper(task_runner_).Pass(); 50 helper_ = service_->CreatePolicyHeaderIOHelper(task_runner_);
48 } 51 }
49 52
50 void TearDown() override { 53 void TearDown() override {
51 task_runner_->RunUntilIdle(); 54 task_runner_->RunUntilIdle();
52 // Helper should outlive the service. 55 // Helper should outlive the service.
53 service_.reset(); 56 service_.reset();
54 helper_.reset(); 57 helper_.reset();
55 } 58 }
56 59
57 void ValidateHeader(const net::HttpRequestHeaders& headers, 60 void ValidateHeader(const net::HttpRequestHeaders& headers,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 EXPECT_TRUE(helper_); 100 EXPECT_TRUE(helper_);
98 } 101 }
99 102
100 TEST_F(PolicyHeaderServiceTest, TestWithAndWithoutPolicyHeader) { 103 TEST_F(PolicyHeaderServiceTest, TestWithAndWithoutPolicyHeader) {
101 // Set policy - this should push a header to the PolicyHeaderIOHelper. 104 // Set policy - this should push a header to the PolicyHeaderIOHelper.
102 scoped_ptr<PolicyData> policy(new PolicyData()); 105 scoped_ptr<PolicyData> policy(new PolicyData());
103 std::string expected_dmtoken = "expected_dmtoken"; 106 std::string expected_dmtoken = "expected_dmtoken";
104 std::string expected_policy_token = "expected_dmtoken"; 107 std::string expected_policy_token = "expected_dmtoken";
105 policy->set_request_token(expected_dmtoken); 108 policy->set_request_token(expected_dmtoken);
106 policy->set_policy_token(expected_policy_token); 109 policy->set_policy_token(expected_policy_token);
107 user_store_.SetPolicy(policy.Pass()); 110 user_store_.SetPolicy(std::move(policy));
108 task_runner_->RunUntilIdle(); 111 task_runner_->RunUntilIdle();
109 112
110 net::TestURLRequestContext context; 113 net::TestURLRequestContext context;
111 scoped_ptr<net::URLRequest> request(context.CreateRequest( 114 scoped_ptr<net::URLRequest> request(context.CreateRequest(
112 GURL(kDMServerURL), net::DEFAULT_PRIORITY, NULL)); 115 GURL(kDMServerURL), net::DEFAULT_PRIORITY, NULL));
113 helper_->AddPolicyHeaders(request->url(), request.get()); 116 helper_->AddPolicyHeaders(request->url(), request.get());
114 ValidateHeader(request->extra_request_headers(), expected_dmtoken, 117 ValidateHeader(request->extra_request_headers(), expected_dmtoken,
115 expected_policy_token); 118 expected_policy_token);
116 119
117 // Now blow away the policy data. 120 // Now blow away the policy data.
118 user_store_.SetPolicy(scoped_ptr<PolicyData>()); 121 user_store_.SetPolicy(scoped_ptr<PolicyData>());
119 task_runner_->RunUntilIdle(); 122 task_runner_->RunUntilIdle();
120 123
121 scoped_ptr<net::URLRequest> request2(context.CreateRequest( 124 scoped_ptr<net::URLRequest> request2(context.CreateRequest(
122 GURL(kDMServerURL), net::DEFAULT_PRIORITY, NULL)); 125 GURL(kDMServerURL), net::DEFAULT_PRIORITY, NULL));
123 helper_->AddPolicyHeaders(request2->url(), request2.get()); 126 helper_->AddPolicyHeaders(request2->url(), request2.get());
124 ValidateHeader(request2->extra_request_headers(), "", ""); 127 ValidateHeader(request2->extra_request_headers(), "", "");
125 } 128 }
126 129
127 } // namespace policy 130 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698