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

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

Issue 5219006: Refresh policies from DM server periodically (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 10 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/scoped_temp_dir.h" 6 #include "base/scoped_temp_dir.h"
7 #include "chrome/browser/browser_thread.h" 7 #include "chrome/browser/browser_thread.h"
8 #include "chrome/browser/net/gaia/token_service.h" 8 #include "chrome/browser/net/gaia/token_service.h"
9 #include "chrome/browser/policy/configuration_policy_pref_store.h" 9 #include "chrome/browser/policy/configuration_policy_pref_store.h"
10 #include "chrome/browser/policy/device_management_policy_provider.h" 10 #include "chrome/browser/policy/device_management_policy_provider.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 provider_->Provide(&store); 69 provider_->Provide(&store);
70 ASSERT_EQ(1U, store.policy_map().size()); 70 ASSERT_EQ(1U, store.policy_map().size());
71 Mock::VerifyAndClearExpectations(backend_); 71 Mock::VerifyAndClearExpectations(backend_);
72 Mock::VerifyAndClearExpectations(&store); 72 Mock::VerifyAndClearExpectations(&store);
73 } 73 }
74 74
75 virtual void TearDown() { 75 virtual void TearDown() {
76 loop_.RunAllPending(); 76 loop_.RunAllPending();
77 } 77 }
78 78
79 protected:
80 MockDeviceManagementBackend* backend_; // weak 79 MockDeviceManagementBackend* backend_; // weak
81 scoped_ptr<DeviceManagementPolicyProvider> provider_; 80 scoped_ptr<DeviceManagementPolicyProvider> provider_;
82 81
82 protected:
83 void SetRefreshDelays(DeviceManagementPolicyProvider* provider,
84 int64 policy_refresh_rate_ms,
85 int64 policy_refresh_max_earlier_ms,
86 int64 policy_refresh_error_delay_ms,
87 int64 token_fetch_error_delay_ms) {
88 provider->set_policy_refresh_rate_ms(policy_refresh_rate_ms);
89 provider->set_policy_refresh_max_earlier_ms(policy_refresh_max_earlier_ms);
90 provider->set_policy_refresh_error_delay_ms(policy_refresh_error_delay_ms);
91 provider->set_token_fetch_error_delay_ms(token_fetch_error_delay_ms);
92 }
93
83 private: 94 private:
84 MessageLoop loop_; 95 MessageLoop loop_;
85 BrowserThread ui_thread_; 96 BrowserThread ui_thread_;
86 BrowserThread file_thread_; 97 BrowserThread file_thread_;
87 ScopedTempDir storage_dir_; 98 ScopedTempDir storage_dir_;
88 scoped_ptr<TokenService> token_service_; 99 scoped_ptr<TokenService> token_service_;
89 100
90 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest); 101 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest);
91 }; 102 };
92 103
(...skipping 27 matching lines...) Expand all
120 EXPECT_TRUE(store.policy_map().empty()); 131 EXPECT_TRUE(store.policy_map().empty());
121 } 132 }
122 133
123 // If a policy has been fetched previously, if should be available even before 134 // If a policy has been fetched previously, if should be available even before
124 // the login succeeds or the device management backend is available. 135 // the login succeeds or the device management backend is available.
125 TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) { 136 TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) {
126 // Pre-fetch and persist a policy 137 // Pre-fetch and persist a policy
127 SimulateSuccessfulInitialPolicyFetch(); 138 SimulateSuccessfulInitialPolicyFetch();
128 139
129 // Simulate a app relaunch by constructing a new provider. Policy should be 140 // Simulate a app relaunch by constructing a new provider. Policy should be
130 // immediately provided and no refresh should be triggered. 141 // refreshed (since that might be the purpose of the app relaunch).
131 CreateNewBackend(); 142 CreateNewBackend();
132 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).Times(0); 143 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).Times(1);
133 CreateNewProvider(); 144 CreateNewProvider();
145 Mock::VerifyAndClearExpectations(backend_);
146
147 // Simulate another app relaunch, this time against a failing backend.
148 // Cached policy should still be available.
149 CreateNewBackend();
150 backend_->AllShouldFail();
134 MockConfigurationPolicyStore store; 151 MockConfigurationPolicyStore store;
152 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).Times(1);
153 CreateNewProvider();
154 SimulateSuccessfulLoginAndRunPending();
135 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); 155 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1);
136 provider_->Provide(&store); 156 provider_->Provide(&store);
157 ASSERT_EQ(1U, store.policy_map().size());
137 } 158 }
138 159
139 // When policy is successfully fetched from the device management server, it 160 // When policy is successfully fetched from the device management server, it
140 // should force a policy refresh. 161 // should force a policy refresh.
141 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) { 162 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) {
142 MockNotificationObserver observer; 163 MockNotificationObserver observer;
143 NotificationRegistrar registrar; 164 NotificationRegistrar registrar;
144 registrar.Add(&observer, 165 registrar.Add(&observer,
145 NotificationType::POLICY_CHANGED, 166 NotificationType::POLICY_CHANGED,
146 NotificationService::AllSources()); 167 NotificationService::AllSources());
147 EXPECT_CALL(observer, 168 EXPECT_CALL(observer, Observe(_, _, _)).Times(1);
148 Observe(_, _, _)).Times(1);
149 SimulateSuccessfulInitialPolicyFetch(); 169 SimulateSuccessfulInitialPolicyFetch();
150 } 170 }
151 171
172 TEST_F(DeviceManagementPolicyProviderTest, ErrorCausesNewRequest) {
173 backend_->RegisterFailsOncePolicyFailsTwice();
174 SetRefreshDelays(provider_.get(), 1000 * 1000, 0, 0, 0);
175 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(2);
176 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).Times(3);
177 SimulateSuccessfulLoginAndRunPending();
152 } 178 }
179
180 TEST_F(DeviceManagementPolicyProviderTest, RefreshPolicies) {
181 backend_->AllWorksFirstPolicyFailsLater();
182 SetRefreshDelays(provider_.get(), 0, 0, 1000 * 1000, 1000);
183 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1);
184 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).Times(4);
185 SimulateSuccessfulLoginAndRunPending();
186 }
187
188 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_management_policy_provider.cc ('k') | chrome/browser/policy/device_token_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698