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

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

Issue 2033753002: Remove use of deprecated MessageLoop methods in chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: manual change Created 4 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h"
12 #include "chrome/browser/chromeos/attestation/attestation_key_payload.pb.h" 15 #include "chrome/browser/chromeos/attestation/attestation_key_payload.pb.h"
13 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" 16 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h"
14 #include "chrome/browser/chromeos/attestation/fake_certificate.h" 17 #include "chrome/browser/chromeos/attestation/fake_certificate.h"
15 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" 18 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
16 #include "chromeos/attestation/mock_attestation_flow.h" 19 #include "chromeos/attestation/mock_attestation_flow.h"
17 #include "chromeos/dbus/mock_cryptohome_client.h" 20 #include "chromeos/dbus/mock_cryptohome_client.h"
18 #include "chromeos/settings/cros_settings_names.h" 21 #include "chromeos/settings/cros_settings_names.h"
19 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" 22 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
20 #include "content/public/test/test_browser_thread.h" 23 #include "content/public/test/test_browser_thread.h"
21 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
22 25
23 using testing::_; 26 using testing::_;
24 using testing::Invoke; 27 using testing::Invoke;
25 using testing::StrictMock; 28 using testing::StrictMock;
26 using testing::WithArgs; 29 using testing::WithArgs;
27 30
28 namespace chromeos { 31 namespace chromeos {
29 namespace attestation { 32 namespace attestation {
30 33
31 namespace { 34 namespace {
32 35
33 const int64_t kCertValid = 90; 36 const int64_t kCertValid = 90;
34 const int64_t kCertExpiringSoon = 20; 37 const int64_t kCertExpiringSoon = 20;
35 const int64_t kCertExpired = -20; 38 const int64_t kCertExpired = -20;
36 39
37 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { 40 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) {
38 base::MessageLoop::current()->PostTask( 41 base::ThreadTaskRunnerHandle::Get()->PostTask(
39 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); 42 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
40 } 43 }
41 44
42 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) { 45 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) {
43 base::MessageLoop::current()->PostTask( 46 base::ThreadTaskRunnerHandle::Get()->PostTask(
44 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); 47 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
45 } 48 }
46 49
47 void DBusCallbackError(const BoolDBusMethodCallback& callback) { 50 void DBusCallbackError(const BoolDBusMethodCallback& callback) {
48 base::MessageLoop::current()->PostTask( 51 base::ThreadTaskRunnerHandle::Get()->PostTask(
49 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_FAILURE, false)); 52 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_FAILURE, false));
50 } 53 }
51 54
52 void CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) { 55 void CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) {
53 base::MessageLoop::current()->PostTask( 56 base::ThreadTaskRunnerHandle::Get()->PostTask(
54 FROM_HERE, base::Bind(callback, true, "fake_cert")); 57 FROM_HERE, base::Bind(callback, true, "fake_cert"));
55 } 58 }
56 59
57 void StatusCallbackSuccess( 60 void StatusCallbackSuccess(
58 const policy::CloudPolicyClient::StatusCallback& callback) { 61 const policy::CloudPolicyClient::StatusCallback& callback) {
59 base::MessageLoop::current()->PostTask( 62 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
60 FROM_HERE, base::Bind(callback, true)); 63 base::Bind(callback, true));
61 } 64 }
62 65
63 class FakeDBusData { 66 class FakeDBusData {
64 public: 67 public:
65 explicit FakeDBusData(const std::string& data) : data_(data) {} 68 explicit FakeDBusData(const std::string& data) : data_(data) {}
66 69
67 void operator() (const CryptohomeClient::DataMethodCallback& callback) { 70 void operator() (const CryptohomeClient::DataMethodCallback& callback) {
68 base::MessageLoop::current()->PostTask( 71 base::ThreadTaskRunnerHandle::Get()->PostTask(
69 FROM_HERE, 72 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, data_));
70 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, data_));
71 } 73 }
72 74
73 private: 75 private:
74 std::string data_; 76 std::string data_;
75 }; 77 };
76 78
77 } // namespace 79 } // namespace
78 80
79 class AttestationPolicyObserverTest : public ::testing::Test { 81 class AttestationPolicyObserverTest : public ::testing::Test {
80 public: 82 public:
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 SetupMocks(MOCK_NEW_KEY, ""); 220 SetupMocks(MOCK_NEW_KEY, "");
219 // Simulate a DBus failure. 221 // Simulate a DBus failure.
220 EXPECT_CALL(cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) 222 EXPECT_CALL(cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _))
221 .WillOnce(WithArgs<3>(Invoke(DBusCallbackError))) 223 .WillOnce(WithArgs<3>(Invoke(DBusCallbackError)))
222 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackFalse))); 224 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackFalse)));
223 Run(); 225 Run();
224 } 226 }
225 227
226 } // namespace attestation 228 } // namespace attestation
227 } // namespace chromeos 229 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698