security/sandbox/win/src/ipc_ping_test.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 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 "testing/gtest/include/gtest/gtest.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
michael@0 11 namespace sandbox {
michael@0 12
michael@0 13 // Tests that the IPC is working by issuing a special IPC that is not exposed
michael@0 14 // in the public API.
michael@0 15 SBOX_TESTS_COMMAND int IPC_Ping(int argc, wchar_t **argv) {
michael@0 16 if (argc != 1)
michael@0 17 return SBOX_TEST_FAILED;
michael@0 18
michael@0 19 TargetServices* ts = SandboxFactory::GetTargetServices();
michael@0 20 if (NULL == ts)
michael@0 21 return SBOX_TEST_FAILED;
michael@0 22
michael@0 23 // Downcast because we have internal knowledge of the object returned.
michael@0 24 TargetServicesBase* ts_base = reinterpret_cast<TargetServicesBase*>(ts);
michael@0 25
michael@0 26 int version = 0;
michael@0 27 if (L'1' == argv[0][0])
michael@0 28 version = 1;
michael@0 29 else
michael@0 30 version = 2;
michael@0 31
michael@0 32 if (!ts_base->TestIPCPing(version))
michael@0 33 return SBOX_TEST_FAILED;
michael@0 34
michael@0 35 ::Sleep(1);
michael@0 36 if (!ts_base->TestIPCPing(version))
michael@0 37 return SBOX_TEST_FAILED;
michael@0 38
michael@0 39 return SBOX_TEST_SUCCEEDED;
michael@0 40 }
michael@0 41
michael@0 42 // The IPC ping test should work before and after the token drop.
michael@0 43 TEST(IPCTest, IPCPingTestSimple) {
michael@0 44 TestRunner runner;
michael@0 45 runner.SetTimeout(2000);
michael@0 46 runner.SetTestState(EVERY_STATE);
michael@0 47 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"IPC_Ping 1"));
michael@0 48 }
michael@0 49
michael@0 50 TEST(IPCTest, IPCPingTestWithOutput) {
michael@0 51 TestRunner runner;
michael@0 52 runner.SetTimeout(2000);
michael@0 53 runner.SetTestState(EVERY_STATE);
michael@0 54 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"IPC_Ping 2"));
michael@0 55 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"IPC_Ping 2"));
michael@0 56 }
michael@0 57
michael@0 58 } // namespace sandbox

mercurial