security/sandbox/win/src/ipc_ping_test.cc

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial