diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /netwerk/test/gtest/TestStandardURL.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/test/gtest/TestStandardURL.cpp')
-rw-r--r-- | netwerk/test/gtest/TestStandardURL.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
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<nsIURL> 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<nsIURL> 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); + } +}); |