Add ICU message format support
[chromium-blink-merge.git] / sandbox / win / src / unload_dll_test.cc
blob620016c6bd8bbfb1eaad2f1fa8fb4e8e57f15167
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
3 // found in the LICENSE file.
5 #include "base/win/scoped_handle.h"
6 #include "sandbox/win/src/sandbox.h"
7 #include "sandbox/win/src/sandbox_factory.h"
8 #include "sandbox/win/src/target_services.h"
9 #include "sandbox/win/tests/common/controller.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace sandbox {
14 // Loads and or unloads a DLL passed in the second parameter of argv.
15 // The first parameter of argv is 'L' = load, 'U' = unload or 'B' for both.
16 SBOX_TESTS_COMMAND int UseOneDLL(int argc, wchar_t **argv) {
17 if (argc != 2)
18 return SBOX_TEST_FAILED_TO_RUN_TEST;
19 int rv = SBOX_TEST_FAILED_TO_RUN_TEST;
21 wchar_t option = (argv[0])[0];
22 if ((option == L'L') || (option == L'B')) {
23 HMODULE module1 = ::LoadLibraryW(argv[1]);
24 rv = (module1 == NULL) ? SBOX_TEST_FAILED : SBOX_TEST_SUCCEEDED;
27 if ((option == L'U') || (option == L'B')) {
28 HMODULE module2 = ::GetModuleHandleW(argv[1]);
29 rv = ::FreeLibrary(module2) ? SBOX_TEST_SUCCEEDED : SBOX_TEST_FAILED;
31 return rv;
34 // Opens an event passed as the first parameter of argv.
35 SBOX_TESTS_COMMAND int SimpleOpenEvent(int argc, wchar_t **argv) {
36 if (argc != 1)
37 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
39 base::win::ScopedHandle event_open(::OpenEvent(SYNCHRONIZE, FALSE, argv[0]));
40 return event_open.Get() ? SBOX_TEST_SUCCEEDED : SBOX_TEST_FAILED;
43 // Flaky on windows, see http://crbug.com/80569.
44 TEST(UnloadDllTest, DISABLED_BaselineAvicapDll) {
45 TestRunner runner;
46 runner.SetTestState(BEFORE_REVERT);
47 runner.SetTimeout(2000);
48 // Add a sync rule, because that ensures that the interception agent has
49 // more than one item in its internal table.
50 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC,
51 TargetPolicy::EVENTS_ALLOW_ANY, L"t0001"));
53 // Note for the puzzled: avicap32.dll is a 64-bit dll in 64-bit versions of
54 // windows so this test and the others just work.
55 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"UseOneDLL L avicap32.dll"));
56 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"UseOneDLL B avicap32.dll"));
59 // Flaky on windows, see http://crbug.com/80569.
60 TEST(UnloadDllTest, DISABLED_UnloadAviCapDllNoPatching) {
61 TestRunner runner;
62 runner.SetTestState(BEFORE_REVERT);
63 runner.SetTimeout(2000);
64 sandbox::TargetPolicy* policy = runner.GetPolicy();
65 policy->AddDllToUnload(L"avicap32.dll");
66 EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(L"UseOneDLL L avicap32.dll"));
67 EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(L"UseOneDLL B avicap32.dll"));
70 // Flaky: http://crbug.com/38404
71 TEST(UnloadDllTest, DISABLED_UnloadAviCapDllWithPatching) {
72 TestRunner runner;
73 runner.SetTimeout(2000);
74 runner.SetTestState(BEFORE_REVERT);
75 sandbox::TargetPolicy* policy = runner.GetPolicy();
76 policy->AddDllToUnload(L"avicap32.dll");
78 base::win::ScopedHandle handle1(::CreateEvent(
79 NULL, FALSE, FALSE, L"tst0001"));
81 // Add a couple of rules that ensures that the interception agent add EAT
82 // patching on the client which makes sure that the unload dll record does
83 // not interact badly with them.
84 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_REGISTRY,
85 TargetPolicy::REG_ALLOW_ANY,
86 L"HKEY_LOCAL_MACHINE\\Software\\Microsoft"));
87 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_SYNC,
88 TargetPolicy::EVENTS_ALLOW_ANY, L"tst0001"));
90 EXPECT_EQ(SBOX_TEST_FAILED, runner.RunTest(L"UseOneDLL L avicap32.dll"));
92 runner.SetTestState(AFTER_REVERT);
93 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"SimpleOpenEvent tst0001"));
96 } // namespace sandbox