2 * Copyright (c) 2013, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/html/LinkRelAttribute.h"
34 #include "platform/RuntimeEnabledFeatures.h"
35 #include "wtf/text/CString.h"
36 #include <gtest/gtest.h>
40 class LinkRelAttributeTest
: public testing::Test
{
44 m_touchIconLoadingEnabled
= RuntimeEnabledFeatures::touchIconLoadingEnabled();
47 void TearDown() override
49 RuntimeEnabledFeatures::setTouchIconLoadingEnabled(m_touchIconLoadingEnabled
);
53 bool m_touchIconLoadingEnabled
;
56 static inline void testLinkRelAttribute(String value
, bool isStyleSheet
, IconType iconType
, bool isAlternate
, bool isDNSPrefetch
, bool isLinkSubresource
, bool isLinkPrerender
, bool isImport
= false, bool isPreconnect
= false)
58 LinkRelAttribute
linkRelAttribute(value
);
59 ASSERT_EQ(isStyleSheet
, linkRelAttribute
.isStyleSheet()) << value
.utf8().data();
60 ASSERT_EQ(iconType
, linkRelAttribute
.iconType()) << value
.utf8().data();
61 ASSERT_EQ(isAlternate
, linkRelAttribute
.isAlternate()) << value
.utf8().data();
62 ASSERT_EQ(isDNSPrefetch
, linkRelAttribute
.isDNSPrefetch()) << value
.utf8().data();
63 ASSERT_EQ(isLinkSubresource
, linkRelAttribute
.isLinkSubresource()) << value
.utf8().data();
64 ASSERT_EQ(isLinkPrerender
, linkRelAttribute
.isLinkPrerender()) << value
.utf8().data();
65 ASSERT_EQ(isImport
, linkRelAttribute
.isImport()) << value
.utf8().data();
66 ASSERT_EQ(isPreconnect
, linkRelAttribute
.isPreconnect()) << value
.utf8().data();
69 TEST_F(LinkRelAttributeTest
, Constructor
)
71 RuntimeEnabledFeatures::setTouchIconLoadingEnabled(false);
73 testLinkRelAttribute("stylesheet", true, InvalidIcon
, false, false, false, false);
74 testLinkRelAttribute("sTyLeShEeT", true, InvalidIcon
, false, false, false, false);
76 testLinkRelAttribute("icon", false, Favicon
, false, false, false, false);
77 testLinkRelAttribute("iCoN", false, Favicon
, false, false, false, false);
78 testLinkRelAttribute("shortcut icon", false, Favicon
, false, false, false, false);
79 testLinkRelAttribute("sHoRtCuT iCoN", false, Favicon
, false, false, false, false);
81 testLinkRelAttribute("dns-prefetch", false, InvalidIcon
, false, true, false, false);
82 testLinkRelAttribute("dNs-pReFeTcH", false, InvalidIcon
, false, true, false, false);
84 testLinkRelAttribute("apple-touch-icon", false, InvalidIcon
, false, false, false, false);
85 testLinkRelAttribute("aPpLe-tOuCh-IcOn", false, InvalidIcon
, false, false, false, false);
86 testLinkRelAttribute("apple-touch-icon-precomposed", false, InvalidIcon
, false, false, false, false);
87 testLinkRelAttribute("aPpLe-tOuCh-IcOn-pReCoMpOsEd", false, InvalidIcon
, false, false, false, false);
89 testLinkRelAttribute("alternate stylesheet", true, InvalidIcon
, true, false, false, false);
90 testLinkRelAttribute("stylesheet alternate", true, InvalidIcon
, true, false, false, false);
91 testLinkRelAttribute("aLtErNaTe sTyLeShEeT", true, InvalidIcon
, true, false, false, false);
92 testLinkRelAttribute("sTyLeShEeT aLtErNaTe", true, InvalidIcon
, true, false, false, false);
94 testLinkRelAttribute("stylesheet icon prerender aLtErNaTe", true, Favicon
, true, false, false, true);
95 testLinkRelAttribute("alternate subresource", false, InvalidIcon
, true, false, true, false);
96 testLinkRelAttribute("alternate icon stylesheet", true, Favicon
, true, false, false, false);
98 testLinkRelAttribute("import", false, InvalidIcon
, false, false, false, false, true);
99 // "import" is mutually exclusive and "stylesheet" wins when they conflict.
100 testLinkRelAttribute("stylesheet import", true, InvalidIcon
, false, false, false, false, false);
102 testLinkRelAttribute("preconnect", false, InvalidIcon
, false, false, false, false, false, true);
103 testLinkRelAttribute("pReCoNnEcT", false, InvalidIcon
, false, false, false, false, false, true);
106 TEST_F(LinkRelAttributeTest
, ConstructorTouchIconLoadingEnabled
)
108 RuntimeEnabledFeatures::setTouchIconLoadingEnabled(true);
110 testLinkRelAttribute("stylesheet", true, InvalidIcon
, false, false, false, false);
111 testLinkRelAttribute("sTyLeShEeT", true, InvalidIcon
, false, false, false, false);
113 testLinkRelAttribute("icon", false, Favicon
, false, false, false, false);
114 testLinkRelAttribute("iCoN", false, Favicon
, false, false, false, false);
115 testLinkRelAttribute("shortcut icon", false, Favicon
, false, false, false, false);
116 testLinkRelAttribute("sHoRtCuT iCoN", false, Favicon
, false, false, false, false);
118 testLinkRelAttribute("dns-prefetch", false, InvalidIcon
, false, true, false, false);
119 testLinkRelAttribute("dNs-pReFeTcH", false, InvalidIcon
, false, true, false, false);
120 testLinkRelAttribute("alternate dNs-pReFeTcH", false, InvalidIcon
, true, true, false, false);
122 testLinkRelAttribute("apple-touch-icon", false, TouchIcon
, false, false, false, false);
123 testLinkRelAttribute("aPpLe-tOuCh-IcOn", false, TouchIcon
, false, false, false, false);
124 testLinkRelAttribute("apple-touch-icon-precomposed", false, TouchPrecomposedIcon
, false, false, false, false);
125 testLinkRelAttribute("aPpLe-tOuCh-IcOn-pReCoMpOsEd", false, TouchPrecomposedIcon
, false, false, false, false);
127 testLinkRelAttribute("alternate stylesheet", true, InvalidIcon
, true, false, false, false);
128 testLinkRelAttribute("stylesheet alternate", true, InvalidIcon
, true, false, false, false);
129 testLinkRelAttribute("aLtErNaTe sTyLeShEeT", true, InvalidIcon
, true, false, false, false);
130 testLinkRelAttribute("sTyLeShEeT aLtErNaTe", true, InvalidIcon
, true, false, false, false);
132 testLinkRelAttribute("stylesheet icon prerender aLtErNaTe", true, Favicon
, true, false, false, true);
133 testLinkRelAttribute("alternate subresource", false, InvalidIcon
, true, false, true, false);
134 testLinkRelAttribute("alternate icon stylesheet", true, Favicon
, true, false, false, false);
136 testLinkRelAttribute("import", false, InvalidIcon
, false, false, false, false, true);
137 testLinkRelAttribute("alternate import", false, InvalidIcon
, true, false, false, false, true);
138 testLinkRelAttribute("stylesheet import", true, InvalidIcon
, false, false, false, false, false);
140 testLinkRelAttribute("preconnect", false, InvalidIcon
, false, false, false, false, false, true);
141 testLinkRelAttribute("pReCoNnEcT", false, InvalidIcon
, false, false, false, false, false, true);