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 "chrome_frame/dll_redirector.h" | 5 #include "chrome_frame/dll_redirector.h" |
6 | 6 |
7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
8 #include "base/sys_info.h" | |
9 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
10 #include "base/version.h" | 9 #include "base/version.h" |
11 #include "base/win/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
| 11 #include "base/win/windows_version.h" |
12 #include "chrome_frame/test/chrome_frame_test_utils.h" | 12 #include "chrome_frame/test/chrome_frame_test_utils.h" |
13 #include "gtest/gtest.h" | 13 #include "gtest/gtest.h" |
14 | 14 |
15 extern "C" IMAGE_DOS_HEADER __ImageBase; | 15 extern "C" IMAGE_DOS_HEADER __ImageBase; |
16 | 16 |
17 const char kMockVersionString[] = "42.42.42.42"; | 17 const char kMockVersionString[] = "42.42.42.42"; |
18 const char kMockVersionString2[] = "133.33.33.7"; | 18 const char kMockVersionString2[] = "133.33.33.7"; |
19 | 19 |
20 const HMODULE kMockModuleHandle = reinterpret_cast<HMODULE>(42); | 20 const HMODULE kMockModuleHandle = reinterpret_cast<HMODULE>(42); |
21 const HMODULE kMockModuleHandle2 = reinterpret_cast<HMODULE>(43); | 21 const HMODULE kMockModuleHandle2 = reinterpret_cast<HMODULE>(43); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 // Ensure that the shared memory is read-only: | 322 // Ensure that the shared memory is read-only: |
323 EXPECT_FALSE(shared_memory.Open(kTestVersionBeaconName, false)); | 323 EXPECT_FALSE(shared_memory.Open(kTestVersionBeaconName, false)); |
324 shared_memory.Close(); | 324 shared_memory.Close(); |
325 EXPECT_TRUE(shared_memory.Open(kTestVersionBeaconName, true)); | 325 EXPECT_TRUE(shared_memory.Open(kTestVersionBeaconName, true)); |
326 shared_memory.Close(); | 326 shared_memory.Close(); |
327 | 327 |
328 if (mutex_locked) | 328 if (mutex_locked) |
329 shared_memory.Unlock(); | 329 shared_memory.Unlock(); |
330 } | 330 } |
331 | 331 |
332 int32 major_version, minor_version, fix_version; | 332 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
333 base::SysInfo::OperatingSystemVersionNumbers(&major_version, | |
334 &minor_version, | |
335 &fix_version); | |
336 if (major_version >= 6) { | |
337 // Now move to low integrity | 333 // Now move to low integrity |
338 chrome_frame_test::LowIntegrityToken low_integrity_token; | 334 chrome_frame_test::LowIntegrityToken low_integrity_token; |
339 ASSERT_TRUE(low_integrity_token.Impersonate()); | 335 ASSERT_TRUE(low_integrity_token.Impersonate()); |
340 | 336 |
341 // Ensure that we can also acquire the mutex from low integrity. | 337 // Ensure that we can also acquire the mutex from low integrity. |
342 base::SharedMemory shared_memory(ASCIIToWide(kTestVersionBeaconName)); | 338 base::SharedMemory shared_memory(ASCIIToWide(kTestVersionBeaconName)); |
343 bool mutex_locked = shared_memory.Lock(kWaitTestTimeout, NULL); | 339 bool mutex_locked = shared_memory.Lock(kWaitTestTimeout, NULL); |
344 EXPECT_TRUE(mutex_locked); | 340 EXPECT_TRUE(mutex_locked); |
345 | 341 |
346 // Ensure that the shared memory is read-only: | 342 // Ensure that the shared memory is read-only: |
(...skipping 21 matching lines...) Expand all Loading... |
368 EXPECT_TRUE(mutex_locked); | 364 EXPECT_TRUE(mutex_locked); |
369 | 365 |
370 // We should be able to open the memory as read/write. | 366 // We should be able to open the memory as read/write. |
371 EXPECT_TRUE(shared_memory.Open(kTestVersionBeaconName, false)); | 367 EXPECT_TRUE(shared_memory.Open(kTestVersionBeaconName, false)); |
372 shared_memory.Close(); | 368 shared_memory.Close(); |
373 | 369 |
374 if (mutex_locked) | 370 if (mutex_locked) |
375 shared_memory.Unlock(); | 371 shared_memory.Unlock(); |
376 } | 372 } |
377 | 373 |
378 int32 major_version, minor_version, fix_version; | 374 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
379 base::SysInfo::OperatingSystemVersionNumbers(&major_version, | |
380 &minor_version, | |
381 &fix_version); | |
382 if (major_version >= 6) { | |
383 // Now move to low integrity | 375 // Now move to low integrity |
384 chrome_frame_test::LowIntegrityToken low_integrity_token; | 376 chrome_frame_test::LowIntegrityToken low_integrity_token; |
385 low_integrity_token.Impersonate(); | 377 low_integrity_token.Impersonate(); |
386 | 378 |
387 // Ensure that we can't acquire the mutex without having set the | 379 // Ensure that we can't acquire the mutex without having set the |
388 // Low Integrity ACE in the SACL. | 380 // Low Integrity ACE in the SACL. |
389 base::SharedMemory shared_memory(ASCIIToWide(kTestVersionBeaconName)); | 381 base::SharedMemory shared_memory(ASCIIToWide(kTestVersionBeaconName)); |
390 bool mutex_locked = shared_memory.Lock(kWaitTestTimeout, NULL); | 382 bool mutex_locked = shared_memory.Lock(kWaitTestTimeout, NULL); |
391 EXPECT_FALSE(mutex_locked); | 383 EXPECT_FALSE(mutex_locked); |
392 | 384 |
393 // We shouldn't be able to open the memory. | 385 // We shouldn't be able to open the memory. |
394 EXPECT_FALSE(shared_memory.Open(kTestVersionBeaconName, false)); | 386 EXPECT_FALSE(shared_memory.Open(kTestVersionBeaconName, false)); |
395 shared_memory.Close(); | 387 shared_memory.Close(); |
396 | 388 |
397 if (mutex_locked) | 389 if (mutex_locked) |
398 shared_memory.Unlock(); | 390 shared_memory.Unlock(); |
399 } | 391 } |
400 } | 392 } |
OLD | NEW |