diff options
author | oshima <oshima@chromium.org> | 2015-12-16 14:40:16 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-16 22:42:16 +0000 |
commit | 76ebe14aeee04f02c62273c638e110f621c162aa (patch) | |
tree | 88fe36d76b45deb111199594f92b9f7d167581c4 | |
parent | 3b4338fc32cf20703baa8066bdad7ce07c5ae696 (diff) | |
download | chromium_src-76ebe14aeee04f02c62273c638e110f621c162aa.zip chromium_src-76ebe14aeee04f02c62273c638e110f621c162aa.tar.gz chromium_src-76ebe14aeee04f02c62273c638e110f621c162aa.tar.bz2 |
Support device scale factor test with popups in LayoutTest
* Sends DSF to host so that host can send a resize request with requested DSF.
* Updated X11's screen so that displays contains specified DSF.
This is used by RWH to construct WebScreenInfo with updated DSF.
- Win/Mac will use the DSF specified by command line flag.
* Scale the popup location based on the device scale factor.
This is done by compositor in normal scenario.
BUG=567837
TEST=added popu-menu-appearance-dsf2.html
Review URL: https://codereview.chromium.org/1525933002
Cr-Commit-Position: refs/heads/master@{#365647}
16 files changed, 132 insertions, 3 deletions
diff --git a/components/html_viewer/web_test_delegate_impl.cc b/components/html_viewer/web_test_delegate_impl.cc index 9aba1a6..1645fd0 100644 --- a/components/html_viewer/web_test_delegate_impl.cc +++ b/components/html_viewer/web_test_delegate_impl.cc @@ -358,4 +358,10 @@ void WebTestDelegateImpl::OnWebTestProxyBaseDestroy( test_runner::WebTestProxyBase* base) { } +blink::WebPoint WebTestDelegateImpl::ConvertDIPToNative( + const blink::WebPoint& point_in_dip) const { + NOTIMPLEMENTED(); + return point_in_dip; +} + } // namespace html_viewer diff --git a/components/html_viewer/web_test_delegate_impl.h b/components/html_viewer/web_test_delegate_impl.h index 3bbb264..1debfeb 100644 --- a/components/html_viewer/web_test_delegate_impl.h +++ b/components/html_viewer/web_test_delegate_impl.h @@ -124,6 +124,8 @@ class WebTestDelegateImpl : public test_runner::WebTestDelegate { blink::WebLocalFrame* frame, const blink::WebPluginParams& params) override; void OnWebTestProxyBaseDestroy(test_runner::WebTestProxyBase* base) override; + blink::WebPoint ConvertDIPToNative( + const blink::WebPoint& point_in_dip) const override; // Must not be constructed until after blink has been initialized. scoped_ptr<test_runner::TestPreferences> prefs_; diff --git a/components/test_runner/web_test_delegate.h b/components/test_runner/web_test_delegate.h index 753831d..d9881f6 100644 --- a/components/test_runner/web_test_delegate.h +++ b/components/test_runner/web_test_delegate.h @@ -30,6 +30,7 @@ class WebLocalFrame; class WebMediaStream; class WebPlugin; struct WebPluginParams; +struct WebPoint; struct WebRect; struct WebSize; struct WebURLError; @@ -280,6 +281,10 @@ class WebTestDelegate { const blink::WebPluginParams& params) = 0; virtual void OnWebTestProxyBaseDestroy(WebTestProxyBase* proxy) = 0; + + // Convert the position in DIP to native coordinates. + virtual blink::WebPoint ConvertDIPToNative( + const blink::WebPoint& point_in_dip) const = 0; }; } // namespace test_runner diff --git a/components/test_runner/web_test_proxy.cc b/components/test_runner/web_test_proxy.cc index 44a1fc9..90c6c46 100644 --- a/components/test_runner/web_test_proxy.cc +++ b/components/test_runner/web_test_proxy.cc @@ -670,7 +670,8 @@ void WebTestProxyBase::CapturePixelsAsync( web_widget_->compositeAndReadbackAsync(capture_callback); if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { capture_callback->set_wait_for_popup(true); - capture_callback->set_popup_position(popup->positionRelativeToOwner()); + capture_callback->set_popup_position( + delegate_->ConvertDIPToNative(popup->positionRelativeToOwner())); popup->compositeAndReadbackAsync(capture_callback); } } diff --git a/content/shell/browser/blink_test_controller.cc b/content/shell/browser/blink_test_controller.cc index 7b55670..c34a716 100644 --- a/content/shell/browser/blink_test_controller.cc +++ b/content/shell/browser/blink_test_controller.cc @@ -413,6 +413,8 @@ bool BlinkTestController::OnMessageReceived(const IPC::Message& message) { OnGetBluetoothManualChooserEvents) IPC_MESSAGE_HANDLER(ShellViewHostMsg_SendBluetoothManualChooserEvent, OnSendBluetoothManualChooserEvent) + IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetDeviceScaleFactor, + OnSetDeviceScaleFactor) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -772,4 +774,8 @@ void BlinkTestController::OnSendBluetoothManualChooserEvent( bluetooth_chooser_factory_->SendEvent(event, argument); } +void BlinkTestController::OnSetDeviceScaleFactor(float scale) { + main_window_->SetDeviceScaleFactor(scale); +} + } // namespace content diff --git a/content/shell/browser/blink_test_controller.h b/content/shell/browser/blink_test_controller.h index 4f36c03..cb1b06e 100644 --- a/content/shell/browser/blink_test_controller.h +++ b/content/shell/browser/blink_test_controller.h @@ -186,6 +186,7 @@ class BlinkTestController : public base::NonThreadSafe, void OnGetBluetoothManualChooserEvents(); void OnSendBluetoothManualChooserEvent(const std::string& event, const std::string& argument); + void OnSetDeviceScaleFactor(float scale); scoped_ptr<BlinkTestResultPrinter> printer_; diff --git a/content/shell/browser/shell.cc b/content/shell/browser/shell.cc index 12fde0b..de63272 100644 --- a/content/shell/browser/shell.cc +++ b/content/shell/browser/shell.cc @@ -18,6 +18,7 @@ #include "content/public/browser/navigation_entry.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_widget_host.h" +#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/content_switches.h" @@ -34,6 +35,12 @@ #include "content/shell/browser/shell_javascript_dialog_manager.h" #include "content/shell/common/shell_messages.h" #include "content/shell/common/shell_switches.h" +#include "ui/gfx/display.h" +#include "ui/gfx/switches.h" + +#if defined(USE_X11) && !defined(OS_CHROMEOS) +#include "ui/views/widget/desktop_aura/desktop_screen_x11.h" +#endif namespace content { @@ -383,6 +390,19 @@ bool Shell::HandleContextMenu(const content::ContextMenuParams& params) { return PlatformHandleContextMenu(params); } +void Shell::SetDeviceScaleFactor(float scale) { +#if !defined(OS_CHROMEOS) + gfx::Display::ResetForceDeviceScaleFactorForTesting(); + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kForceDeviceScaleFactor, base::StringPrintf("%f", scale)); +#if defined(USE_X11) + views::DesktopScreenX11::UpdateDeviceScaleFactorForTest(); +#endif +#endif + RenderWidgetHostView* host_view = web_contents_->GetRenderWidgetHostView(); + host_view->SetSize(host_view->GetViewBounds().size()); +} + gfx::Size Shell::GetShellDefaultSize() { static gfx::Size default_shell_size; if (!default_shell_size.IsEmpty()) diff --git a/content/shell/browser/shell.h b/content/shell/browser/shell.h index 4ca03f9..e21370b 100644 --- a/content/shell/browser/shell.h +++ b/content/shell/browser/shell.h @@ -150,6 +150,8 @@ class Shell : public WebContentsDelegate, void ActivateContents(WebContents* contents) override; bool HandleContextMenu(const content::ContextMenuParams& params) override; + void SetDeviceScaleFactor(float scale); + static gfx::Size GetShellDefaultSize(); private: diff --git a/content/shell/renderer/layout_test/blink_test_runner.cc b/content/shell/renderer/layout_test/blink_test_runner.cc index 583745c..c3a2eb5 100644 --- a/content/shell/renderer/layout_test/blink_test_runner.cc +++ b/content/shell/renderer/layout_test/blink_test_runner.cc @@ -32,6 +32,7 @@ #include "components/test_runner/web_test_interfaces.h" #include "components/test_runner/web_test_proxy.h" #include "components/test_runner/web_test_runner.h" +#include "content/common/content_switches_internal.h" #include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" #include "content/public/common/web_preferences.h" @@ -265,8 +266,8 @@ BlinkTestRunner::BlinkTestRunner(RenderView* render_view) focused_view_(NULL), is_main_window_(false), focus_on_next_commit_(false), - leak_detector_(new LeakDetector(this)) { -} + leak_detector_(new LeakDetector(this)), + device_scale_factor_(1.f) {} BlinkTestRunner::~BlinkTestRunner() { } @@ -512,7 +513,11 @@ void BlinkTestRunner::SimulateWebNotificationClick(const std::string& title, } void BlinkTestRunner::SetDeviceScaleFactor(float factor) { + if (device_scale_factor_ == factor) + return; + device_scale_factor_ = factor; content::SetDeviceScaleFactor(render_view(), factor); + Send(new ShellViewHostMsg_SetDeviceScaleFactor(routing_id(), factor)); } void BlinkTestRunner::SetDeviceColorProfile(const std::string& name) { @@ -760,6 +765,11 @@ void BlinkTestRunner::OnWebTestProxyBaseDestroy( test_runner::WebTestProxyBase* proxy) { } +blink::WebPoint BlinkTestRunner::ConvertDIPToNative( + const blink::WebPoint& point_in_dip) const { + return blink::WebPoint(point_in_dip.x * device_scale_factor_, + point_in_dip.y * device_scale_factor_); +} bool BlinkTestRunner::AddMediaStreamVideoSourceAndTrack( blink::WebMediaStream* stream) { DCHECK(stream); diff --git a/content/shell/renderer/layout_test/blink_test_runner.h b/content/shell/renderer/layout_test/blink_test_runner.h index 9e0f053..b5369dc 100644 --- a/content/shell/renderer/layout_test/blink_test_runner.h +++ b/content/shell/renderer/layout_test/blink_test_runner.h @@ -149,6 +149,8 @@ class BlinkTestRunner : public RenderViewObserver, blink::WebLocalFrame* frame, const blink::WebPluginParams& params) override; void OnWebTestProxyBaseDestroy(test_runner::WebTestProxyBase* proxy) override; + blink::WebPoint ConvertDIPToNative( + const blink::WebPoint& point_in_dip) const override; void Reset(); @@ -198,6 +200,8 @@ class BlinkTestRunner : public RenderViewObserver, scoped_ptr<LeakDetector> leak_detector_; bool needs_leak_detector_; + float device_scale_factor_; + DISALLOW_COPY_AND_ASSIGN(BlinkTestRunner); }; diff --git a/third_party/WebKit/LayoutTests/TestExpectations b/third_party/WebKit/LayoutTests/TestExpectations index 3fe8de2..444a684 100644 --- a/third_party/WebKit/LayoutTests/TestExpectations +++ b/third_party/WebKit/LayoutTests/TestExpectations @@ -235,6 +235,8 @@ crbug.com/542541 [ Debug ] fast/events/click-count.html [ Pass Failure ] crbug.com/542541 [ Debug ] virtual/trustedeventsdefaultaction/fast/events/click-count.html [ Pass Failure ] crbug.com/542541 [ Debug ] virtual/pointerevent/fast/events/click-count.html [ Pass Failure ] +crbug.com/495750 fast/hidpi/popup-menu-appearance-dsf2.html [ NeedsRebaseline ] + # TODO(ojan): These tests aren't flaky. See crbug.com/517144. # Release trybots run asserts, but the main waterfall ones don't. So, even # though this is a non-flaky assert failure, we need to mark it [ Pass Crash ]. diff --git a/third_party/WebKit/LayoutTests/fast/hidpi/popup-menu-appearance-dsf2.html b/third_party/WebKit/LayoutTests/fast/hidpi/popup-menu-appearance-dsf2.html new file mode 100644 index 0000000..ecd67c2 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/hidpi/popup-menu-appearance-dsf2.html @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<html> +<head> +<script> + window.enablePixelTesting = true; + function startTest() { + if (window.testRunner) { + testRunner.setBackingScaleFactor(2.0, function() {}); + } + } + window.matchMedia('screen and (min-resolution: 2dppx)'). + addListener(function(e) { + if (e.matches) { + openMenu(); + } + }); + + function openMenu() { + openPicker(menu, done, function () { + testFailed('picker didn\'t open') + finishJSTest(); + }); + } + function done() { + finishJSTest(); + } +</script> +<script src="../../resources/js-test.js"></script> +<script src="../forms/resources/picker-common.js"></script> +</head> +<body onLoad="startTest()"> +<p>The font size in the popup should be same as the font size of the SELECT element except the third OPTION.</p> +<select id="menu"> + <option>foo</option> + <option selected>bar</option> + <option hidden>qux</option> + <option>baz</option> + <optgroup label="Group"> + <option>foo</option> + <option>bar</option> + </optgroup> +</select> +<p id="description" style="opacity: 0"></p> +select<sediv id="console" style="opacity: 0"></div> +<script> +</script> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/platform/linux/fast/hidpi/popup-menu-appearance-dsf2-expected.png b/third_party/WebKit/LayoutTests/platform/linux/fast/hidpi/popup-menu-appearance-dsf2-expected.png Binary files differnew file mode 100644 index 0000000..54eec95 --- /dev/null +++ b/third_party/WebKit/LayoutTests/platform/linux/fast/hidpi/popup-menu-appearance-dsf2-expected.png diff --git a/third_party/WebKit/LayoutTests/platform/linux/fast/hidpi/popup-menu-appearance-dsf2-expected.txt b/third_party/WebKit/LayoutTests/platform/linux/fast/hidpi/popup-menu-appearance-dsf2-expected.txt new file mode 100644 index 0000000..5a520ce --- /dev/null +++ b/third_party/WebKit/LayoutTests/platform/linux/fast/hidpi/popup-menu-appearance-dsf2-expected.txt @@ -0,0 +1,11 @@ +The font size in the popup should be same as the font size of the SELECT element except the third OPTION. + + +select + + + +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/ui/views/widget/desktop_aura/desktop_screen_x11.cc b/ui/views/widget/desktop_aura/desktop_screen_x11.cc index 2214654..7486332 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_x11.cc +++ b/ui/views/widget/desktop_aura/desktop_screen_x11.cc @@ -10,7 +10,9 @@ // It clashes with out RootWindow. #undef RootWindow +#include "base/command_line.h" #include "base/logging.h" +#include "base/strings/stringprintf.h" #include "base/trace_event/trace_event.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" @@ -252,6 +254,13 @@ uint32_t DesktopScreenX11::DispatchEvent(const ui::PlatformEvent& event) { return ui::POST_DISPATCH_NONE; } +// static +void DesktopScreenX11::UpdateDeviceScaleFactorForTest() { + DesktopScreenX11* screen = + static_cast<DesktopScreenX11*>(gfx::Screen::GetNativeScreen()); + screen->ConfigureTimerFired(); +} + //////////////////////////////////////////////////////////////////////////////// // DesktopScreenX11, private: diff --git a/ui/views/widget/desktop_aura/desktop_screen_x11.h b/ui/views/widget/desktop_aura/desktop_screen_x11.h index 4466ba4..38f4036 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_x11.h +++ b/ui/views/widget/desktop_aura/desktop_screen_x11.h @@ -47,6 +47,8 @@ class VIEWS_EXPORT DesktopScreenX11 : public gfx::Screen, bool CanDispatchEvent(const ui::PlatformEvent& event) override; uint32_t DispatchEvent(const ui::PlatformEvent& event) override; + static void UpdateDeviceScaleFactorForTest(); + private: friend class DesktopScreenX11Test; |