Commit e2efb1be authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

ws: Add a DesktopWindowTreeHostMus test for setting bounds during init

Adds a unit test split out from https://crrev.com/c/1311080 (PS9)
Landing separately to make release branch merging easier.

Bug: 899084
Test: Automated
Change-Id: Icadd82f2490bc4f3bbbdd1c73f8cdbe584f03289
Reviewed-on: https://chromium-review.googlesource.com/c/1318363
Commit-Queue: Michael Wasserman <msw@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605623}
parent ed198292
......@@ -169,6 +169,7 @@ void TestWindowTree::SetWindowBounds(
const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
window_id_ = window_id;
last_local_surface_id_ = local_surface_id;
second_last_set_window_bounds_ = last_set_window_bounds_;
last_set_window_bounds_ = bounds;
OnChangeReceived(change_id, WindowTreeChangeType::BOUNDS);
}
......
......@@ -120,6 +120,9 @@ class TestWindowTree : public ws::mojom::WindowTree {
const gfx::Rect& last_set_window_bounds() const {
return last_set_window_bounds_;
}
const gfx::Rect& second_last_set_window_bounds() const {
return second_last_set_window_bounds_;
}
ws::Id last_not_cancelled_window_id() const {
return last_not_cancelled_window_id_;
......@@ -295,7 +298,11 @@ class TestWindowTree : public ws::mojom::WindowTree {
base::Optional<viz::LocalSurfaceId> last_local_surface_id_;
// Records the last *two* window bounds set, useful for top-level windows,
// where each client-side DesktopWindowTreeHostMus has two aura::Windows (for
// the frame and the content), and both set bounds during views::Widget::Init.
gfx::Rect last_set_window_bounds_;
gfx::Rect second_last_set_window_bounds_;
ws::Id last_not_cancelled_window_id_ = 0u;
ws::Id last_cancelled_window_id_ = 0u;
......
......@@ -4,6 +4,7 @@
#include "ui/views/mus/desktop_window_tree_host_mus.h"
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h"
#include "services/ws/test_ws/test_ws.mojom.h"
......@@ -22,10 +23,12 @@
#include "ui/aura/test/mus/test_window_tree.h"
#include "ui/aura/test/mus/window_tree_client_test_api.h"
#include "ui/aura/window.h"
#include "ui/display/display_switches.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/gestures/gesture_recognizer.h"
#include "ui/events/gestures/gesture_recognizer_observer.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/mus/mus_client.h"
#include "ui/views/mus/mus_client_test_api.h"
......@@ -412,6 +415,50 @@ TEST_F(DesktopWindowTreeHostMusTest, CreateFullscreenWidget) {
}
}
// DesktopWindowTreeHostMusTest with --force-device-scale-factor=2.
class DesktopWindowTreeHostMusTestHighDPI
: public DesktopWindowTreeHostMusTest {
public:
DesktopWindowTreeHostMusTestHighDPI() = default;
~DesktopWindowTreeHostMusTestHighDPI() override = default;
// DesktopWindowTreeHostMusTest:
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kForceDeviceScaleFactor, "2");
DesktopWindowTreeHostMusTest::SetUp();
}
private:
DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostMusTestHighDPI);
};
// Ensure menu widgets correctly scale initial bounds: http://crbug.com/899084
TEST_F(DesktopWindowTreeHostMusTestHighDPI, InitializeMenuWithDIPBounds) {
// Swap the WindowTree implementation to verify SetWindowBounds() is called
// with the correct DIP bounds, using the host's cached device_scale_factor.
aura::TestWindowTree test_window_tree;
aura::WindowTreeClientTestApi test_api(
MusClient::Get()->window_tree_client());
ws::mojom::WindowTree* old_tree = test_api.SwapTree(&test_window_tree);
Widget widget;
Widget::InitParams params(Widget::InitParams::TYPE_MENU);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(2, 4, 60, 80);
widget.Init(params);
// Check the second-last set window bounds (for the frame, not the content).
EXPECT_EQ(params.bounds, test_window_tree.second_last_set_window_bounds());
EXPECT_EQ(params.bounds, widget.GetWindowBoundsInScreen());
EXPECT_EQ(2.0f, widget.GetNativeWindow()->GetHost()->device_scale_factor());
gfx::Rect pixels(gfx::ConvertRectToPixel(2.0f, params.bounds));
EXPECT_EQ(pixels, widget.GetNativeWindow()->GetHost()->GetBoundsInPixels());
widget.CloseNow();
test_api.SwapTree(old_tree);
}
TEST_F(DesktopWindowTreeHostMusTest, GetWindowBoundsInScreen) {
ScreenMus* screen = MusClientTestApi::screen();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment