| 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 "chrome/browser/chromeos/settings/owner_key_util.h" | 5 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilTest); | 66 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilTest); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 TEST_F(OwnerKeyUtilTest, ImportPublicKey) { | 69 TEST_F(OwnerKeyUtilTest, ImportPublicKey) { |
| 70 // Export public key, so that we can compare it to the one we get off disk. | 70 // Export public key, so that we can compare it to the one we get off disk. |
| 71 std::vector<uint8> public_key(kTestKeyData, | 71 std::vector<uint8> public_key(kTestKeyData, |
| 72 kTestKeyData + sizeof(kTestKeyData)); | 72 kTestKeyData + sizeof(kTestKeyData)); |
| 73 ASSERT_EQ(static_cast<int>(public_key.size()), | 73 ASSERT_EQ(static_cast<int>(public_key.size()), |
| 74 file_util::WriteFile( | 74 base::WriteFile( |
| 75 key_file_, | 75 key_file_, |
| 76 reinterpret_cast<const char*>(vector_as_array(&public_key)), | 76 reinterpret_cast<const char*>(vector_as_array(&public_key)), |
| 77 public_key.size())); | 77 public_key.size())); |
| 78 EXPECT_TRUE(util_->IsPublicKeyPresent()); | 78 EXPECT_TRUE(util_->IsPublicKeyPresent()); |
| 79 | 79 |
| 80 std::vector<uint8> from_disk; | 80 std::vector<uint8> from_disk; |
| 81 EXPECT_TRUE(util_->ImportPublicKey(&from_disk)); | 81 EXPECT_TRUE(util_->ImportPublicKey(&from_disk)); |
| 82 | 82 |
| 83 EXPECT_EQ(public_key, from_disk); | 83 EXPECT_EQ(public_key, from_disk); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(OwnerKeyUtilTest, ImportPublicKeyFailed) { | 86 TEST_F(OwnerKeyUtilTest, ImportPublicKeyFailed) { |
| 87 // First test the case where the file is missing which should fail. | 87 // First test the case where the file is missing which should fail. |
| 88 EXPECT_FALSE(util_->IsPublicKeyPresent()); | 88 EXPECT_FALSE(util_->IsPublicKeyPresent()); |
| 89 std::vector<uint8> from_disk; | 89 std::vector<uint8> from_disk; |
| 90 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); | 90 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); |
| 91 | 91 |
| 92 // Next try empty file. This should fail and the array should be empty. | 92 // Next try empty file. This should fail and the array should be empty. |
| 93 from_disk.resize(10); | 93 from_disk.resize(10); |
| 94 ASSERT_EQ(0, file_util::WriteFile(key_file_, "", 0)); | 94 ASSERT_EQ(0, base::WriteFile(key_file_, "", 0)); |
| 95 EXPECT_TRUE(util_->IsPublicKeyPresent()); | 95 EXPECT_TRUE(util_->IsPublicKeyPresent()); |
| 96 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); | 96 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); |
| 97 EXPECT_FALSE(from_disk.size()); | 97 EXPECT_FALSE(from_disk.size()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace chromeos | 100 } // namespace chromeos |
| OLD | NEW |