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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_util.h"
7 #include "base/callback.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h"
11 #include "components/policy/core/common/cloud/cloud_external_data_manager.h"
12 #include "components/policy/core/common/cloud/cloud_policy_core.h"
13 #include "components/policy/core/common/cloud/cloud_policy_store.h"
14 #include "components/policy/core/common/external_data_fetcher.h"
15 #include "components/policy/core/common/policy_map.h"
16 #include "components/policy/core/common/policy_types.h"
17 #include "crypto/sha2.h"
18 #include "testing/gtest/include/gtest/gtest.h"
23 void ExternalDataFetchCallback(scoped_ptr
<std::string
>* destination
,
24 const base::Closure
& done_callback
,
25 scoped_ptr
<std::string
> data
) {
26 *destination
= data
.Pass();
30 scoped_ptr
<base::DictionaryValue
> ConstructExternalDataReference(
31 const std::string
& url
,
32 const std::string
& data
) {
33 const std::string hash
= crypto::SHA256HashString(data
);
34 scoped_ptr
<base::DictionaryValue
> metadata(new base::DictionaryValue
);
35 metadata
->SetStringWithoutPathExpansion("url", url
);
36 metadata
->SetStringWithoutPathExpansion("hash", base::HexEncode(hash
.c_str(),
38 return metadata
.Pass();
41 void SetExternalDataReference(CloudPolicyCore
* core
,
42 const std::string
& policy
,
43 scoped_ptr
<base::DictionaryValue
> metadata
) {
44 CloudPolicyStore
* store
= core
->store();
47 policy_map
.Set(policy
,
48 POLICY_LEVEL_MANDATORY
, POLICY_SCOPE_USER
, POLICY_SOURCE_CLOUD
,
50 new ExternalDataFetcher(store
->external_data_manager(),
52 store
->SetPolicyMapForTesting(policy_map
);