| Index: chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_util.cc
|
| diff --git a/chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_util.cc b/chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_util.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b816db99b83eeb16a3c3257a651ac549f193c21d
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_util.cc
|
| @@ -0,0 +1,56 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_util.h"
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/sha1.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "base/values.h"
|
| +#include "chrome/browser/policy/cloud/cloud_external_data_manager.h"
|
| +#include "chrome/browser/policy/cloud/cloud_policy_core.h"
|
| +#include "chrome/browser/policy/cloud/cloud_policy_store.h"
|
| +#include "chrome/browser/policy/external_data_fetcher.h"
|
| +#include "chrome/browser/policy/policy_map.h"
|
| +#include "chrome/browser/policy/policy_types.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace policy {
|
| +namespace test {
|
| +
|
| +void ExternalDataFetchCallback(scoped_ptr<std::string>* destination,
|
| + const base::Closure& done_callback,
|
| + scoped_ptr<std::string> data) {
|
| + *destination = data.Pass();
|
| + done_callback.Run();
|
| +}
|
| +
|
| +scoped_ptr<base::DictionaryValue> ConstructExternalDataReference(
|
| + const std::string& url,
|
| + const std::string& data) {
|
| + const std::string hash = base::SHA1HashString(data);
|
| + scoped_ptr<base::DictionaryValue> metadata(new base::DictionaryValue);
|
| + metadata->SetStringWithoutPathExpansion("url", url);
|
| + metadata->SetStringWithoutPathExpansion("hash", base::HexEncode(hash.c_str(),
|
| + hash.size()));
|
| + return metadata.Pass();
|
| +}
|
| +
|
| +void SetExternalDataReference(CloudPolicyCore* core,
|
| + const std::string& policy,
|
| + scoped_ptr<base::DictionaryValue> metadata) {
|
| + CloudPolicyStore* store = core->store();
|
| + ASSERT_TRUE(store);
|
| + PolicyMap policy_map;
|
| + policy_map.Set(policy,
|
| + POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
|
| + metadata.release(),
|
| + new ExternalDataFetcher(store->external_data_manager(),
|
| + policy));
|
| + store->SetPolicyMapForTesting(policy_map);
|
| +}
|
| +
|
| +} // namespace test
|
| +} // namespace policy
|
|
|