Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: components/policy/core/common/cloud/component_cloud_policy_service_unittest.cc

Issue 1144153004: components: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "components/policy/core/common/cloud/component_cloud_policy_service.h" 5 #include "components/policy/core/common/cloud/component_cloud_policy_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 12 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
15 #include "base/stl_util.h" 14 #include "base/stl_util.h"
16 #include "base/values.h" 15 #include "base/values.h"
17 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 16 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
18 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" 17 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
19 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" 18 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
20 #include "components/policy/core/common/cloud/policy_builder.h" 19 #include "components/policy/core/common/cloud/policy_builder.h"
21 #include "components/policy/core/common/cloud/resource_cache.h" 20 #include "components/policy/core/common/cloud/resource_cache.h"
22 #include "components/policy/core/common/external_data_fetcher.h" 21 #include "components/policy/core/common/external_data_fetcher.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 ~TestURLRequestContextGetter() override {} 98 ~TestURLRequestContextGetter() override {}
100 99
101 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 100 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
102 }; 101 };
103 102
104 } // namespace 103 } // namespace
105 104
106 class ComponentCloudPolicyServiceTest : public testing::Test { 105 class ComponentCloudPolicyServiceTest : public testing::Test {
107 protected: 106 protected:
108 ComponentCloudPolicyServiceTest() 107 ComponentCloudPolicyServiceTest()
109 : request_context_( 108 : request_context_(new TestURLRequestContextGetter(loop_.task_runner())),
110 new TestURLRequestContextGetter(loop_.message_loop_proxy())),
111 cache_(nullptr), 109 cache_(nullptr),
112 client_(nullptr), 110 client_(nullptr),
113 core_(GetChromeUserPolicyType(), 111 core_(GetChromeUserPolicyType(),
114 std::string(), 112 std::string(),
115 &store_, 113 &store_,
116 loop_.message_loop_proxy()) {} 114 loop_.task_runner()) {}
117 115
118 void SetUp() override { 116 void SetUp() override {
119 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 117 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
120 118
121 owned_cache_.reset( 119 owned_cache_.reset(
122 new ResourceCache(temp_dir_.path(), loop_.message_loop_proxy())); 120 new ResourceCache(temp_dir_.path(), loop_.task_runner()));
123 cache_ = owned_cache_.get(); 121 cache_ = owned_cache_.get();
124 122
125 builder_.policy_data().set_policy_type( 123 builder_.policy_data().set_policy_type(
126 dm_protocol::kChromeExtensionPolicyType); 124 dm_protocol::kChromeExtensionPolicyType);
127 builder_.policy_data().set_settings_entity_id(kTestExtension); 125 builder_.policy_data().set_settings_entity_id(kTestExtension);
128 builder_.payload().set_download_url(kTestDownload); 126 builder_.payload().set_download_url(kTestDownload);
129 builder_.payload().set_secure_hash(crypto::SHA256HashString(kTestPolicy)); 127 builder_.payload().set_secure_hash(crypto::SHA256HashString(kTestPolicy));
130 128
131 expected_policy_.Set("Name", 129 expected_policy_.Set("Name",
132 POLICY_LEVEL_MANDATORY, 130 POLICY_LEVEL_MANDATORY,
(...skipping 13 matching lines...) Expand all
146 RunUntilIdle(); 144 RunUntilIdle();
147 } 145 }
148 146
149 void RunUntilIdle() { 147 void RunUntilIdle() {
150 base::RunLoop().RunUntilIdle(); 148 base::RunLoop().RunUntilIdle();
151 } 149 }
152 150
153 void Connect() { 151 void Connect() {
154 client_ = new MockCloudPolicyClient(); 152 client_ = new MockCloudPolicyClient();
155 service_.reset(new ComponentCloudPolicyService( 153 service_.reset(new ComponentCloudPolicyService(
156 &delegate_, 154 &delegate_, &registry_, &core_, client_, owned_cache_.Pass(),
157 &registry_, 155 request_context_, loop_.task_runner(), loop_.task_runner()));
158 &core_,
159 client_,
160 owned_cache_.Pass(),
161 request_context_,
162 loop_.message_loop_proxy(),
163 loop_.message_loop_proxy()));
164 156
165 client_->SetDMToken(ComponentPolicyBuilder::kFakeToken); 157 client_->SetDMToken(ComponentPolicyBuilder::kFakeToken);
166 EXPECT_EQ(1u, client_->types_to_fetch_.size()); 158 EXPECT_EQ(1u, client_->types_to_fetch_.size());
167 core_.Connect(scoped_ptr<CloudPolicyClient>(client_)); 159 core_.Connect(scoped_ptr<CloudPolicyClient>(client_));
168 EXPECT_EQ(2u, client_->types_to_fetch_.size()); 160 EXPECT_EQ(2u, client_->types_to_fetch_.size());
169 161
170 // Also initialize the refresh scheduler, so that calls to 162 // Also initialize the refresh scheduler, so that calls to
171 // core()->RefreshSoon() trigger a FetchPolicy() call on the mock |client_|. 163 // core()->RefreshSoon() trigger a FetchPolicy() call on the mock |client_|.
172 // The |service_| should never trigger new fetches. 164 // The |service_| should never trigger new fetches.
173 EXPECT_CALL(*client_, FetchPolicy()); 165 EXPECT_CALL(*client_, FetchPolicy());
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 EXPECT_TRUE(ContainsKey(contents, kTestExtension)); 572 EXPECT_TRUE(ContainsKey(contents, kTestExtension));
581 EXPECT_FALSE(ContainsKey(contents, kTestExtension2)); 573 EXPECT_FALSE(ContainsKey(contents, kTestExtension2));
582 574
583 // And the service isn't publishing policy for the second extension anymore. 575 // And the service isn't publishing policy for the second extension anymore.
584 expected_bundle.Clear(); 576 expected_bundle.Clear();
585 expected_bundle.Get(ns).CopyFrom(expected_policy_); 577 expected_bundle.Get(ns).CopyFrom(expected_policy_);
586 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); 578 EXPECT_TRUE(service_->policy().Equals(expected_bundle));
587 } 579 }
588 580
589 } // namespace policy 581 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698