WKPreferences.cpp 6.3 KB

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