Chromium Code Reviews| 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 "chrome/browser/chromeos/policy/cloud_external_data_manager_base.h" | 5 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/logging.h" | |
|
bartfab (slow)
2013/11/08 12:40:37
Nit: Where is this used?
Joao da Silva
2013/11/08 14:26:55
Oops, removed
| |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/sha1.h" | 17 #include "base/sha1.h" |
| 17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/test/test_simple_task_runner.h" | 20 #include "base/test/test_simple_task_runner.h" |
| 20 #include "base/values.h" | 21 #include "base/values.h" |
| 21 #include "chrome/browser/chromeos/policy/cloud_external_data_store.h" | 22 #include "chrome/browser/chromeos/policy/cloud_external_data_store.h" |
| 22 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" | 23 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
| 23 #include "chrome/browser/policy/cloud/resource_cache.h" | 24 #include "chrome/browser/policy/cloud/resource_cache.h" |
| 24 #include "chrome/browser/policy/external_data_fetcher.h" | 25 #include "chrome/browser/policy/external_data_fetcher.h" |
| 25 #include "chrome/browser/policy/policy_map.h" | 26 #include "chrome/browser/policy/policy_map.h" |
| 26 #include "chrome/browser/policy/policy_types.h" | 27 #include "chrome/browser/policy/policy_types.h" |
| 28 #include "chrome/browser/policy/test/policy_test_utils.h" | |
| 29 #include "components/policy/core/common/policy_details.h" | |
|
bartfab (slow)
2013/11/08 12:40:37
Nit: Already included by header file.
Joao da Silva
2013/11/08 14:26:55
Done.
| |
| 27 #include "net/http/http_status_code.h" | 30 #include "net/http/http_status_code.h" |
| 28 #include "net/url_request/test_url_fetcher_factory.h" | 31 #include "net/url_request/test_url_fetcher_factory.h" |
| 29 #include "net/url_request/url_fetcher.h" | 32 #include "net/url_request/url_fetcher.h" |
| 30 #include "net/url_request/url_fetcher_delegate.h" | 33 #include "net/url_request/url_fetcher_delegate.h" |
| 31 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
| 32 #include "net/url_request/url_request_test_util.h" | 35 #include "net/url_request/url_request_test_util.h" |
| 33 #include "policy/policy_constants.h" | |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 36 | 38 |
| 37 namespace policy { | 39 namespace policy { |
| 38 | 40 |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 // A string policy. | 43 // A string policy. |
| 42 const char kStringPolicy[] = "StringPolicy"; | 44 const char kStringPolicy[] = "StringPolicy"; |
| 43 // A policy that may reference up to 10 bytes of external data. | 45 // A policy that may reference up to 10 bytes of external data. |
| 44 const char k10BytePolicy[] = "10BytePolicy"; | 46 const char k10BytePolicy[] = "10BytePolicy"; |
| 45 // A policy that may reference up to 20 bytes of external data. | 47 // A policy that may reference up to 20 bytes of external data. |
| 46 const char k20BytePolicy[] = "20BytePolicy"; | 48 const char k20BytePolicy[] = "20BytePolicy"; |
| 47 // A nonexistent policy. | 49 // A nonexistent policy. |
| 48 const char kUnknownPolicy[] = "UnknownPolicy"; | 50 const char kUnknownPolicy[] = "UnknownPolicy"; |
| 49 | 51 |
| 50 const char k10BytePolicyURL[] = "http://localhost/10_bytes"; | 52 const char k10BytePolicyURL[] = "http://localhost/10_bytes"; |
| 51 const char k20BytePolicyURL[] = "http://localhost/20_bytes"; | 53 const char k20BytePolicyURL[] = "http://localhost/20_bytes"; |
| 52 | 54 |
| 53 const char k10ByteData[] = "10 bytes.."; | 55 const char k10ByteData[] = "10 bytes.."; |
| 54 const char k20ByteData[] = "20 bytes............"; | 56 const char k20ByteData[] = "20 bytes............"; |
| 55 | 57 |
| 56 const PolicyDefinitionList::Entry kPolicyDefinitionListEntries[] = { | 58 const PolicyDetails kPolicyDetails[] = { |
| 57 { kStringPolicy, base::Value::TYPE_STRING, false, 1, 0 }, | 59 // is_deprecated is_device_policy id max_external_data_size |
| 58 { k10BytePolicy, base::Value::TYPE_DICTIONARY, false, 2, 10 }, | 60 { false, false, 1, 0 }, |
| 59 { k20BytePolicy, base::Value::TYPE_DICTIONARY, false, 3, 20 }, | 61 { false, false, 2, 10 }, |
| 60 }; | 62 { false, false, 3, 20 }, |
| 61 | |
| 62 const PolicyDefinitionList kPolicyDefinitionList = { | |
| 63 kPolicyDefinitionListEntries, | |
| 64 kPolicyDefinitionListEntries + arraysize(kPolicyDefinitionListEntries), | |
| 65 }; | 63 }; |
| 66 | 64 |
| 67 const char kCacheKey[] = "data"; | 65 const char kCacheKey[] = "data"; |
| 68 | 66 |
| 69 // A variant of net::FakeURLFetcherFactory that makes it an error to request a | 67 // A variant of net::FakeURLFetcherFactory that makes it an error to request a |
| 70 // fetcher for an unknown URL. | 68 // fetcher for an unknown URL. |
| 71 class FakeURLFetcherFactory : public net::FakeURLFetcherFactory { | 69 class FakeURLFetcherFactory : public net::FakeURLFetcherFactory { |
| 72 public: | 70 public: |
| 73 FakeURLFetcherFactory(); | 71 FakeURLFetcherFactory(); |
| 74 virtual ~FakeURLFetcherFactory(); | 72 virtual ~FakeURLFetcherFactory(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 base::MessageLoop message_loop_; | 131 base::MessageLoop message_loop_; |
| 134 base::ScopedTempDir temp_dir_; | 132 base::ScopedTempDir temp_dir_; |
| 135 scoped_ptr<ResourceCache> resource_cache_; | 133 scoped_ptr<ResourceCache> resource_cache_; |
| 136 MockCloudPolicyStore cloud_policy_store_; | 134 MockCloudPolicyStore cloud_policy_store_; |
| 137 scoped_refptr<net::TestURLRequestContextGetter> request_content_getter_; | 135 scoped_refptr<net::TestURLRequestContextGetter> request_content_getter_; |
| 138 FakeURLFetcherFactory fetcher_factory_; | 136 FakeURLFetcherFactory fetcher_factory_; |
| 139 | 137 |
| 140 scoped_ptr<CloudExternalDataManagerBase> external_data_manager_; | 138 scoped_ptr<CloudExternalDataManagerBase> external_data_manager_; |
| 141 | 139 |
| 142 std::map<int, std::string*> callback_data_; | 140 std::map<int, std::string*> callback_data_; |
| 141 PolicyDetailsMap policy_details_; | |
| 143 | 142 |
| 144 DISALLOW_COPY_AND_ASSIGN(CloudExternalDataManagerBaseTest); | 143 DISALLOW_COPY_AND_ASSIGN(CloudExternalDataManagerBaseTest); |
| 145 }; | 144 }; |
| 146 | 145 |
| 147 CloudExternalDataManagerBaseTest::CloudExternalDataManagerBaseTest() { | 146 CloudExternalDataManagerBaseTest::CloudExternalDataManagerBaseTest() { |
| 148 } | 147 } |
| 149 | 148 |
| 150 void CloudExternalDataManagerBaseTest::SetUp() { | 149 void CloudExternalDataManagerBaseTest::SetUp() { |
| 151 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 150 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 152 resource_cache_.reset(new ResourceCache(temp_dir_.path(), | 151 resource_cache_.reset(new ResourceCache(temp_dir_.path(), |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 164 k10BytePolicy, | 163 k10BytePolicy, |
| 165 ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k10ByteData))); | 164 ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k10ByteData))); |
| 166 // Make |k20BytePolicy| reference 20 bytes of external data. | 165 // Make |k20BytePolicy| reference 20 bytes of external data. |
| 167 SetExternalDataReference( | 166 SetExternalDataReference( |
| 168 k20BytePolicy, | 167 k20BytePolicy, |
| 169 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); | 168 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); |
| 170 cloud_policy_store_.NotifyStoreLoaded(); | 169 cloud_policy_store_.NotifyStoreLoaded(); |
| 171 | 170 |
| 172 request_content_getter_ = new net::TestURLRequestContextGetter( | 171 request_content_getter_ = new net::TestURLRequestContextGetter( |
| 173 base::MessageLoopProxy::current()); | 172 base::MessageLoopProxy::current()); |
| 173 | |
| 174 policy_details_.SetDetails(kStringPolicy, &kPolicyDetails[0]); | |
| 175 policy_details_.SetDetails(k10BytePolicy, &kPolicyDetails[1]); | |
| 176 policy_details_.SetDetails(k20BytePolicy, &kPolicyDetails[2]); | |
| 174 } | 177 } |
| 175 | 178 |
| 176 void CloudExternalDataManagerBaseTest::TearDown() { | 179 void CloudExternalDataManagerBaseTest::TearDown() { |
| 177 external_data_manager_.reset(); | 180 external_data_manager_.reset(); |
| 178 base::RunLoop().RunUntilIdle(); | 181 base::RunLoop().RunUntilIdle(); |
| 179 ResetCallbackData(); | 182 ResetCallbackData(); |
| 180 } | 183 } |
| 181 | 184 |
| 182 void CloudExternalDataManagerBaseTest::SetUpExternalDataManager() { | 185 void CloudExternalDataManagerBaseTest::SetUpExternalDataManager() { |
| 183 external_data_manager_.reset(new CloudExternalDataManagerBase( | 186 external_data_manager_.reset(new CloudExternalDataManagerBase( |
| 184 &kPolicyDefinitionList, | 187 policy_details_.GetCallback(), |
| 185 message_loop_.message_loop_proxy(), | 188 message_loop_.message_loop_proxy(), |
| 186 message_loop_.message_loop_proxy())); | 189 message_loop_.message_loop_proxy())); |
| 187 external_data_manager_->SetExternalDataStore(make_scoped_ptr( | 190 external_data_manager_->SetExternalDataStore(make_scoped_ptr( |
| 188 new CloudExternalDataStore(kCacheKey, | 191 new CloudExternalDataStore(kCacheKey, |
| 189 message_loop_.message_loop_proxy(), | 192 message_loop_.message_loop_proxy(), |
| 190 resource_cache_.get()))); | 193 resource_cache_.get()))); |
| 191 external_data_manager_->SetPolicyStore(&cloud_policy_store_); | 194 external_data_manager_->SetPolicyStore(&cloud_policy_store_); |
| 192 } | 195 } |
| 193 | 196 |
| 194 scoped_ptr<base::DictionaryValue> | 197 scoped_ptr<base::DictionaryValue> |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k10ByteData))); | 747 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k10ByteData))); |
| 745 cloud_policy_store_.NotifyStoreLoaded(); | 748 cloud_policy_store_.NotifyStoreLoaded(); |
| 746 base::RunLoop().RunUntilIdle(); | 749 base::RunLoop().RunUntilIdle(); |
| 747 EXPECT_EQ(1u, callback_data_.size()); | 750 EXPECT_EQ(1u, callback_data_.size()); |
| 748 ASSERT_TRUE(callback_data_[1]); | 751 ASSERT_TRUE(callback_data_[1]); |
| 749 EXPECT_EQ(k10ByteData, *callback_data_[1]); | 752 EXPECT_EQ(k10ByteData, *callback_data_[1]); |
| 750 ResetCallbackData(); | 753 ResetCallbackData(); |
| 751 } | 754 } |
| 752 | 755 |
| 753 } // namespace policy | 756 } // namespace policy |
| OLD | NEW |