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"
33 #include "RuntimeEnabledFeatures.h"
35 #include "wtf/text/CString.h"
36 #include <gtest/gtest.h>
38 using namespace WebCore;
42 class LinkRelAttributeTest : public testing::Test {
46 m_touchIconLoadingEnabled = RuntimeEnabledFeatures::touchIconLoadingEnabled();
49 virtual void TearDown()
51 RuntimeEnabledFeatures::setTouchIconLoadingEnabled(m_touchIconLoadingEnabled);
55 bool m_touchIconLoadingEnabled;
58 static inline void testLinkRelAttribute(String value, bool isStyleSheet, IconType iconType, bool isAlternate, bool isDNSPrefetch, bool isLinkSubresource, bool isLinkPrerender, bool isImport = false)
60 LinkRelAttribute linkRelAttribute(value);
61 ASSERT_EQ(isStyleSheet, linkRelAttribute.isStyleSheet()) << value.utf8().data();
62 ASSERT_EQ(iconType, linkRelAttribute.iconType()) << value.utf8().data();
63 ASSERT_EQ(isAlternate, linkRelAttribute.isAlternate()) << value.utf8().data();
64 ASSERT_EQ(isDNSPrefetch, linkRelAttribute.isDNSPrefetch()) << value.utf8().data();
65 ASSERT_EQ(isLinkSubresource, linkRelAttribute.isLinkSubresource()) << value.utf8().data();
66 ASSERT_EQ(isLinkPrerender, linkRelAttribute.isLinkPrerender()) << value.utf8().data();
67 ASSERT_EQ(isImport, linkRelAttribute.isImport()) << value.utf8().data();
70 TEST_F(LinkRelAttributeTest, Constructor)
72 RuntimeEnabledFeatures::setTouchIconLoadingEnabled(false);
74 testLinkRelAttribute("stylesheet", true, InvalidIcon, false, false, false, false);
75 testLinkRelAttribute("sTyLeShEeT", true, InvalidIcon, false, false, false, false);
77 testLinkRelAttribute("icon", false, Favicon, false, false, false, false);
78 testLinkRelAttribute("iCoN", false, Favicon, false, false, false, false);
79 testLinkRelAttribute("shortcut icon", false, Favicon, false, false, false, false);
80 testLinkRelAttribute("sHoRtCuT iCoN", false, Favicon, false, false, false, false);
82 testLinkRelAttribute("dns-prefetch", false, InvalidIcon, false, true, false, false);
83 testLinkRelAttribute("dNs-pReFeTcH", false, InvalidIcon, false, true, false, false);
85 testLinkRelAttribute("apple-touch-icon", false, InvalidIcon, false, false, false, false);
86 testLinkRelAttribute("aPpLe-tOuCh-IcOn", false, InvalidIcon, false, false, false, false);
87 testLinkRelAttribute("apple-touch-icon-precomposed", false, InvalidIcon, false, false, false, false);
88 testLinkRelAttribute("aPpLe-tOuCh-IcOn-pReCoMpOsEd", false, InvalidIcon, false, false, false, false);
90 testLinkRelAttribute("alternate stylesheet", true, InvalidIcon, true, false, false, false);
91 testLinkRelAttribute("stylesheet alternate", true, InvalidIcon, true, false, false, false);
92 testLinkRelAttribute("aLtErNaTe sTyLeShEeT", true, InvalidIcon, true, false, false, false);
93 testLinkRelAttribute("sTyLeShEeT aLtErNaTe", true, InvalidIcon, true, false, false, false);
95 testLinkRelAttribute("stylesheet icon prerender aLtErNaTe", true, Favicon, true, false, false, true);
96 testLinkRelAttribute("alternate subresource", false, InvalidIcon, true, false, true, false);
97 testLinkRelAttribute("alternate icon stylesheet", true, Favicon, true, false, false, false);
99 testLinkRelAttribute("import", false, InvalidIcon, false, false, false, false, true);
100 // "import" is mutually exclusive and "stylesheet" wins when they conflict.
101 testLinkRelAttribute("stylesheet import", true, InvalidIcon, false, false, false, false, false);
104 TEST_F(LinkRelAttributeTest, ConstructorTouchIconLoadingEnabled)
106 RuntimeEnabledFeatures::setTouchIconLoadingEnabled(true);
108 testLinkRelAttribute("stylesheet", true, InvalidIcon, false, false, false, false);
109 testLinkRelAttribute("sTyLeShEeT", true, InvalidIcon, false, false, false, false);
111 testLinkRelAttribute("icon", false, Favicon, false, false, false, false);
112 testLinkRelAttribute("iCoN", false, Favicon, false, false, false, false);
113 testLinkRelAttribute("shortcut icon", false, Favicon, false, false, false, false);
114 testLinkRelAttribute("sHoRtCuT iCoN", false, Favicon, false, false, false, false);
116 testLinkRelAttribute("dns-prefetch", false, InvalidIcon, false, true, false, false);
117 testLinkRelAttribute("dNs-pReFeTcH", false, InvalidIcon, false, true, false, false);
118 testLinkRelAttribute("alternate dNs-pReFeTcH", false, InvalidIcon, true, true, false, false);
120 testLinkRelAttribute("apple-touch-icon", false, TouchIcon, false, false, false, false);
121 testLinkRelAttribute("aPpLe-tOuCh-IcOn", false, TouchIcon, false, false, false, false);
122 testLinkRelAttribute("apple-touch-icon-precomposed", false, TouchPrecomposedIcon, false, false, false, false);
123 testLinkRelAttribute("aPpLe-tOuCh-IcOn-pReCoMpOsEd", false, TouchPrecomposedIcon, false, false, false, false);
125 testLinkRelAttribute("alternate stylesheet", true, InvalidIcon, true, false, false, false);
126 testLinkRelAttribute("stylesheet alternate", true, InvalidIcon, true, false, false, false);
127 testLinkRelAttribute("aLtErNaTe sTyLeShEeT", true, InvalidIcon, true, false, false, false);
128 testLinkRelAttribute("sTyLeShEeT aLtErNaTe", true, InvalidIcon, true, false, false, false);
130 testLinkRelAttribute("stylesheet icon prerender aLtErNaTe", true, Favicon, true, false, false, true);
131 testLinkRelAttribute("alternate subresource", false, InvalidIcon, true, false, true, false);
132 testLinkRelAttribute("alternate icon stylesheet", true, Favicon, true, false, false, false);
134 testLinkRelAttribute("import", false, InvalidIcon, false, false, false, false, true);
135 testLinkRelAttribute("alternate import", false, InvalidIcon, true, false, false, false, true);
136 testLinkRelAttribute("stylesheet import", true, InvalidIcon, false, false, false, false, false);