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

Unified Diff: third_party/WebKit/Source/platform/network/LinkHeaderTest.cpp

Issue 1811163002: Share link header parsing code between blink and content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@base-optional
Patch Set: Created 4 years, 9 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
Index: third_party/WebKit/Source/platform/network/LinkHeaderTest.cpp
diff --git a/third_party/WebKit/Source/core/loader/LinkHeaderTest.cpp b/third_party/WebKit/Source/platform/network/LinkHeaderTest.cpp
similarity index 88%
rename from third_party/WebKit/Source/core/loader/LinkHeaderTest.cpp
rename to third_party/WebKit/Source/platform/network/LinkHeaderTest.cpp
index 9eabb394d4d7cb8742dbc871c64ccc3a539f1008..2457896666112d19f3ad993d527b08c989cc7147 100644
--- a/third_party/WebKit/Source/core/loader/LinkHeaderTest.cpp
+++ b/third_party/WebKit/Source/platform/network/LinkHeaderTest.cpp
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/loader/LinkHeader.h"
+#include "platform/network/LinkHeader.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <base/macros.h>
@@ -34,8 +34,8 @@ struct SingleTestCase {
{"</images/cat.jpg> ; rel=prefetch", true, "/images/cat.jpg", "prefetch", "", ""},
{"< /images/cat.jpg> ; rel=prefetch", true, "/images/cat.jpg", "prefetch", "", ""},
{"</images/cat.jpg > ; rel=prefetch", true, "/images/cat.jpg", "prefetch", "", ""},
- {"</images/cat.jpg wutwut> ; rel=prefetch", true, "/images/cat.jpg", "prefetch", "", ""},
- {"</images/cat.jpg wutwut \t > ; rel=prefetch", true, "/images/cat.jpg", "prefetch", "", ""},
+ {"</images/cat.jpg wutwut> ; rel=prefetch", true, "/images/cat.jpg wutwut", "prefetch", "", ""},
+ {"</images/cat.jpg wutwut \t > ; rel=prefetch", true, "/images/cat.jpg wutwut", "prefetch", "", ""},
Yoav Weiss 2016/03/30 07:38:52 Looking at https://tools.ietf.org/html/rfc3986 tha
{"</images/cat.jpg>; rel=prefetch ", true, "/images/cat.jpg", "prefetch", "", ""},
{"</images/cat.jpg>; Rel=prefetch ", true, "/images/cat.jpg", "prefetch", "", ""},
{"</images/cat.jpg>; Rel=PReFetCh ", true, "/images/cat.jpg", "prefetch", "", ""},
@@ -55,7 +55,7 @@ struct SingleTestCase {
{"</images/cat.jpg>; wut=sup ; rel =prefetch \t ;", true, "/images/cat.jpg", "prefetch", "", ""},
{"</images/cat.jpg> wut=sup ; rel =prefetch \t ;", false},
{"< /images/cat.jpg", false},
- {"< http://wut.com/ sdfsdf ?sd>; rel=dns-prefetch", true, "http://wut.com/", "dns-prefetch", "", ""},
+ {"< http://wut.com/ sdfsdf ?sd>; rel=dns-prefetch", true, "http://wut.com/ sdfsdf ?sd", "dns-prefetch", "", ""},
{"< http://wut.com/%20%20%3dsdfsdf?sd>; rel=dns-prefetch", true, "http://wut.com/%20%20%3dsdfsdf?sd", "dns-prefetch", "", ""},
{"< http://wut.com/dfsdf?sdf=ghj&wer=rty>; rel=prefetch", true, "http://wut.com/dfsdf?sdf=ghj&wer=rty", "prefetch", "", ""},
{"< http://wut.com/dfsdf?sdf=ghj&wer=rty>;;;;; rel=prefetch", true, "http://wut.com/dfsdf?sdf=ghj&wer=rty", "prefetch", "", ""},
@@ -70,7 +70,7 @@ struct SingleTestCase {
{"</images/cat.jpg>; rel=prefetch ;", true, "/images/cat.jpg", "prefetch", "", ""},
{"</images/ca,t.jpg>; rel=prefetch ;", true, "/images/ca,t.jpg", "prefetch", "", ""},
{"<simple.css>; rel=stylesheet; title=\"title with a DQUOTE and backslash\"", true, "simple.css", "stylesheet", "", ""},
- {"<simple.css>; rel=stylesheet; title=\"title with a DQUOTE \\\" and backslash: \\\"", false},
+ {"<simple.css>; rel=stylesheet; title=\"title with a DQUOTE \\\" and backslash: \\\"", true, "simple.css", "stylesheet", ""},
Yoav Weiss 2016/03/30 07:38:52 That doesn't seem correct according to the definit
Marijn Kruisselbrink 2016/04/20 01:45:03 Yeah, net::HttpUtil::NameValuePairsIterator delibe
{"<simple.css>; title=\"title with a DQUOTE \\\" and backslash: \"; rel=stylesheet; ", true, "simple.css", "stylesheet", "", ""},
{"<simple.css>; title=\'title with a DQUOTE \\\' and backslash: \'; rel=stylesheet; ", true, "simple.css", "stylesheet", "", ""},
{"<simple.css>; title=\"title with a DQUOTE \\\" and ;backslash,: \"; rel=stylesheet; ", true, "simple.css", "stylesheet", "", ""},
@@ -91,8 +91,8 @@ struct SingleTestCase {
{"<simple.css>; rel=''; type", false},
{"<simple.css>; rel=''; rev", false},
{"<simple.css>; rel=''; bla", true, "simple.css", "", "", ""},
- {"<simple.css>; rel='prefetch", false},
- {"<simple.css>; rel=\"prefetch", false},
+ {"<simple.css>; rel='prefetch", true, "simple.css", "prefetch", ""},
+ {"<simple.css>; rel=\"prefetch", true, "simple.css", "prefetch", ""},
{"<simple.css>; rel=\"", false},
{"<http://whatever.com>; rel=preconnect; valid!", true, "http://whatever.com", "preconnect", "", ""},
{"<http://whatever.com>; rel=preconnect; valid$", true, "http://whatever.com", "preconnect", "", ""},
@@ -140,6 +140,7 @@ struct DoubleTestCase {
{"<ybg.css>; rel=stylesheet, <simple.css>; rel=stylesheet", "ybg.css", "stylesheet", true, "simple.css", "stylesheet", true},
{"<ybg.css>; rel=stylesheet,<simple.css>; rel=stylesheet", "ybg.css", "stylesheet", true, "simple.css", "stylesheet", true},
{"<ybg.css>; rel=stylesheet;crossorigin,<simple.css>; rel=stylesheet", "ybg.css", "stylesheet", true, "simple.css", "stylesheet", true},
+ {"<hel,lo.css>; rel=stylesheet; title=\"foo,bar\", <simple.css>; rel=stylesheet; title=\"foo;bar\"", "hel,lo.css", "stylesheet", true, "simple.css", "stylesheet", true},
};
void PrintTo(const DoubleTestCase& test, std::ostream* os)
@@ -170,22 +171,22 @@ struct CrossOriginTestCase {
const char* headerValue;
const char* url;
const char* rel;
- const CrossOriginAttributeValue crossorigin;
+ const char* crossorigin;
bool valid;
} crossOriginTestCases[] = {
- {"<http://whatever.com>; rel=preconnect", "http://whatever.com", "preconnect", CrossOriginAttributeNotSet, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin=", "http://whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin", "http://whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin ", "http://whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin;", "http://whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin, <http://whatever2.com>; rel=preconnect", "http://whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin , <http://whatever2.com>; rel=preconnect", "http://whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin,<http://whatever2.com>; rel=preconnect", "http://whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin=anonymous", "http://whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin=use-credentials", "http://whatever.com", "preconnect", CrossOriginAttributeUseCredentials, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin=whatever", "http://whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
- {"<http://whatever.com>; rel=preconnect; crossorig|in=whatever", "http://whatever.com", "preconnect", CrossOriginAttributeNotSet, true},
- {"<http://whatever.com>; rel=preconnect; crossorigin|=whatever", "http://whatever.com", "preconnect", CrossOriginAttributeNotSet, true},
+ {"<http://whatever.com>; rel=preconnect", "http://whatever.com", "preconnect", nullptr, true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin=", "", "", "", false},
+ {"<http://whatever.com>; rel=preconnect; crossorigin", "http://whatever.com", "preconnect", "", true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin ", "http://whatever.com", "preconnect", "", true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin;", "http://whatever.com", "preconnect", "", true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin, <http://whatever2.com>; rel=preconnect", "http://whatever.com", "preconnect", "", true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin , <http://whatever2.com>; rel=preconnect", "http://whatever.com", "preconnect", "", true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin,<http://whatever2.com>; rel=preconnect", "http://whatever.com", "preconnect", "", true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin=anonymous", "http://whatever.com", "preconnect", "anonymous", true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin=use-credentials", "http://whatever.com", "preconnect", "use-credentials", true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin=whatever", "http://whatever.com", "preconnect", "whatever", true},
+ {"<http://whatever.com>; rel=preconnect; crossorig|in=whatever", "http://whatever.com", "preconnect", nullptr, true},
+ {"<http://whatever.com>; rel=preconnect; crossorigin|=whatever", "http://whatever.com", "preconnect", nullptr, true},
};
void PrintTo(const CrossOriginTestCase& test, std::ostream* os)
@@ -203,8 +204,11 @@ TEST_P(CrossOriginLinkHeaderTest, CrossOrigin)
LinkHeader& header = headerSet[0];
EXPECT_STREQ(testCase.url, header.url().ascii().data());
EXPECT_STREQ(testCase.rel, header.rel().ascii().data());
- EXPECT_EQ(testCase.crossorigin, header.crossOrigin());
EXPECT_EQ(testCase.valid, header.valid());
+ if (!testCase.crossorigin)
+ EXPECT_TRUE(header.crossOrigin().isNull());
+ else
+ EXPECT_STREQ(testCase.crossorigin, header.crossOrigin().ascii().data());
}
INSTANTIATE_TEST_CASE_P(LinkHeaderTest, CrossOriginLinkHeaderTest, testing::ValuesIn(crossOriginTestCases));

Powered by Google App Engine
This is Rietveld 408576698