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

Unified Diff: url/origin_unittest.cc

Issue 2378323003: Add url::Origin::GetURL() to convert Origins to URLs without reparsing (Closed)
Patch Set: revert the file:/// changes Created 4 years, 2 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/scheme_host_port.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 416e0e35ee56b5a23159c6731dc01fb46f2664ec..9bb9b0317a41726d9ffd93f7db39dc3ccf8a9e9d 100644
--- a/url/origin_unittest.cc
+++ b/url/origin_unittest.cc
@@ -13,6 +13,26 @@
namespace {
+void ExpectParsedComponentEqual(const url::Component& a,
+ const url::Component& b) {
+ EXPECT_EQ(a.begin, b.begin);
+ EXPECT_EQ(a.len, b.len);
+}
+
+void ExpectParsedUrlsEqual(const GURL& a, const GURL& b) {
+ EXPECT_EQ(a, b);
+ const url::Parsed& a_parsed = a.parsed_for_possibly_invalid_spec();
+ const url::Parsed& b_parsed = b.parsed_for_possibly_invalid_spec();
+ ExpectParsedComponentEqual(a_parsed.scheme, b_parsed.scheme);
+ ExpectParsedComponentEqual(a_parsed.username, b_parsed.username);
+ ExpectParsedComponentEqual(a_parsed.password, b_parsed.password);
+ ExpectParsedComponentEqual(a_parsed.host, b_parsed.host);
+ ExpectParsedComponentEqual(a_parsed.port, b_parsed.port);
+ ExpectParsedComponentEqual(a_parsed.path, b_parsed.path);
+ ExpectParsedComponentEqual(a_parsed.query, b_parsed.query);
+ ExpectParsedComponentEqual(a_parsed.ref, b_parsed.ref);
+}
+
TEST(OriginTest, UniqueOriginComparison) {
url::Origin unique_origin;
EXPECT_EQ("", unique_origin.scheme());
@@ -38,6 +58,8 @@ TEST(OriginTest, UniqueOriginComparison) {
EXPECT_FALSE(origin.IsSameOriginWith(origin));
EXPECT_FALSE(unique_origin.IsSameOriginWith(origin));
EXPECT_FALSE(origin.IsSameOriginWith(unique_origin));
+
+ ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL());
}
}
@@ -103,6 +125,8 @@ TEST(OriginTest, ConstructFromGURL) {
EXPECT_TRUE(origin.IsSameOriginWith(origin));
EXPECT_FALSE(different_origin.IsSameOriginWith(origin));
EXPECT_FALSE(origin.IsSameOriginWith(different_origin));
+
+ ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL());
}
}
@@ -127,7 +151,10 @@ TEST(OriginTest, Serialization) {
GURL url(test_case.url);
EXPECT_TRUE(url.is_valid());
url::Origin origin(url);
- EXPECT_EQ(test_case.expected, origin.Serialize());
+ std::string serialized = origin.Serialize();
+ ExpectParsedUrlsEqual(GURL(serialized), origin.GetURL());
+
+ EXPECT_EQ(test_case.expected, serialized);
// The '<<' operator should produce the same serialization as Serialize().
std::stringstream out;
@@ -186,6 +213,8 @@ TEST(OriginTest, UnsafelyCreate) {
EXPECT_EQ(test.port, origin.port());
EXPECT_FALSE(origin.unique());
EXPECT_TRUE(origin.IsSameOriginWith(origin));
+
+ ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL());
}
}
@@ -221,6 +250,8 @@ TEST(OriginTest, UnsafelyCreateUniqueOnInvalidInput) {
EXPECT_EQ(0, origin.port());
EXPECT_TRUE(origin.unique());
EXPECT_FALSE(origin.IsSameOriginWith(origin));
+
+ ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL());
}
}
@@ -249,6 +280,8 @@ TEST(OriginTest, UnsafelyCreateUniqueViaEmbeddedNulls) {
EXPECT_EQ(0, origin.port());
EXPECT_TRUE(origin.unique());
EXPECT_FALSE(origin.IsSameOriginWith(origin));
+
+ ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL());
}
}
« no previous file with comments | « url/origin.cc ('k') | url/scheme_host_port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698