4c8032b936cfe3a591f202ef0e0ea1df0ef7d7b7
[WebKit-https.git] / Tools / TestWebKitAPI / Tests / WebCore / UserAgentQuirks.cpp
1 /*
2  * Copyright (C) 2014 Igalia S.L.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27
28 #include <WebCore/URL.h>
29 #include <WebCore/UserAgent.h>
30
31 using namespace WebCore;
32
33 namespace TestWebKitAPI {
34
35 static void assertUserAgentForURLHasChromeBrowserQuirk(const char* url)
36 {
37     String uaString = standardUserAgentForURL(URL({ }, url));
38
39     EXPECT_TRUE(uaString.contains("Chrome"));
40     EXPECT_TRUE(uaString.contains("Safari"));
41     EXPECT_FALSE(uaString.contains("Chromium"));
42     EXPECT_FALSE(uaString.contains("Firefox"));
43 }
44
45 static void assertUserAgentForURLHasLinuxPlatformQuirk(const char* url)
46 {
47     String uaString = standardUserAgentForURL(URL({ }, url));
48
49     EXPECT_TRUE(uaString.contains("Linux"));
50     EXPECT_FALSE(uaString.contains("Macintosh"));
51     EXPECT_FALSE(uaString.contains("Mac OS X"));
52     EXPECT_FALSE(uaString.contains("Windows"));
53     EXPECT_FALSE(uaString.contains("Chrome"));
54     EXPECT_FALSE(uaString.contains("FreeBSD"));
55 }
56
57 static void assertUserAgentForURLHasMacPlatformQuirk(const char* url)
58 {
59     String uaString = standardUserAgentForURL(URL({ }, url));
60
61     EXPECT_TRUE(uaString.contains("Macintosh"));
62     EXPECT_TRUE(uaString.contains("Mac OS X"));
63     EXPECT_FALSE(uaString.contains("Linux"));
64     EXPECT_FALSE(uaString.contains("Windows"));
65     EXPECT_FALSE(uaString.contains("Chrome"));
66     EXPECT_FALSE(uaString.contains("FreeBSD"));
67 }
68
69 TEST(UserAgentTest, Quirks)
70 {
71     // A site with not quirks should return a null String.
72     String uaString = standardUserAgentForURL(URL({ }, "http://www.webkit.org/"));
73     EXPECT_TRUE(uaString.isNull());
74
75 #if !OS(LINUX) || !CPU(X86_64)
76     // Google quirk should not affect sites with similar domains.
77     uaString = standardUserAgentForURL(URL({ }, "http://www.googleblog.com/"));
78     EXPECT_FALSE(uaString.contains("Linux x86_64"));
79 #endif
80
81     assertUserAgentForURLHasChromeBrowserQuirk("http://typekit.com/");
82     assertUserAgentForURLHasChromeBrowserQuirk("http://typekit.net/");
83     assertUserAgentForURLHasChromeBrowserQuirk("http://www.washingtonpost.com/");
84
85     assertUserAgentForURLHasLinuxPlatformQuirk("http://www.google.com/");
86     assertUserAgentForURLHasLinuxPlatformQuirk("http://www.google.es/");
87     assertUserAgentForURLHasLinuxPlatformQuirk("http://calendar.google.com/");
88     assertUserAgentForURLHasLinuxPlatformQuirk("http://plus.google.com/");
89
90     assertUserAgentForURLHasMacPlatformQuirk("http://www.yahoo.com/");
91     assertUserAgentForURLHasMacPlatformQuirk("http://finance.yahoo.com/");
92     assertUserAgentForURLHasMacPlatformQuirk("http://intl.taobao.com/");
93     assertUserAgentForURLHasMacPlatformQuirk("http://www.whatsapp.com/");
94     assertUserAgentForURLHasMacPlatformQuirk("http://web.whatsapp.com/");
95     assertUserAgentForURLHasMacPlatformQuirk("http://www.chase.com/");
96     assertUserAgentForURLHasMacPlatformQuirk("http://docs.google.com/");
97     assertUserAgentForURLHasMacPlatformQuirk("http://paypal.com/");
98 }
99
100 } // namespace TestWebKitAPI