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

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

Issue 1135203002: Add <link rel=preconnect> crossorigin attribute (take 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Todo 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 (size_t i = 0; i < arraysize(cases); ++i) { 91 for (auto& testCase : cases) {
92 TestCase& testCase = cases[i];
93 LinkHeaderSet headerSet(testCase.headerValue); 92 LinkHeaderSet headerSet(testCase.headerValue);
94 LinkHeader& header = headerSet[0]; 93 LinkHeader& header = headerSet[0];
95 ASSERT_STREQ(testCase.url, header.url().ascii().data()); 94 ASSERT_STREQ(testCase.url, header.url().ascii().data());
96 ASSERT_STREQ(testCase.rel, header.rel().ascii().data()); 95 ASSERT_STREQ(testCase.rel, header.rel().ascii().data());
97 ASSERT_EQ(testCase.valid, header.valid()); 96 ASSERT_EQ(testCase.valid, header.valid());
98 } 97 }
99 } 98 }
100 99
101 TEST(LinkHeaderTest, Double) 100 TEST(LinkHeaderTest, Double)
102 { 101 {
103 struct DoubleTestCase { 102 struct DoubleTestCase {
104 const char* headerValue; 103 const char* headerValue;
105 const char* url; 104 const char* url;
106 const char* rel; 105 const char* rel;
107 bool valid; 106 bool valid;
108 const char* url2; 107 const char* url2;
109 const char* rel2; 108 const char* rel2;
110 bool valid2; 109 bool valid2;
111 } doubleCases[] = { 110 } cases[] = {
112 {"<ybg.css>; rel=stylesheet, <simple.css>; rel=stylesheet", "ybg.css", " stylesheet", true, "simple.css", "stylesheet", true}, 111 {"<ybg.css>; rel=stylesheet, <simple.css>; rel=stylesheet", "ybg.css", " stylesheet", true, "simple.css", "stylesheet", true},
113 }; 112 };
114 113
115 for (size_t i = 0; i < arraysize(doubleCases); ++i) { 114 for (auto& testCase : cases) {
116 DoubleTestCase& testCase = doubleCases[i];
117 LinkHeaderSet headerSet(testCase.headerValue); 115 LinkHeaderSet headerSet(testCase.headerValue);
118 LinkHeader& header1 = headerSet[0]; 116 LinkHeader& header1 = headerSet[0];
119 LinkHeader& header2 = headerSet[1]; 117 LinkHeader& header2 = headerSet[1];
120 ASSERT_STREQ(testCase.url, header1.url().ascii().data()); 118 ASSERT_STREQ(testCase.url, header1.url().ascii().data());
121 ASSERT_STREQ(testCase.rel, header1.rel().ascii().data()); 119 ASSERT_STREQ(testCase.rel, header1.rel().ascii().data());
122 ASSERT_EQ(testCase.valid, header1.valid()); 120 ASSERT_EQ(testCase.valid, header1.valid());
123 ASSERT_STREQ(testCase.url2, header2.url().ascii().data()); 121 ASSERT_STREQ(testCase.url2, header2.url().ascii().data());
124 ASSERT_STREQ(testCase.rel2, header2.rel().ascii().data()); 122 ASSERT_STREQ(testCase.rel2, header2.rel().ascii().data());
125 ASSERT_EQ(testCase.valid2, header2.valid()); 123 ASSERT_EQ(testCase.valid2, header2.valid());
126 } 124 }
127 } 125 }
128 126
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 }
129 } // namespace blink 155 } // 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