[email protected] | 55915a7 | 2012-12-18 11:55:25 | [diff] [blame] | 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/webkit_test_helpers.h" |
| 6 | |
[email protected] | 0989186e | 2013-03-06 09:43:46 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 294e74f | 2013-04-29 14:50:54 | [diff] [blame^] | 8 | #include "base/file_util.h" |
| 9 | #include "base/path_service.h" |
[email protected] | 933bdfbc | 2013-01-11 11:48:11 | [diff] [blame] | 10 | #include "base/utf_string_conversions.h" |
[email protected] | 0989186e | 2013-03-06 09:43:46 | [diff] [blame] | 11 | #include "content/shell/shell_switches.h" |
[email protected] | 55915a7 | 2012-12-18 11:55:25 | [diff] [blame] | 12 | #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebPreferences.h" |
| 13 | #include "webkit/glue/webpreferences.h" |
| 14 | |
| 15 | using WebTestRunner::WebPreferences; |
| 16 | |
| 17 | namespace content { |
| 18 | |
[email protected] | d48eab08 | 2012-12-19 09:25:47 | [diff] [blame] | 19 | void ExportLayoutTestSpecificPreferences(const WebPreferences& from, |
| 20 | webkit_glue::WebPreferences* to) { |
[email protected] | 55915a7 | 2012-12-18 11:55:25 | [diff] [blame] | 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 = |
| 27 | static_cast<webkit_glue::WebPreferences::EditingBehavior>( |
| 28 | from.editingBehavior); |
[email protected] | 375db13a | 2012-12-18 21:42:58 | [diff] [blame] | 29 | to->default_font_size = from.defaultFontSize; |
| 30 | to->minimum_font_size = from.minimumFontSize; |
| 31 | to->default_encoding = from.defaultTextEncodingName.utf8().data(); |
| 32 | to->javascript_enabled = from.javaScriptEnabled; |
| 33 | to->supports_multiple_windows = from.supportsMultipleWindows; |
| 34 | to->loads_images_automatically = from.loadsImagesAutomatically; |
| 35 | to->plugins_enabled = from.pluginsEnabled; |
| 36 | to->java_enabled = from.javaEnabled; |
[email protected] | 375db13a | 2012-12-18 21:42:58 | [diff] [blame] | 37 | to->application_cache_enabled = from.offlineWebApplicationCacheEnabled; |
| 38 | to->tabs_to_links = from.tabsToLinks; |
| 39 | to->experimental_webgl_enabled = from.experimentalWebGLEnabled; |
| 40 | to->css_grid_layout_enabled = from.experimentalCSSGridLayoutEnabled; |
| 41 | // experimentalCSSRegionsEnabled is deprecated and ignored. |
| 42 | to->hyperlink_auditing_enabled = from.hyperlinkAuditingEnabled; |
| 43 | to->caret_browsing_enabled = from.caretBrowsingEnabled; |
| 44 | to->allow_displaying_insecure_content = from.allowDisplayOfInsecureContent; |
| 45 | to->allow_running_insecure_content = from.allowRunningOfInsecureContent; |
| 46 | to->css_shaders_enabled = from.cssCustomFilterEnabled; |
| 47 | to->should_respect_image_orientation = from.shouldRespectImageOrientation; |
[email protected] | a7aca15 | 2013-02-21 13:29:09 | [diff] [blame] | 48 | to->asynchronous_spell_checking_enabled = |
| 49 | from.asynchronousSpellCheckingEnabled; |
[email protected] | 52097ca | 2013-02-21 14:32:49 | [diff] [blame] | 50 | to->allow_file_access_from_file_urls = from.allowFileAccessFromFileURLs; |
| 51 | to->author_and_user_styles_enabled = from.authorAndUserStylesEnabled; |
| 52 | to->javascript_can_open_windows_automatically = |
| 53 | from.javaScriptCanOpenWindowsAutomatically; |
| 54 | to->user_style_sheet_location = from.userStyleSheetLocation; |
[email protected] | 7e1ca11 | 2013-02-23 01:07:36 | [diff] [blame] | 55 | to->touch_drag_drop_enabled = from.touchDragDropEnabled; |
[email protected] | 55915a7 | 2012-12-18 11:55:25 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | 52097ca | 2013-02-21 14:32:49 | [diff] [blame] | 58 | // Applies settings that differ between layout tests and regular mode. Some |
| 59 | // of the defaults are controlled via command line flags which are |
| 60 | // automatically set for layout tests. |
[email protected] | f0c25f0 | 2012-12-21 17:55:55 | [diff] [blame] | 61 | void ApplyLayoutTestDefaultPreferences(webkit_glue::WebPreferences* prefs) { |
[email protected] | 0989186e | 2013-03-06 09:43:46 | [diff] [blame] | 62 | CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | f0c25f0 | 2012-12-21 17:55:55 | [diff] [blame] | 63 | prefs->allow_universal_access_from_file_urls = true; |
| 64 | prefs->dom_paste_enabled = true; |
| 65 | prefs->javascript_can_access_clipboard = true; |
| 66 | prefs->xss_auditor_enabled = false; |
| 67 | #if defined(OS_MACOSX) |
| 68 | prefs->editing_behavior = webkit_glue::WebPreferences::EDITING_BEHAVIOR_MAC; |
| 69 | #else |
| 70 | prefs->editing_behavior = webkit_glue::WebPreferences::EDITING_BEHAVIOR_WIN; |
| 71 | #endif |
| 72 | prefs->java_enabled = false; |
| 73 | prefs->application_cache_enabled = true; |
| 74 | prefs->tabs_to_links = false; |
| 75 | prefs->hyperlink_auditing_enabled = false; |
| 76 | prefs->allow_displaying_insecure_content = true; |
| 77 | prefs->allow_running_insecure_content = true; |
[email protected] | 3bbab7e | 2012-12-22 07:07:16 | [diff] [blame] | 78 | prefs->webgl_errors_to_console_enabled = false; |
[email protected] | 933bdfbc | 2013-01-11 11:48:11 | [diff] [blame] | 79 | string16 serif; |
| 80 | #if defined(OS_MACOSX) |
| 81 | prefs->cursive_font_family_map[webkit_glue::WebPreferences::kCommonScript] = |
| 82 | ASCIIToUTF16("Apple Chancery"); |
| 83 | prefs->fantasy_font_family_map[webkit_glue::WebPreferences::kCommonScript] = |
| 84 | ASCIIToUTF16("Papyrus"); |
| 85 | serif = ASCIIToUTF16("Times"); |
| 86 | #else |
| 87 | prefs->cursive_font_family_map[webkit_glue::WebPreferences::kCommonScript] = |
| 88 | ASCIIToUTF16("Comic Sans MS"); |
| 89 | prefs->fantasy_font_family_map[webkit_glue::WebPreferences::kCommonScript] = |
| 90 | ASCIIToUTF16("Impact"); |
| 91 | serif = ASCIIToUTF16("times new roman"); |
| 92 | #endif |
| 93 | prefs->serif_font_family_map[webkit_glue::WebPreferences::kCommonScript] = |
| 94 | serif; |
| 95 | prefs->standard_font_family_map[webkit_glue::WebPreferences::kCommonScript] = |
| 96 | serif; |
| 97 | prefs->fixed_font_family_map[webkit_glue::WebPreferences::kCommonScript] = |
| 98 | ASCIIToUTF16("Courier"); |
| 99 | prefs->sans_serif_font_family_map[ |
| 100 | webkit_glue::WebPreferences::kCommonScript] = ASCIIToUTF16("Helvetica"); |
| 101 | prefs->minimum_logical_font_size = 9; |
[email protected] | 9de7a11c | 2013-01-23 16:09:02 | [diff] [blame] | 102 | prefs->asynchronous_spell_checking_enabled = false; |
[email protected] | 52097ca | 2013-02-21 14:32:49 | [diff] [blame] | 103 | prefs->user_style_sheet_enabled = true; |
[email protected] | 1796b7c | 2013-02-28 10:42:14 | [diff] [blame] | 104 | prefs->threaded_html_parser = true; |
[email protected] | 0989186e | 2013-03-06 09:43:46 | [diff] [blame] | 105 | prefs->accelerated_2d_canvas_enabled = |
| 106 | command_line.HasSwitch(switches::kEnableAccelerated2DCanvas); |
[email protected] | 92ee7d6b | 2013-03-04 09:08:59 | [diff] [blame] | 107 | prefs->accelerated_compositing_for_video_enabled = false; |
[email protected] | 92ee7d6b | 2013-03-04 09:08:59 | [diff] [blame] | 108 | prefs->mock_scrollbars_enabled = false; |
[email protected] | e94f211 | 2013-03-16 19:04:11 | [diff] [blame] | 109 | prefs->fixed_position_creates_stacking_context = false; |
[email protected] | e8f35bc | 2013-03-18 15:22:01 | [diff] [blame] | 110 | prefs->apply_page_scale_factor_in_compositor = false; |
[email protected] | 85f5450d | 2013-03-18 17:13:59 | [diff] [blame] | 111 | prefs->smart_insert_delete_enabled = true; |
[email protected] | 9c0e9df | 2013-03-18 22:51:18 | [diff] [blame] | 112 | prefs->minimum_accelerated_2d_canvas_size = 0; |
[email protected] | d48eab08 | 2012-12-19 09:25:47 | [diff] [blame] | 113 | } |
| 114 | |
[email protected] | 294e74f | 2013-04-29 14:50:54 | [diff] [blame^] | 115 | base::FilePath GetWebKitRootDirFilePath() { |
| 116 | base::FilePath base_path; |
| 117 | PathService::Get(base::DIR_SOURCE_ROOT, &base_path); |
| 118 | if (file_util::PathExists( |
| 119 | base_path.Append(FILE_PATH_LITERAL("third_party/WebKit")))) { |
| 120 | // We're in a WebKit-in-chrome checkout. |
| 121 | return base_path.Append(FILE_PATH_LITERAL("third_party/WebKit")); |
| 122 | } else if (file_util::PathExists( |
| 123 | base_path.Append(FILE_PATH_LITERAL("chromium")))) { |
| 124 | // We're in a WebKit-only checkout on Windows. |
| 125 | return base_path.Append(FILE_PATH_LITERAL("../..")); |
| 126 | } else if (file_util::PathExists( |
| 127 | base_path.Append(FILE_PATH_LITERAL("webkit/support")))) { |
| 128 | // We're in a WebKit-only/xcodebuild checkout on Mac |
| 129 | return base_path.Append(FILE_PATH_LITERAL("../../..")); |
| 130 | } |
| 131 | // We're in a WebKit-only, make-build, so the DIR_SOURCE_ROOT is already the |
| 132 | // WebKit root. That, or we have no idea where we are. |
| 133 | return base_path; |
| 134 | } |
| 135 | |
| 136 | base::FilePath GetChromiumRootDirFilePath() { |
| 137 | base::FilePath webkit_path = GetWebKitRootDirFilePath(); |
| 138 | if (file_util::PathExists(webkit_path.Append( |
| 139 | FILE_PATH_LITERAL("Source/WebKit/chromium/webkit/support")))) { |
| 140 | // We're in a WebKit-only checkout. |
| 141 | return webkit_path.Append(FILE_PATH_LITERAL("Source/WebKit/chromium")); |
| 142 | } else { |
| 143 | // We're in a Chromium checkout, and WebKit is in third_party/WebKit. |
| 144 | return webkit_path.Append(FILE_PATH_LITERAL("../..")); |
| 145 | } |
| 146 | } |
| 147 | |
[email protected] | 55915a7 | 2012-12-18 11:55:25 | [diff] [blame] | 148 | } // namespace content |