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

Side by Side Diff: chrome/browser/chromeos/attestation/attestation_policy_observer_unittest.cc

Issue 18053006: Added retry support to AttestationPolicyObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/attestation/attestation_policy_observer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chrome/browser/chromeos/attestation/attestation_key_payload.pb.h" 10 #include "chrome/browser/chromeos/attestation/attestation_key_payload.pb.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { 68 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) {
69 base::MessageLoop::current()->PostTask( 69 base::MessageLoop::current()->PostTask(
70 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); 70 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
71 } 71 }
72 72
73 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) { 73 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) {
74 base::MessageLoop::current()->PostTask( 74 base::MessageLoop::current()->PostTask(
75 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); 75 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
76 } 76 }
77 77
78 void DBusCallbackError(const BoolDBusMethodCallback& callback) {
79 base::MessageLoop::current()->PostTask(
80 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_FAILURE, false));
81 }
82
78 void CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) { 83 void CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) {
79 base::MessageLoop::current()->PostTask( 84 base::MessageLoop::current()->PostTask(
80 FROM_HERE, base::Bind(callback, true, "fake_cert")); 85 FROM_HERE, base::Bind(callback, true, "fake_cert"));
81 } 86 }
82 87
83 void StatusCallbackSuccess( 88 void StatusCallbackSuccess(
84 const policy::CloudPolicyClient::StatusCallback& callback) { 89 const policy::CloudPolicyClient::StatusCallback& callback) {
85 base::MessageLoop::current()->PostTask( 90 base::MessageLoop::current()->PostTask(
86 FROM_HERE, base::Bind(callback, true)); 91 FROM_HERE, base::Bind(callback, true));
87 } 92 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if (new_key) { 185 if (new_key) {
181 EXPECT_CALL(attestation_flow_, GetCertificate(_, _, _)) 186 EXPECT_CALL(attestation_flow_, GetCertificate(_, _, _))
182 .WillOnce(WithArgs<2>(Invoke(CertCallbackSuccess))); 187 .WillOnce(WithArgs<2>(Invoke(CertCallbackSuccess)));
183 } 188 }
184 } 189 }
185 190
186 void Run() { 191 void Run() {
187 AttestationPolicyObserver observer(&policy_client_, 192 AttestationPolicyObserver observer(&policy_client_,
188 &cryptohome_client_, 193 &cryptohome_client_,
189 &attestation_flow_); 194 &attestation_flow_);
195 observer.set_retry_delay(0);
190 base::RunLoop().RunUntilIdle(); 196 base::RunLoop().RunUntilIdle();
191 } 197 }
192 198
193 std::string CreatePayload() { 199 std::string CreatePayload() {
194 AttestationKeyPayload proto; 200 AttestationKeyPayload proto;
195 proto.set_is_certificate_uploaded(true); 201 proto.set_is_certificate_uploaded(true);
196 std::string serialized; 202 std::string serialized;
197 proto.SerializeToString(&serialized); 203 proto.SerializeToString(&serialized);
198 return serialized; 204 return serialized;
199 } 205 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 ASSERT_TRUE(CreateCertificate(CERT_EXPIRED, &certificate)); 287 ASSERT_TRUE(CreateCertificate(CERT_EXPIRED, &certificate));
282 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED | MOCK_NEW_KEY, certificate); 288 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED | MOCK_NEW_KEY, certificate);
283 Run(); 289 Run();
284 } 290 }
285 291
286 TEST_F(AttestationPolicyObserverTest, IgnoreUnknownCertFormat) { 292 TEST_F(AttestationPolicyObserverTest, IgnoreUnknownCertFormat) {
287 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED, "unsupported"); 293 SetupMocks(MOCK_KEY_EXISTS | MOCK_KEY_UPLOADED, "unsupported");
288 Run(); 294 Run();
289 } 295 }
290 296
297 TEST_F(AttestationPolicyObserverTest, DBusFailureRetry) {
298 SetupMocks(MOCK_NEW_KEY, "");
299 // Simulate a DBus failure.
300 EXPECT_CALL(cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _))
301 .WillOnce(WithArgs<2>(Invoke(DBusCallbackError)))
302 .WillRepeatedly(WithArgs<2>(Invoke(DBusCallbackFalse)));
303 Run();
304 }
305
291 } // namespace attestation 306 } // namespace attestation
292 } // namespace chromeos 307 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/attestation/attestation_policy_observer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698