From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- netwerk/test/gtest/TestProtocolProxyService.cpp | 128 ++++++++++++++++++++++++ netwerk/test/gtest/TestStandardURL.cpp | 69 +++++++++++++ netwerk/test/gtest/moz.build | 14 +++ 3 files changed, 211 insertions(+) create mode 100644 netwerk/test/gtest/TestProtocolProxyService.cpp create mode 100644 netwerk/test/gtest/TestStandardURL.cpp create mode 100644 netwerk/test/gtest/moz.build (limited to 'netwerk/test/gtest') diff --git a/netwerk/test/gtest/TestProtocolProxyService.cpp b/netwerk/test/gtest/TestProtocolProxyService.cpp new file mode 100644 index 000000000..a49e9f961 --- /dev/null +++ b/netwerk/test/gtest/TestProtocolProxyService.cpp @@ -0,0 +1,128 @@ +#include "gtest/gtest.h" + +#include "nsCOMPtr.h" +#include "nsNetCID.h" +#include "nsIURL.h" +#include "nsString.h" +#include "nsComponentManagerUtils.h" +#include "../../base/nsProtocolProxyService.h" +#include "nsServiceManagerUtils.h" +#include "mozilla/Preferences.h" + +namespace mozilla { +namespace net { + +TEST(TestProtocolProxyService, LoadHostFilters) { + nsCOMPtr ps = do_GetService(NS_PROTOCOLPROXYSERVICE_CID); + ASSERT_TRUE(ps); + mozilla::net::nsProtocolProxyService* pps = static_cast(ps.get()); + + nsCOMPtr url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) ); + ASSERT_TRUE(url) << "couldn't create URL"; + + nsAutoCString spec; + + auto CheckLoopbackURLs = [&](bool expected) + { + // loopback IPs are always filtered + spec = "http://127.0.0.1"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + spec = "http://[::1]"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + }; + + auto CheckURLs = [&](bool expected) + { + spec = "http://example.com"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + + spec = "https://10.2.3.4"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 443), expected); + + spec = "http://1.2.3.4"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + + spec = "http://1.2.3.4:8080"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + + spec = "http://[2001::1]"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + + spec = "http://2.3.4.5:7777"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + + spec = "http://[abcd::2]:123"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + + spec = "http://bla.test.com"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + }; + + auto CheckPortDomain = [&](bool expected) + { + spec = "http://blabla.com:10"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + }; + + auto CheckLocalDomain = [&](bool expected) + { + spec = "http://test"; + ASSERT_EQ(url->SetSpec(spec), NS_OK); + ASSERT_EQ(pps->CanUseProxy(url, 80), expected); + }; + + // -------------------------------------------------------------------------- + + nsAutoCString filter; + + // Anything is allowed when there are no filters set + printf("Testing empty filter: %s\n", filter.get()); + pps->LoadHostFilters(filter); + + CheckLoopbackURLs(true); // only time when loopbacks can be proxied. bug? + CheckLocalDomain(true); + CheckURLs(true); + CheckPortDomain(true); + + // -------------------------------------------------------------------------- + + filter = "example.com, 1.2.3.4/16, [2001::1], 10.0.0.0/8, 2.3.0.0/16:7777, [abcd::1]/64:123, *.test.com"; + printf("Testing filter: %s\n", filter.get()); + pps->LoadHostFilters(filter); + // Check URLs can no longer use filtered proxy + CheckURLs(false); + CheckLoopbackURLs(false); + CheckLocalDomain(true); + CheckPortDomain(true); + + // -------------------------------------------------------------------------- + + // This is space separated. See bug 1346711 comment 4. We check this to keep + // backwards compatibility. + filter = " blabla.com:10"; + printf("Testing filter: %s\n", filter.get()); + pps->LoadHostFilters(filter); + CheckURLs(true); + CheckLoopbackURLs(false); + CheckLocalDomain(false); + CheckPortDomain(false); + + // Check that we don't crash on weird input + filter = "a b c abc:1x2, ,, * ** *.* *:10 :20 :40/12 */12:90"; + printf("Testing filter: %s\n", filter.get()); + pps->LoadHostFilters(filter); +} + +} // namespace net +} // namespace mozila diff --git a/netwerk/test/gtest/TestStandardURL.cpp b/netwerk/test/gtest/TestStandardURL.cpp new file mode 100644 index 000000000..ccab556a9 --- /dev/null +++ b/netwerk/test/gtest/TestStandardURL.cpp @@ -0,0 +1,69 @@ +#include "gtest/gtest.h" +#include "gtest/MozGTestBench.h" // For MOZ_GTEST_BENCH + +#include "nsCOMPtr.h" +#include "nsNetCID.h" +#include "nsIURL.h" +#include "nsString.h" +#include "nsComponentManagerUtils.h" + +TEST(TestStandardURL, Simple) { + nsCOMPtr url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) ); + ASSERT_TRUE(url); + ASSERT_EQ(url->SetSpec(NS_LITERAL_CSTRING("http://example.com")), NS_OK); + + nsAutoCString out; + + ASSERT_EQ(url->GetSpec(out), NS_OK); + ASSERT_TRUE(out == NS_LITERAL_CSTRING("http://example.com/")); + + ASSERT_EQ(url->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), out), NS_OK); + ASSERT_TRUE(out == NS_LITERAL_CSTRING("http://example.com/foo.html?q=45")); + + ASSERT_EQ(url->SetScheme(NS_LITERAL_CSTRING("foo")), NS_OK); + + ASSERT_EQ(url->GetScheme(out), NS_OK); + ASSERT_TRUE(out == NS_LITERAL_CSTRING("foo")); + + ASSERT_EQ(url->GetHost(out), NS_OK); + ASSERT_TRUE(out == NS_LITERAL_CSTRING("example.com")); + ASSERT_EQ(url->SetHost(NS_LITERAL_CSTRING("www.yahoo.com")), NS_OK); + ASSERT_EQ(url->GetHost(out), NS_OK); + ASSERT_TRUE(out == NS_LITERAL_CSTRING("www.yahoo.com")); + + ASSERT_EQ(url->SetPath(NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you")), NS_OK); + ASSERT_EQ(url->GetPath(out), NS_OK); + ASSERT_TRUE(out == NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you")); + + ASSERT_EQ(url->SetQuery(NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45")), NS_OK); + ASSERT_EQ(url->GetQuery(out), NS_OK); + ASSERT_TRUE(out == NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45")); + + ASSERT_EQ(url->SetRef(NS_LITERAL_CSTRING("#some-book-mark")), NS_OK); + ASSERT_EQ(url->GetRef(out), NS_OK); + ASSERT_TRUE(out == NS_LITERAL_CSTRING("some-book-mark")); +} + +#define COUNT 10000 + +MOZ_GTEST_BENCH(TestStandardURL, Perf, [] { + nsCOMPtr url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) ); + ASSERT_TRUE(url); + nsAutoCString out; + + for (int i = COUNT; i; --i) { + ASSERT_EQ(url->SetSpec(NS_LITERAL_CSTRING("http://example.com")), NS_OK); + ASSERT_EQ(url->GetSpec(out), NS_OK); + url->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), out); + url->SetScheme(NS_LITERAL_CSTRING("foo")); + url->GetScheme(out); + url->SetHost(NS_LITERAL_CSTRING("www.yahoo.com")); + url->GetHost(out); + url->SetPath(NS_LITERAL_CSTRING("/some-path/one-the-net/about.html?with-a-query#for-you")); + url->GetPath(out); + url->SetQuery(NS_LITERAL_CSTRING("a=b&d=c&what-ever-you-want-to-be-called=45")); + url->GetQuery(out); + url->SetRef(NS_LITERAL_CSTRING("#some-book-mark")); + url->GetRef(out); + } +}); diff --git a/netwerk/test/gtest/moz.build b/netwerk/test/gtest/moz.build new file mode 100644 index 000000000..6e6c80152 --- /dev/null +++ b/netwerk/test/gtest/moz.build @@ -0,0 +1,14 @@ +# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +UNIFIED_SOURCES += [ + 'TestProtocolProxyService.cpp', + 'TestStandardURL.cpp', +] + +include('/ipc/chromium/chromium-config.mozbuild') + +FINAL_LIBRARY = 'xul-gtest' -- cgit v1.2.3