Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / shell / common / webkit_test_helpers.cc
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/public/common/web_preferences.h"
14 #include "content/shell/common/shell_switches.h"
15 #include "content/shell/common/test_runner/test_preferences.h"
16
17 namespace content {
18
19 void 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 }
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 = EDITING_BEHAVIOR_MAC;
64 #else
65   prefs->editing_behavior = 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[kCommonScript] =
77       base::ASCIIToUTF16("Apple Chancery");
78   prefs->fantasy_font_family_map[kCommonScript] = base::ASCIIToUTF16("Papyrus");
79   serif = base::ASCIIToUTF16("Times");
80 #else
81   prefs->cursive_font_family_map[kCommonScript] =
82       base::ASCIIToUTF16("Comic Sans MS");
83   prefs->fantasy_font_family_map[kCommonScript] = base::ASCIIToUTF16("Impact");
84   serif = base::ASCIIToUTF16("times new roman");
85 #endif
86   prefs->serif_font_family_map[kCommonScript] = serif;
87   prefs->standard_font_family_map[kCommonScript] = serif;
88   prefs->fixed_font_family_map[kCommonScript] = base::ASCIIToUTF16("Courier");
89   prefs->sans_serif_font_family_map[kCommonScript] =
90       base::ASCIIToUTF16("Helvetica");
91   prefs->minimum_logical_font_size = 9;
92   prefs->asynchronous_spell_checking_enabled = false;
93   prefs->accelerated_2d_canvas_enabled =
94       command_line.HasSwitch(switches::kEnableAccelerated2DCanvas);
95   prefs->mock_scrollbars_enabled = false;
96   prefs->smart_insert_delete_enabled = true;
97   prefs->minimum_accelerated_2d_canvas_size = 0;
98 #if defined(OS_ANDROID)
99   prefs->text_autosizing_enabled = false;
100 #endif
101   prefs->viewport_enabled = false;
102 }
103
104 base::FilePath GetWebKitRootDirFilePath() {
105   base::FilePath base_path;
106   PathService::Get(base::DIR_SOURCE_ROOT, &base_path);
107   return base_path.Append(FILE_PATH_LITERAL("third_party/WebKit"));
108 }
109
110 std::vector<std::string> GetSideloadFontFiles() {
111   std::vector<std::string> files;
112   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
113   if (command_line.HasSwitch(switches::kRegisterFontFiles)) {
114     base::SplitString(
115         command_line.GetSwitchValueASCII(switches::kRegisterFontFiles),
116         ';',
117         &files);
118   }
119   return files;
120 }
121
122 }  // namespace content