1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/win/src/ipc_ping_test.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "testing/gtest/include/gtest/gtest.h" 1.9 +#include "sandbox/win/src/sandbox.h" 1.10 +#include "sandbox/win/src/sandbox_factory.h" 1.11 +#include "sandbox/win/src/target_services.h" 1.12 +#include "sandbox/win/tests/common/controller.h" 1.13 + 1.14 +namespace sandbox { 1.15 + 1.16 +// Tests that the IPC is working by issuing a special IPC that is not exposed 1.17 +// in the public API. 1.18 +SBOX_TESTS_COMMAND int IPC_Ping(int argc, wchar_t **argv) { 1.19 + if (argc != 1) 1.20 + return SBOX_TEST_FAILED; 1.21 + 1.22 + TargetServices* ts = SandboxFactory::GetTargetServices(); 1.23 + if (NULL == ts) 1.24 + return SBOX_TEST_FAILED; 1.25 + 1.26 + // Downcast because we have internal knowledge of the object returned. 1.27 + TargetServicesBase* ts_base = reinterpret_cast<TargetServicesBase*>(ts); 1.28 + 1.29 + int version = 0; 1.30 + if (L'1' == argv[0][0]) 1.31 + version = 1; 1.32 + else 1.33 + version = 2; 1.34 + 1.35 + if (!ts_base->TestIPCPing(version)) 1.36 + return SBOX_TEST_FAILED; 1.37 + 1.38 + ::Sleep(1); 1.39 + if (!ts_base->TestIPCPing(version)) 1.40 + return SBOX_TEST_FAILED; 1.41 + 1.42 + return SBOX_TEST_SUCCEEDED; 1.43 +} 1.44 + 1.45 +// The IPC ping test should work before and after the token drop. 1.46 +TEST(IPCTest, IPCPingTestSimple) { 1.47 + TestRunner runner; 1.48 + runner.SetTimeout(2000); 1.49 + runner.SetTestState(EVERY_STATE); 1.50 + EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"IPC_Ping 1")); 1.51 +} 1.52 + 1.53 +TEST(IPCTest, IPCPingTestWithOutput) { 1.54 + TestRunner runner; 1.55 + runner.SetTimeout(2000); 1.56 + runner.SetTestState(EVERY_STATE); 1.57 + EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"IPC_Ping 2")); 1.58 + EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"IPC_Ping 2")); 1.59 +} 1.60 + 1.61 +} // namespace sandbox