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/installer/setup/setup_util_unittest.h" | 5 #include "chrome/installer/setup/setup_util_unittest.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 }; | 48 }; |
49 | 49 |
50 // The privilege tested in ScopeTokenPrivilege tests below. | 50 // The privilege tested in ScopeTokenPrivilege tests below. |
51 // Use SE_RESTORE_NAME as it is one of the many privileges that is available, | 51 // Use SE_RESTORE_NAME as it is one of the many privileges that is available, |
52 // but not enabled by default on processes running at high integrity. | 52 // but not enabled by default on processes running at high integrity. |
53 static const wchar_t kTestedPrivilege[] = SE_RESTORE_NAME; | 53 static const wchar_t kTestedPrivilege[] = SE_RESTORE_NAME; |
54 | 54 |
55 // Returns true if the current process' token has privilege |privilege_name| | 55 // Returns true if the current process' token has privilege |privilege_name| |
56 // enabled. | 56 // enabled. |
57 bool CurrentProcessHasPrivilege(const wchar_t* privilege_name) { | 57 bool CurrentProcessHasPrivilege(const wchar_t* privilege_name) { |
58 base::win::ScopedHandle token; | 58 HANDLE temp_handle; |
59 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, | 59 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, |
60 token.Receive())) { | 60 &temp_handle)) { |
61 ADD_FAILURE(); | 61 ADD_FAILURE(); |
62 return false; | 62 return false; |
63 } | 63 } |
64 | 64 |
| 65 base::win::ScopedHandle token(temp_handle); |
| 66 |
65 // First get the size of the buffer needed for |privileges| below. | 67 // First get the size of the buffer needed for |privileges| below. |
66 DWORD size; | 68 DWORD size; |
67 EXPECT_FALSE(::GetTokenInformation(token, TokenPrivileges, NULL, 0, &size)); | 69 EXPECT_FALSE(::GetTokenInformation(token, TokenPrivileges, NULL, 0, &size)); |
68 | 70 |
69 scoped_ptr<BYTE[]> privileges_bytes(new BYTE[size]); | 71 scoped_ptr<BYTE[]> privileges_bytes(new BYTE[size]); |
70 TOKEN_PRIVILEGES* privileges = | 72 TOKEN_PRIVILEGES* privileges = |
71 reinterpret_cast<TOKEN_PRIVILEGES*>(privileges_bytes.get()); | 73 reinterpret_cast<TOKEN_PRIVILEGES*>(privileges_bytes.get()); |
72 | 74 |
73 if (!::GetTokenInformation(token, TokenPrivileges, privileges, size, &size)) { | 75 if (!::GetTokenInformation(token, TokenPrivileges, privileges, size, &size)) { |
74 ADD_FAILURE(); | 76 ADD_FAILURE(); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 BrowserDistribution::CHROME_FRAME)); | 478 BrowserDistribution::CHROME_FRAME)); |
477 EXPECT_TRUE(chrome_frame.GetUsageStats(&usagestats)); | 479 EXPECT_TRUE(chrome_frame.GetUsageStats(&usagestats)); |
478 EXPECT_EQ(1U, usagestats); | 480 EXPECT_EQ(1U, usagestats); |
479 EXPECT_EQ(L"2.0-dev", chrome_frame.channel().value()); | 481 EXPECT_EQ(L"2.0-dev", chrome_frame.channel().value()); |
480 | 482 |
481 // Confirm that the binaries' channel no longer contains GCF. | 483 // Confirm that the binaries' channel no longer contains GCF. |
482 ASSERT_TRUE(binaries.Initialize(kSystemLevel, | 484 ASSERT_TRUE(binaries.Initialize(kSystemLevel, |
483 BrowserDistribution::CHROME_BINARIES)); | 485 BrowserDistribution::CHROME_BINARIES)); |
484 EXPECT_EQ(L"2.0-dev-multi", binaries.channel().value()); | 486 EXPECT_EQ(L"2.0-dev-multi", binaries.channel().value()); |
485 } | 487 } |
OLD | NEW |