OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
6 #include <wincrypt.h> | 6 #include <wincrypt.h> |
7 | 7 |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 // Get four bytes of randomness. Use CAPI rather than the CRT since I've | 22 // Get four bytes of randomness. Use CAPI rather than the CRT since I've |
23 // seen the latter trivially repeat. | 23 // seen the latter trivially repeat. |
24 EXPECT_NE(FALSE, CryptAcquireContext(&crypt_ctx, NULL, NULL, PROV_RSA_FULL, | 24 EXPECT_NE(FALSE, CryptAcquireContext(&crypt_ctx, NULL, NULL, PROV_RSA_FULL, |
25 CRYPT_VERIFYCONTEXT)); | 25 CRYPT_VERIFYCONTEXT)); |
26 EXPECT_NE(FALSE, CryptGenRandom(crypt_ctx, arraysize(data), &data[0])); | 26 EXPECT_NE(FALSE, CryptGenRandom(crypt_ctx, arraysize(data), &data[0])); |
27 EXPECT_NE(FALSE, CryptReleaseContext(crypt_ctx, 0)); | 27 EXPECT_NE(FALSE, CryptReleaseContext(crypt_ctx, 0)); |
28 | 28 |
29 // Hexify the value. | 29 // Hexify the value. |
30 std::string result(base::HexEncode(&data[0], arraysize(data))); | 30 std::string result(base::HexEncode(&data[0], arraysize(data))); |
31 EXPECT_EQ(8, result.size()); | 31 EXPECT_EQ(8u, result.size()); |
32 | 32 |
33 // Replace the first digit with the letter 'R' (for "random", get it?). | 33 // Replace the first digit with the letter 'R' (for "random", get it?). |
34 result[0] = 'R'; | 34 result[0] = 'R'; |
35 | 35 |
36 return result; | 36 return result; |
37 } | 37 } |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 namespace installer { | 41 namespace installer { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); | 152 EXPECT_TRUE(work_dir.CreateUniqueTempDir()); |
153 | 153 |
154 // Make up some path under the temp dir. | 154 // Make up some path under the temp dir. |
155 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); | 155 base::FilePath parent_temp_dir(work_dir.path().Append(L"One").Append(L"Two")); |
156 { | 156 { |
157 SelfCleaningTempDir temp_dir; | 157 SelfCleaningTempDir temp_dir; |
158 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three")); | 158 EXPECT_TRUE(temp_dir.Initialize(parent_temp_dir, L"Three")); |
159 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path()); | 159 EXPECT_EQ(parent_temp_dir.Append(L"Three"), temp_dir.path()); |
160 EXPECT_TRUE(base::DirectoryExists(temp_dir.path())); | 160 EXPECT_TRUE(base::DirectoryExists(temp_dir.path())); |
161 // Drop a file somewhere. | 161 // Drop a file somewhere. |
162 EXPECT_EQ(arraysize(kHiHon) - 1, | 162 EXPECT_EQ(static_cast<int>(arraysize(kHiHon) - 1), |
163 base::WriteFile(parent_temp_dir.AppendASCII(GetRandomFilename()), | 163 base::WriteFile(parent_temp_dir.AppendASCII(GetRandomFilename()), |
164 kHiHon, arraysize(kHiHon) - 1)); | 164 kHiHon, arraysize(kHiHon) - 1)); |
165 } | 165 } |
166 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three"))); | 166 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.Append(L"Three"))); |
167 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir)); | 167 EXPECT_TRUE(base::DirectoryExists(parent_temp_dir)); |
168 EXPECT_TRUE(work_dir.Delete()); | 168 EXPECT_TRUE(work_dir.Delete()); |
169 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName())); | 169 EXPECT_FALSE(base::DirectoryExists(parent_temp_dir.DirName().DirName())); |
170 } | 170 } |
171 | 171 |
172 } // namespace installer | 172 } // namespace installer |
OLD | NEW |