summaryrefslogtreecommitdiffstats
path: root/netwerk/test/gtest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /netwerk/test/gtest
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/gtest')
-rw-r--r--netwerk/test/gtest/TestIDNA.cpp77
-rw-r--r--netwerk/test/gtest/TestStandardURL.cpp28
-rw-r--r--netwerk/test/gtest/moz.build1
3 files changed, 106 insertions, 0 deletions
diff --git a/netwerk/test/gtest/TestIDNA.cpp b/netwerk/test/gtest/TestIDNA.cpp
new file mode 100644
index 0000000000..544debbd43
--- /dev/null
+++ b/netwerk/test/gtest/TestIDNA.cpp
@@ -0,0 +1,77 @@
+#include "gtest/gtest.h"
+#include "gtest/MozGTestBench.h" // For MOZ_GTEST_BENCH
+#include "gtest/BlackBox.h"
+
+#include "nsNetUtil.h"
+
+#define TEST_COUNT 10000
+
+class TestIDNA : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ // Intentionally Assign and not AssignLiteral
+ // to simulate the usual heap case.
+ mPlainASCII.Assign("example.com");
+ mLeadingDigitASCII.Assign("1test.example");
+ mUnicodeMixed.Assign("مثال.example");
+ mPunycodeMixed.Assign("xn--mgbh0fb.example");
+ mUnicodeLTR.Assign("නම.උදාහරණ");
+ mPunycodeLTR.Assign("xn--r0co.xn--ozc8dl2c3bxd");
+ mUnicodeRTL.Assign("الاسم.مثال");
+ mPunycodeRTL.Assign("xn--mgba0b1dh.xn--mgbh0fb");
+ // Intentionally not assigning to mEmpty
+ }
+
+ public:
+ nsCString mPlainASCII;
+ nsCString mLeadingDigitASCII;
+ nsCString mUnicodeMixed;
+ nsCString mPunycodeMixed;
+ nsCString mUnicodeLTR;
+ nsCString mPunycodeLTR;
+ nsCString mUnicodeRTL;
+ nsCString mPunycodeRTL;
+ nsCString mEmpty; // Extremely suspicious measurement!
+};
+
+#define IDNA_ITERATIONS 50000
+
+#define IDNA_BENCH(name, func, src) \
+ MOZ_GTEST_BENCH_F(TestIDNA, name, [this] { \
+ for (int i = 0; i < IDNA_ITERATIONS; i++) { \
+ nsCString dst; \
+ func(*mozilla::BlackBox(&src), *mozilla::BlackBox(&dst)); \
+ } \
+ });
+
+IDNA_BENCH(BenchToASCIIPlainASCII, NS_DomainToASCII, mPlainASCII);
+IDNA_BENCH(BenchToASCIILeadingDigitASCII, NS_DomainToASCII, mLeadingDigitASCII);
+IDNA_BENCH(BenchToASCIIUnicodeMixed, NS_DomainToASCII, mUnicodeMixed);
+IDNA_BENCH(BenchToASCIIPunycodeMixed, NS_DomainToASCII, mPunycodeMixed);
+IDNA_BENCH(BenchToASCIIUnicodeLTR, NS_DomainToASCII, mUnicodeLTR);
+IDNA_BENCH(BenchToASCIIPunycodeLTR, NS_DomainToASCII, mPunycodeLTR);
+IDNA_BENCH(BenchToASCIIUnicodeRTL, NS_DomainToASCII, mUnicodeRTL);
+IDNA_BENCH(BenchToASCIIPunycodeRTL, NS_DomainToASCII, mPunycodeRTL);
+IDNA_BENCH(BenchToASCIIEmpty, NS_DomainToASCII, mEmpty);
+
+IDNA_BENCH(BenchToDisplayPlainASCII, NS_DomainToDisplay, mPlainASCII);
+IDNA_BENCH(BenchToDisplayLeadingDigitASCII, NS_DomainToDisplay,
+ mLeadingDigitASCII);
+IDNA_BENCH(BenchToDisplayUnicodeMixed, NS_DomainToDisplay, mUnicodeMixed);
+IDNA_BENCH(BenchToDisplayPunycodeMixed, NS_DomainToDisplay, mPunycodeMixed);
+IDNA_BENCH(BenchToDisplayUnicodeLTR, NS_DomainToDisplay, mUnicodeLTR);
+IDNA_BENCH(BenchToDisplayPunycodeLTR, NS_DomainToDisplay, mPunycodeLTR);
+IDNA_BENCH(BenchToDisplayUnicodeRTL, NS_DomainToDisplay, mUnicodeRTL);
+IDNA_BENCH(BenchToDisplayPunycodeRTL, NS_DomainToDisplay, mPunycodeRTL);
+IDNA_BENCH(BenchToDisplayEmpty, NS_DomainToDisplay, mEmpty);
+
+IDNA_BENCH(BenchToUnicodePlainASCII, NS_DomainToUnicode, mPlainASCII);
+IDNA_BENCH(BenchToUnicodeLeadingDigitASCII, NS_DomainToUnicode,
+ mLeadingDigitASCII);
+IDNA_BENCH(BenchToUnicodeUnicodeMixed, NS_DomainToUnicode, mUnicodeMixed);
+IDNA_BENCH(BenchToUnicodePunycodeMixed, NS_DomainToUnicode, mPunycodeMixed);
+IDNA_BENCH(BenchToUnicodeUnicodeLTR, NS_DomainToUnicode, mUnicodeLTR);
+IDNA_BENCH(BenchToUnicodePunycodeLTR, NS_DomainToUnicode, mPunycodeLTR);
+IDNA_BENCH(BenchToUnicodeUnicodeRTL, NS_DomainToUnicode, mUnicodeRTL);
+IDNA_BENCH(BenchToUnicodePunycodeRTL, NS_DomainToUnicode, mPunycodeRTL);
+IDNA_BENCH(BenchToUnicodeEmpty, NS_DomainToUnicode, mEmpty);
diff --git a/netwerk/test/gtest/TestStandardURL.cpp b/netwerk/test/gtest/TestStandardURL.cpp
index 035c92fcc2..64a57ed7fb 100644
--- a/netwerk/test/gtest/TestStandardURL.cpp
+++ b/netwerk/test/gtest/TestStandardURL.cpp
@@ -14,6 +14,7 @@
#include "nsSerializationHelper.h"
#include "mozilla/Base64.h"
#include "nsEscape.h"
+#include "nsURLHelper.h"
using namespace mozilla;
@@ -439,3 +440,30 @@ TEST(TestStandardURL, ParseIPv4Num)
Test_ParseIPv4Number("0x10"_ns, 16, number, 255);
ASSERT_EQ(number, (uint32_t)16);
}
+
+TEST(TestStandardURL, CoalescePath)
+{
+ auto testCoalescing = [](const char* input, const char* expected) {
+ nsAutoCString buf(input);
+ net_CoalesceDirs(NET_COALESCE_NORMAL, buf.BeginWriting());
+ ASSERT_EQ(nsCString(buf.get()), nsCString(expected));
+ };
+
+ testCoalescing("/.", "/");
+ testCoalescing("/..", "/");
+ testCoalescing("/foo/foo1/.", "/foo/foo1/");
+ testCoalescing("/foo/../foo1", "/foo1");
+ testCoalescing("/foo/./foo1", "/foo/foo1");
+ testCoalescing("/foo/foo1/..", "/foo/");
+
+ // Bug 1890346
+ testCoalescing("/..?/..", "/?/..");
+
+ testCoalescing("/.?/..", "/?/..");
+ testCoalescing("/./../?", "/?");
+ testCoalescing("/.abc", "/.abc");
+ testCoalescing("//", "//");
+ testCoalescing("/../", "/");
+ testCoalescing("/./", "/");
+ testCoalescing("/.../", "/.../");
+}
diff --git a/netwerk/test/gtest/moz.build b/netwerk/test/gtest/moz.build
index 571c908707..8e0d66f4e2 100644
--- a/netwerk/test/gtest/moz.build
+++ b/netwerk/test/gtest/moz.build
@@ -17,6 +17,7 @@ UNIFIED_SOURCES += [
"TestHttpAuthUtils.cpp",
"TestHttpChannel.cpp",
"TestHttpResponseHead.cpp",
+ "TestIDNA.cpp",
"TestInputStreamTransport.cpp",
"TestIsValidIp.cpp",
"TestLinkHeader.cpp",