tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestDescendant.cpp (3195B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /*
      8 * Test multiple levels of descendant managed protocols.
      9 */
     10 
     11 #include "gtest/gtest.h"
     12 
     13 #include "mozilla/_ipdltest/IPDLUnitTest.h"
     14 #include "mozilla/_ipdltest/PTestDescendantChild.h"
     15 #include "mozilla/_ipdltest/PTestDescendantParent.h"
     16 #include "mozilla/_ipdltest/PTestDescendantSubChild.h"
     17 #include "mozilla/_ipdltest/PTestDescendantSubParent.h"
     18 #include "mozilla/_ipdltest/PTestDescendantSubsubChild.h"
     19 #include "mozilla/_ipdltest/PTestDescendantSubsubParent.h"
     20 
     21 using namespace mozilla::ipc;
     22 
     23 namespace mozilla::_ipdltest {
     24 
     25 class TestDescendantSubsubParent : public PTestDescendantSubsubParent {
     26  NS_INLINE_DECL_REFCOUNTING(TestDescendantSubsubParent, override)
     27 private:
     28  ~TestDescendantSubsubParent() = default;
     29 };
     30 
     31 class TestDescendantSubsubChild : public PTestDescendantSubsubChild {
     32  NS_INLINE_DECL_REFCOUNTING(TestDescendantSubsubChild, override)
     33 private:
     34  ~TestDescendantSubsubChild() = default;
     35 };
     36 
     37 class TestDescendantSubParent : public PTestDescendantSubParent {
     38  NS_INLINE_DECL_REFCOUNTING(TestDescendantSubParent, override)
     39 private:
     40  ~TestDescendantSubParent() = default;
     41 };
     42 
     43 class TestDescendantSubChild : public PTestDescendantSubChild {
     44  NS_INLINE_DECL_REFCOUNTING(TestDescendantSubChild, override)
     45 private:
     46  already_AddRefed<PTestDescendantSubsubChild> AllocPTestDescendantSubsubChild()
     47      final override {
     48    return MakeAndAddRef<TestDescendantSubsubChild>();
     49  }
     50 
     51  ~TestDescendantSubChild() = default;
     52 };
     53 
     54 class TestDescendantParent : public PTestDescendantParent {
     55  NS_INLINE_DECL_REFCOUNTING(TestDescendantParent, override)
     56 private:
     57  IPCResult RecvOk(NotNull<PTestDescendantSubsubParent*> a) final override {
     58    EXPECT_TRUE(PTestDescendantSubsubParent::Send__delete__(a))
     59        << "deleting Subsub";
     60 
     61    Close();
     62 
     63    return IPC_OK();
     64  }
     65 
     66  ~TestDescendantParent() = default;
     67 };
     68 
     69 class TestDescendantChild : public PTestDescendantChild {
     70  NS_INLINE_DECL_REFCOUNTING(TestDescendantChild, override)
     71 private:
     72  already_AddRefed<PTestDescendantSubChild> AllocPTestDescendantSubChild(
     73      PTestDescendantSubsubChild* dummy) final override {
     74    EXPECT_FALSE(dummy) << "actor supposed to be null";
     75    return MakeAndAddRef<TestDescendantSubChild>();
     76  }
     77 
     78  IPCResult RecvTest(NotNull<PTestDescendantSubsubChild*> a) final override {
     79    EXPECT_TRUE(SendOk(a)) << "couldn't send Ok()";
     80    return IPC_OK();
     81  }
     82 
     83  ~TestDescendantChild() = default;
     84 };
     85 
     86 IPDL_TEST(TestDescendant) {
     87  auto p = MakeRefPtr<TestDescendantSubParent>();
     88  auto* rv1 = mActor->SendPTestDescendantSubConstructor(p, nullptr);
     89  EXPECT_EQ(p, rv1) << "can't allocate Sub";
     90 
     91  auto pp = MakeRefPtr<TestDescendantSubsubParent>();
     92  auto* rv2 = p->SendPTestDescendantSubsubConstructor(pp);
     93  EXPECT_EQ(pp, rv2) << "can't allocate Subsub";
     94 
     95  EXPECT_TRUE(mActor->SendTest(WrapNotNull(pp))) << "can't send Subsub";
     96 }
     97 
     98 }  // namespace mozilla::_ipdltest