TestScopedLogExtraInfo.cpp (2478B)
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 #include "gtest/gtest.h" 8 #include "mozilla/dom/quota/ScopedLogExtraInfo.h" 9 10 using namespace mozilla::dom::quota; 11 12 TEST(DOM_Quota_ScopedLogExtraInfo, AddAndRemove) 13 { 14 static constexpr auto text = "foo"_ns; 15 16 { 17 const auto extraInfo = 18 ScopedLogExtraInfo{ScopedLogExtraInfo::kTagQueryTainted, text}; 19 20 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED 21 const auto& extraInfoMap = ScopedLogExtraInfo::GetExtraInfoMap(); 22 23 const auto& queryValueTainted = 24 *extraInfoMap.at(ScopedLogExtraInfo::kTagQueryTainted); 25 26 EXPECT_EQ(text, MOZ_NO_VALIDATE(queryValueTainted, 27 "It's ok to use query value in tests.")); 28 #endif 29 } 30 31 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED 32 const auto& extraInfoMap = ScopedLogExtraInfo::GetExtraInfoMap(); 33 34 EXPECT_EQ(0u, extraInfoMap.count(ScopedLogExtraInfo::kTagQueryTainted)); 35 #endif 36 } 37 38 TEST(DOM_Quota_ScopedLogExtraInfo, Nested) 39 { 40 static constexpr auto text = "foo"_ns; 41 static constexpr auto nestedText = "bar"_ns; 42 43 { 44 const auto extraInfo = 45 ScopedLogExtraInfo{ScopedLogExtraInfo::kTagQueryTainted, text}; 46 47 { 48 const auto extraInfo = 49 ScopedLogExtraInfo{ScopedLogExtraInfo::kTagQueryTainted, nestedText}; 50 51 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED 52 const auto& extraInfoMap = ScopedLogExtraInfo::GetExtraInfoMap(); 53 54 const auto& queryValueTainted = 55 *extraInfoMap.at(ScopedLogExtraInfo::kTagQueryTainted); 56 57 EXPECT_EQ(nestedText, 58 MOZ_NO_VALIDATE(queryValueTainted, 59 "It's ok to use query value in tests.")); 60 #endif 61 } 62 63 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED 64 const auto& extraInfoMap = ScopedLogExtraInfo::GetExtraInfoMap(); 65 66 const auto& queryValueTainted = 67 *extraInfoMap.at(ScopedLogExtraInfo::kTagQueryTainted); 68 69 EXPECT_EQ(text, MOZ_NO_VALIDATE(queryValueTainted, 70 "It's ok to use query value in tests.")); 71 #endif 72 } 73 74 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED 75 const auto& extraInfoMap = ScopedLogExtraInfo::GetExtraInfoMap(); 76 77 EXPECT_EQ(0u, extraInfoMap.count(ScopedLogExtraInfo::kTagQueryTainted)); 78 #endif 79 }