Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "base/win/scoped_handle.h" |
michael@0 | 6 | #include "sandbox/win/src/sandbox.h" |
michael@0 | 7 | #include "sandbox/win/src/sandbox_factory.h" |
michael@0 | 8 | #include "sandbox/win/src/target_services.h" |
michael@0 | 9 | #include "sandbox/win/tests/common/controller.h" |
michael@0 | 10 | #include "testing/gtest/include/gtest/gtest.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace sandbox { |
michael@0 | 13 | |
michael@0 | 14 | // Loads and or unloads a DLL passed in the second parameter of argv. |
michael@0 | 15 | // The first parameter of argv is 'L' = load, 'U' = unload or 'B' for both. |
michael@0 | 16 | SBOX_TESTS_COMMAND int UseOneDLL(int argc, wchar_t **argv) { |
michael@0 | 17 | if (argc != 2) |
michael@0 | 18 | return SBOX_TEST_FAILED_TO_RUN_TEST; |
michael@0 | 19 | int rv = SBOX_TEST_FAILED_TO_RUN_TEST; |
michael@0 | 20 | |
michael@0 | 21 | wchar_t option = (argv[0])[0]; |
michael@0 | 22 | if ((option == L'L') || (option == L'B')) { |
michael@0 | 23 | HMODULE module1 = ::LoadLibraryW(argv[1]); |
michael@0 | 24 | rv = (module1 == NULL) ? SBOX_TEST_FAILED : SBOX_TEST_SUCCEEDED; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | if ((option == L'U') || (option == L'B')) { |
michael@0 | 28 | HMODULE module2 = ::GetModuleHandleW(argv[1]); |
michael@0 | 29 | rv = ::FreeLibrary(module2) ? SBOX_TEST_SUCCEEDED : SBOX_TEST_FAILED; |
michael@0 | 30 | } |
michael@0 | 31 | return rv; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | // Opens an event passed as the first parameter of argv. |
michael@0 | 35 | SBOX_TESTS_COMMAND int SimpleOpenEvent(int argc, wchar_t **argv) { |
michael@0 | 36 | if (argc != 1) |
michael@0 | 37 | return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; |
michael@0 | 38 | |
michael@0 | 39 | base::win::ScopedHandle event_open(::OpenEvent(SYNCHRONIZE, FALSE, argv[0])); |
michael@0 | 40 | return event_open.Get() ? SBOX_TEST_SUCCEEDED : SBOX_TEST_FAILED; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | // Flaky on windows, see http://crbug.com/80569. |
michael@0 | 44 | TEST(UnloadDllTest, DISABLED_BaselineAvicapDll) { |
michael@0 | 45 | TestRunner runner; |
michael@0 | 46 | runner.SetTestState(BEFORE_REVERT); |
michael@0 | 47 | runner.SetTimeout(2000); |
michael@0 | 48 | // Add a sync rule, because that ensures that the interception agent has |
michael@0 | 49 | // more than one item in its internal table. |
michael@0 | 50 | EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC, |
michael@0 | 51 | TargetPolicy::EVENTS_ALLOW_ANY, L"t0001")); |
michael@0 | 52 | |
michael@0 | 53 | // Note for the puzzled: avicap32.dll is a 64-bit dll in 64-bit versions of |
michael@0 | 54 | // windows so this test and the others just work. |
michael@0 | 55 | EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"UseOneDLL L avicap32.dll")); |
michael@0 | 56 | EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"UseOneDLL B avicap32.dll")); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | // Flaky on windows, see http://crbug.com/80569. |
michael@0 | 60 | TEST(UnloadDllTest, DISABLED_UnloadAviCapDllNoPatching) { |
michael@0 | 61 | TestRunner runner; |
michael@0 | 62 | runner.SetTestState(BEFORE_REVERT); |
michael@0 | 63 | runner.SetTimeout(2000); |
michael@0 | 64 | sandbox::TargetPolicy* policy = runner.GetPolicy(); |
michael@0 | 65 | policy->AddDllToUnload(L"avicap32.dll"); |
michael@0 | 66 | EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(L"UseOneDLL L avicap32.dll")); |
michael@0 | 67 | EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(L"UseOneDLL B avicap32.dll")); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | // Flaky: http://crbug.com/38404 |
michael@0 | 71 | TEST(UnloadDllTest, DISABLED_UnloadAviCapDllWithPatching) { |
michael@0 | 72 | TestRunner runner; |
michael@0 | 73 | runner.SetTimeout(2000); |
michael@0 | 74 | runner.SetTestState(BEFORE_REVERT); |
michael@0 | 75 | sandbox::TargetPolicy* policy = runner.GetPolicy(); |
michael@0 | 76 | policy->AddDllToUnload(L"avicap32.dll"); |
michael@0 | 77 | |
michael@0 | 78 | base::win::ScopedHandle handle1(::CreateEvent( |
michael@0 | 79 | NULL, FALSE, FALSE, L"tst0001")); |
michael@0 | 80 | |
michael@0 | 81 | // Add a couple of rules that ensures that the interception agent add EAT |
michael@0 | 82 | // patching on the client which makes sure that the unload dll record does |
michael@0 | 83 | // not interact badly with them. |
michael@0 | 84 | EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_REGISTRY, |
michael@0 | 85 | TargetPolicy::REG_ALLOW_ANY, |
michael@0 | 86 | L"HKEY_LOCAL_MACHINE\\Software\\Microsoft")); |
michael@0 | 87 | EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC, |
michael@0 | 88 | TargetPolicy::EVENTS_ALLOW_ANY, L"tst0001")); |
michael@0 | 89 | |
michael@0 | 90 | EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(L"UseOneDLL L avicap32.dll")); |
michael@0 | 91 | |
michael@0 | 92 | runner.SetTestState(AFTER_REVERT); |
michael@0 | 93 | EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"SimpleOpenEvent tst0001")); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | } // namespace sandbox |