Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Unified Diff: url/origin_unittest.cc

Issue 1153763002: Hardening the 'url::Origin' implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « url/origin.cc ('k') | url/url_constants.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « url/origin.cc ('k') | url/url_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698