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