Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: chrome/installer/setup/setup_util_unittest.cc

Issue 71013004: Base: Remove Receive() from ScopedHandle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ScopedProcessInfo Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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;
66 token.Set(temp_handle);
67
65 // First get the size of the buffer needed for |privileges| below. 68 // First get the size of the buffer needed for |privileges| below.
66 DWORD size; 69 DWORD size;
67 EXPECT_FALSE(::GetTokenInformation(token, TokenPrivileges, NULL, 0, &size)); 70 EXPECT_FALSE(::GetTokenInformation(token, TokenPrivileges, NULL, 0, &size));
68 71
69 scoped_ptr<BYTE[]> privileges_bytes(new BYTE[size]); 72 scoped_ptr<BYTE[]> privileges_bytes(new BYTE[size]);
70 TOKEN_PRIVILEGES* privileges = 73 TOKEN_PRIVILEGES* privileges =
71 reinterpret_cast<TOKEN_PRIVILEGES*>(privileges_bytes.get()); 74 reinterpret_cast<TOKEN_PRIVILEGES*>(privileges_bytes.get());
72 75
73 if (!::GetTokenInformation(token, TokenPrivileges, privileges, size, &size)) { 76 if (!::GetTokenInformation(token, TokenPrivileges, privileges, size, &size)) {
74 ADD_FAILURE(); 77 ADD_FAILURE();
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 BrowserDistribution::CHROME_FRAME)); 483 BrowserDistribution::CHROME_FRAME));
481 EXPECT_TRUE(chrome_frame.GetUsageStats(&usagestats)); 484 EXPECT_TRUE(chrome_frame.GetUsageStats(&usagestats));
482 EXPECT_EQ(1U, usagestats); 485 EXPECT_EQ(1U, usagestats);
483 EXPECT_EQ(L"2.0-dev", chrome_frame.channel().value()); 486 EXPECT_EQ(L"2.0-dev", chrome_frame.channel().value());
484 487
485 // Confirm that the binaries' channel no longer contains GCF. 488 // Confirm that the binaries' channel no longer contains GCF.
486 ASSERT_TRUE(binaries.Initialize(kSystemLevel, 489 ASSERT_TRUE(binaries.Initialize(kSystemLevel,
487 BrowserDistribution::CHROME_BINARIES)); 490 BrowserDistribution::CHROME_BINARIES));
488 EXPECT_EQ(L"2.0-dev-multi", binaries.channel().value()); 491 EXPECT_EQ(L"2.0-dev-multi", binaries.channel().value());
489 } 492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698