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

Unified Diff: url/origin_unittest.cc

Issue 2688573002: Allow a unique origin to compare equal to itself
Patch Set: Fix after rebase Created 3 years, 4 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') | no next file » | 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 9784655c890af40d9513f4ea019e8f129dc5d4ef..eb24050403f2d7489e2e4690c2cafe91ed2defed 100644
--- a/url/origin_unittest.cc
+++ b/url/origin_unittest.cc
@@ -41,7 +41,12 @@ TEST(OriginTest, OpaqueOriginComparison) {
EXPECT_EQ("", opaque_origin.host());
EXPECT_EQ(0, opaque_origin.port());
EXPECT_TRUE(opaque_origin.opaque());
- EXPECT_FALSE(opaque_origin.IsSameOriginWith(opaque_origin));
+ // An opaque origin is same origin with itself
+ EXPECT_TRUE(opaque_origin.IsSameOriginWith(opaque_origin));
+ // An opaque origin is not same origin with any other opaque origin
+ url::Origin second_opaque_origin;
+ EXPECT_FALSE(opaque_origin.IsSameOriginWith(second_opaque_origin));
+ EXPECT_FALSE(second_opaque_origin.IsSameOriginWith(opaque_origin));
const char* const urls[] = {"data:text/html,Hello!",
"javascript:alert(1)",
@@ -57,10 +62,25 @@ TEST(OriginTest, OpaqueOriginComparison) {
EXPECT_EQ("", origin.host());
EXPECT_EQ(0, origin.port());
EXPECT_TRUE(origin.opaque());
- EXPECT_FALSE(origin.IsSameOriginWith(origin));
+
+ // An opaque origin is same origin with itself
+ EXPECT_TRUE(origin.IsSameOriginWith(origin));
+
+ // An opaque origin is not same origin with any other opaque origin
EXPECT_FALSE(opaque_origin.IsSameOriginWith(origin));
EXPECT_FALSE(origin.IsSameOriginWith(opaque_origin));
+ // A second opaque origin from the same source string is not same origin
+ // with the first.
+ url::Origin duplicated_origin(url);
+ EXPECT_FALSE(origin.IsSameOriginWith(duplicated_origin));
+ EXPECT_FALSE(duplicated_origin.IsSameOriginWith(origin));
+
+ // A copy of an opaque origin is not same origin with the original.
+ url::Origin copied_origin(origin);
+ EXPECT_FALSE(origin.IsSameOriginWith(copied_origin));
+ EXPECT_FALSE(copied_origin.IsSameOriginWith(origin));
+
ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL());
}
}
@@ -405,7 +425,17 @@ TEST(OriginTest, UnsafelyCreateUniqueOnInvalidInput) {
EXPECT_EQ("", origin.host());
EXPECT_EQ(0, origin.port());
EXPECT_TRUE(origin.opaque());
- EXPECT_FALSE(origin.IsSameOriginWith(origin));
+
+ // An opaque origin is same origin with itself
+ EXPECT_TRUE(origin.IsSameOriginWith(origin));
+
+ // A second opaque origin from the same URL components is not same origin
+ // with the first.
+ url::Origin duplicated_origin =
+ url::Origin::UnsafelyCreateOriginWithoutNormalization(
+ test.scheme, test.host, test.port, "");
+ EXPECT_FALSE(origin.IsSameOriginWith(duplicated_origin));
+ EXPECT_FALSE(duplicated_origin.IsSameOriginWith(origin));
ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL());
}
@@ -435,7 +465,18 @@ TEST(OriginTest, UnsafelyCreateUniqueViaEmbeddedNulls) {
EXPECT_EQ("", origin.host());
EXPECT_EQ(0, origin.port());
EXPECT_TRUE(origin.opaque());
- EXPECT_FALSE(origin.IsSameOriginWith(origin));
+
+ // An opaque origin is same origin with itself
+ EXPECT_TRUE(origin.IsSameOriginWith(origin));
+
+ // A second opaque origin from the same URL components is not same origin
+ // with the first.
+ url::Origin duplicated_origin =
+ url::Origin::UnsafelyCreateOriginWithoutNormalization(
+ std::string(test.scheme, test.scheme_length),
+ std::string(test.host, test.host_length), test.port, "");
+ EXPECT_FALSE(origin.IsSameOriginWith(duplicated_origin));
+ EXPECT_FALSE(duplicated_origin.IsSameOriginWith(origin));
ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL());
}
« no previous file with comments | « url/origin.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698