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

Side by Side Diff: components/policy/core/common/async_policy_provider_unittest.cc

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias Created 4 years, 8 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 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 "components/policy/core/common/async_policy_provider.h" 5 #include "components/policy/core/common/async_policy_provider.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 27 matching lines...) Expand all
38 new base::StringValue(value), 38 new base::StringValue(value),
39 NULL); 39 NULL);
40 } 40 }
41 41
42 class MockPolicyLoader : public AsyncPolicyLoader { 42 class MockPolicyLoader : public AsyncPolicyLoader {
43 public: 43 public:
44 explicit MockPolicyLoader( 44 explicit MockPolicyLoader(
45 scoped_refptr<base::SequencedTaskRunner> task_runner); 45 scoped_refptr<base::SequencedTaskRunner> task_runner);
46 ~MockPolicyLoader() override; 46 ~MockPolicyLoader() override;
47 47
48 // Load() returns a scoped_ptr<PolicyBundle> but it can't be mocked because 48 // Load() returns a std::unique_ptr<PolicyBundle> but it can't be mocked
49 // scoped_ptr is moveable but not copyable. This override forwards the 49 // because std::unique_ptr is moveable but not copyable. This override
50 // call to MockLoad() which returns a PolicyBundle*, and returns a copy 50 // forwards the call to MockLoad() which returns a PolicyBundle*, and returns
51 // wrapped in a passed scoped_ptr. 51 // a copy wrapped in a std::unique_ptr.
52 scoped_ptr<PolicyBundle> Load() override; 52 std::unique_ptr<PolicyBundle> Load() override;
53 53
54 MOCK_METHOD0(MockLoad, const PolicyBundle*()); 54 MOCK_METHOD0(MockLoad, const PolicyBundle*());
55 MOCK_METHOD0(InitOnBackgroundThread, void()); 55 MOCK_METHOD0(InitOnBackgroundThread, void());
56 MOCK_METHOD0(LastModificationTime, base::Time()); 56 MOCK_METHOD0(LastModificationTime, base::Time());
57 57
58 private: 58 private:
59 DISALLOW_COPY_AND_ASSIGN(MockPolicyLoader); 59 DISALLOW_COPY_AND_ASSIGN(MockPolicyLoader);
60 }; 60 };
61 61
62 MockPolicyLoader::MockPolicyLoader( 62 MockPolicyLoader::MockPolicyLoader(
63 scoped_refptr<base::SequencedTaskRunner> task_runner) 63 scoped_refptr<base::SequencedTaskRunner> task_runner)
64 : AsyncPolicyLoader(task_runner) {} 64 : AsyncPolicyLoader(task_runner) {}
65 65
66 MockPolicyLoader::~MockPolicyLoader() {} 66 MockPolicyLoader::~MockPolicyLoader() {}
67 67
68 scoped_ptr<PolicyBundle> MockPolicyLoader::Load() { 68 std::unique_ptr<PolicyBundle> MockPolicyLoader::Load() {
69 scoped_ptr<PolicyBundle> bundle; 69 std::unique_ptr<PolicyBundle> bundle;
70 const PolicyBundle* loaded = MockLoad(); 70 const PolicyBundle* loaded = MockLoad();
71 if (loaded) { 71 if (loaded) {
72 bundle.reset(new PolicyBundle()); 72 bundle.reset(new PolicyBundle());
73 bundle->CopyFrom(*loaded); 73 bundle->CopyFrom(*loaded);
74 } 74 }
75 return bundle; 75 return bundle;
76 } 76 }
77 77
78 } // namespace 78 } // namespace
79 79
80 class AsyncPolicyProviderTest : public testing::Test { 80 class AsyncPolicyProviderTest : public testing::Test {
81 protected: 81 protected:
82 AsyncPolicyProviderTest(); 82 AsyncPolicyProviderTest();
83 ~AsyncPolicyProviderTest() override; 83 ~AsyncPolicyProviderTest() override;
84 84
85 void SetUp() override; 85 void SetUp() override;
86 void TearDown() override; 86 void TearDown() override;
87 87
88 base::MessageLoop loop_; 88 base::MessageLoop loop_;
89 SchemaRegistry schema_registry_; 89 SchemaRegistry schema_registry_;
90 PolicyBundle initial_bundle_; 90 PolicyBundle initial_bundle_;
91 MockPolicyLoader* loader_; 91 MockPolicyLoader* loader_;
92 scoped_ptr<AsyncPolicyProvider> provider_; 92 std::unique_ptr<AsyncPolicyProvider> provider_;
93 93
94 private: 94 private:
95 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProviderTest); 95 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProviderTest);
96 }; 96 };
97 97
98 AsyncPolicyProviderTest::AsyncPolicyProviderTest() {} 98 AsyncPolicyProviderTest::AsyncPolicyProviderTest() {}
99 99
100 AsyncPolicyProviderTest::~AsyncPolicyProviderTest() {} 100 AsyncPolicyProviderTest::~AsyncPolicyProviderTest() {}
101 101
102 void AsyncPolicyProviderTest::SetUp() { 102 void AsyncPolicyProviderTest::SetUp() {
103 SetPolicy(&initial_bundle_, "policy", "initial"); 103 SetPolicy(&initial_bundle_, "policy", "initial");
104 loader_ = new MockPolicyLoader(loop_.task_runner()); 104 loader_ = new MockPolicyLoader(loop_.task_runner());
105 EXPECT_CALL(*loader_, LastModificationTime()) 105 EXPECT_CALL(*loader_, LastModificationTime())
106 .WillRepeatedly(Return(base::Time())); 106 .WillRepeatedly(Return(base::Time()));
107 EXPECT_CALL(*loader_, InitOnBackgroundThread()).Times(1); 107 EXPECT_CALL(*loader_, InitOnBackgroundThread()).Times(1);
108 EXPECT_CALL(*loader_, MockLoad()).WillOnce(Return(&initial_bundle_)); 108 EXPECT_CALL(*loader_, MockLoad()).WillOnce(Return(&initial_bundle_));
109 109
110 provider_.reset(new AsyncPolicyProvider( 110 provider_.reset(new AsyncPolicyProvider(
111 &schema_registry_, scoped_ptr<AsyncPolicyLoader>(loader_))); 111 &schema_registry_, std::unique_ptr<AsyncPolicyLoader>(loader_)));
112 provider_->Init(&schema_registry_); 112 provider_->Init(&schema_registry_);
113 // Verify that the initial load is done synchronously: 113 // Verify that the initial load is done synchronously:
114 EXPECT_TRUE(provider_->policies().Equals(initial_bundle_)); 114 EXPECT_TRUE(provider_->policies().Equals(initial_bundle_));
115 115
116 loop_.RunUntilIdle(); 116 loop_.RunUntilIdle();
117 Mock::VerifyAndClearExpectations(loader_); 117 Mock::VerifyAndClearExpectations(loader_);
118 118
119 EXPECT_CALL(*loader_, LastModificationTime()) 119 EXPECT_CALL(*loader_, LastModificationTime())
120 .WillRepeatedly(Return(base::Time())); 120 .WillRepeatedly(Return(base::Time()));
121 } 121 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(0); 220 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(0);
221 provider_->Shutdown(); 221 provider_->Shutdown();
222 loop_.RunUntilIdle(); 222 loop_.RunUntilIdle();
223 Mock::VerifyAndClearExpectations(&observer); 223 Mock::VerifyAndClearExpectations(&observer);
224 224
225 provider_->RemoveObserver(&observer); 225 provider_->RemoveObserver(&observer);
226 provider_.reset(); 226 provider_.reset();
227 } 227 }
228 228
229 } // namespace policy 229 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/async_policy_provider.cc ('k') | components/policy/core/common/cloud/cloud_policy_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698