OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/loader/LinkHeader.h" |
| 7 |
| 8 #include <base/macros.h> |
| 9 #include <gtest/gtest.h> |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 TEST(LinkHeaderTest, Basic) |
| 14 { |
| 15 struct TestCase { |
| 16 const char* headerValue; |
| 17 const char* url; |
| 18 const char* rel; |
| 19 bool valid; |
| 20 } cases[] = { |
| 21 {0, "", "", false}, |
| 22 {"", "", "", false}, |
| 23 {"</images/cat.jpg>; rel=prefetch", "/images/cat.jpg", "prefetch", true}
, |
| 24 {"</images/cat.jpg>;rel=prefetch", "/images/cat.jpg", "prefetch", true}, |
| 25 {"</images/cat.jpg> ;rel=prefetch", "/images/cat.jpg", "prefetch", tru
e}, |
| 26 {"</images/cat.jpg> ; rel=prefetch", "/images/cat.jpg", "prefetch",
true}, |
| 27 {"< /images/cat.jpg> ; rel=prefetch", "/images/cat.jpg", "prefetch",
true}, |
| 28 {"</images/cat.jpg > ; rel=prefetch", "/images/cat.jpg", "prefetch",
true}, |
| 29 {"</images/cat.jpg wutwut> ; rel=prefetch", "/images/cat.jpg", "pref
etch", true}, |
| 30 {"</images/cat.jpg wutwut \t > ; rel=prefetch", "/images/cat.jpg",
"prefetch", true}, |
| 31 {"</images/cat.jpg>; rel=prefetch ", "/images/cat.jpg", "prefetch", tr
ue}, |
| 32 {" </images/cat.jpg>; rel=prefetch ", "/images/cat.jpg", "prefetch",
true}, |
| 33 {"\t </images/cat.jpg>; rel=prefetch ", "/images/cat.jpg", "prefetch"
, true}, |
| 34 {"</images/cat.jpg>\t\t ; \trel=prefetch \t ", "/images/cat.jpg", "pref
etch", true}, |
| 35 {"\f</images/cat.jpg>\t\t ; \trel=prefetch \t ", "", "", false}, |
| 36 {"</images/cat.jpg>; rel= prefetch", "/images/cat.jpg", "prefetch", true
}, |
| 37 {"</images/cat.jpg>; rel =prefetch", "/images/cat.jpg", "prefetch", true
}, |
| 38 {"</images/cat.jpg>; rel pel=prefetch", "/images/cat.jpg", "", false}, |
| 39 {"< /images/cat.jpg>", "/images/cat.jpg", "", true}, |
| 40 {"</images/cat.jpg>; rel =", "/images/cat.jpg", "", false}, |
| 41 {"</images/cat.jpg>; wut=sup; rel =prefetch", "/images/cat.jpg", "prefet
ch", true}, |
| 42 {"</images/cat.jpg>; wut=sup ; rel =prefetch", "/images/cat.jpg", "prefe
tch", true}, |
| 43 {"</images/cat.jpg>; wut=sup ; rel =prefetch \t ;", "/images/cat.jpg",
"prefetch", true}, |
| 44 {"</images/cat.jpg> wut=sup ; rel =prefetch \t ;", "/images/cat.jpg",
"", false}, |
| 45 {"< /images/cat.jpg", "", "", false}, |
| 46 {"< http://wut.com/ sdfsdf ?sd>; rel=dns-prefetch", "http://wut.com/"
, "dns-prefetch", true}, |
| 47 {"< http://wut.com/%20%20%3dsdfsdf?sd>; rel=dns-prefetch", "http://wut
.com/%20%20%3dsdfsdf?sd", "dns-prefetch", true}, |
| 48 {"< http://wut.com/dfsdf?sdf=ghj&wer=rty>; rel=prefetch", "http://wut.
com/dfsdf?sdf=ghj&wer=rty", "prefetch", true}, |
| 49 {"< http://wut.com/dfsdf?sdf=ghj&wer=rty>;;;;; rel=prefetch", "http://
wut.com/dfsdf?sdf=ghj&wer=rty", "", false}, |
| 50 }; |
| 51 |
| 52 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 53 const char* headerValue = cases[i].headerValue; |
| 54 const char* url = cases[i].url; |
| 55 const char* rel = cases[i].rel; |
| 56 bool valid = cases[i].valid; |
| 57 |
| 58 LinkHeader header(headerValue); |
| 59 ASSERT_EQ(valid, header.valid()); |
| 60 ASSERT_STREQ(url, header.url().ascii().data()); |
| 61 ASSERT_STREQ(rel, header.rel().ascii().data()); |
| 62 } |
| 63 } |
| 64 |
| 65 } // namespace blink |
OLD | NEW |