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

Side by Side Diff: chrome/browser/policy/asynchronous_policy_loader_unittest.cc

Issue 8467011: Include only policy definitions that apply to the platfrom in the policy definition list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust all policy provider tests to use shared testing code. Net-negative line counts! Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "chrome/browser/policy/asynchronous_policy_loader.h" 7 #include "chrome/browser/policy/asynchronous_policy_loader.h"
8 #include "chrome/browser/policy/asynchronous_policy_provider.h" 8 #include "chrome/browser/policy/asynchronous_policy_provider.h"
9 #include "chrome/browser/policy/asynchronous_policy_test_base.h" 9 #include "chrome/browser/policy/asynchronous_policy_test_base.h"
10 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 10 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 12
13 using ::testing::_;
14 using ::testing::InSequence; 13 using ::testing::InSequence;
15 using ::testing::Return; 14 using ::testing::Return;
15 using ::testing::_;
16 16
17 namespace policy { 17 namespace policy {
18 18
19 namespace { 19 namespace {
20 20
21 void IgnoreCallback() { 21 void IgnoreCallback() {
22 } 22 }
23 23
24 } // namespace 24 } // namespace
25 25
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 int dictionary_number = 0; 79 int dictionary_number = 0;
80 InSequence s; 80 InSequence s;
81 EXPECT_CALL(*delegate_, Load()).WillOnce( 81 EXPECT_CALL(*delegate_, Load()).WillOnce(
82 CreateSequencedTestDictionary(&dictionary_number)); 82 CreateSequencedTestDictionary(&dictionary_number));
83 EXPECT_CALL(*delegate_, Load()).WillOnce( 83 EXPECT_CALL(*delegate_, Load()).WillOnce(
84 CreateSequencedTestDictionary(&dictionary_number)); 84 CreateSequencedTestDictionary(&dictionary_number));
85 scoped_refptr<AsynchronousPolicyLoader> loader = 85 scoped_refptr<AsynchronousPolicyLoader> loader =
86 new AsynchronousPolicyLoader(delegate_.release(), 10); 86 new AsynchronousPolicyLoader(delegate_.release(), 10);
87 loader->Init(ignore_callback_); 87 loader->Init(ignore_callback_);
88 loop_.RunAllPending(); 88 loop_.RunAllPending();
89 loader->Reload(); 89 loader->Reload(true);
90 loop_.RunAllPending(); 90 loop_.RunAllPending();
91 91
92 const DictionaryValue* loaded_dict(loader->policy()); 92 const DictionaryValue* loaded_dict(loader->policy());
93 int loaded_number; 93 int loaded_number;
94 EXPECT_TRUE(loaded_dict->GetInteger("id", &loaded_number)); 94 EXPECT_TRUE(loaded_dict->GetInteger("id", &loaded_number));
95 EXPECT_EQ(dictionary_number, loaded_number); 95 EXPECT_EQ(dictionary_number, loaded_number);
96 } 96 }
97 97
98 // Ensure that calling stop on the loader stops subsequent reloads from 98 // Ensure that calling stop on the loader stops subsequent reloads from
99 // happening. 99 // happening.
100 TEST_F(AsynchronousPolicyLoaderTest, Stop) { 100 TEST_F(AsynchronousPolicyLoaderTest, Stop) {
101 ON_CALL(*delegate_, Load()).WillByDefault(CreateTestDictionary()); 101 ON_CALL(*delegate_, Load()).WillByDefault(CreateTestDictionary());
102 EXPECT_CALL(*delegate_, Load()).Times(1); 102 EXPECT_CALL(*delegate_, Load()).Times(1);
103 scoped_refptr<AsynchronousPolicyLoader> loader = 103 scoped_refptr<AsynchronousPolicyLoader> loader =
104 new AsynchronousPolicyLoader(delegate_.release(), 10); 104 new AsynchronousPolicyLoader(delegate_.release(), 10);
105 loader->Init(ignore_callback_); 105 loader->Init(ignore_callback_);
106 loop_.RunAllPending(); 106 loop_.RunAllPending();
107 loader->Stop(); 107 loader->Stop();
108 loop_.RunAllPending(); 108 loop_.RunAllPending();
109 loader->Reload(); 109 loader->Reload(true);
110 loop_.RunAllPending(); 110 loop_.RunAllPending();
111 } 111 }
112 112
113 // Verifies that the provider is notified upon policy reload. 113 // Verifies that the provider is notified upon policy reload.
114 TEST_F(AsynchronousPolicyLoaderTest, ProviderNotificationOnPolicyChange) { 114 TEST_F(AsynchronousPolicyLoaderTest, ProviderNotificationOnPolicyChange) {
115 InSequence s; 115 InSequence s;
116 MockConfigurationPolicyObserver observer; 116 MockConfigurationPolicyObserver observer;
117 int dictionary_number_1 = 0; 117 int dictionary_number_1 = 0;
118 int dictionary_number_2 = 0; 118 int dictionary_number_2 = 0;
119 EXPECT_CALL(*delegate_, Load()).WillOnce( 119 EXPECT_CALL(*delegate_, Load()).WillOnce(
120 CreateSequencedTestDictionary(&dictionary_number_1)); 120 CreateSequencedTestDictionary(&dictionary_number_1));
121 EXPECT_CALL(*delegate_, Load()).WillOnce( 121 EXPECT_CALL(*delegate_, Load()).WillOnce(
122 CreateSequencedTestDictionary(&dictionary_number_2)); 122 CreateSequencedTestDictionary(&dictionary_number_2));
123 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); 123 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1);
124 EXPECT_CALL(*delegate_, Load()).WillOnce( 124 EXPECT_CALL(*delegate_, Load()).WillOnce(
125 CreateSequencedTestDictionary(&dictionary_number_2)); 125 CreateSequencedTestDictionary(&dictionary_number_2));
126 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); 126 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1);
127 EXPECT_CALL(*delegate_, Load()).WillOnce( 127 EXPECT_CALL(*delegate_, Load()).WillOnce(
128 CreateSequencedTestDictionary(&dictionary_number_1)); 128 CreateSequencedTestDictionary(&dictionary_number_1));
129 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); 129 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1);
130 scoped_refptr<AsynchronousPolicyLoader> loader = 130 scoped_refptr<AsynchronousPolicyLoader> loader =
131 new AsynchronousPolicyLoader(delegate_.release(), 10); 131 new AsynchronousPolicyLoader(delegate_.release(), 10);
132 AsynchronousPolicyProvider provider(NULL, loader); 132 AsynchronousPolicyProvider provider(NULL, loader);
133 // |registrar| must be declared last so that it is destroyed first. 133 // |registrar| must be declared last so that it is destroyed first.
134 ConfigurationPolicyObserverRegistrar registrar; 134 ConfigurationPolicyObserverRegistrar registrar;
135 registrar.Init(&provider, &observer); 135 registrar.Init(&provider, &observer);
136 loop_.RunAllPending(); 136 loop_.RunAllPending();
137 loader->Reload(); 137 loader->Reload(true);
138 loop_.RunAllPending();
139 loader->Reload();
140 loop_.RunAllPending();
141 loader->Reload();
142 loop_.RunAllPending(); 138 loop_.RunAllPending();
143 } 139 }
144 140
145 } // namespace policy 141 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698