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("PContentParent", emptyFilter
));
18 EXPECT_FALSE(LoggingEnabledFor("PContentChild", emptyFilter
));
21 TEST(IPCLogging
, SingleProtocolFilter
)
23 const char* contentParentFilter
= "PContentParent";
24 EXPECT_TRUE(LoggingEnabledFor("PContentParent", contentParentFilter
));
25 EXPECT_FALSE(LoggingEnabledFor("PContentChild", contentParentFilter
));
28 TEST(IPCLogging
, CommaDelimitedProtocolsFilter
)
30 const char* gmpContentFilter
= "PGMPContentChild,PGMPContentParent";
31 EXPECT_TRUE(LoggingEnabledFor("PGMPContentChild", gmpContentFilter
));
32 EXPECT_TRUE(LoggingEnabledFor("PGMPContentParent", gmpContentFilter
));
33 EXPECT_FALSE(LoggingEnabledFor("PContentParent", gmpContentFilter
));
34 EXPECT_FALSE(LoggingEnabledFor("PContentChild", gmpContentFilter
));
37 TEST(IPCLogging
, SpaceDelimitedProtocolsFilter
)
39 const char* gmpContentFilter
= "PGMPContentChild PGMPContentParent";
40 EXPECT_TRUE(LoggingEnabledFor("PGMPContentChild", gmpContentFilter
));
41 EXPECT_TRUE(LoggingEnabledFor("PGMPContentParent", gmpContentFilter
));
42 EXPECT_FALSE(LoggingEnabledFor("PContentParent", gmpContentFilter
));
43 EXPECT_FALSE(LoggingEnabledFor("PContentChild", gmpContentFilter
));
46 TEST(IPCLogging
, CatchAllFilter
)
48 const char* catchAllFilter
= "1";
49 EXPECT_TRUE(LoggingEnabledFor("PGMPContentChild", catchAllFilter
));
50 EXPECT_TRUE(LoggingEnabledFor("PGMPContentParent", catchAllFilter
));
51 EXPECT_TRUE(LoggingEnabledFor("PContentParent", catchAllFilter
));
52 EXPECT_TRUE(LoggingEnabledFor("PContentChild", catchAllFilter
));
54 #endif // defined(DEBUG) || defined(FUZZING)
56 } // namespace mozilla::ipc