| 1 | /* |
| 2 | * Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without modification, |
| 5 | * are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, |
| 8 | * this list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation and/or |
| 12 | * other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of Motorola Mobility, Inc. nor the names of its contributors may |
| 15 | * be used to endorse or promote products derived from this software without |
| 16 | * 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 LIMITED TO, |
| 20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 26 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include "config.h" |
| 32 | |
| 33 | #include "TestMain.h" |
| 34 | #include "WebKitTestServer.h" |
| 35 | #include "WebViewTest.h" |
| 36 | #include <wtf/glib/GRefPtr.h> |
| 37 | |
| 38 | static WebKitTestServer* gServer; |
| 39 | |
| 40 | static void testWebKitSettings(Test*, gconstpointer) |
| 41 | { |
| 42 | WebKitSettings* settings = webkit_settings_new(); |
| 43 | |
| 44 | // JavaScript is enabled by default. |
| 45 | g_assert_true(webkit_settings_get_enable_javascript(settings)); |
| 46 | webkit_settings_set_enable_javascript(settings, FALSE); |
| 47 | g_assert_false(webkit_settings_get_enable_javascript(settings)); |
| 48 | |
| 49 | // By default auto-load-image is true. |
| 50 | g_assert_true(webkit_settings_get_auto_load_images(settings)); |
| 51 | webkit_settings_set_auto_load_images(settings, FALSE); |
| 52 | g_assert_false(webkit_settings_get_auto_load_images(settings)); |
| 53 | |
| 54 | // load-icons-ignoring-image-load-setting is false by default. |
| 55 | g_assert_false(webkit_settings_get_load_icons_ignoring_image_load_setting(settings)); |
| 56 | webkit_settings_set_load_icons_ignoring_image_load_setting(settings, TRUE); |
| 57 | g_assert_true(webkit_settings_get_load_icons_ignoring_image_load_setting(settings)); |
| 58 | |
| 59 | // Offline application cache is true by default. |
| 60 | g_assert_true(webkit_settings_get_enable_offline_web_application_cache(settings)); |
| 61 | webkit_settings_set_enable_offline_web_application_cache(settings, FALSE); |
| 62 | g_assert_false(webkit_settings_get_enable_offline_web_application_cache(settings)); |
| 63 | |
| 64 | // Local storage is enable by default. |
| 65 | g_assert_true(webkit_settings_get_enable_html5_local_storage(settings)); |
| 66 | webkit_settings_set_enable_html5_local_storage(settings, FALSE); |
| 67 | g_assert_false(webkit_settings_get_enable_html5_local_storage(settings)); |
| 68 | |
| 69 | // HTML5 database is enabled by default. |
| 70 | g_assert_true(webkit_settings_get_enable_html5_database(settings)); |
| 71 | webkit_settings_set_enable_html5_database(settings, FALSE); |
| 72 | g_assert_false(webkit_settings_get_enable_html5_database(settings)); |
| 73 | |
| 74 | // XSS Auditor is enabled by default. |
| 75 | g_assert_true(webkit_settings_get_enable_xss_auditor(settings)); |
| 76 | webkit_settings_set_enable_xss_auditor(settings, FALSE); |
| 77 | g_assert_false(webkit_settings_get_enable_xss_auditor(settings)); |
| 78 | |
| 79 | // Frame flattening is disabled by default. |
| 80 | g_assert_false(webkit_settings_get_enable_frame_flattening(settings)); |
| 81 | webkit_settings_set_enable_frame_flattening(settings, TRUE); |
| 82 | g_assert_true(webkit_settings_get_enable_frame_flattening(settings)); |
| 83 | |
| 84 | // Plugins are enabled by default. |
| 85 | g_assert_true(webkit_settings_get_enable_plugins(settings)); |
| 86 | webkit_settings_set_enable_plugins(settings, FALSE); |
| 87 | g_assert_false(webkit_settings_get_enable_plugins(settings)); |
| 88 | |
| 89 | // Java is enabled by default. |
| 90 | g_assert_true(webkit_settings_get_enable_java(settings)); |
| 91 | webkit_settings_set_enable_java(settings, FALSE); |
| 92 | g_assert_false(webkit_settings_get_enable_java(settings)); |
| 93 | |
| 94 | // By default, JavaScript can open windows automatically is disabled. |
| 95 | g_assert_false(webkit_settings_get_javascript_can_open_windows_automatically(settings)); |
| 96 | webkit_settings_set_javascript_can_open_windows_automatically(settings, TRUE); |
| 97 | g_assert_true(webkit_settings_get_javascript_can_open_windows_automatically(settings)); |
| 98 | |
| 99 | // By default hyper link auditing is disabled. |
| 100 | g_assert_false(webkit_settings_get_enable_hyperlink_auditing(settings)); |
| 101 | webkit_settings_set_enable_hyperlink_auditing(settings, TRUE); |
| 102 | g_assert_true(webkit_settings_get_enable_hyperlink_auditing(settings)); |
| 103 | |
| 104 | // Default font family is "sans-serif". |
| 105 | g_assert_cmpstr(webkit_settings_get_default_font_family(settings), ==, "sans-serif" ); |
| 106 | webkit_settings_set_default_font_family(settings, "monospace" ); |
| 107 | g_assert_cmpstr(webkit_settings_get_default_font_family(settings), ==, "monospace" ); |
| 108 | |
| 109 | // Default monospace font family font family is "monospace". |
| 110 | g_assert_cmpstr(webkit_settings_get_monospace_font_family(settings), ==, "monospace" ); |
| 111 | webkit_settings_set_monospace_font_family(settings, "sans-serif" ); |
| 112 | g_assert_cmpstr(webkit_settings_get_monospace_font_family(settings), ==, "sans-serif" ); |
| 113 | |
| 114 | // Default serif font family is "serif". |
| 115 | g_assert_cmpstr(webkit_settings_get_serif_font_family(settings), ==, "serif" ); |
| 116 | webkit_settings_set_serif_font_family(settings, "sans-serif" ); |
| 117 | g_assert_cmpstr(webkit_settings_get_serif_font_family(settings), ==, "sans-serif" ); |
| 118 | |
| 119 | // Default sans serif font family is "sans-serif". |
| 120 | g_assert_cmpstr(webkit_settings_get_sans_serif_font_family(settings), ==, "sans-serif" ); |
| 121 | webkit_settings_set_sans_serif_font_family(settings, "serif" ); |
| 122 | g_assert_cmpstr(webkit_settings_get_sans_serif_font_family(settings), ==, "serif" ); |
| 123 | |
| 124 | // Default cursive font family "serif". |
| 125 | g_assert_cmpstr(webkit_settings_get_cursive_font_family(settings), ==, "serif" ); |
| 126 | webkit_settings_set_cursive_font_family(settings, "sans-serif" ); |
| 127 | g_assert_cmpstr(webkit_settings_get_cursive_font_family(settings), ==, "sans-serif" ); |
| 128 | |
| 129 | // Default fantasy font family is "serif". |
| 130 | g_assert_cmpstr(webkit_settings_get_fantasy_font_family(settings), ==, "serif" ); |
| 131 | webkit_settings_set_fantasy_font_family(settings, "sans-serif" ); |
| 132 | g_assert_cmpstr(webkit_settings_get_fantasy_font_family(settings), ==, "sans-serif" ); |
| 133 | |
| 134 | // Default pictograph font family is "serif". |
| 135 | g_assert_cmpstr(webkit_settings_get_pictograph_font_family(settings), ==, "serif" ); |
| 136 | webkit_settings_set_pictograph_font_family(settings, "sans-serif" ); |
| 137 | g_assert_cmpstr(webkit_settings_get_pictograph_font_family(settings), ==, "sans-serif" ); |
| 138 | |
| 139 | // Default font size is 16. |
| 140 | g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 16); |
| 141 | webkit_settings_set_default_font_size(settings, 14); |
| 142 | g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 14); |
| 143 | |
| 144 | // Default monospace font size is 13. |
| 145 | g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 13); |
| 146 | webkit_settings_set_default_monospace_font_size(settings, 10); |
| 147 | g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 10); |
| 148 | |
| 149 | // Default minimum font size is 0. |
| 150 | g_assert_cmpuint(webkit_settings_get_minimum_font_size(settings), ==, 0); |
| 151 | webkit_settings_set_minimum_font_size(settings, 7); |
| 152 | g_assert_cmpuint(webkit_settings_get_minimum_font_size(settings), ==, 7); |
| 153 | |
| 154 | // Test conversion between pixels and points. Use a standard DPI of 96. |
| 155 | // Set DPI explicitly to avoid the tests failing for users that use a |
| 156 | // different default DPI. This doesn't affect the system's DPI outside |
| 157 | // of the tests scope, so we don't need to change it back to the original |
| 158 | // value. We can control DPI only on GTK. On WPE, WebCore defaults it to 96. |
| 159 | #if PLATFORM(GTK) |
| 160 | GtkSettings* gtkSettings = gtk_settings_get_default(); |
| 161 | if (gtkSettings) |
| 162 | g_object_set(gtkSettings, "gtk-xft-dpi" , 96 * 1024, nullptr); |
| 163 | |
| 164 | // At 96 DPI, 9 points is 12 pixels and 24 points is 32 pixels. |
| 165 | g_assert_cmpuint(webkit_settings_font_size_to_pixels(9), ==, 12); |
| 166 | g_assert_cmpuint(webkit_settings_font_size_to_pixels(24), ==, 32); |
| 167 | |
| 168 | // At 96 DPI, 8 pixels is 6 points and 24 pixels is 18 points. |
| 169 | g_assert_cmpuint(webkit_settings_font_size_to_points(8), ==, 6); |
| 170 | g_assert_cmpuint(webkit_settings_font_size_to_points(24), ==, 18); |
| 171 | |
| 172 | // Test font size on DPI change. The font size value in pixels should scale |
| 173 | // accordingly, while the font size value in points should remain the same. |
| 174 | if (gtkSettings) { |
| 175 | // At 96 DPI, 20 pixels is 15 points. |
| 176 | webkit_settings_set_default_font_size(settings, 20); |
| 177 | g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_font_size(settings)), ==, 15); |
| 178 | // At 96 DPI, 16 pixels is 12 points. |
| 179 | webkit_settings_set_default_monospace_font_size(settings, 16); |
| 180 | g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_monospace_font_size(settings)), ==, 12); |
| 181 | |
| 182 | // Set DPI to 120. The scaling factor is 120 / 96 == 1.25. |
| 183 | g_object_set(gtkSettings, "gtk-xft-dpi" , 120 * 1024, nullptr); |
| 184 | g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 25); |
| 185 | g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_font_size(settings)), ==, 15); |
| 186 | g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 20); |
| 187 | g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_monospace_font_size(settings)), ==, 12); |
| 188 | |
| 189 | // Set DPI back to 96. The scaling factor is 96 / 120 == 0.8. |
| 190 | g_object_set(gtkSettings, "gtk-xft-dpi" , 96 * 1024, nullptr); |
| 191 | g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 20); |
| 192 | g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_font_size(settings)), ==, 15); |
| 193 | g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 16); |
| 194 | g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_monospace_font_size(settings)), ==, 12); |
| 195 | } |
| 196 | #endif |
| 197 | |
| 198 | // Default charset is "iso-8859-1". |
| 199 | g_assert_cmpstr(webkit_settings_get_default_charset(settings), ==, "iso-8859-1" ); |
| 200 | webkit_settings_set_default_charset(settings, "utf8" ); |
| 201 | g_assert_cmpstr(webkit_settings_get_default_charset(settings), ==, "utf8" ); |
| 202 | |
| 203 | #if PLATFORM(GTK) |
| 204 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 205 | g_assert_false(webkit_settings_get_enable_private_browsing(settings)); |
| 206 | webkit_settings_set_enable_private_browsing(settings, TRUE); |
| 207 | g_assert_true(webkit_settings_get_enable_private_browsing(settings)); |
| 208 | G_GNUC_END_IGNORE_DEPRECATIONS; |
| 209 | #endif |
| 210 | |
| 211 | g_assert_false(webkit_settings_get_enable_developer_extras(settings)); |
| 212 | webkit_settings_set_enable_developer_extras(settings, TRUE); |
| 213 | g_assert_true(webkit_settings_get_enable_developer_extras(settings)); |
| 214 | |
| 215 | g_assert_true(webkit_settings_get_enable_resizable_text_areas(settings)); |
| 216 | webkit_settings_set_enable_resizable_text_areas(settings, FALSE); |
| 217 | g_assert_false(webkit_settings_get_enable_resizable_text_areas(settings)); |
| 218 | |
| 219 | g_assert_true(webkit_settings_get_enable_tabs_to_links(settings)); |
| 220 | webkit_settings_set_enable_tabs_to_links(settings, FALSE); |
| 221 | g_assert_false(webkit_settings_get_enable_tabs_to_links(settings)); |
| 222 | |
| 223 | g_assert_false(webkit_settings_get_enable_dns_prefetching(settings)); |
| 224 | webkit_settings_set_enable_dns_prefetching(settings, TRUE); |
| 225 | g_assert_true(webkit_settings_get_enable_dns_prefetching(settings)); |
| 226 | |
| 227 | // Caret browsing is disabled by default. |
| 228 | g_assert_false(webkit_settings_get_enable_caret_browsing(settings)); |
| 229 | webkit_settings_set_enable_caret_browsing(settings, TRUE); |
| 230 | g_assert_true(webkit_settings_get_enable_caret_browsing(settings)); |
| 231 | |
| 232 | // Fullscreen JavaScript API is enabled by default. |
| 233 | g_assert_true(webkit_settings_get_enable_fullscreen(settings)); |
| 234 | webkit_settings_set_enable_fullscreen(settings, FALSE); |
| 235 | g_assert_false(webkit_settings_get_enable_fullscreen(settings)); |
| 236 | |
| 237 | // Print backgrounds is enabled by default |
| 238 | g_assert_true(webkit_settings_get_print_backgrounds(settings)); |
| 239 | webkit_settings_set_print_backgrounds(settings, FALSE); |
| 240 | g_assert_false(webkit_settings_get_print_backgrounds(settings)); |
| 241 | |
| 242 | // WebAudio is disabled by default. |
| 243 | g_assert_false(webkit_settings_get_enable_webaudio(settings)); |
| 244 | webkit_settings_set_enable_webaudio(settings, TRUE); |
| 245 | g_assert_true(webkit_settings_get_enable_webaudio(settings)); |
| 246 | |
| 247 | // WebGL is disabled by default. |
| 248 | g_assert_false(webkit_settings_get_enable_webgl(settings)); |
| 249 | webkit_settings_set_enable_webgl(settings, TRUE); |
| 250 | g_assert_true(webkit_settings_get_enable_webgl(settings)); |
| 251 | |
| 252 | // Allow Modal Dialogs is disabled by default. |
| 253 | g_assert_false(webkit_settings_get_allow_modal_dialogs(settings)); |
| 254 | webkit_settings_set_allow_modal_dialogs(settings, TRUE); |
| 255 | g_assert_true(webkit_settings_get_allow_modal_dialogs(settings)); |
| 256 | |
| 257 | // Zoom text only is disabled by default. |
| 258 | g_assert_false(webkit_settings_get_zoom_text_only(settings)); |
| 259 | webkit_settings_set_zoom_text_only(settings, TRUE); |
| 260 | g_assert_true(webkit_settings_get_zoom_text_only(settings)); |
| 261 | |
| 262 | // By default, JavaScript cannot access the clipboard. |
| 263 | g_assert_false(webkit_settings_get_javascript_can_access_clipboard(settings)); |
| 264 | webkit_settings_set_javascript_can_access_clipboard(settings, TRUE); |
| 265 | g_assert_true(webkit_settings_get_javascript_can_access_clipboard(settings)); |
| 266 | |
| 267 | // By default, media playback doesn't require user gestures. |
| 268 | g_assert_false(webkit_settings_get_media_playback_requires_user_gesture(settings)); |
| 269 | webkit_settings_set_media_playback_requires_user_gesture(settings, TRUE); |
| 270 | g_assert_true(webkit_settings_get_media_playback_requires_user_gesture(settings)); |
| 271 | |
| 272 | // By default, inline media playback is allowed |
| 273 | g_assert_true(webkit_settings_get_media_playback_allows_inline(settings)); |
| 274 | webkit_settings_set_media_playback_allows_inline(settings, FALSE); |
| 275 | g_assert_false(webkit_settings_get_media_playback_allows_inline(settings)); |
| 276 | |
| 277 | // By default, debug indicators are disabled. |
| 278 | g_assert_false(webkit_settings_get_draw_compositing_indicators(settings)); |
| 279 | webkit_settings_set_draw_compositing_indicators(settings, TRUE); |
| 280 | g_assert_true(webkit_settings_get_draw_compositing_indicators(settings)); |
| 281 | |
| 282 | // By default, site specific quirks are enabled. |
| 283 | g_assert_true(webkit_settings_get_enable_site_specific_quirks(settings)); |
| 284 | webkit_settings_set_enable_site_specific_quirks(settings, FALSE); |
| 285 | g_assert_false(webkit_settings_get_enable_site_specific_quirks(settings)); |
| 286 | |
| 287 | // By default, page cache is enabled. |
| 288 | g_assert_true(webkit_settings_get_enable_page_cache(settings)); |
| 289 | webkit_settings_set_enable_page_cache(settings, FALSE); |
| 290 | g_assert_false(webkit_settings_get_enable_page_cache(settings)); |
| 291 | |
| 292 | // By default, smooth scrolling is disabled. |
| 293 | g_assert_false(webkit_settings_get_enable_smooth_scrolling(settings)); |
| 294 | webkit_settings_set_enable_smooth_scrolling(settings, TRUE); |
| 295 | g_assert_true(webkit_settings_get_enable_smooth_scrolling(settings)); |
| 296 | |
| 297 | // By default, accelerated 2D canvas is disabled. |
| 298 | g_assert_false(webkit_settings_get_enable_accelerated_2d_canvas(settings)); |
| 299 | webkit_settings_set_enable_accelerated_2d_canvas(settings, TRUE); |
| 300 | g_assert_true(webkit_settings_get_enable_accelerated_2d_canvas(settings)); |
| 301 | |
| 302 | // By default, writing of console messages to stdout is disabled. |
| 303 | g_assert_false(webkit_settings_get_enable_write_console_messages_to_stdout(settings)); |
| 304 | webkit_settings_set_enable_write_console_messages_to_stdout(settings, TRUE); |
| 305 | g_assert_true(webkit_settings_get_enable_write_console_messages_to_stdout(settings)); |
| 306 | |
| 307 | // MediaStream is disabled by default. |
| 308 | g_assert_false(webkit_settings_get_enable_media_stream(settings)); |
| 309 | webkit_settings_set_enable_media_stream(settings, TRUE); |
| 310 | g_assert_true(webkit_settings_get_enable_media_stream(settings)); |
| 311 | |
| 312 | // By default, SpatialNavigation is disabled |
| 313 | g_assert_false(webkit_settings_get_enable_spatial_navigation(settings)); |
| 314 | webkit_settings_set_enable_spatial_navigation(settings, TRUE); |
| 315 | g_assert_true(webkit_settings_get_enable_spatial_navigation(settings)); |
| 316 | |
| 317 | // MediaSource is enabled by default |
| 318 | g_assert_true(webkit_settings_get_enable_mediasource(settings)); |
| 319 | webkit_settings_set_enable_mediasource(settings, FALSE); |
| 320 | g_assert_false(webkit_settings_get_enable_mediasource(settings)); |
| 321 | |
| 322 | // EncryptedMedia is disabled by default |
| 323 | g_assert_false(webkit_settings_get_enable_encrypted_media(settings)); |
| 324 | webkit_settings_set_enable_encrypted_media(settings, TRUE); |
| 325 | g_assert_true(webkit_settings_get_enable_encrypted_media(settings)); |
| 326 | |
| 327 | // MediaCapabilities is disabled by default |
| 328 | g_assert_false(webkit_settings_get_enable_media_capabilities(settings)); |
| 329 | webkit_settings_set_enable_media_capabilities(settings, TRUE); |
| 330 | g_assert_true(webkit_settings_get_enable_media_capabilities(settings)); |
| 331 | |
| 332 | // File access from file URLs is not allowed by default. |
| 333 | g_assert_false(webkit_settings_get_allow_file_access_from_file_urls(settings)); |
| 334 | webkit_settings_set_allow_file_access_from_file_urls(settings, TRUE); |
| 335 | g_assert_true(webkit_settings_get_allow_file_access_from_file_urls(settings)); |
| 336 | |
| 337 | // Universal access from file URLs is not allowed by default. |
| 338 | g_assert_false(webkit_settings_get_allow_universal_access_from_file_urls(settings)); |
| 339 | webkit_settings_set_allow_universal_access_from_file_urls(settings, TRUE); |
| 340 | g_assert_true(webkit_settings_get_allow_universal_access_from_file_urls(settings)); |
| 341 | |
| 342 | // Media is enabled by default. |
| 343 | g_assert_true(webkit_settings_get_enable_media(settings)); |
| 344 | webkit_settings_set_enable_media(settings, FALSE); |
| 345 | g_assert_false(webkit_settings_get_enable_media(settings)); |
| 346 | |
| 347 | #if PLATFORM(GTK) |
| 348 | // Ondemand is the default hardware acceleration policy. |
| 349 | g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND); |
| 350 | webkit_settings_set_hardware_acceleration_policy(settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER); |
| 351 | g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER); |
| 352 | webkit_settings_set_hardware_acceleration_policy(settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS); |
| 353 | g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS); |
| 354 | webkit_settings_set_hardware_acceleration_policy(settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND); |
| 355 | g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND); |
| 356 | |
| 357 | // Back-forward navigation gesture is disabled by default |
| 358 | g_assert_false(webkit_settings_get_enable_back_forward_navigation_gestures(settings)); |
| 359 | webkit_settings_set_enable_back_forward_navigation_gestures(settings, TRUE); |
| 360 | g_assert_true(webkit_settings_get_enable_back_forward_navigation_gestures(settings)); |
| 361 | #endif |
| 362 | |
| 363 | // JavaScript markup is enabled by default. |
| 364 | g_assert_true(webkit_settings_get_enable_javascript_markup(settings)); |
| 365 | webkit_settings_set_enable_javascript_markup(settings, FALSE); |
| 366 | g_assert_false(webkit_settings_get_enable_javascript_markup(settings)); |
| 367 | |
| 368 | g_object_unref(G_OBJECT(settings)); |
| 369 | } |
| 370 | |
| 371 | void testWebKitSettingsNewWithSettings(Test* test, gconstpointer) |
| 372 | { |
| 373 | GRefPtr<WebKitSettings> settings = adoptGRef(webkit_settings_new_with_settings( |
| 374 | "enable-javascript" , FALSE, |
| 375 | "auto-load-images" , FALSE, |
| 376 | "load-icons-ignoring-image-load-setting" , TRUE, |
| 377 | nullptr)); |
| 378 | test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(settings.get())); |
| 379 | g_assert_false(webkit_settings_get_enable_javascript(settings.get())); |
| 380 | g_assert_false(webkit_settings_get_auto_load_images(settings.get())); |
| 381 | g_assert_true(webkit_settings_get_load_icons_ignoring_image_load_setting(settings.get())); |
| 382 | } |
| 383 | |
| 384 | #if PLATFORM(GTK) |
| 385 | static CString convertWebViewMainResourceDataToCString(WebViewTest* test) |
| 386 | { |
| 387 | size_t mainResourceDataSize = 0; |
| 388 | const char* mainResourceData = test->mainResourceData(mainResourceDataSize); |
| 389 | return CString(mainResourceData, mainResourceDataSize); |
| 390 | } |
| 391 | |
| 392 | static void (WebViewTest* test, const CString& userAgent) |
| 393 | { |
| 394 | test->loadURI(gServer->getURIForPath("/" ).data()); |
| 395 | test->waitUntilLoadFinished(); |
| 396 | ASSERT_CMP_CSTRING(convertWebViewMainResourceDataToCString(test), ==, userAgent); |
| 397 | } |
| 398 | |
| 399 | static void testWebKitSettingsUserAgent(WebViewTest* test, gconstpointer) |
| 400 | { |
| 401 | GRefPtr<WebKitSettings> settings = adoptGRef(webkit_settings_new()); |
| 402 | CString defaultUserAgent = webkit_settings_get_user_agent(settings.get()); |
| 403 | webkit_web_view_set_settings(test->m_webView, settings.get()); |
| 404 | |
| 405 | g_assert_nonnull(g_strstr_len(defaultUserAgent.data(), -1, "AppleWebKit" )); |
| 406 | g_assert_nonnull(g_strstr_len(defaultUserAgent.data(), -1, "Safari" )); |
| 407 | |
| 408 | webkit_settings_set_user_agent(settings.get(), 0); |
| 409 | g_assert_cmpstr(defaultUserAgent.data(), ==, webkit_settings_get_user_agent(settings.get())); |
| 410 | assertThatUserAgentIsSentInHeaders(test, defaultUserAgent.data()); |
| 411 | |
| 412 | webkit_settings_set_user_agent(settings.get(), "" ); |
| 413 | g_assert_cmpstr(defaultUserAgent.data(), ==, webkit_settings_get_user_agent(settings.get())); |
| 414 | |
| 415 | const char* funkyUserAgent = "Funky!" ; |
| 416 | webkit_settings_set_user_agent(settings.get(), funkyUserAgent); |
| 417 | g_assert_cmpstr(funkyUserAgent, ==, webkit_settings_get_user_agent(settings.get())); |
| 418 | assertThatUserAgentIsSentInHeaders(test, funkyUserAgent); |
| 419 | |
| 420 | webkit_settings_set_user_agent_with_application_details(settings.get(), "WebKitGTK+" , 0); |
| 421 | const char* userAgentWithNullVersion = webkit_settings_get_user_agent(settings.get()); |
| 422 | g_assert_cmpstr(g_strstr_len(userAgentWithNullVersion, -1, defaultUserAgent.data()), ==, userAgentWithNullVersion); |
| 423 | g_assert_nonnull(g_strstr_len(userAgentWithNullVersion, -1, "WebKitGTK+" )); |
| 424 | |
| 425 | webkit_settings_set_user_agent_with_application_details(settings.get(), "WebKitGTK+" , "" ); |
| 426 | g_assert_cmpstr(webkit_settings_get_user_agent(settings.get()), ==, userAgentWithNullVersion); |
| 427 | |
| 428 | webkit_settings_set_user_agent_with_application_details(settings.get(), "WebCatGTK+" , "3.4.5" ); |
| 429 | const char* newUserAgent = webkit_settings_get_user_agent(settings.get()); |
| 430 | g_assert_nonnull(g_strstr_len(newUserAgent, -1, "3.4.5" )); |
| 431 | g_assert_nonnull(g_strstr_len(newUserAgent, -1, "WebCatGTK+" )); |
| 432 | |
| 433 | GUniquePtr<char> applicationUserAgent(g_strdup_printf("%s %s" , defaultUserAgent.data(), "WebCatGTK+/3.4.5" )); |
| 434 | g_assert_cmpstr(applicationUserAgent.get(), ==, webkit_settings_get_user_agent(settings.get())); |
| 435 | } |
| 436 | #endif // PLATFORM(GTK) |
| 437 | |
| 438 | static void testWebKitSettingsJavaScriptMarkup(WebViewTest* test, gconstpointer) |
| 439 | { |
| 440 | webkit_settings_set_enable_javascript_markup(webkit_web_view_get_settings(test->m_webView), FALSE); |
| 441 | static const char* html = |
| 442 | "<html>" |
| 443 | " <head>" |
| 444 | " <title>No JavaScript allowed</title>" |
| 445 | " <script>document.title = 'JavaScript allowed from head script'</script>" |
| 446 | " </head>" |
| 447 | " <body onload='document.title = \"JavaScript allowed from body onload attribute\"'>" |
| 448 | " <p>No JavaScript markup should be allowed</p>" |
| 449 | " <script>document.title = 'JavaScript allowed from body script'</script>" |
| 450 | " </body>" |
| 451 | "</html>" ; |
| 452 | test->loadHtml(html, nullptr); |
| 453 | test->waitUntilLoadFinished(); |
| 454 | |
| 455 | g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, "No JavaScript allowed" ); |
| 456 | auto* jsResult = test->runJavaScriptAndWaitUntilFinished("document.getElementsByTagName('script').length" , nullptr); |
| 457 | g_assert(jsResult); |
| 458 | g_assert_cmpfloat(WebViewTest::javascriptResultToNumber(jsResult), ==, 0); |
| 459 | |
| 460 | webkit_settings_set_enable_javascript_markup(webkit_web_view_get_settings(test->m_webView), TRUE); |
| 461 | } |
| 462 | |
| 463 | static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) |
| 464 | { |
| 465 | if (message->method != SOUP_METHOD_GET) { |
| 466 | soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); |
| 467 | return; |
| 468 | } |
| 469 | |
| 470 | if (g_str_equal(path, "/" )) { |
| 471 | const char* userAgent = soup_message_headers_get_one(message->request_headers, "User-Agent" ); |
| 472 | soup_message_set_status(message, SOUP_STATUS_OK); |
| 473 | soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, userAgent, strlen(userAgent)); |
| 474 | soup_message_body_complete(message->response_body); |
| 475 | } else |
| 476 | soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); |
| 477 | } |
| 478 | |
| 479 | void beforeAll() |
| 480 | { |
| 481 | gServer = new WebKitTestServer(); |
| 482 | gServer->run(serverCallback); |
| 483 | |
| 484 | Test::add("WebKitSettings" , "webkit-settings" , testWebKitSettings); |
| 485 | Test::add("WebKitSettings" , "new-with-settings" , testWebKitSettingsNewWithSettings); |
| 486 | #if PLATFORM(GTK) |
| 487 | WebViewTest::add("WebKitSettings" , "user-agent" , testWebKitSettingsUserAgent); |
| 488 | #endif |
| 489 | WebViewTest::add("WebKitSettings" , "javascript-markup" , testWebKitSettingsJavaScriptMarkup); |
| 490 | } |
| 491 | |
| 492 | void afterAll() |
| 493 | { |
| 494 | delete gServer; |
| 495 | } |
| 496 | |
| 497 | |