| OLD | NEW |
| 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 "base/base64.h" | 5 #include "base/base64.h" |
| 6 #include "base/json/json_reader.h" | 6 #include "base/json/json_reader.h" |
| 7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" | 9 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" |
| 10 #include "components/policy/core/common/cloud/policy_header_io_helper.h" | 10 #include "components/policy/core/common/cloud/policy_header_io_helper.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 if (expected_dmtoken.empty()) { | 54 if (expected_dmtoken.empty()) { |
| 55 EXPECT_TRUE(headers.IsEmpty()); | 55 EXPECT_TRUE(headers.IsEmpty()); |
| 56 } else { | 56 } else { |
| 57 // Read header. | 57 // Read header. |
| 58 std::string header; | 58 std::string header; |
| 59 EXPECT_TRUE(headers.GetHeader(kPolicyHeaderName, &header)); | 59 EXPECT_TRUE(headers.GetHeader(kPolicyHeaderName, &header)); |
| 60 // Decode the base64 value into JSON. | 60 // Decode the base64 value into JSON. |
| 61 std::string decoded; | 61 std::string decoded; |
| 62 base::Base64Decode(header, &decoded); | 62 base::Base64Decode(header, &decoded); |
| 63 // Parse the JSON. | 63 // Parse the JSON. |
| 64 scoped_ptr<Value> value(base::JSONReader::Read(decoded)); | 64 scoped_ptr<base::Value> value(base::JSONReader::Read(decoded)); |
| 65 ASSERT_TRUE(value); | 65 ASSERT_TRUE(value); |
| 66 DictionaryValue* dict; | 66 base::DictionaryValue* dict; |
| 67 EXPECT_TRUE(value->GetAsDictionary(&dict)); | 67 EXPECT_TRUE(value->GetAsDictionary(&dict)); |
| 68 // Read the values and verify them vs the expected values. | 68 // Read the values and verify them vs the expected values. |
| 69 std::string dm_token; | 69 std::string dm_token; |
| 70 dict->GetString("user_dmtoken", &dm_token); | 70 dict->GetString("user_dmtoken", &dm_token); |
| 71 EXPECT_EQ(dm_token, expected_dmtoken); | 71 EXPECT_EQ(dm_token, expected_dmtoken); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 base::MessageLoop loop_; | 75 base::MessageLoop loop_; |
| 76 scoped_ptr<PolicyHeaderService> service_; | 76 scoped_ptr<PolicyHeaderService> service_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 106 user_store_.SetPolicy(scoped_ptr<PolicyData>()); | 106 user_store_.SetPolicy(scoped_ptr<PolicyData>()); |
| 107 task_runner_->RunUntilIdle(); | 107 task_runner_->RunUntilIdle(); |
| 108 | 108 |
| 109 net::TestURLRequest request2( | 109 net::TestURLRequest request2( |
| 110 GURL(kDMServerURL), net::DEFAULT_PRIORITY, NULL, &context); | 110 GURL(kDMServerURL), net::DEFAULT_PRIORITY, NULL, &context); |
| 111 helper_->AddPolicyHeaders(&request2); | 111 helper_->AddPolicyHeaders(&request2); |
| 112 ValidateHeader(request2.extra_request_headers(), ""); | 112 ValidateHeader(request2.extra_request_headers(), ""); |
| 113 } | 113 } |
| 114 | 114 |
| 115 } // namespace policy | 115 } // namespace policy |
| OLD | NEW |