Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (c) 2013, Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      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
     13  * distribution.
     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.
     17  *
     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.
     29  */
     30 
     31 #include "config.h"
     32 
     33 #include <gtest/gtest.h>
     34 #include "core/html/LinkRelAttribute.h"
     35 
     36 using namespace WebCore;
     37 
     38 namespace {
     39 
     40 static inline void testLinkRelAttribute(String value, bool isStyleSheet, IconType iconType, bool isAlternate, bool isDNSPrefetch, bool isLinkSubresource, bool isLinkPrerender, bool isImport = false)
     41 {
     42     LinkRelAttribute linkRelAttribute(value);
     43     ASSERT_EQ(isStyleSheet, linkRelAttribute.isStyleSheet()) << value.utf8().data();
     44     ASSERT_EQ(iconType, linkRelAttribute.iconType()) << value.utf8().data();
     45     ASSERT_EQ(isAlternate, linkRelAttribute.isAlternate()) << value.utf8().data();
     46     ASSERT_EQ(isDNSPrefetch, linkRelAttribute.isDNSPrefetch()) << value.utf8().data();
     47     ASSERT_EQ(isLinkSubresource, linkRelAttribute.isLinkSubresource()) << value.utf8().data();
     48     ASSERT_EQ(isLinkPrerender, linkRelAttribute.isLinkPrerender()) << value.utf8().data();
     49     ASSERT_EQ(isImport, linkRelAttribute.isImport()) << value.utf8().data();
     50 }
     51 
     52 TEST(CoreLinkRelAttribute, Constructor)
     53 {
     54     testLinkRelAttribute("stylesheet", true, InvalidIcon, false, false, false, false);
     55     testLinkRelAttribute("sTyLeShEeT", true, InvalidIcon, false, false, false, false);
     56 
     57     testLinkRelAttribute("icon", false, Favicon, false, false, false, false);
     58     testLinkRelAttribute("iCoN", false, Favicon, false, false, false, false);
     59     testLinkRelAttribute("shortcut icon", false, Favicon, false, false, false, false);
     60     testLinkRelAttribute("sHoRtCuT iCoN", false, Favicon, false, false, false, false);
     61 
     62 #if ENABLE(TOUCH_ICON_LOADING)
     63     testLinkRelAttribute("apple-touch-icon", false, TouchIcon, false, false, false, false);
     64     testLinkRelAttribute("aPpLe-tOuCh-IcOn", false, TouchIcon, false, false, false, false);
     65 
     66     testLinkRelAttribute("apple-touch-icon-precomposed", false, TouchPrecomposedIcon, false, false, false, false);
     67     testLinkRelAttribute("aPpLe-tOuCh-IcOn-pReCoMpOsEd", false, TouchPrecomposedIcon, false, false, false, false);
     68 #endif
     69 
     70     testLinkRelAttribute("dns-prefetch", false, InvalidIcon, false, true, false, false);
     71     testLinkRelAttribute("dNs-pReFeTcH", false, InvalidIcon, false, true, false, false);
     72 
     73     testLinkRelAttribute("alternate stylesheet", true, InvalidIcon, true, false, false, false);
     74     testLinkRelAttribute("stylesheet alternate", true, InvalidIcon, true, false, false, false);
     75     testLinkRelAttribute("aLtErNaTe sTyLeShEeT", true, InvalidIcon, true, false, false, false);
     76     testLinkRelAttribute("sTyLeShEeT aLtErNaTe", true, InvalidIcon, true, false, false, false);
     77 
     78     testLinkRelAttribute("stylesheet icon prerender aLtErNaTe", true, Favicon, true, false, false, true);
     79     testLinkRelAttribute("alternate subresource", false, InvalidIcon, true, false, true, false);
     80     testLinkRelAttribute("alternate icon stylesheet", true, Favicon, true, false, false, false);
     81 
     82     testLinkRelAttribute("import", false, InvalidIcon, false, false, false, false, true);
     83     // "import" is mutually exclusive and "stylesheet" wins when they conflict.
     84     testLinkRelAttribute("stylesheet import", true, InvalidIcon, false, false, false, false, false);
     85 }
     86 
     87 } // namespace
     88