1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// found in the LICENSE file. 4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_util.h" 6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/callback.h" 8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/memory/weak_ptr.h" 9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/strings/string_number_conversions.h" 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/values.h" 11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/cloud/cloud_external_data_manager.h" 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/cloud/cloud_policy_core.h" 13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/cloud/cloud_policy_store.h" 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/external_data_fetcher.h" 15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/policy_map.h" 16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/policy_types.h" 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "crypto/sha2.h" 18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace policy { 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace test { 22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ExternalDataFetchCallback(scoped_ptr<std::string>* destination, 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const base::Closure& done_callback, 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<std::string> data) { 26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) *destination = data.Pass(); 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) done_callback.Run(); 28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)scoped_ptr<base::DictionaryValue> ConstructExternalDataReference( 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const std::string& url, 32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const std::string& data) { 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string hash = crypto::SHA256HashString(data); 34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<base::DictionaryValue> metadata(new base::DictionaryValue); 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) metadata->SetStringWithoutPathExpansion("url", url); 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) metadata->SetStringWithoutPathExpansion("hash", base::HexEncode(hash.c_str(), 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) hash.size())); 38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return metadata.Pass(); 39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SetExternalDataReference(CloudPolicyCore* core, 42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const std::string& policy, 43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<base::DictionaryValue> metadata) { 44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) CloudPolicyStore* store = core->store(); 45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ASSERT_TRUE(store); 46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) PolicyMap policy_map; 47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) policy_map.Set(policy, 48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) metadata.release(), 50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) new ExternalDataFetcher(store->external_data_manager(), 51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) policy)); 52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) store->SetPolicyMapForTesting(policy_map); 53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} // namespace test 56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} // namespace policy 57