38183e0f479b571e5f0da37be52f4c8b2569da05
[WebKit-https.git] / Tools / TestWebKitAPI / Tests / WebKit2 / WKPreferences.cpp
1 /*
2  * Copyright (C) 2010 Apple 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
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 #include "PlatformUtilities.h"
28 #include <WebKit/WKPreferencesRefPrivate.h>
29 #include <WebKit/WKRetainPtr.h>
30
31 namespace TestWebKitAPI {
32
33 TEST(WebKit2, WKPreferencesBasic)
34 {
35     WKPreferencesRef preference = WKPreferencesCreate();
36
37     EXPECT_EQ(WKPreferencesGetTypeID(), WKGetTypeID(preference));
38
39     WKRelease(preference);
40 }
41
42 TEST(WebKit2, WKPreferencesDefaults)
43 {
44 #if PLATFORM(WIN)
45     static const char* expectedStandardFontFamily = "Times New Roman";
46     static const char* expectedFixedFontFamily = "Courier New";
47     static const char* expectedSerifFontFamily = "Times New Roman";
48     static const char* expectedSansSerifFontFamily = "Arial";
49     static const char* expectedCursiveFontFamily = "Comic Sans MS";
50     static const char* expectedFantasyFontFamily = "Comic Sans MS";
51     static const char* expectedPictographFontFamily = "Times New Roman";
52 #elif PLATFORM(MAC)
53     static const char* expectedStandardFontFamily = "Times";
54     static const char* expectedFixedFontFamily = "Courier";
55     static const char* expectedSerifFontFamily = "Times";
56     static const char* expectedSansSerifFontFamily = "Helvetica";
57     static const char* expectedCursiveFontFamily = "Apple Chancery";
58     static const char* expectedFantasyFontFamily = "Papyrus";
59     static const char* expectedPictographFontFamily = "Apple Color Emoji";
60 #elif PLATFORM(IOS)
61     static const char* expectedStandardFontFamily = "Times";
62     static const char* expectedFixedFontFamily = "Courier";
63     static const char* expectedSerifFontFamily = "Times";
64     static const char* expectedSansSerifFontFamily = "Helvetica";
65     static const char* expectedCursiveFontFamily = "Snell Roundhand";
66     static const char* expectedFantasyFontFamily = "Papyrus";
67     static const char* expectedPictographFontFamily = "AppleColorEmoji";
68 #elif PLATFORM(GTK) || PLATFORM(EFL)
69     static const char* expectedStandardFontFamily = "Times";
70     static const char* expectedFixedFontFamily = "Courier New";
71     static const char* expectedSerifFontFamily = "Times";
72     static const char* expectedSansSerifFontFamily = "Helvetica";
73     static const char* expectedCursiveFontFamily = "Comic Sans MS";
74     static const char* expectedFantasyFontFamily = "Impact";
75     static const char* expectedPictographFontFamily = "Times";
76 #endif
77
78     WKPreferencesRef preference = WKPreferencesCreate();
79
80     EXPECT_TRUE(WKPreferencesGetJavaScriptEnabled(preference));
81     EXPECT_TRUE(WKPreferencesGetLoadsImagesAutomatically(preference));
82     EXPECT_FALSE(WKPreferencesGetOfflineWebApplicationCacheEnabled(preference));
83     EXPECT_TRUE(WKPreferencesGetLocalStorageEnabled(preference));
84     EXPECT_TRUE(WKPreferencesGetXSSAuditorEnabled(preference));
85     EXPECT_FALSE(WKPreferencesGetFrameFlatteningEnabled(preference));
86     EXPECT_TRUE(WKPreferencesGetPluginsEnabled(preference));
87     EXPECT_TRUE(WKPreferencesGetJavaEnabled(preference));
88     EXPECT_TRUE(WKPreferencesGetJavaScriptCanOpenWindowsAutomatically(preference));
89     EXPECT_TRUE(WKPreferencesGetHyperlinkAuditingEnabled(preference));
90     EXPECT_WK_STREQ(expectedStandardFontFamily, adoptWK(WKPreferencesCopyStandardFontFamily(preference)));
91     EXPECT_WK_STREQ(expectedFixedFontFamily, adoptWK(WKPreferencesCopyFixedFontFamily(preference)));
92     EXPECT_WK_STREQ(expectedSerifFontFamily, adoptWK(WKPreferencesCopySerifFontFamily(preference)));
93     EXPECT_WK_STREQ(expectedSansSerifFontFamily, adoptWK(WKPreferencesCopySansSerifFontFamily(preference)));
94     EXPECT_WK_STREQ(expectedCursiveFontFamily, adoptWK(WKPreferencesCopyCursiveFontFamily(preference)));
95     EXPECT_WK_STREQ(expectedFantasyFontFamily, adoptWK(WKPreferencesCopyFantasyFontFamily(preference)));
96     EXPECT_WK_STREQ(expectedPictographFontFamily, adoptWK(WKPreferencesCopyPictographFontFamily(preference)));
97     EXPECT_EQ(0u, WKPreferencesGetMinimumFontSize(preference));
98     EXPECT_FALSE(WKPreferencesGetPrivateBrowsingEnabled(preference));
99     EXPECT_FALSE(WKPreferencesGetDeveloperExtrasEnabled(preference));
100     EXPECT_TRUE(WKPreferencesGetTextAreasAreResizable(preference));
101
102 #if PLATFORM(WIN)
103     EXPECT_EQ(kWKFontSmoothingLevelWindows, WKPreferencesGetFontSmoothingLevel(preference));
104 #else
105     EXPECT_EQ(kWKFontSmoothingLevelMedium, WKPreferencesGetFontSmoothingLevel(preference));
106 #endif
107
108     EXPECT_TRUE(WKPreferencesGetAcceleratedCompositingEnabled(preference));
109     EXPECT_FALSE(WKPreferencesGetCompositingBordersVisible(preference));
110     EXPECT_FALSE(WKPreferencesGetCompositingRepaintCountersVisible(preference));
111     EXPECT_FALSE(WKPreferencesGetNeedsSiteSpecificQuirks(preference));
112     EXPECT_EQ(kWKAllowAllStorage, WKPreferencesGetStorageBlockingPolicy(preference));
113     EXPECT_FALSE(WKPreferencesGetTextAutosizingEnabled(preference));
114
115     WKRelease(preference);
116 }
117
118 TEST(WebKit2, WKPreferencesCopying)
119 {
120     WKRetainPtr<WKStringRef> identifier(AdoptWK, WKStringCreateWithUTF8CString("identifier"));
121
122     WKRetainPtr<WKPreferencesRef> preferences(AdoptWK, WKPreferencesCreateWithIdentifier(identifier.get()));
123     WKPreferencesSetDefaultFontSize(preferences.get(), 36);
124
125     WKRetainPtr<WKPreferencesRef> copy(AdoptWK, WKPreferencesCreateCopy(preferences.get()));
126
127     WKPreferencesSetDefaultFontSize(preferences.get(), 24);
128     EXPECT_EQ(24u, WKPreferencesGetDefaultFontSize(preferences.get()));
129     EXPECT_EQ(36u, WKPreferencesGetDefaultFontSize(copy.get()));
130 }
131
132 } // namespace TestWebKitAPI