| Index: ios/web/public/referrer_util_unittest.cc
|
| diff --git a/ios/web/public/referrer_util_unittest.cc b/ios/web/public/referrer_util_unittest.cc
|
| index 0d4cb23c3bf1a1fe3d47025e7184e8a8acbf076d..9da6fae1e97af149af7a5338c6eae03b573d74e6 100644
|
| --- a/ios/web/public/referrer_util_unittest.cc
|
| +++ b/ios/web/public/referrer_util_unittest.cc
|
| @@ -128,6 +128,65 @@ TEST(ReferrerUtilTest, OriginWhenCrossOriginPolicy) {
|
| }
|
| }
|
|
|
| +// Tests that the same-origin policy works as expected.
|
| +TEST(ReferrerUtilTest, SameOriginPolicy) {
|
| + for (unsigned int source = 0; source < arraysize(kTestUrls); ++source) {
|
| + for (unsigned int dest = 1; dest < arraysize(kTestUrls); ++dest) {
|
| + GURL source_url(kTestUrls[source]);
|
| + GURL dest_url(kTestUrls[dest]);
|
| + Referrer referrer(source_url, ReferrerPolicySameOrigin);
|
| + std::string value = ReferrerHeaderValueForNavigation(dest_url, referrer);
|
| +
|
| + // Full URL for the same origin, and nothing for all other cases.
|
| + if (source_url.GetOrigin() == dest_url.GetOrigin())
|
| + EXPECT_EQ(source_url.GetAsReferrer().spec(), value);
|
| + else
|
| + EXPECT_EQ(std::string(), value);
|
| + }
|
| + }
|
| +}
|
| +
|
| +// Tests that the strict-origin policy works as expected.
|
| +TEST(ReferrerUtilTest, StrictOriginPolicy) {
|
| + for (unsigned int source = 0; source < arraysize(kTestUrls); ++source) {
|
| + for (unsigned int dest = 1; dest < arraysize(kTestUrls); ++dest) {
|
| + GURL source_url(kTestUrls[source]);
|
| + GURL dest_url(kTestUrls[dest]);
|
| + Referrer referrer(source_url, ReferrerPolicyStrictOrigin);
|
| + std::string value = ReferrerHeaderValueForNavigation(dest_url, referrer);
|
| +
|
| + // No referrer when downgrading, and origin otherwise.
|
| + if (source_url.SchemeIsCryptographic() &&
|
| + !dest_url.SchemeIsCryptographic())
|
| + EXPECT_EQ("", value);
|
| + else
|
| + EXPECT_EQ(source_url.GetOrigin().spec(), value);
|
| + }
|
| + }
|
| +}
|
| +
|
| +// Tests that the strict-origin-when-cross-origin policy works as expected.
|
| +TEST(ReferrerUtilTest, StrictOriginWhenCrossOriginPolicy) {
|
| + for (unsigned int source = 0; source < arraysize(kTestUrls); ++source) {
|
| + for (unsigned int dest = 1; dest < arraysize(kTestUrls); ++dest) {
|
| + GURL source_url(kTestUrls[source]);
|
| + GURL dest_url(kTestUrls[dest]);
|
| + Referrer referrer(source_url, ReferrerPolicyStrictOriginWhenCrossOrigin);
|
| + std::string value = ReferrerHeaderValueForNavigation(dest_url, referrer);
|
| +
|
| + // No referrer when downgrading, origin when cross-origin but not
|
| + // downgrading, and full referrer otherwise.
|
| + if (source_url.SchemeIsCryptographic() &&
|
| + !dest_url.SchemeIsCryptographic())
|
| + EXPECT_EQ("", value);
|
| + else if (source_url.GetOrigin() == dest_url.GetOrigin())
|
| + EXPECT_EQ(source_url.GetAsReferrer().spec(), value);
|
| + else
|
| + EXPECT_EQ(source_url.GetOrigin().spec(), value);
|
| + }
|
| + }
|
| +}
|
| +
|
| // Tests that PolicyForNavigation gives the right values.
|
| TEST(ReferrerUtilTest, PolicyForNavigation) {
|
| // The request and destination URLs are unused in the current implementation,
|
| @@ -142,33 +201,34 @@ TEST(ReferrerUtilTest, PolicyForNavigation) {
|
| // testing, and thus less likely to have a copy/paste bug that passes
|
| // incorrect mappings.
|
| switch (net_request_policy) {
|
| + case net::URLRequest::
|
| + CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE:
|
| + // This corresponds directly to ReferrerPolicyNoReferrerWhenDowngrade,
|
| + // which is also how Default works on iOS.
|
| + EXPECT_TRUE(policy == ReferrerPolicyDefault ||
|
| + policy == ReferrerPolicyNoReferrerWhenDowngrade);
|
| + break;
|
| case net::URLRequest::
|
| REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN:
|
| - // Nothing currently maps to this policy on iOS.
|
| - FAIL();
|
| + EXPECT_EQ(ReferrerPolicyStrictOriginWhenCrossOrigin, policy);
|
| break;
|
| case net::URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN:
|
| EXPECT_EQ(ReferrerPolicyOriginWhenCrossOrigin, policy);
|
| break;
|
| case net::URLRequest::NEVER_CLEAR_REFERRER:
|
| - // This request policy should be used when the referrer policy is always
|
| - // the same regardless of source and destination.
|
| - EXPECT_TRUE(policy == ReferrerPolicyAlways ||
|
| - policy == ReferrerPolicyNever ||
|
| - policy == ReferrerPolicyOrigin);
|
| - break;
|
| - case net::URLRequest::
|
| - CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE:
|
| - // This corresponds directly to ReferrerPolicyNoReferrerWhenDowngrade,
|
| - // which is also how Default works on iOS.
|
| - EXPECT_TRUE(policy == ReferrerPolicyDefault ||
|
| - policy == ReferrerPolicyNoReferrerWhenDowngrade);
|
| + EXPECT_EQ(ReferrerPolicyAlways, policy);
|
| break;
|
| case net::URLRequest::ORIGIN:
|
| - EXPECT_TRUE(policy == ReferrerPolicyOrigin);
|
| + EXPECT_EQ(ReferrerPolicyOrigin, policy);
|
| + break;
|
| + case net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN:
|
| + EXPECT_EQ(ReferrerPolicySameOrigin, policy);
|
| + break;
|
| + case net::URLRequest::ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE:
|
| + EXPECT_EQ(ReferrerPolicyStrictOrigin, policy);
|
| break;
|
| case net::URLRequest::NO_REFERRER:
|
| - EXPECT_TRUE(policy == ReferrerPolicyNever);
|
| + EXPECT_EQ(ReferrerPolicyNever, policy);
|
| break;
|
| case net::URLRequest::MAX_REFERRER_POLICY:
|
| FAIL();
|
| @@ -189,6 +249,9 @@ TEST(ReferrerUtilTest, PolicyFromString) {
|
| "no-referrer",
|
| "origin",
|
| "origin-when-cross-origin",
|
| + "same-origin",
|
| + "strict-origin",
|
| + "strict-origin-when-cross-origin",
|
| };
|
| // Test that all the values are supported.
|
| for (int i = 0; i < ReferrerPolicyLast; ++i) {
|
| @@ -210,9 +273,9 @@ TEST(ReferrerUtilTest, PolicyFromString) {
|
| ReferrerPolicyFromString("default"));
|
| EXPECT_EQ(ReferrerPolicyAlways, ReferrerPolicyFromString("always"));
|
|
|
| - // Test that invalid values map to Never.
|
| - EXPECT_EQ(ReferrerPolicyNever, ReferrerPolicyFromString(""));
|
| - EXPECT_EQ(ReferrerPolicyNever, ReferrerPolicyFromString("made-up"));
|
| + // Test that invalid values map to Default.
|
| + EXPECT_EQ(ReferrerPolicyDefault, ReferrerPolicyFromString(""));
|
| + EXPECT_EQ(ReferrerPolicyDefault, ReferrerPolicyFromString("made-up"));
|
| }
|
|
|
| } // namespace web
|
|
|