1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 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/. */
7 #include "gtest/gtest.h"
9 #include "mozilla/ipc/ProtocolUtils.h"
11 namespace mozilla::ipc
{
13 #if defined(DEBUG) || defined(FUZZING)
14 TEST(IPCLogging
, EmptyFilter
)
16 const char* emptyFilter
= "";
17 EXPECT_FALSE(LoggingEnabledFor("PContent", ParentSide
, emptyFilter
));
18 EXPECT_FALSE(LoggingEnabledFor("PContent", ChildSide
, emptyFilter
));
21 TEST(IPCLogging
, SingleProtocolFilter
)
23 const char* contentParentFilter
= "PContentParent";
24 EXPECT_TRUE(LoggingEnabledFor("PContent", ParentSide
, contentParentFilter
));
25 EXPECT_FALSE(LoggingEnabledFor("PContent", ChildSide
, contentParentFilter
));
28 TEST(IPCLogging
, CommaDelimitedProtocolsFilter
)
30 const char* gmpContentFilter
= "PGMPContentChild,PGMPContentParent";
31 EXPECT_TRUE(LoggingEnabledFor("PGMPContent", ChildSide
, gmpContentFilter
));
32 EXPECT_TRUE(LoggingEnabledFor("PGMPContent", ParentSide
, gmpContentFilter
));
33 EXPECT_FALSE(LoggingEnabledFor("PContent", ParentSide
, gmpContentFilter
));
34 EXPECT_FALSE(LoggingEnabledFor("PContent", ChildSide
, gmpContentFilter
));
37 TEST(IPCLogging
, SpaceDelimitedProtocolsFilter
)
39 const char* gmpContentFilter
= "PGMPContentChild PGMPContentParent";
40 EXPECT_TRUE(LoggingEnabledFor("PGMPContent", ChildSide
, gmpContentFilter
));
41 EXPECT_TRUE(LoggingEnabledFor("PGMPContent", ParentSide
, gmpContentFilter
));
42 EXPECT_FALSE(LoggingEnabledFor("PContent", ParentSide
, gmpContentFilter
));
43 EXPECT_FALSE(LoggingEnabledFor("PContent", ChildSide
, gmpContentFilter
));
46 TEST(IPCLogging
, CatchAllFilter
)
48 const char* catchAllFilter
= "1";
49 EXPECT_TRUE(LoggingEnabledFor("PGMPContent", ChildSide
, catchAllFilter
));
50 EXPECT_TRUE(LoggingEnabledFor("PGMPContent", ParentSide
, catchAllFilter
));
51 EXPECT_TRUE(LoggingEnabledFor("PContent", ParentSide
, catchAllFilter
));
52 EXPECT_TRUE(LoggingEnabledFor("PContent", ChildSide
, catchAllFilter
));
55 TEST(IPCLogging
, BothSidesFilter
)
57 const char* gmpContentFilter
= "PGMPContent,PContentParent";
58 EXPECT_TRUE(LoggingEnabledFor("PGMPContent", ChildSide
, gmpContentFilter
));
59 EXPECT_TRUE(LoggingEnabledFor("PGMPContent", ParentSide
, gmpContentFilter
));
60 EXPECT_TRUE(LoggingEnabledFor("PContent", ParentSide
, gmpContentFilter
));
61 EXPECT_FALSE(LoggingEnabledFor("PContent", ChildSide
, gmpContentFilter
));
63 #endif // defined(DEBUG) || defined(FUZZING)
65 } // namespace mozilla::ipc