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/files/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/public/common/web_preferences.h"
14#include "content/shell/common/shell_switches.h"
15#include "content/shell/common/test_runner/test_preferences.h"
16
17namespace content {
18
19void ExportLayoutTestSpecificPreferences(const TestPreferences& from,
20                                         WebPreferences* to) {
21  to->allow_universal_access_from_file_urls =
22      from.allow_universal_access_from_file_urls;
23  to->dom_paste_enabled = from.dom_paste_allowed;
24  to->javascript_can_access_clipboard = from.java_script_can_access_clipboard;
25  to->xss_auditor_enabled = from.xss_auditor_enabled;
26  to->editing_behavior = static_cast<EditingBehavior>(from.editing_behavior);
27  to->default_font_size = from.default_font_size;
28  to->minimum_font_size = from.minimum_font_size;
29  to->default_encoding = from.default_text_encoding_name.utf8().data();
30  to->javascript_enabled = from.java_script_enabled;
31  to->supports_multiple_windows = from.supports_multiple_windows;
32  to->loads_images_automatically = from.loads_images_automatically;
33  to->plugins_enabled = from.plugins_enabled;
34  to->java_enabled = from.java_enabled;
35  to->application_cache_enabled = from.offline_web_application_cache_enabled;
36  to->tabs_to_links = from.tabs_to_links;
37  to->experimental_webgl_enabled = from.experimental_webgl_enabled;
38  // experimentalCSSRegionsEnabled is deprecated and ignored.
39  to->hyperlink_auditing_enabled = from.hyperlink_auditing_enabled;
40  to->caret_browsing_enabled = from.caret_browsing_enabled;
41  to->allow_displaying_insecure_content =
42      from.allow_display_of_insecure_content;
43  to->allow_running_insecure_content = from.allow_running_of_insecure_content;
44  to->should_respect_image_orientation = from.should_respect_image_orientation;
45  to->asynchronous_spell_checking_enabled =
46      from.asynchronous_spell_checking_enabled;
47  to->allow_file_access_from_file_urls = from.allow_file_access_from_file_urls;
48  to->javascript_can_open_windows_automatically =
49      from.java_script_can_open_windows_automatically;
50  to->web_security_enabled =
51      from.web_security_enabled;
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.
57void 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 = EDITING_BEHAVIOR_MAC;
66#else
67  prefs->editing_behavior = 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[kCommonScript] =
79      base::ASCIIToUTF16("Apple Chancery");
80  prefs->fantasy_font_family_map[kCommonScript] = base::ASCIIToUTF16("Papyrus");
81  serif = base::ASCIIToUTF16("Times");
82#else
83  prefs->cursive_font_family_map[kCommonScript] =
84      base::ASCIIToUTF16("Comic Sans MS");
85  prefs->fantasy_font_family_map[kCommonScript] = base::ASCIIToUTF16("Impact");
86  serif = base::ASCIIToUTF16("times new roman");
87#endif
88  prefs->serif_font_family_map[kCommonScript] = serif;
89  prefs->standard_font_family_map[kCommonScript] = serif;
90  prefs->fixed_font_family_map[kCommonScript] = base::ASCIIToUTF16("Courier");
91  prefs->sans_serif_font_family_map[kCommonScript] =
92      base::ASCIIToUTF16("Helvetica");
93  prefs->minimum_logical_font_size = 9;
94  prefs->asynchronous_spell_checking_enabled = false;
95  prefs->accelerated_2d_canvas_enabled =
96      command_line.HasSwitch(switches::kEnableAccelerated2DCanvas);
97  prefs->mock_scrollbars_enabled = false;
98  prefs->smart_insert_delete_enabled = true;
99  prefs->minimum_accelerated_2d_canvas_size = 0;
100#if defined(OS_ANDROID)
101  prefs->text_autosizing_enabled = false;
102#endif
103  prefs->viewport_enabled = false;
104}
105
106base::FilePath GetWebKitRootDirFilePath() {
107  base::FilePath base_path;
108  PathService::Get(base::DIR_SOURCE_ROOT, &base_path);
109  return base_path.Append(FILE_PATH_LITERAL("third_party/WebKit"));
110}
111
112std::vector<std::string> GetSideloadFontFiles() {
113  std::vector<std::string> files;
114  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
115  if (command_line.HasSwitch(switches::kRegisterFontFiles)) {
116    base::SplitString(
117        command_line.GetSwitchValueASCII(switches::kRegisterFontFiles),
118        ';',
119        &files);
120  }
121  return files;
122}
123
124}  // namespace content
125