From 375db13aefaca77bce16bc0a71467038c81652c4 Mon Sep 17 00:00:00 2001 From: "jochen@chromium.org" Date: Tue, 18 Dec 2012 21:42:58 +0000 Subject: [PATCH] [content shell] implement testRunner.overridePreference BUG=111316 R=jam@chromium.org,tony@chromium.org,tsepez@chromium.org Review URL: https://codereview.chromium.org/11602009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173791 0039d316-1c4b-4281-b951-d872f2087c98 --- content/public/common/common_param_traits_macros.h | 4 +- content/shell/webkit_test_helpers.cc | 21 +++++++++ content/shell/webkit_test_runner.cc | 54 ++++++++++++++++++++++ content/shell/webkit_test_runner.h | 2 + content/shell/webkit_test_runner.js | 4 ++ content/shell/webkit_test_runner_bindings.cc | 15 ++++++ webkit/glue/webpreferences.cc | 11 +++-- webkit/glue/webpreferences.h | 4 +- 8 files changed, 110 insertions(+), 5 deletions(-) diff --git a/content/public/common/common_param_traits_macros.h b/content/public/common/common_param_traits_macros.h index d050eea96d44..13d308b2a297 100644 --- a/content/public/common/common_param_traits_macros.h +++ b/content/public/common/common_param_traits_macros.h @@ -118,6 +118,7 @@ IPC_STRUCT_TRAITS_BEGIN(webkit_glue::WebPreferences) IPC_STRUCT_TRAITS_MEMBER(java_enabled) IPC_STRUCT_TRAITS_MEMBER(allow_scripts_to_close_windows) IPC_STRUCT_TRAITS_MEMBER(uses_page_cache) + IPC_STRUCT_TRAITS_MEMBER(page_cache_supports_plugins) IPC_STRUCT_TRAITS_MEMBER(remote_fonts_enabled) IPC_STRUCT_TRAITS_MEMBER(javascript_can_access_clipboard) IPC_STRUCT_TRAITS_MEMBER(xss_auditor_enabled) @@ -182,15 +183,16 @@ IPC_STRUCT_TRAITS_BEGIN(webkit_glue::WebPreferences) IPC_STRUCT_TRAITS_MEMBER(fixed_position_creates_stacking_context) IPC_STRUCT_TRAITS_MEMBER(sync_xhr_in_documents_enabled) IPC_STRUCT_TRAITS_MEMBER(deferred_image_decoding_enabled) + IPC_STRUCT_TRAITS_MEMBER(should_respect_image_orientation) IPC_STRUCT_TRAITS_MEMBER(number_of_cpu_cores) IPC_STRUCT_TRAITS_MEMBER(editing_behavior) + IPC_STRUCT_TRAITS_MEMBER(supports_multiple_windows) IPC_STRUCT_TRAITS_MEMBER(cookie_enabled) IPC_STRUCT_TRAITS_MEMBER(apply_page_scale_factor_in_compositor) #if defined(OS_ANDROID) IPC_STRUCT_TRAITS_MEMBER(text_autosizing_enabled) IPC_STRUCT_TRAITS_MEMBER(font_scale_factor) IPC_STRUCT_TRAITS_MEMBER(force_enable_zoom) - IPC_STRUCT_TRAITS_MEMBER(supports_multiple_windows) #endif IPC_STRUCT_TRAITS_END() diff --git a/content/shell/webkit_test_helpers.cc b/content/shell/webkit_test_helpers.cc index 9911ab23531a..8867febe6f8c 100644 --- a/content/shell/webkit_test_helpers.cc +++ b/content/shell/webkit_test_helpers.cc @@ -21,6 +21,27 @@ void ExportPreferences(const WebPreferences& from, to->editing_behavior = static_cast( from.editingBehavior); + to->default_font_size = from.defaultFontSize; + to->minimum_font_size = from.minimumFontSize; + to->default_encoding = from.defaultTextEncodingName.utf8().data(); + to->javascript_enabled = from.javaScriptEnabled; + to->supports_multiple_windows = from.supportsMultipleWindows; + to->loads_images_automatically = from.loadsImagesAutomatically; + to->plugins_enabled = from.pluginsEnabled; + to->java_enabled = from.javaEnabled; + to->uses_page_cache = from.usesPageCache; + to->page_cache_supports_plugins = from.pageCacheSupportsPlugins; + to->application_cache_enabled = from.offlineWebApplicationCacheEnabled; + to->tabs_to_links = from.tabsToLinks; + to->experimental_webgl_enabled = from.experimentalWebGLEnabled; + to->css_grid_layout_enabled = from.experimentalCSSGridLayoutEnabled; + // experimentalCSSRegionsEnabled is deprecated and ignored. + to->hyperlink_auditing_enabled = from.hyperlinkAuditingEnabled; + to->caret_browsing_enabled = from.caretBrowsingEnabled; + to->allow_displaying_insecure_content = from.allowDisplayOfInsecureContent; + to->allow_running_insecure_content = from.allowRunningOfInsecureContent; + to->css_shaders_enabled = from.cssCustomFilterEnabled; + to->should_respect_image_orientation = from.shouldRespectImageOrientation; } } // namespace content diff --git a/content/shell/webkit_test_runner.cc b/content/shell/webkit_test_runner.cc index 44c78599b471..52ad1266aa87 100644 --- a/content/shell/webkit_test_runner.cc +++ b/content/shell/webkit_test_runner.cc @@ -386,6 +386,60 @@ void WebKitTestRunner::ExecCommand(const std::string& command, WebString::fromUTF8(command), WebString::fromUTF8(value)); } +void WebKitTestRunner::OverridePreference(const std::string& key, + v8::Local value) { + if (key == "WebKitDefaultFontSize") { + prefs_.defaultFontSize = value->Int32Value(); + } else if (key == "WebKitMinimumFontSize") { + prefs_.minimumFontSize = value->Int32Value(); + } else if (key == "WebKitDefaultTextEncodingName") { + prefs_.defaultTextEncodingName = + WebString::fromUTF8(std::string(*v8::String::AsciiValue(value))); + } else if (key == "WebKitJavaScriptEnabled") { + prefs_.javaScriptEnabled = value->BooleanValue(); + } else if (key == "WebKitSupportsMultipleWindows") { + prefs_.supportsMultipleWindows = value->BooleanValue(); + } else if (key == "WebKitDisplayImagesKey") { + prefs_.loadsImagesAutomatically = value->BooleanValue(); + } else if (key == "WebKitPluginsEnabled") { + prefs_.pluginsEnabled = value->BooleanValue(); + } else if (key == "WebKitJavaEnabled") { + prefs_.javaEnabled = value->BooleanValue(); + } else if (key == "WebKitUsesPageCachePreferenceKey") { + prefs_.usesPageCache = value->BooleanValue(); + } else if (key == "WebKitPageCacheSupportsPluginsPreferenceKey") { + prefs_.pageCacheSupportsPlugins = value->BooleanValue(); + } else if (key == "WebKitOfflineWebApplicationCacheEnabled") { + prefs_.offlineWebApplicationCacheEnabled = value->BooleanValue(); + } else if (key == "WebKitTabToLinksPreferenceKey") { + prefs_.tabsToLinks = value->BooleanValue(); + } else if (key == "WebKitWebGLEnabled") { + prefs_.experimentalWebGLEnabled = value->BooleanValue(); + } else if (key == "WebKitCSSRegionsEnabled") { + prefs_.experimentalCSSRegionsEnabled = value->BooleanValue(); + } else if (key == "WebKitCSSGridLayoutEnabled") { + prefs_.experimentalCSSGridLayoutEnabled = value->BooleanValue(); + } else if (key == "WebKitHyperlinkAuditingEnabled") { + prefs_.hyperlinkAuditingEnabled = value->BooleanValue(); + } else if (key == "WebKitEnableCaretBrowsing") { + prefs_.caretBrowsingEnabled = value->BooleanValue(); + } else if (key == "WebKitAllowDisplayingInsecureContent") { + prefs_.allowDisplayOfInsecureContent = value->BooleanValue(); + } else if (key == "WebKitAllowRunningInsecureContent") { + prefs_.allowRunningOfInsecureContent = value->BooleanValue(); + } else if (key == "WebKitCSSCustomFilterEnabled") { + prefs_.cssCustomFilterEnabled = value->BooleanValue(); + } else if (key == "WebKitShouldRespectImageOrientation") { + prefs_.shouldRespectImageOrientation = value->BooleanValue(); + } else if (key == "WebKitWebAudioEnabled") { + DCHECK(value->BooleanValue()); + } else { + std::string message("CONSOLE MESSAGE: Invalid name for preference: "); + printMessage(message + key + "\n"); + } + applyPreferences(); +} + void WebKitTestRunner::NotImplemented(const std::string& object, const std::string& method) { Send(new ShellViewHostMsg_NotImplemented(routing_id(), object, method)); diff --git a/content/shell/webkit_test_runner.h b/content/shell/webkit_test_runner.h index 8e56a9e3c430..72fdba41153a 100644 --- a/content/shell/webkit_test_runner.h +++ b/content/shell/webkit_test_runner.h @@ -10,6 +10,7 @@ #include "content/public/renderer/render_view_observer.h" #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebPreferences.h" #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h" +#include "v8/include/v8.h" class SkCanvas; @@ -76,6 +77,7 @@ class WebKitTestRunner : public RenderViewObserver, void CloseWebInspector(); void EvaluateInWebInspector(int32_t call_id, const std::string& script); void ExecCommand(const std::string& command, const std::string& value); + void OverridePreference(const std::string& key, v8::Local value); void NotImplemented(const std::string& object, const std::string& method); diff --git a/content/shell/webkit_test_runner.js b/content/shell/webkit_test_runner.js index 4159b5548a2d..6c49c5d08084 100644 --- a/content/shell/webkit_test_runner.js +++ b/content/shell/webkit_test_runner.js @@ -11,6 +11,7 @@ var testRunner = testRunner || {}; native function ExecCommand(); native function GetWorkerThreadCount(); native function NotifyDone(); + native function OverridePreference(); native function SetCanOpenWindows(); native function SetDumpAsText(); native function SetDumpChildFramesAsText(); @@ -77,6 +78,9 @@ var testRunner = testRunner || {}; "evaluateInWebInspector", {value: EvaluateInWebInspector}); Object.defineProperty(this, "execCommand", {value: ExecCommand}); + Object.defineProperty(this, + "overridePreference", + {value: OverridePreference}); Object.defineProperty(this, diff --git a/content/shell/webkit_test_runner_bindings.cc b/content/shell/webkit_test_runner_bindings.cc index 0194c6042579..7bfa092dc943 100644 --- a/content/shell/webkit_test_runner_bindings.cc +++ b/content/shell/webkit_test_runner_bindings.cc @@ -183,6 +183,19 @@ v8::Handle ExecCommand(const v8::Arguments& args) { return v8::Undefined(); } +v8::Handle OverridePreference(const v8::Arguments& args) { + if (args.Length() != 2 || !args[0]->IsString()) + return v8::Undefined(); + + WebKitTestRunner* runner = + ShellRenderProcessObserver::GetInstance()->main_test_runner(); + if (!runner) + return v8::Undefined(); + + runner->OverridePreference(*v8::String::AsciiValue(args[0]), args[1]); + return v8::Undefined(); +} + v8::Handle GetGlobalFlag(const v8::Arguments& args) { return v8::Boolean::New(g_global_flag); } @@ -264,6 +277,8 @@ WebKitTestRunnerBindings::GetNativeFunction(v8::Handle name) { return v8::FunctionTemplate::New(EvaluateInWebInspector); if (name->Equals(v8::String::New("ExecCommand"))) return v8::FunctionTemplate::New(ExecCommand); + if (name->Equals(v8::String::New("OverridePreference"))) + return v8::FunctionTemplate::New(OverridePreference); if (name->Equals(v8::String::New("GetGlobalFlag"))) return v8::FunctionTemplate::New(GetGlobalFlag); if (name->Equals(v8::String::New("SetGlobalFlag"))) diff --git a/webkit/glue/webpreferences.cc b/webkit/glue/webpreferences.cc index 93a87bdc7e92..ac59a21abc9a 100644 --- a/webkit/glue/webpreferences.cc +++ b/webkit/glue/webpreferences.cc @@ -56,6 +56,7 @@ WebPreferences::WebPreferences() java_enabled(true), allow_scripts_to_close_windows(false), uses_page_cache(false), + page_cache_supports_plugins(false), remote_fonts_enabled(true), javascript_can_access_clipboard(false), xss_auditor_enabled(true), @@ -123,6 +124,7 @@ WebPreferences::WebPreferences() fixed_position_creates_stacking_context(false), sync_xhr_in_documents_enabled(true), deferred_image_decoding_enabled(false), + should_respect_image_orientation(false), number_of_cpu_cores(1), #if defined(OS_MACOSX) editing_behavior(EDITING_BEHAVIOR_MAC), @@ -133,14 +135,14 @@ WebPreferences::WebPreferences() #else editing_behavior(EDITING_BEHAVIOR_MAC), #endif + supports_multiple_windows(true), cookie_enabled(true) #if defined(OS_ANDROID) , text_autosizing_enabled(true), font_scale_factor(1.0f), force_enable_zoom(false), - user_gesture_required_for_media_playback(true), - supports_multiple_windows(true) + user_gesture_required_for_media_playback(true) #endif { standard_font_family_map[kCommonScript] = @@ -291,6 +293,7 @@ void WebPreferences::Apply(WebView* web_view) const { settings->setUserStyleSheetLocation(WebURL()); settings->setAuthorAndUserStylesEnabled(author_and_user_styles_enabled); settings->setUsesPageCache(uses_page_cache); + settings->setPageCacheSupportsPlugins(page_cache_supports_plugins); settings->setDownloadableBinaryFontsEnabled(remote_fonts_enabled); settings->setJavaScriptCanAccessClipboard(javascript_can_access_clipboard); settings->setXSSAuditorEnabled(xss_auditor_enabled); @@ -456,10 +459,13 @@ void WebPreferences::Apply(WebView* web_view) const { fixed_position_creates_stacking_context); settings->setDeferredImageDecodingEnabled(deferred_image_decoding_enabled); + settings->setShouldRespectImageOrientation(should_respect_image_orientation); settings->setEditingBehavior( static_cast(editing_behavior)); + settings->setSupportsMultipleWindows(supports_multiple_windows); + #if defined(OS_ANDROID) settings->setAllowCustomScrollbarInMainFrame(false); settings->setTextAutosizingEnabled(text_autosizing_enabled); @@ -469,7 +475,6 @@ void WebPreferences::Apply(WebView* web_view) const { settings->setDoubleTapToZoomEnabled(true); settings->setMediaPlaybackRequiresUserGesture( user_gesture_required_for_media_playback); - settings->setSupportsMultipleWindows(supports_multiple_windows); #endif WebNetworkStateNotifier::setOnLine(is_online); diff --git a/webkit/glue/webpreferences.h b/webkit/glue/webpreferences.h index b99873f151d4..f50734b6c7f6 100644 --- a/webkit/glue/webpreferences.h +++ b/webkit/glue/webpreferences.h @@ -75,6 +75,7 @@ struct WEBKIT_GLUE_EXPORT WebPreferences { bool java_enabled; bool allow_scripts_to_close_windows; bool uses_page_cache; + bool page_cache_supports_plugins; bool remote_fonts_enabled; bool javascript_can_access_clipboard; bool xss_auditor_enabled; @@ -146,8 +147,10 @@ struct WEBKIT_GLUE_EXPORT WebPreferences { bool fixed_position_creates_stacking_context; bool sync_xhr_in_documents_enabled; bool deferred_image_decoding_enabled; + bool should_respect_image_orientation; int number_of_cpu_cores; EditingBehavior editing_behavior; + bool supports_multiple_windows; // This flags corresponds to a Page's Settings' setCookieEnabled state. It // only controls whether or not the "document.cookie" field is properly @@ -161,7 +164,6 @@ struct WEBKIT_GLUE_EXPORT WebPreferences { float font_scale_factor; bool force_enable_zoom; bool user_gesture_required_for_media_playback; - bool supports_multiple_windows; #endif // We try to keep the default values the same as the default values in -- 2.11.4.GIT