1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "content/shell/common/webkit_test_helpers.h" 6 7 #include "base/command_line.h" 8 #include "base/file_util.h" 9 #include "base/path_service.h" 10 #include "base/strings/utf_string_conversions.h" 11 #include "content/public/common/content_switches.h" 12 #include "content/shell/common/shell_switches.h" 13 #include "third_party/WebKit/public/testing/WebPreferences.h" 14 #include "webkit/common/webpreferences.h" 15 16 namespace content { 17 18 void ExportLayoutTestSpecificPreferences( 19 const WebTestRunner::WebPreferences& from, 20 WebPreferences* to) { 21 to->allow_universal_access_from_file_urls = 22 from.allowUniversalAccessFromFileURLs; 23 to->dom_paste_enabled = from.DOMPasteAllowed; 24 to->javascript_can_access_clipboard = from.javaScriptCanAccessClipboard; 25 to->xss_auditor_enabled = from.XSSAuditorEnabled; 26 to->editing_behavior = static_cast<webkit_glue::EditingBehavior>( 27 from.editingBehavior); 28 to->default_font_size = from.defaultFontSize; 29 to->minimum_font_size = from.minimumFontSize; 30 to->default_encoding = from.defaultTextEncodingName.utf8().data(); 31 to->javascript_enabled = from.javaScriptEnabled; 32 to->supports_multiple_windows = from.supportsMultipleWindows; 33 to->loads_images_automatically = from.loadsImagesAutomatically; 34 to->plugins_enabled = from.pluginsEnabled; 35 to->java_enabled = from.javaEnabled; 36 to->application_cache_enabled = from.offlineWebApplicationCacheEnabled; 37 to->tabs_to_links = from.tabsToLinks; 38 to->experimental_webgl_enabled = from.experimentalWebGLEnabled; 39 // experimentalCSSRegionsEnabled is deprecated and ignored. 40 to->hyperlink_auditing_enabled = from.hyperlinkAuditingEnabled; 41 to->caret_browsing_enabled = from.caretBrowsingEnabled; 42 to->allow_displaying_insecure_content = from.allowDisplayOfInsecureContent; 43 to->allow_running_insecure_content = from.allowRunningOfInsecureContent; 44 to->should_respect_image_orientation = from.shouldRespectImageOrientation; 45 to->asynchronous_spell_checking_enabled = 46 from.asynchronousSpellCheckingEnabled; 47 to->allow_file_access_from_file_urls = from.allowFileAccessFromFileURLs; 48 to->javascript_can_open_windows_automatically = 49 from.javaScriptCanOpenWindowsAutomatically; 50 } 51 52 // Applies settings that differ between layout tests and regular mode. Some 53 // of the defaults are controlled via command line flags which are 54 // automatically set for layout tests. 55 void ApplyLayoutTestDefaultPreferences(WebPreferences* prefs) { 56 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 57 prefs->allow_universal_access_from_file_urls = true; 58 prefs->dom_paste_enabled = true; 59 prefs->javascript_can_access_clipboard = true; 60 prefs->xslt_enabled = true; 61 prefs->xss_auditor_enabled = false; 62 #if defined(OS_MACOSX) 63 prefs->editing_behavior = webkit_glue::EDITING_BEHAVIOR_MAC; 64 #else 65 prefs->editing_behavior = webkit_glue::EDITING_BEHAVIOR_WIN; 66 #endif 67 prefs->java_enabled = false; 68 prefs->application_cache_enabled = true; 69 prefs->tabs_to_links = false; 70 prefs->hyperlink_auditing_enabled = false; 71 prefs->allow_displaying_insecure_content = true; 72 prefs->allow_running_insecure_content = true; 73 prefs->webgl_errors_to_console_enabled = false; 74 base::string16 serif; 75 #if defined(OS_MACOSX) 76 prefs->cursive_font_family_map[webkit_glue::kCommonScript] = 77 ASCIIToUTF16("Apple Chancery"); 78 prefs->fantasy_font_family_map[webkit_glue::kCommonScript] = 79 ASCIIToUTF16("Papyrus"); 80 serif = ASCIIToUTF16("Times"); 81 #else 82 prefs->cursive_font_family_map[webkit_glue::kCommonScript] = 83 ASCIIToUTF16("Comic Sans MS"); 84 prefs->fantasy_font_family_map[webkit_glue::kCommonScript] = 85 ASCIIToUTF16("Impact"); 86 serif = ASCIIToUTF16("times new roman"); 87 #endif 88 prefs->serif_font_family_map[webkit_glue::kCommonScript] = 89 serif; 90 prefs->standard_font_family_map[webkit_glue::kCommonScript] = 91 serif; 92 prefs->fixed_font_family_map[webkit_glue::kCommonScript] = 93 ASCIIToUTF16("Courier"); 94 prefs->sans_serif_font_family_map[ 95 webkit_glue::kCommonScript] = ASCIIToUTF16("Helvetica"); 96 prefs->minimum_logical_font_size = 9; 97 prefs->asynchronous_spell_checking_enabled = false; 98 prefs->threaded_html_parser = true; 99 prefs->accelerated_2d_canvas_enabled = 100 command_line.HasSwitch(switches::kEnableAccelerated2DCanvas); 101 prefs->force_compositing_mode = 102 command_line.HasSwitch(switches::kForceCompositingMode); 103 prefs->accelerated_compositing_for_video_enabled = false; 104 prefs->mock_scrollbars_enabled = false; 105 prefs->fixed_position_creates_stacking_context = false; 106 prefs->smart_insert_delete_enabled = true; 107 prefs->minimum_accelerated_2d_canvas_size = 0; 108 #if defined(OS_ANDROID) 109 prefs->text_autosizing_enabled = false; 110 #endif 111 prefs->viewport_enabled = false; 112 } 113 114 base::FilePath GetWebKitRootDirFilePath() { 115 base::FilePath base_path; 116 PathService::Get(base::DIR_SOURCE_ROOT, &base_path); 117 return base_path.Append(FILE_PATH_LITERAL("third_party/WebKit")); 118 } 119 120 } // namespace content 121