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

Unified Diff: content/public/common/referrer_unittest.cc

Issue 263563003: Add referrer & load flag support to BitmapFetcher class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove temp comments Created 6 years, 8 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
« content/public/common/referrer.cc ('K') | « content/public/common/referrer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/common/referrer_unittest.cc
diff --git a/content/public/common/referrer_unittest.cc b/content/public/common/referrer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6030a2b98b9509d7fea730bee1e45204d9ec5002
--- /dev/null
+++ b/content/public/common/referrer_unittest.cc
@@ -0,0 +1,87 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
Kibeom Kim (inactive) 2014/04/30 00:58:56 from https://chrome-internal.googlesource.com/blin
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/common/referrer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char* kTestURL = "http://google.com/";
+
+// Check that copying Referrer objects works.
+TEST(ReferrerTest, Copy) {
+ content::Referrer r1(GURL(kTestURL), blink::WebReferrerPolicyAlways);
+ content::Referrer r2;
+
+ r2 = r1;
+ EXPECT_EQ(GURL(kTestURL), r2.url);
+ EXPECT_EQ(blink::WebReferrerPolicyAlways, r2.policy);
+}
+
+TEST(ReferrerTest, Sanitization) {
+ content::Referrer referrer(
+ GURL("http://user:password@foo.com/bar/baz.html#fragment"),
+ blink::WebReferrerPolicyAlways);
+ GURL sanitized =
+ referrer.ReferrerHeaderUrlForNavigation(GURL("http://www.bar.com"));
+ EXPECT_EQ("http://foo.com/bar/baz.html", sanitized.spec());
+}
+
+TEST(ReferrerTest, PolicyHandling) {
+ const char* test_urls[] = {
+ "http://insecure.com/foo/bar.html",
+ "https://secure.net/trustworthy.html",
+ };
+
+ // Default: all but secure->insecure should have a full referrer.
+ for (unsigned int source = 0; source < arraysize(test_urls); ++source) {
+ for (unsigned int dest = 0; dest < arraysize(test_urls); ++dest) {
+ content::Referrer referrer(GURL(test_urls[source]),
+ blink::WebReferrerPolicyDefault);
+ const GURL referrer_url =
+ referrer.ReferrerHeaderUrlForNavigation(GURL(test_urls[dest]));
+ if (source == 1 && dest == 0) {
+ EXPECT_EQ("", referrer_url.spec());
+ } else {
+ EXPECT_EQ(test_urls[source], referrer_url.spec());
+ }
+ }
+ }
+
+ // Never: always empty string.
+ for (unsigned int source = 0; source < arraysize(test_urls); ++source) {
+ for (unsigned int dest = 0; dest < arraysize(test_urls); ++dest) {
+ content::Referrer referrer(GURL(test_urls[source]),
+ blink::WebReferrerPolicyNever);
+ const GURL referrer_url =
+ referrer.ReferrerHeaderUrlForNavigation(GURL(test_urls[dest]));
+ EXPECT_EQ("", referrer_url.spec());
+ }
+ }
+
+ // Always: always the full referrer.
+ for (unsigned int source = 0; source < arraysize(test_urls); ++source) {
+ for (unsigned int dest = 0; dest < arraysize(test_urls); ++dest) {
+ content::Referrer referrer(GURL(test_urls[source]),
+ blink::WebReferrerPolicyAlways);
+ const GURL referrer_url =
+ referrer.ReferrerHeaderUrlForNavigation(GURL(test_urls[dest]));
+ EXPECT_EQ(test_urls[source], referrer_url.spec());
+ }
+ }
+
+ // Always: always just the origin.
+ for (unsigned int source = 0; source < arraysize(test_urls); ++source) {
+ for (unsigned int dest = 0; dest < arraysize(test_urls); ++dest) {
+ content::Referrer referrer(GURL(test_urls[source]),
+ blink::WebReferrerPolicyOrigin);
+ const GURL referrer_url =
+ referrer.ReferrerHeaderUrlForNavigation(GURL(test_urls[dest]));
+ EXPECT_EQ(GURL(test_urls[source]).GetOrigin().spec(),
+ referrer_url.spec());
+ }
+ }
+}
+
+} // namespace
« content/public/common/referrer.cc ('K') | « content/public/common/referrer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698