Index: url/origin_unittest.cc |
diff --git a/url/origin_unittest.cc b/url/origin_unittest.cc |
index c094ee6cf50efe6470da1da9586a11a4644fc341..468b2016daf5411d8ed2201241e562c40e24b5ba 100644 |
--- a/url/origin_unittest.cc |
+++ b/url/origin_unittest.cc |
@@ -3,6 +3,7 @@ |
// found in the LICENSE file. |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
#include "url/origin.h" |
namespace url { |
@@ -13,27 +14,159 @@ namespace { |
// violating DCHECKs. |
TEST(OriginTest, constructEmpty) { |
Origin origin; |
- EXPECT_EQ("null", origin.string()); |
+ EXPECT_EQ("null", origin.serialize()); |
} |
TEST(OriginTest, constructNull) { |
Origin origin("null"); |
- EXPECT_EQ("null", origin.string()); |
+ EXPECT_EQ("null", origin.serialize()); |
} |
TEST(OriginTest, constructValidOrigin) { |
Origin origin("http://example.com:8080"); |
- EXPECT_EQ("http://example.com:8080", origin.string()); |
+ EXPECT_EQ("http://example.com:8080", origin.serialize()); |
} |
TEST(OriginTest, constructValidFileOrigin) { |
Origin origin("file://"); |
- EXPECT_EQ("file://", origin.string()); |
+ EXPECT_EQ("file://", origin.serialize()); |
} |
TEST(OriginTest, constructValidOriginWithoutPort) { |
Origin origin("wss://example2.com"); |
- EXPECT_EQ("wss://example2.com", origin.string()); |
+ EXPECT_EQ("wss://example2.com", origin.serialize()); |
+} |
+ |
+TEST(OriginTest, Constructors) { |
+ struct TestCases { |
+ const char* url; |
+ const char* scheme; |
+ const char* host; |
+ unsigned short port; |
+ bool unique; |
+ bool valid; |
+ const char* serialized; |
+ } cases[] = { |
+ // Invalid/unique URLs |
+ {"", "", "", 0, true, false, "null"}, |
+ {"null", "", "", 0, true, false, "null"}, |
+ {"!", "", "", 0, true, false, "null"}, |
+ {"javascript:window.alert(\"hello,world\");", |
+ "", |
+ "", |
+ 0, |
+ true, |
+ true, |
+ "null"}, |
+ |
+ // File URLs |
+ {"file:///path/to/file", "file", "", 0, false, true, "file://"}, |
+ {"file:///path/to/another/file", "file", "", 0, false, true, "file://"}, |
+ |
+ // Webby URLs |
+ {"http://example.com/", |
+ "http", |
+ "example.com", |
+ 80, |
+ false, |
+ true, |
+ "http://example.com"}, |
+ {"http://example.com:80/", |
+ "http", |
+ "example.com", |
+ 80, |
+ false, |
+ true, |
+ "http://example.com"}, |
+ {"http://example.com:81/", |
+ "http", |
+ "example.com", |
+ 81, |
+ false, |
+ true, |
+ "http://example.com:81"}, |
+ {"http://user:pass@example.com:81/blah#baz", |
+ "http", |
+ "example.com", |
+ 81, |
+ false, |
+ true, |
+ "http://example.com:81"}, |
+ {"https://example.com/", |
+ "https", |
+ "example.com", |
+ 443, |
+ false, |
+ true, |
+ "https://example.com"}, |
+ {"https://example.com:443/", |
+ "https", |
+ "example.com", |
+ 443, |
+ false, |
+ true, |
+ "https://example.com"}, |
+ {"https://example.com:444/", |
+ "https", |
+ "example.com", |
+ 444, |
+ false, |
+ true, |
+ "https://example.com:444"}, |
+ {"https://user:pass@example.com:444/blah#baz", |
+ "https", |
+ "example.com", |
+ 444, |
+ false, |
+ true, |
+ "https://example.com:444"}, |
+ |
+ // Inner URLs |
+ {"filesystem:http://example.com/temporary/", |
+ "http", |
+ "example.com", |
+ 80, |
+ false, |
+ true, |
+ "http://example.com"}, |
+ {"filesystem:http://user:pass@example.com:21/blah#baz", |
+ "http", |
+ "example.com", |
+ 21, |
+ false, |
+ true, |
+ "http://example.com:21"}}; |
+ |
+ for (const auto& test : cases) { |
+ SCOPED_TRACE(::testing::Message() << "Testing '" << test.url << "'."); |
+ Origin origin_from_gurl(GURL(test.url)); |
+ Origin origin_from_string(test.url); |
+ Origin origin_from_tuple(test.scheme, test.host, test.port); |
+ |
+ EXPECT_EQ(!test.unique, |
+ origin_from_gurl.IsSameOriginWith(origin_from_string)); |
+ EXPECT_EQ(!test.unique, |
+ origin_from_string.IsSameOriginWith(origin_from_gurl)); |
+ EXPECT_EQ(!test.unique, |
+ origin_from_tuple.IsSameOriginWith(origin_from_gurl)); |
+ |
+ EXPECT_EQ(test.scheme, origin_from_gurl.scheme()); |
+ EXPECT_EQ(test.host, origin_from_gurl.host()); |
+ EXPECT_EQ(test.port, origin_from_gurl.port()); |
+ EXPECT_EQ(test.serialized, origin_from_gurl.serialize()); |
+ EXPECT_EQ(test.valid, origin_from_gurl.is_valid()); |
+ |
+ EXPECT_EQ(test.scheme, origin_from_string.scheme()); |
+ EXPECT_EQ(test.host, origin_from_string.host()); |
+ EXPECT_EQ(test.port, origin_from_string.port()); |
+ EXPECT_EQ(test.serialized, origin_from_string.serialize()); |
+ EXPECT_EQ(test.valid, origin_from_gurl.is_valid()); |
+ |
+ EXPECT_EQ(test.scheme, origin_from_tuple.scheme()); |
+ EXPECT_EQ(test.host, origin_from_tuple.host()); |
+ EXPECT_EQ(test.port, origin_from_tuple.port()); |
+ EXPECT_EQ(test.serialized, origin_from_tuple.serialize()); |
+ } |
} |
} // namespace |