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

Side by Side Diff: Source/core/loader/LinkHeaderTest.cpp

Issue 1131513004: Revert of Added <link rel=preconnect> crossorigin attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « Source/core/loader/LinkHeader.cpp ('k') | Source/core/loader/LinkLoader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/loader/LinkHeader.h" 6 #include "core/loader/LinkHeader.h"
7 7
8 #include <base/macros.h> 8 #include <base/macros.h>
9 #include <gtest/gtest.h> 9 #include <gtest/gtest.h>
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 {"<simple.css>; rel=\"bla'sdf\"; title=\"", "simple.css", "bla'sdf", fal se}, 81 {"<simple.css>; rel=\"bla'sdf\"; title=\"", "simple.css", "bla'sdf", fal se},
82 {"<simple.css>; rel=\"\"; title=\"\"", "simple.css", "", true}, 82 {"<simple.css>; rel=\"\"; title=\"\"", "simple.css", "", true},
83 {"<simple.css>; rel=''; title=\"\"", "simple.css", "", true}, 83 {"<simple.css>; rel=''; title=\"\"", "simple.css", "", true},
84 {"<simple.css>; rel='prefetch", "simple.css", "", false}, 84 {"<simple.css>; rel='prefetch", "simple.css", "", false},
85 {"<simple.css>; rel=\"prefetch", "simple.css", "", false}, 85 {"<simple.css>; rel=\"prefetch", "simple.css", "", false},
86 {"<simple.css>; rel=\"", "simple.css", "", false}, 86 {"<simple.css>; rel=\"", "simple.css", "", false},
87 }; 87 };
88 88
89 89
90 // Test the cases with a single header 90 // Test the cases with a single header
91 for (auto& testCase : cases) { 91 for (size_t i = 0; i < arraysize(cases); ++i) {
92 TestCase& testCase = cases[i];
92 LinkHeaderSet headerSet(testCase.headerValue); 93 LinkHeaderSet headerSet(testCase.headerValue);
93 LinkHeader& header = headerSet[0]; 94 LinkHeader& header = headerSet[0];
94 ASSERT_STREQ(testCase.url, header.url().ascii().data()); 95 ASSERT_STREQ(testCase.url, header.url().ascii().data());
95 ASSERT_STREQ(testCase.rel, header.rel().ascii().data()); 96 ASSERT_STREQ(testCase.rel, header.rel().ascii().data());
96 ASSERT_EQ(testCase.valid, header.valid()); 97 ASSERT_EQ(testCase.valid, header.valid());
97 } 98 }
98 } 99 }
99 100
100 TEST(LinkHeaderTest, Double) 101 TEST(LinkHeaderTest, Double)
101 { 102 {
102 struct DoubleTestCase { 103 struct DoubleTestCase {
103 const char* headerValue; 104 const char* headerValue;
104 const char* url; 105 const char* url;
105 const char* rel; 106 const char* rel;
106 bool valid; 107 bool valid;
107 const char* url2; 108 const char* url2;
108 const char* rel2; 109 const char* rel2;
109 bool valid2; 110 bool valid2;
110 } cases[] = { 111 } doubleCases[] = {
111 {"<ybg.css>; rel=stylesheet, <simple.css>; rel=stylesheet", "ybg.css", " stylesheet", true, "simple.css", "stylesheet", true}, 112 {"<ybg.css>; rel=stylesheet, <simple.css>; rel=stylesheet", "ybg.css", " stylesheet", true, "simple.css", "stylesheet", true},
112 }; 113 };
113 114
114 for (auto& testCase : cases) { 115 for (size_t i = 0; i < arraysize(doubleCases); ++i) {
116 DoubleTestCase& testCase = doubleCases[i];
115 LinkHeaderSet headerSet(testCase.headerValue); 117 LinkHeaderSet headerSet(testCase.headerValue);
116 LinkHeader& header1 = headerSet[0]; 118 LinkHeader& header1 = headerSet[0];
117 LinkHeader& header2 = headerSet[1]; 119 LinkHeader& header2 = headerSet[1];
118 ASSERT_STREQ(testCase.url, header1.url().ascii().data()); 120 ASSERT_STREQ(testCase.url, header1.url().ascii().data());
119 ASSERT_STREQ(testCase.rel, header1.rel().ascii().data()); 121 ASSERT_STREQ(testCase.rel, header1.rel().ascii().data());
120 ASSERT_EQ(testCase.valid, header1.valid()); 122 ASSERT_EQ(testCase.valid, header1.valid());
121 ASSERT_STREQ(testCase.url2, header2.url().ascii().data()); 123 ASSERT_STREQ(testCase.url2, header2.url().ascii().data());
122 ASSERT_STREQ(testCase.rel2, header2.rel().ascii().data()); 124 ASSERT_STREQ(testCase.rel2, header2.rel().ascii().data());
123 ASSERT_EQ(testCase.valid2, header2.valid()); 125 ASSERT_EQ(testCase.valid2, header2.valid());
124 } 126 }
125 } 127 }
126 128
127 TEST(LinkHeaderTest, CrossOrigin)
128 {
129 struct TestCase {
130 const char* headerValue;
131 const char* url;
132 const char* rel;
133 const CrossOriginAttributeValue crossorigin;
134 bool valid;
135 } cases[] = {
136 {"<http://whatever.com>; rel=preconnect", "http://whatever.com", "precon nect", CrossOriginAttributeNotSet, true},
137 {"<http://whatever.com>; rel=preconnect; crossorigin=", "http://whatever .com", "preconnect", CrossOriginAttributeAnonymous, true},
138 {"<http://whatever.com>; rel=preconnect; crossorigin", "http://whatever. com", "preconnect", CrossOriginAttributeAnonymous, true},
139 {"<http://whatever.com>; rel=preconnect; crossorigin=anonymous", "http:/ /whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
140 {"<http://whatever.com>; rel=preconnect; crossorigin=use-credentials", " http://whatever.com", "preconnect", CrossOriginAttributeUseCredentials, true},
141 {"<http://whatever.com>; rel=preconnect; crossorigin=whatever", "http:// whatever.com", "preconnect", CrossOriginAttributeAnonymous, true},
142 };
143
144
145 // Test the cases with a single header
146 for (auto& testCase : cases) {
147 LinkHeaderSet headerSet(testCase.headerValue);
148 LinkHeader& header = headerSet[0];
149 ASSERT_STREQ(testCase.url, header.url().ascii().data());
150 ASSERT_STREQ(testCase.rel, header.rel().ascii().data());
151 ASSERT_EQ(testCase.crossorigin, header.crossOrigin());
152 ASSERT_EQ(testCase.valid, header.valid());
153 }
154 }
155 } // namespace blink 129 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/loader/LinkHeader.cpp ('k') | Source/core/loader/LinkLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698