| OLD | NEW |
| 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/location.h" |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "chrome/browser/chromeos/attestation/attestation_key_payload.pb.h" | 14 #include "chrome/browser/chromeos/attestation/attestation_key_payload.pb.h" |
| 16 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" | 15 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" |
| 17 #include "chrome/browser/chromeos/attestation/fake_certificate.h" | 16 #include "chrome/browser/chromeos/attestation/fake_certificate.h" |
| 18 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" | 17 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" |
| 19 #include "chromeos/attestation/mock_attestation_flow.h" | 18 #include "chromeos/attestation/mock_attestation_flow.h" |
| 20 #include "chromeos/dbus/mock_cryptohome_client.h" | 19 #include "chromeos/dbus/mock_cryptohome_client.h" |
| 21 #include "chromeos/settings/cros_settings_names.h" | 20 #include "chromeos/settings/cros_settings_names.h" |
| 22 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" | 21 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 24 |
| 26 using testing::_; | 25 using testing::_; |
| 27 using testing::Invoke; | 26 using testing::Invoke; |
| 28 using testing::StrictMock; | 27 using testing::StrictMock; |
| 29 using testing::WithArgs; | 28 using testing::WithArgs; |
| 30 | 29 |
| 31 namespace chromeos { | 30 namespace chromeos { |
| 32 namespace attestation { | 31 namespace attestation { |
| 33 | 32 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 72 } |
| 74 | 73 |
| 75 private: | 74 private: |
| 76 std::string data_; | 75 std::string data_; |
| 77 }; | 76 }; |
| 78 | 77 |
| 79 } // namespace | 78 } // namespace |
| 80 | 79 |
| 81 class AttestationPolicyObserverTest : public ::testing::Test { | 80 class AttestationPolicyObserverTest : public ::testing::Test { |
| 82 public: | 81 public: |
| 83 AttestationPolicyObserverTest() | 82 AttestationPolicyObserverTest() { |
| 84 : ui_thread_(content::BrowserThread::UI, &message_loop_) { | |
| 85 settings_helper_.ReplaceProvider(kDeviceAttestationEnabled); | 83 settings_helper_.ReplaceProvider(kDeviceAttestationEnabled); |
| 86 settings_helper_.SetBoolean(kDeviceAttestationEnabled, true); | 84 settings_helper_.SetBoolean(kDeviceAttestationEnabled, true); |
| 87 policy_client_.SetDMToken("fake_dm_token"); | 85 policy_client_.SetDMToken("fake_dm_token"); |
| 88 } | 86 } |
| 89 | 87 |
| 90 protected: | 88 protected: |
| 91 enum MockOptions { | 89 enum MockOptions { |
| 92 MOCK_KEY_EXISTS = 1, // Configure so a certified key exists. | 90 MOCK_KEY_EXISTS = 1, // Configure so a certified key exists. |
| 93 MOCK_KEY_UPLOADED = (1 << 1), // Configure so an upload has occurred. | 91 MOCK_KEY_UPLOADED = (1 << 1), // Configure so an upload has occurred. |
| 94 MOCK_NEW_KEY = (1 << 2) // Configure expecting new key generation. | 92 MOCK_NEW_KEY = (1 << 2) // Configure expecting new key generation. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 147 } |
| 150 | 148 |
| 151 std::string CreatePayload() { | 149 std::string CreatePayload() { |
| 152 AttestationKeyPayload proto; | 150 AttestationKeyPayload proto; |
| 153 proto.set_is_certificate_uploaded(true); | 151 proto.set_is_certificate_uploaded(true); |
| 154 std::string serialized; | 152 std::string serialized; |
| 155 proto.SerializeToString(&serialized); | 153 proto.SerializeToString(&serialized); |
| 156 return serialized; | 154 return serialized; |
| 157 } | 155 } |
| 158 | 156 |
| 159 base::MessageLoopForUI message_loop_; | 157 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 160 content::TestBrowserThread ui_thread_; | |
| 161 ScopedCrosSettingsTestHelper settings_helper_; | 158 ScopedCrosSettingsTestHelper settings_helper_; |
| 162 StrictMock<MockCryptohomeClient> cryptohome_client_; | 159 StrictMock<MockCryptohomeClient> cryptohome_client_; |
| 163 StrictMock<MockAttestationFlow> attestation_flow_; | 160 StrictMock<MockAttestationFlow> attestation_flow_; |
| 164 StrictMock<policy::MockCloudPolicyClient> policy_client_; | 161 StrictMock<policy::MockCloudPolicyClient> policy_client_; |
| 165 }; | 162 }; |
| 166 | 163 |
| 167 TEST_F(AttestationPolicyObserverTest, FeatureDisabled) { | 164 TEST_F(AttestationPolicyObserverTest, FeatureDisabled) { |
| 168 settings_helper_.SetBoolean(kDeviceAttestationEnabled, false); | 165 settings_helper_.SetBoolean(kDeviceAttestationEnabled, false); |
| 169 Run(); | 166 Run(); |
| 170 } | 167 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 SetupMocks(MOCK_NEW_KEY, ""); | 217 SetupMocks(MOCK_NEW_KEY, ""); |
| 221 // Simulate a DBus failure. | 218 // Simulate a DBus failure. |
| 222 EXPECT_CALL(cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) | 219 EXPECT_CALL(cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) |
| 223 .WillOnce(WithArgs<3>(Invoke(DBusCallbackError))) | 220 .WillOnce(WithArgs<3>(Invoke(DBusCallbackError))) |
| 224 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackFalse))); | 221 .WillRepeatedly(WithArgs<3>(Invoke(DBusCallbackFalse))); |
| 225 Run(); | 222 Run(); |
| 226 } | 223 } |
| 227 | 224 |
| 228 } // namespace attestation | 225 } // namespace attestation |
| 229 } // namespace chromeos | 226 } // namespace chromeos |
| OLD | NEW |