| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chromeos/attestation/mock_attestation_flow.h" | 8 #include "chromeos/attestation/mock_attestation_flow.h" |
| 9 #include "chromeos/cryptohome/mock_async_method_caller.h" | 9 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 10 #include "chromeos/dbus/mock_cryptohome_client.h" | 10 #include "chromeos/dbus/mock_cryptohome_client.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using testing::_; | 14 using testing::_; |
| 15 using testing::Invoke; | 15 using testing::Invoke; |
| 16 using testing::Sequence; | 16 using testing::Sequence; |
| 17 using testing::StrictMock; | 17 using testing::StrictMock; |
| 18 using testing::WithArgs; | 18 using testing::WithArgs; |
| 19 | 19 |
| 20 namespace chromeos { | 20 namespace chromeos { |
| 21 namespace attestation { | 21 namespace attestation { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { | 25 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { |
| 26 MessageLoop::current()->PostTask( | 26 base::MessageLoop::current()->PostTask( |
| 27 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | 27 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) { | 30 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) { |
| 31 MessageLoop::current()->PostTask( | 31 base::MessageLoop::current()->PostTask( |
| 32 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | 32 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void DBusCallbackFail(const BoolDBusMethodCallback& callback) { | 35 void DBusCallbackFail(const BoolDBusMethodCallback& callback) { |
| 36 MessageLoop::current()->PostTask( | 36 base::MessageLoop::current()->PostTask( |
| 37 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_FAILURE, false)); | 37 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_FAILURE, false)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void AsyncCallbackFalse(cryptohome::AsyncMethodCaller::Callback callback) { | 40 void AsyncCallbackFalse(cryptohome::AsyncMethodCaller::Callback callback) { |
| 41 callback.Run(false, cryptohome::MOUNT_ERROR_NONE); | 41 callback.Run(false, cryptohome::MOUNT_ERROR_NONE); |
| 42 } | 42 } |
| 43 | 43 |
| 44 class FakeDBusData { | 44 class FakeDBusData { |
| 45 public: | 45 public: |
| 46 explicit FakeDBusData(const std::string& data) : data_(data) {} | 46 explicit FakeDBusData(const std::string& data) : data_(data) {} |
| 47 | 47 |
| 48 void operator() (const CryptohomeClient::DataMethodCallback& callback) { | 48 void operator() (const CryptohomeClient::DataMethodCallback& callback) { |
| 49 MessageLoop::current()->PostTask( | 49 base::MessageLoop::current()->PostTask( |
| 50 FROM_HERE, | 50 FROM_HERE, |
| 51 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, data_)); | 51 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, data_)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 std::string data_; | 55 std::string data_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 class AttestationFlowTest : public testing::Test { | 60 class AttestationFlowTest : public testing::Test { |
| 61 protected: | 61 protected: |
| 62 void Run() { | 62 void Run() { |
| 63 base::RunLoop run_loop; | 63 base::RunLoop run_loop; |
| 64 run_loop.RunUntilIdle(); | 64 run_loop.RunUntilIdle(); |
| 65 } | 65 } |
| 66 MessageLoop message_loop_; | 66 base::MessageLoop message_loop_; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 TEST_F(AttestationFlowTest, GetCertificate) { | 69 TEST_F(AttestationFlowTest, GetCertificate) { |
| 70 // Verify the order of calls in a sequence. | 70 // Verify the order of calls in a sequence. |
| 71 Sequence flow_order; | 71 Sequence flow_order; |
| 72 | 72 |
| 73 // Use DBusCallbackFalse so the full enrollment flow is triggered. | 73 // Use DBusCallbackFalse so the full enrollment flow is triggered. |
| 74 chromeos::MockCryptohomeClient client; | 74 chromeos::MockCryptohomeClient client; |
| 75 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 75 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
| 76 .InSequence(flow_order) | 76 .InSequence(flow_order) |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 414 |
| 415 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | 415 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 416 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | 416 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
| 417 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, | 417 flow.GetCertificate(PROFILE_ENTERPRISE_USER_CERTIFICATE, |
| 418 false, mock_callback); | 418 false, mock_callback); |
| 419 Run(); | 419 Run(); |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace attestation | 422 } // namespace attestation |
| 423 } // namespace chromeos | 423 } // namespace chromeos |
| OLD | NEW |