Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "platform/network/LinkHeader.h" | 5 #include "platform/network/LinkHeader.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include <base/macros.h> | 8 #include <base/macros.h> |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 TEST(LinkHeaderTest, Empty) { | 13 TEST(LinkHeaderTest, Empty) { |
| 14 String nullString; | 14 String nullString; |
| 15 LinkHeaderSet nullHeaderSet(nullString); | 15 LinkHeaderSet nullHeaderSet(nullString); |
| 16 ASSERT_EQ(nullHeaderSet.size(), unsigned(0)); | 16 ASSERT_EQ(nullHeaderSet.size(), unsigned(0)); |
| 17 String emptyString(""); | 17 String emptyString(""); |
| 18 LinkHeaderSet emptyHeaderSet(emptyString); | 18 LinkHeaderSet emptyHeaderSet(emptyString); |
| 19 ASSERT_EQ(emptyHeaderSet.size(), unsigned(0)); | 19 ASSERT_EQ(emptyHeaderSet.size(), unsigned(0)); |
| 20 } | 20 } |
| 21 | 21 |
| 22 struct SingleTestCase { | 22 struct SingleTestCase { |
| 23 const char* headerValue; | 23 const char* headerValue; |
| 24 bool valid; | 24 bool valid; |
| 25 const char* url; | 25 const char* url; |
| 26 const char* rel; | 26 const char* rel; |
| 27 const char* as; | 27 const char* as; |
| 28 const char* media; | 28 const char* media; |
| 29 const char* referrerPolicy; | |
| 29 } singleTestCases[] = { | 30 } singleTestCases[] = { |
| 30 {"</images/cat.jpg>; rel=prefetch", true, "/images/cat.jpg", "prefetch", "", | 31 {"</images/cat.jpg>; rel=prefetch", true, "/images/cat.jpg", "prefetch", "", |
| 31 ""}, | 32 ""}, |
| 32 {"</images/cat.jpg>;rel=prefetch", true, "/images/cat.jpg", "prefetch", "", | 33 {"</images/cat.jpg>;rel=prefetch", true, "/images/cat.jpg", "prefetch", "", |
| 33 ""}, | 34 ""}, |
| 34 {"</images/cat.jpg> ;rel=prefetch", true, "/images/cat.jpg", "prefetch", | 35 {"</images/cat.jpg> ;rel=prefetch", true, "/images/cat.jpg", "prefetch", |
| 35 "", ""}, | 36 "", ""}, |
| 36 {"</images/cat.jpg> ; rel=prefetch", true, "/images/cat.jpg", | 37 {"</images/cat.jpg> ; rel=prefetch", true, "/images/cat.jpg", |
| 37 "prefetch", "", ""}, | 38 "prefetch", "", ""}, |
| 38 {"< /images/cat.jpg> ; rel=prefetch", true, "/images/cat.jpg", | 39 {"< /images/cat.jpg> ; rel=prefetch", true, "/images/cat.jpg", |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 {"<http://whatever.com>; rel=preconnect; valid$", true, | 144 {"<http://whatever.com>; rel=preconnect; valid$", true, |
| 144 "http://whatever.com", "preconnect", "", ""}, | 145 "http://whatever.com", "preconnect", "", ""}, |
| 145 {"<http://whatever.com>; rel=preconnect; invalid@", false}, | 146 {"<http://whatever.com>; rel=preconnect; invalid@", false}, |
| 146 {"<http://whatever.com>; rel=preconnect; invalid*", false}, | 147 {"<http://whatever.com>; rel=preconnect; invalid*", false}, |
| 147 {"</images/cat.jpg>; rel=prefetch;media='(max-width: 5000px)'", true, | 148 {"</images/cat.jpg>; rel=prefetch;media='(max-width: 5000px)'", true, |
| 148 "/images/cat.jpg", "prefetch", "", "'(max-width: 5000px)'"}, | 149 "/images/cat.jpg", "prefetch", "", "'(max-width: 5000px)'"}, |
| 149 {"</images/cat.jpg>; rel=prefetch;media=\"(max-width: 5000px)\"", true, | 150 {"</images/cat.jpg>; rel=prefetch;media=\"(max-width: 5000px)\"", true, |
| 150 "/images/cat.jpg", "prefetch", "", "(max-width: 5000px)"}, | 151 "/images/cat.jpg", "prefetch", "", "(max-width: 5000px)"}, |
| 151 {"</images/cat.jpg>; rel=prefetch;media=(max-width:5000px)", true, | 152 {"</images/cat.jpg>; rel=prefetch;media=(max-width:5000px)", true, |
| 152 "/images/cat.jpg", "prefetch", "", "(max-width:5000px)"}, | 153 "/images/cat.jpg", "prefetch", "", "(max-width:5000px)"}, |
| 154 {"</images/cat.jpg>; rel=preload;referrerpolicy=somevalue", true, | |
|
Mike West
2016/10/23 05:25:46
I guess this is a reasonable addition, but it need
Yoav Weiss
2016/10/23 13:27:09
I considered it as a "link-extension" defined in h
| |
| 155 "/images/cat.jpg", "preload", "", "", "somevalue"}, | |
|
Mike West
2016/10/23 05:25:46
I don't understand how this test works. You've add
Yoav Weiss
2016/10/23 13:27:09
my bad. Forgot to add an actual check for the valu
| |
| 153 }; | 156 }; |
| 154 | 157 |
| 155 void PrintTo(const SingleTestCase& test, std::ostream* os) { | 158 void PrintTo(const SingleTestCase& test, std::ostream* os) { |
| 156 *os << ::testing::PrintToString(test.headerValue); | 159 *os << ::testing::PrintToString(test.headerValue); |
| 157 } | 160 } |
| 158 | 161 |
| 159 class SingleLinkHeaderTest : public ::testing::TestWithParam<SingleTestCase> {}; | 162 class SingleLinkHeaderTest : public ::testing::TestWithParam<SingleTestCase> {}; |
| 160 | 163 |
| 161 // Test the cases with a single header | 164 // Test the cases with a single header |
| 162 TEST_P(SingleLinkHeaderTest, Single) { | 165 TEST_P(SingleLinkHeaderTest, Single) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 else | 281 else |
| 279 EXPECT_STREQ(testCase.crossorigin, header.crossOrigin().ascii().data()); | 282 EXPECT_STREQ(testCase.crossorigin, header.crossOrigin().ascii().data()); |
| 280 } | 283 } |
| 281 | 284 |
| 282 INSTANTIATE_TEST_CASE_P(LinkHeaderTest, | 285 INSTANTIATE_TEST_CASE_P(LinkHeaderTest, |
| 283 CrossOriginLinkHeaderTest, | 286 CrossOriginLinkHeaderTest, |
| 284 testing::ValuesIn(crossOriginTestCases)); | 287 testing::ValuesIn(crossOriginTestCases)); |
| 285 | 288 |
| 286 } // namespace | 289 } // namespace |
| 287 } // namespace blink | 290 } // namespace blink |
| OLD | NEW |