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/string_split.h" 11 #include "base/strings/utf_string_conversions.h" 12 #include "content/public/common/content_switches.h" 13 #include "content/shell/common/shell_switches.h" 14 #include "content/shell/common/test_runner/test_preferences.h" 15 #include "webkit/common/webpreferences.h" 16 17 namespace content { 18 19 void ExportLayoutTestSpecificPreferences( 20 const TestPreferences& from, 21 WebPreferences* to) { 22 to->allow_universal_access_from_file_urls = 23 from.allow_universal_access_from_file_urls; 24 to->dom_paste_enabled = from.dom_paste_allowed; 25 to->javascript_can_access_clipboard = from.java_script_can_access_clipboard; 26 to->xss_auditor_enabled = from.xss_auditor_enabled; 27 to->editing_behavior = static_cast<webkit_glue::EditingBehavior>( 28 from.editing_behavior); 29 to->default_font_size = from.default_font_size; 30 to->minimum_font_size = from.minimum_font_size; 31 to->default_encoding = from.default_text_encoding_name.utf8().data(); 32 to->javascript_enabled = from.java_script_enabled; 33 to->supports_multiple_windows = from.supports_multiple_windows; 34 to->loads_images_automatically = from.loads_images_automatically; 35 to->plugins_enabled = from.plugins_enabled; 36 to->java_enabled = from.java_enabled; 37 to->application_cache_enabled = from.offline_web_application_cache_enabled; 38 to->tabs_to_links = from.tabs_to_links; 39 to->experimental_webgl_enabled = from.experimental_webgl_enabled; 40 // experimentalCSSRegionsEnabled is deprecated and ignored. 41 to->hyperlink_auditing_enabled = from.hyperlink_auditing_enabled; 42 to->caret_browsing_enabled = from.caret_browsing_enabled; 43 to->allow_displaying_insecure_content = 44 from.allow_display_of_insecure_content; 45 to->allow_running_insecure_content = from.allow_running_of_insecure_content; 46 to->should_respect_image_orientation = from.should_respect_image_orientation; 47 to->asynchronous_spell_checking_enabled = 48 from.asynchronous_spell_checking_enabled; 49 to->allow_file_access_from_file_urls = from.allow_file_access_from_file_urls; 50 to->javascript_can_open_windows_automatically = 51 from.java_script_can_open_windows_automatically; 52 } 53 54 // Applies settings that differ between layout tests and regular mode. Some 55 // of the defaults are controlled via command line flags which are 56 // automatically set for layout tests. 57 void ApplyLayoutTestDefaultPreferences(WebPreferences* prefs) { 58 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 59 prefs->allow_universal_access_from_file_urls = true; 60 prefs->dom_paste_enabled = true; 61 prefs->javascript_can_access_clipboard = true; 62 prefs->xslt_enabled = true; 63 prefs->xss_auditor_enabled = false; 64 #if defined(OS_MACOSX) 65 prefs->editing_behavior = webkit_glue::EDITING_BEHAVIOR_MAC; 66 #else 67 prefs->editing_behavior = webkit_glue::EDITING_BEHAVIOR_WIN; 68 #endif 69 prefs->java_enabled = false; 70 prefs->application_cache_enabled = true; 71 prefs->tabs_to_links = false; 72 prefs->hyperlink_auditing_enabled = false; 73 prefs->allow_displaying_insecure_content = true; 74 prefs->allow_running_insecure_content = true; 75 prefs->webgl_errors_to_console_enabled = false; 76 base::string16 serif; 77 #if defined(OS_MACOSX) 78 prefs->cursive_font_family_map[webkit_glue::kCommonScript] = 79 base::ASCIIToUTF16("Apple Chancery"); 80 prefs->fantasy_font_family_map[webkit_glue::kCommonScript] = 81 base::ASCIIToUTF16("Papyrus"); 82 serif = base::ASCIIToUTF16("Times"); 83 #else 84 prefs->cursive_font_family_map[webkit_glue::kCommonScript] = 85 base::ASCIIToUTF16("Comic Sans MS"); 86 prefs->fantasy_font_family_map[webkit_glue::kCommonScript] = 87 base::ASCIIToUTF16("Impact"); 88 serif = base::ASCIIToUTF16("times new roman"); 89 #endif 90 prefs->serif_font_family_map[webkit_glue::kCommonScript] = 91 serif; 92 prefs->standard_font_family_map[webkit_glue::kCommonScript] = 93 serif; 94 prefs->fixed_font_family_map[webkit_glue::kCommonScript] = 95 base::ASCIIToUTF16("Courier"); 96 prefs->sans_serif_font_family_map[ 97 webkit_glue::kCommonScript] = base::ASCIIToUTF16("Helvetica"); 98 prefs->minimum_logical_font_size = 9; 99 prefs->asynchronous_spell_checking_enabled = false; 100 prefs->accelerated_2d_canvas_enabled = 101 command_line.HasSwitch(switches::kEnableAccelerated2DCanvas); 102 prefs->accelerated_compositing_for_video_enabled = false; 103 prefs->mock_scrollbars_enabled = false; 104 prefs->smart_insert_delete_enabled = true; 105 prefs->minimum_accelerated_2d_canvas_size = 0; 106 #if defined(OS_ANDROID) 107 prefs->text_autosizing_enabled = false; 108 #endif 109 prefs->viewport_enabled = false; 110 } 111 112 base::FilePath GetWebKitRootDirFilePath() { 113 base::FilePath base_path; 114 PathService::Get(base::DIR_SOURCE_ROOT, &base_path); 115 return base_path.Append(FILE_PATH_LITERAL("third_party/WebKit")); 116 } 117 118 std::vector<std::string> GetSideloadFontFiles() { 119 std::vector<std::string> files; 120 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 121 if (command_line.HasSwitch(switches::kRegisterFontFiles)) { 122 base::SplitString( 123 command_line.GetSwitchValueASCII(switches::kRegisterFontFiles), 124 ';', 125 &files); 126 } 127 return files; 128 } 129 130 } // namespace content 131