| 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 <memory> |
| 5 #include <string> | 6 #include <string> |
| 6 | 7 |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/callback.h" | 9 #include "base/callback.h" |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base.h" | 17 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base.h" |
| 17 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u
til.h" | 18 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u
til.h" |
| 18 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 19 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
| 19 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 20 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
| 20 #include "chrome/browser/policy/profile_policy_connector.h" | 21 #include "chrome/browser/policy/profile_policy_connector.h" |
| 21 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 22 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 50 const GURL url = | 51 const GURL url = |
| 51 embedded_test_server()->GetURL(std::string("/") + kExternalDataPath); | 52 embedded_test_server()->GetURL(std::string("/") + kExternalDataPath); |
| 52 | 53 |
| 53 base::FilePath test_dir; | 54 base::FilePath test_dir; |
| 54 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); | 55 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); |
| 55 std::string external_data; | 56 std::string external_data; |
| 56 ASSERT_TRUE(base::ReadFileToString(test_dir.AppendASCII(kExternalDataPath), | 57 ASSERT_TRUE(base::ReadFileToString(test_dir.AppendASCII(kExternalDataPath), |
| 57 &external_data)); | 58 &external_data)); |
| 58 ASSERT_FALSE(external_data.empty()); | 59 ASSERT_FALSE(external_data.empty()); |
| 59 | 60 |
| 60 scoped_ptr<base::DictionaryValue> metadata = | 61 std::unique_ptr<base::DictionaryValue> metadata = |
| 61 test::ConstructExternalDataReference(url.spec(), external_data); | 62 test::ConstructExternalDataReference(url.spec(), external_data); |
| 62 #if defined(OS_CHROMEOS) | 63 #if defined(OS_CHROMEOS) |
| 63 UserCloudPolicyManagerChromeOS* policy_manager = | 64 UserCloudPolicyManagerChromeOS* policy_manager = |
| 64 UserCloudPolicyManagerFactoryChromeOS::GetForProfile( | 65 UserCloudPolicyManagerFactoryChromeOS::GetForProfile( |
| 65 browser()->profile()); | 66 browser()->profile()); |
| 66 #else | 67 #else |
| 67 UserCloudPolicyManager* policy_manager = | 68 UserCloudPolicyManager* policy_manager = |
| 68 UserCloudPolicyManagerFactory::GetForBrowserContext(browser()->profile()); | 69 UserCloudPolicyManagerFactory::GetForBrowserContext(browser()->profile()); |
| 69 #endif | 70 #endif |
| 70 ASSERT_TRUE(policy_manager); | 71 ASSERT_TRUE(policy_manager); |
| 71 // TODO(bartfab): The test injects an ExternalDataFetcher for an arbitrary | 72 // TODO(bartfab): The test injects an ExternalDataFetcher for an arbitrary |
| 72 // policy. This is only done because there are no policies that reference | 73 // policy. This is only done because there are no policies that reference |
| 73 // external data yet. Once the first such policy is added, switch the test to | 74 // external data yet. Once the first such policy is added, switch the test to |
| 74 // that policy and stop injecting a manually instantiated ExternalDataFetcher. | 75 // that policy and stop injecting a manually instantiated ExternalDataFetcher. |
| 75 test::SetExternalDataReference(policy_manager->core(), | 76 test::SetExternalDataReference(policy_manager->core(), key::kHomepageLocation, |
| 76 key::kHomepageLocation, | 77 base::WrapUnique(metadata->DeepCopy())); |
| 77 make_scoped_ptr(metadata->DeepCopy())); | |
| 78 content::RunAllPendingInMessageLoop(); | 78 content::RunAllPendingInMessageLoop(); |
| 79 | 79 |
| 80 ProfilePolicyConnector* policy_connector = | 80 ProfilePolicyConnector* policy_connector = |
| 81 ProfilePolicyConnectorFactory::GetForBrowserContext(browser()->profile()); | 81 ProfilePolicyConnectorFactory::GetForBrowserContext(browser()->profile()); |
| 82 ASSERT_TRUE(policy_connector); | 82 ASSERT_TRUE(policy_connector); |
| 83 const PolicyMap& policies = policy_connector->policy_service()->GetPolicies( | 83 const PolicyMap& policies = policy_connector->policy_service()->GetPolicies( |
| 84 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 84 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 85 const PolicyMap::Entry* policy_entry = policies.Get(key::kHomepageLocation); | 85 const PolicyMap::Entry* policy_entry = policies.Get(key::kHomepageLocation); |
| 86 ASSERT_TRUE(policy_entry); | 86 ASSERT_TRUE(policy_entry); |
| 87 EXPECT_TRUE(base::Value::Equals(metadata.get(), policy_entry->value)); | 87 EXPECT_TRUE(base::Value::Equals(metadata.get(), policy_entry->value)); |
| 88 ASSERT_TRUE(policy_entry->external_data_fetcher); | 88 ASSERT_TRUE(policy_entry->external_data_fetcher); |
| 89 | 89 |
| 90 base::RunLoop run_loop; | 90 base::RunLoop run_loop; |
| 91 scoped_ptr<std::string> fetched_external_data; | 91 std::unique_ptr<std::string> fetched_external_data; |
| 92 policy_entry->external_data_fetcher->Fetch(base::Bind( | 92 policy_entry->external_data_fetcher->Fetch(base::Bind( |
| 93 &test::ExternalDataFetchCallback, | 93 &test::ExternalDataFetchCallback, |
| 94 &fetched_external_data, | 94 &fetched_external_data, |
| 95 run_loop.QuitClosure())); | 95 run_loop.QuitClosure())); |
| 96 run_loop.Run(); | 96 run_loop.Run(); |
| 97 | 97 |
| 98 ASSERT_TRUE(fetched_external_data); | 98 ASSERT_TRUE(fetched_external_data); |
| 99 EXPECT_EQ(external_data, *fetched_external_data); | 99 EXPECT_EQ(external_data, *fetched_external_data); |
| 100 } | 100 } |
| 101 | 101 |
| 102 } // namespace policy | 102 } // namespace policy |
| OLD | NEW |