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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" 8 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h"
9 #include "chrome/browser/chromeos/settings/cros_settings.h" 9 #include "chrome/browser/chromeos/settings/cros_settings.h"
10 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 10 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
11 #include "chrome/browser/chromeos/settings/device_settings_service.h" 11 #include "chrome/browser/chromeos/settings/device_settings_service.h"
12 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 12 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
13 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" 13 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h"
14 #include "chromeos/attestation/mock_attestation_flow.h" 14 #include "chromeos/attestation/mock_attestation_flow.h"
15 #include "chromeos/dbus/mock_cryptohome_client.h" 15 #include "chromeos/dbus/mock_cryptohome_client.h"
16 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 using testing::_; 19 using testing::_;
20 using testing::Invoke; 20 using testing::Invoke;
21 using testing::StrictMock; 21 using testing::StrictMock;
22 using testing::WithArgs; 22 using testing::WithArgs;
23 23
24 namespace chromeos { 24 namespace chromeos {
25 namespace attestation { 25 namespace attestation {
26 26
27 namespace { 27 namespace {
28 28
29 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { 29 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) {
30 MessageLoop::current()->PostTask( 30 base::MessageLoop::current()->PostTask(
31 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); 31 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
32 } 32 }
33 33
34 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) { 34 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) {
35 MessageLoop::current()->PostTask( 35 base::MessageLoop::current()->PostTask(
36 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); 36 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
37 } 37 }
38 38
39 void DBusDataCallback(const CryptohomeClient::DataMethodCallback& callback) { 39 void DBusDataCallback(const CryptohomeClient::DataMethodCallback& callback) {
40 MessageLoop::current()->PostTask( 40 base::MessageLoop::current()->PostTask(
41 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, "fake")); 41 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, "fake"));
42 } 42 }
43 43
44 void CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) { 44 void CertCallbackSuccess(const AttestationFlow::CertificateCallback& callback) {
45 MessageLoop::current()->PostTask( 45 base::MessageLoop::current()->PostTask(
46 FROM_HERE, base::Bind(callback, true, "fake_cert")); 46 FROM_HERE, base::Bind(callback, true, "fake_cert"));
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
51 class AttestationPolicyObserverTest : public ::testing::Test { 51 class AttestationPolicyObserverTest : public ::testing::Test {
52 public: 52 public:
53 AttestationPolicyObserverTest() 53 AttestationPolicyObserverTest()
54 : message_loop_(MessageLoop::TYPE_UI), 54 : message_loop_(base::MessageLoop::TYPE_UI),
55 ui_thread_(content::BrowserThread::UI, &message_loop_) { 55 ui_thread_(content::BrowserThread::UI, &message_loop_) {
56 // Remove the real DeviceSettingsProvider and replace it with a stub. 56 // Remove the real DeviceSettingsProvider and replace it with a stub.
57 CrosSettings* cros_settings = CrosSettings::Get(); 57 CrosSettings* cros_settings = CrosSettings::Get();
58 device_settings_provider_ = 58 device_settings_provider_ =
59 cros_settings->GetProvider(kDeviceAttestationEnabled); 59 cros_settings->GetProvider(kDeviceAttestationEnabled);
60 cros_settings->RemoveSettingsProvider(device_settings_provider_); 60 cros_settings->RemoveSettingsProvider(device_settings_provider_);
61 cros_settings->AddSettingsProvider(&stub_settings_provider_); 61 cros_settings->AddSettingsProvider(&stub_settings_provider_);
62 cros_settings->SetBoolean(kDeviceAttestationEnabled, true); 62 cros_settings->SetBoolean(kDeviceAttestationEnabled, true);
63 policy_client_.SetDMToken("fake_dm_token"); 63 policy_client_.SetDMToken("fake_dm_token");
64 } 64 }
65 65
66 virtual ~AttestationPolicyObserverTest() { 66 virtual ~AttestationPolicyObserverTest() {
67 // Restore the real DeviceSettingsProvider. 67 // Restore the real DeviceSettingsProvider.
68 CrosSettings* cros_settings = CrosSettings::Get(); 68 CrosSettings* cros_settings = CrosSettings::Get();
69 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); 69 cros_settings->RemoveSettingsProvider(&stub_settings_provider_);
70 cros_settings->AddSettingsProvider(device_settings_provider_); 70 cros_settings->AddSettingsProvider(device_settings_provider_);
71 } 71 }
72 72
73 protected: 73 protected:
74 void Run() { 74 void Run() {
75 AttestationPolicyObserver observer(&policy_client_, 75 AttestationPolicyObserver observer(&policy_client_,
76 &cryptohome_client_, 76 &cryptohome_client_,
77 &attestation_flow_); 77 &attestation_flow_);
78 base::RunLoop().RunUntilIdle(); 78 base::RunLoop().RunUntilIdle();
79 } 79 }
80 80
81 MessageLoop message_loop_; 81 base::MessageLoop message_loop_;
82 content::TestBrowserThread ui_thread_; 82 content::TestBrowserThread ui_thread_;
83 ScopedTestDeviceSettingsService test_device_settings_service_; 83 ScopedTestDeviceSettingsService test_device_settings_service_;
84 ScopedTestCrosSettings test_cros_settings_; 84 ScopedTestCrosSettings test_cros_settings_;
85 CrosSettingsProvider* device_settings_provider_; 85 CrosSettingsProvider* device_settings_provider_;
86 StubCrosSettingsProvider stub_settings_provider_; 86 StubCrosSettingsProvider stub_settings_provider_;
87 StrictMock<MockCryptohomeClient> cryptohome_client_; 87 StrictMock<MockCryptohomeClient> cryptohome_client_;
88 StrictMock<MockAttestationFlow> attestation_flow_; 88 StrictMock<MockAttestationFlow> attestation_flow_;
89 StrictMock<policy::MockCloudPolicyClient> policy_client_; 89 StrictMock<policy::MockCloudPolicyClient> policy_client_;
90 }; 90 };
91 91
(...skipping 19 matching lines...) Expand all
111 TEST_F(AttestationPolicyObserverTest, KeyExists) { 111 TEST_F(AttestationPolicyObserverTest, KeyExists) {
112 EXPECT_CALL(cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _)) 112 EXPECT_CALL(cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _))
113 .WillOnce(WithArgs<2>(Invoke(DBusCallbackTrue))); 113 .WillOnce(WithArgs<2>(Invoke(DBusCallbackTrue)));
114 EXPECT_CALL(cryptohome_client_, TpmAttestationGetCertificate(_, _, _)) 114 EXPECT_CALL(cryptohome_client_, TpmAttestationGetCertificate(_, _, _))
115 .WillOnce(WithArgs<2>(Invoke(DBusDataCallback))); 115 .WillOnce(WithArgs<2>(Invoke(DBusDataCallback)));
116 Run(); 116 Run();
117 } 117 }
118 118
119 } // namespace attestation 119 } // namespace attestation
120 } // namespace chromeos 120 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698