From 3dd521872bb6e6ee0e0fec511b631cb8f013cdc2 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 26 Aug 2020 13:54:53 +0000 Subject: [PATCH] Bug 1536596 - Added unit tests for AnonymizedOriginString. r=dom-workers-and-storage-reviewers,janv Depends on D88288 Differential Revision: https://phabricator.services.mozilla.com/D88289 --- dom/quota/test/gtest/TestQuotaCommon.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dom/quota/test/gtest/TestQuotaCommon.cpp b/dom/quota/test/gtest/TestQuotaCommon.cpp index 514101952d18..b3e364df3aa4 100644 --- a/dom/quota/test/gtest/TestQuotaCommon.cpp +++ b/dom/quota/test/gtest/TestQuotaCommon.cpp @@ -380,6 +380,24 @@ TEST(QuotaCommon_ErrToOkOrErr, NsresultToNsCOMPtr_nullptr_Err) EXPECT_EQ(res.unwrapErr(), NS_ERROR_UNEXPECTED); } +class StringPairParameterized + : public ::testing::TestWithParam> {}; + +TEST_P(StringPairParameterized, AnonymizedOriginString) { + const auto [in, expectedAnonymized] = GetParam(); + const auto anonymized = AnonymizedOriginString(nsDependentCString(in)); + EXPECT_STREQ(anonymized.get(), expectedAnonymized); +} + +INSTANTIATE_TEST_CASE_P( + QuotaCommon, StringPairParameterized, + ::testing::Values( + // XXX Do we really want to anonymize about: origins? + std::pair("about:home", "about:aaaa"), + std::pair("https://foo.bar.com", "https://aaa.aaa.aaa"), + std::pair("https://foo.bar.com:8000", "https://aaa.aaa.aaa:DDDD"), + std::pair("file://UNIVERSAL_FILE_ORIGIN", + "file://aaaaaaaaa_aaaa_aaaaaa"))); TEST(QuotaCommon_ToResultGet, Lambda_NoInput) { auto task = [](nsresult* aRv) -> int32_t {