| Index: services/ui/ws/display_unittest.cc
|
| diff --git a/services/ui/ws/display_unittest.cc b/services/ui/ws/display_unittest.cc
|
| index 7876deb867596a1c6888eb86bf5719b2fd47a22b..1d6ff44b100d873db546248f339596eef69b07f1 100644
|
| --- a/services/ui/ws/display_unittest.cc
|
| +++ b/services/ui/ws/display_unittest.cc
|
| @@ -10,6 +10,7 @@
|
| #include "base/message_loop/message_loop.h"
|
| #include "services/ui/common/types.h"
|
| #include "services/ui/common/util.h"
|
| +#include "services/ui/display/viewport_metrics.h"
|
| #include "services/ui/public/interfaces/window_tree.mojom.h"
|
| #include "services/ui/surfaces/display_compositor.h"
|
| #include "services/ui/ws/display_manager.h"
|
| @@ -28,6 +29,8 @@
|
| #include "ui/events/event.h"
|
| #include "ui/gfx/geometry/rect.h"
|
|
|
| +using display::ViewportMetrics;
|
| +
|
| namespace ui {
|
| namespace ws {
|
| namespace test {
|
| @@ -49,6 +52,42 @@ WindowManagerState* GetWindowManagerStateForUser(Display* display,
|
| return display_root ? display_root->window_manager_state() : nullptr;
|
| }
|
|
|
| +// Returns the root ServerWindow for the specified Display.
|
| +ServerWindow* GetRootOnDisplay(WindowTree* tree, Display* display) {
|
| + for (const ServerWindow* root : tree->roots()) {
|
| + if (tree->GetDisplay(root) == display)
|
| + return const_cast<ServerWindow*>(root);
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| +// Tracks destruction of a ServerWindow, setting a bool* to true when
|
| +// OnWindowDestroyed() is called
|
| +class ServerWindowDestructionObserver : public ServerWindowObserver {
|
| + public:
|
| + ServerWindowDestructionObserver(ServerWindow* window, bool* destroyed)
|
| + : window_(window), destroyed_(destroyed) {
|
| + window_->AddObserver(this);
|
| + }
|
| + ~ServerWindowDestructionObserver() override {
|
| + if (window_)
|
| + window_->RemoveObserver(this);
|
| + }
|
| +
|
| + // ServerWindowObserver:
|
| + void OnWindowDestroyed(ServerWindow* window) override {
|
| + *destroyed_ = true;
|
| + window_->RemoveObserver(this);
|
| + window_ = nullptr;
|
| + }
|
| +
|
| + private:
|
| + ServerWindow* window_;
|
| + bool* destroyed_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ServerWindowDestructionObserver);
|
| +};
|
| +
|
| } // namespace
|
|
|
| // -----------------------------------------------------------------------------
|
| @@ -59,66 +98,133 @@ class DisplayTest : public testing::Test {
|
| ~DisplayTest() override {}
|
|
|
| WindowServer* window_server() { return ws_test_helper_.window_server(); }
|
| + DisplayManager* display_manager() {
|
| + return window_server()->display_manager();
|
| + }
|
| TestWindowServerDelegate* window_server_delegate() {
|
| return ws_test_helper_.window_server_delegate();
|
| }
|
| + TestPlatformScreen& platform_screen() { return platform_screen_; }
|
|
|
| protected:
|
| // testing::Test:
|
| void SetUp() override {
|
| + platform_screen_.Init(window_server()->display_manager());
|
| window_server()->user_id_tracker()->AddUserId(kTestId1);
|
| window_server()->user_id_tracker()->AddUserId(kTestId2);
|
| }
|
|
|
| private:
|
| WindowServerTestHelper ws_test_helper_;
|
| + TestPlatformScreen platform_screen_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(DisplayTest);
|
| };
|
|
|
| -TEST_F(DisplayTest, CallsCreateDefaultDisplays) {
|
| - const int kNumHostsToCreate = 2;
|
| - window_server_delegate()->CreateDisplays(kNumHostsToCreate);
|
| +TEST_F(DisplayTest, CreateDisplay) {
|
| + AddWindowManager(window_server(), kTestId1);
|
| + const int64_t display_id =
|
| + platform_screen().AddDisplay(MakeViewportMetrics(0, 0, 1024, 768, 1.0f));
|
| +
|
| + ASSERT_EQ(1u, display_manager()->displays().size());
|
| + Display* display = display_manager()->GetDisplayById(display_id);
|
| +
|
| + // Display should have root window with correct size.
|
| + ASSERT_NE(nullptr, display->root_window());
|
| + EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString());
|
| +
|
| + // Display should have a WM root window with the correct size too.
|
| + EXPECT_EQ(1u, display->num_window_manger_states());
|
| + WindowManagerDisplayRoot* root1 =
|
| + display->GetWindowManagerDisplayRootForUser(kTestId1);
|
| + ASSERT_NE(nullptr, root1);
|
| + ASSERT_NE(nullptr, root1->root());
|
| + EXPECT_EQ("0,0 1024x768", root1->root()->bounds().ToString());
|
| +}
|
| +
|
| +TEST_F(DisplayTest, CreateDisplayBeforeWM) {
|
| + // Add one display, no WM exists yet.
|
| + const int64_t display_id =
|
| + platform_screen().AddDisplay(MakeViewportMetrics(0, 0, 1024, 768, 1.0f));
|
| + EXPECT_EQ(1u, display_manager()->displays().size());
|
| +
|
| + Display* display = display_manager()->GetDisplayById(display_id);
|
| +
|
| + // Display should have root window with correct size.
|
| + ASSERT_NE(nullptr, display->root_window());
|
| + EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString());
|
| +
|
| + // There should be no WM state for display yet.
|
| + EXPECT_EQ(0u, display->num_window_manger_states());
|
| + EXPECT_EQ(nullptr, display->GetWindowManagerDisplayRootForUser(kTestId1));
|
|
|
| - DisplayManager* display_manager = window_server()->display_manager();
|
| AddWindowManager(window_server(), kTestId1);
|
| - // The first register should trigger creation of the default
|
| - // Displays. There should be kNumHostsToCreate Displays.
|
| - EXPECT_EQ(static_cast<size_t>(kNumHostsToCreate),
|
| - display_manager->displays().size());
|
| -
|
| - // Each host should have a WindowManagerState for kTestId1.
|
| - for (Display* display : display_manager->displays()) {
|
| - EXPECT_EQ(1u, display->num_window_manger_states());
|
| - EXPECT_TRUE(GetWindowManagerStateForUser(display, kTestId1));
|
| - EXPECT_FALSE(GetWindowManagerStateForUser(display, kTestId2));
|
| - }
|
|
|
| - // Add another registry, should trigger creation of another wm.
|
| + // After adding a WM display should have WM state and WM root for the display.
|
| + EXPECT_EQ(1u, display->num_window_manger_states());
|
| + WindowManagerDisplayRoot* root1 =
|
| + display->GetWindowManagerDisplayRootForUser(kTestId1);
|
| + ASSERT_NE(nullptr, root1);
|
| + ASSERT_NE(nullptr, root1->root());
|
| + EXPECT_EQ("0,0 1024x768", root1->root()->bounds().ToString());
|
| +}
|
| +
|
| +TEST_F(DisplayTest, CreateDisplayWithTwoWindowManagers) {
|
| + AddWindowManager(window_server(), kTestId1);
|
| + const int64_t display_id = platform_screen().AddDisplay();
|
| + Display* display = display_manager()->GetDisplayById(display_id);
|
| +
|
| + // There should be only be one WM at this point.
|
| + ASSERT_EQ(1u, display->num_window_manger_states());
|
| + EXPECT_NE(nullptr, display->GetWindowManagerDisplayRootForUser(kTestId1));
|
| + EXPECT_EQ(nullptr, display->GetWindowManagerDisplayRootForUser(kTestId2));
|
| +
|
| AddWindowManager(window_server(), kTestId2);
|
| - for (Display* display : display_manager->displays()) {
|
| - ASSERT_EQ(2u, display->num_window_manger_states());
|
| - WindowManagerDisplayRoot* root1 =
|
| - display->GetWindowManagerDisplayRootForUser(kTestId1);
|
| - ASSERT_TRUE(root1);
|
| - WindowManagerDisplayRoot* root2 =
|
| - display->GetWindowManagerDisplayRootForUser(kTestId2);
|
| - ASSERT_TRUE(root2);
|
| - // Verify the two states have different roots.
|
| - EXPECT_NE(root1, root2);
|
| - EXPECT_NE(root1->root(), root2->root());
|
| - }
|
| +
|
| + // There should now be two WMs.
|
| + ASSERT_EQ(2u, display->num_window_manger_states());
|
| + WindowManagerDisplayRoot* root1 =
|
| + display->GetWindowManagerDisplayRootForUser(kTestId1);
|
| + ASSERT_NE(nullptr, root1);
|
| + WindowManagerDisplayRoot* root2 =
|
| + display->GetWindowManagerDisplayRootForUser(kTestId2);
|
| + ASSERT_NE(nullptr, root2);
|
| +
|
| + // Verify the two WMs have different roots but with the same bounds.
|
| + EXPECT_NE(root1, root2);
|
| + EXPECT_NE(root1->root(), root2->root());
|
| + EXPECT_EQ(root1->root()->bounds(), root2->root()->bounds());
|
| }
|
|
|
| -TEST_F(DisplayTest, Destruction) {
|
| - window_server_delegate()->CreateDisplays(1);
|
| +TEST_F(DisplayTest, CreateDisplayWithDeviceScaleFactor) {
|
| + // The display bounds should be the pixel_size / device_scale_factor.
|
| + const ViewportMetrics metrics = MakeViewportMetrics(0, 0, 1024, 768, 2.0f);
|
| + EXPECT_EQ("0,0 512x384", metrics.bounds.ToString());
|
| + EXPECT_EQ("1024x768", metrics.pixel_size.ToString());
|
| +
|
| + const int64_t display_id = platform_screen().AddDisplay(metrics);
|
| + Display* display = display_manager()->GetDisplayById(display_id);
|
| +
|
| + // The root ServerWindow bounds should be in PP.
|
| + EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString());
|
| +
|
| + ViewportMetrics modified_metrics = metrics;
|
| + modified_metrics.work_area.set_height(metrics.work_area.height() - 48);
|
| + platform_screen().ModifyDisplay(display_id, modified_metrics);
|
| +
|
| + // The root ServerWindow should still be in PP after updating the work area.
|
| + EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString());
|
| +}
|
|
|
| +TEST_F(DisplayTest, Destruction) {
|
| AddWindowManager(window_server(), kTestId1);
|
|
|
| - // Add another registry, should trigger creation of another wm.
|
| - DisplayManager* display_manager = window_server()->display_manager();
|
| + int64_t display_id = platform_screen().AddDisplay();
|
| +
|
| + // Add a second WM.
|
| AddWindowManager(window_server(), kTestId2);
|
| - ASSERT_EQ(1u, display_manager->displays().size());
|
| - Display* display = *display_manager->displays().begin();
|
| + ASSERT_EQ(1u, display_manager()->displays().size());
|
| + Display* display = display_manager()->GetDisplayById(display_id);
|
| ASSERT_EQ(2u, display->num_window_manger_states());
|
| // There should be two trees, one for each windowmanager.
|
| EXPECT_EQ(2u, window_server()->num_trees());
|
| @@ -130,28 +236,27 @@ TEST_F(DisplayTest, Destruction) {
|
| window_server()->DestroyTree(state->window_tree());
|
| ASSERT_EQ(1u, display->num_window_manger_states());
|
| EXPECT_FALSE(GetWindowManagerStateForUser(display, kTestId1));
|
| - EXPECT_EQ(1u, display_manager->displays().size());
|
| + EXPECT_EQ(1u, display_manager()->displays().size());
|
| EXPECT_EQ(1u, window_server()->num_trees());
|
| }
|
|
|
| EXPECT_FALSE(window_server_delegate()->got_on_no_more_displays());
|
| - window_server()->display_manager()->DestroyDisplay(display);
|
| + platform_screen().RemoveDisplay(display_id);
|
| // There is still one tree left.
|
| EXPECT_EQ(1u, window_server()->num_trees());
|
| EXPECT_TRUE(window_server_delegate()->got_on_no_more_displays());
|
| }
|
|
|
| TEST_F(DisplayTest, EventStateResetOnUserSwitch) {
|
| - window_server_delegate()->CreateDisplays(1);
|
| + const int64_t display_id = platform_screen().AddDisplay();
|
|
|
| AddWindowManager(window_server(), kTestId1);
|
| AddWindowManager(window_server(), kTestId2);
|
|
|
| window_server()->user_id_tracker()->SetActiveUserId(kTestId1);
|
|
|
| - DisplayManager* display_manager = window_server()->display_manager();
|
| - ASSERT_EQ(1u, display_manager->displays().size());
|
| - Display* display = *display_manager->displays().begin();
|
| + ASSERT_EQ(1u, display_manager()->displays().size());
|
| + Display* display = display_manager()->GetDisplayById(display_id);
|
| WindowManagerState* active_wms =
|
| display->GetActiveWindowManagerDisplayRoot()->window_manager_state();
|
| ASSERT_TRUE(active_wms);
|
| @@ -186,13 +291,12 @@ TEST_F(DisplayTest, EventStateResetOnUserSwitch) {
|
|
|
| // Verifies capture fails when wm is inactive and succeeds when wm is active.
|
| TEST_F(DisplayTest, SetCaptureFromWindowManager) {
|
| - window_server_delegate()->CreateDisplays(1);
|
| + const int64_t display_id = platform_screen().AddDisplay();
|
| AddWindowManager(window_server(), kTestId1);
|
| AddWindowManager(window_server(), kTestId2);
|
| window_server()->user_id_tracker()->SetActiveUserId(kTestId1);
|
| - DisplayManager* display_manager = window_server()->display_manager();
|
| - ASSERT_EQ(1u, display_manager->displays().size());
|
| - Display* display = *display_manager->displays().begin();
|
| + ASSERT_EQ(1u, display_manager()->displays().size());
|
| + Display* display = display_manager()->GetDisplayById(display_id);
|
| WindowManagerState* wms_for_id2 =
|
| GetWindowManagerStateForUser(display, kTestId2);
|
| ASSERT_TRUE(wms_for_id2);
|
| @@ -215,16 +319,15 @@ TEST_F(DisplayTest, SetCaptureFromWindowManager) {
|
| }
|
|
|
| TEST_F(DisplayTest, FocusFailsForInactiveUser) {
|
| - window_server_delegate()->CreateDisplays(1);
|
| + const int64_t display_id = platform_screen().AddDisplay();
|
| AddWindowManager(window_server(), kTestId1);
|
| TestWindowTreeClient* window_tree_client1 =
|
| window_server_delegate()->last_client();
|
| ASSERT_TRUE(window_tree_client1);
|
| AddWindowManager(window_server(), kTestId2);
|
| window_server()->user_id_tracker()->SetActiveUserId(kTestId1);
|
| - DisplayManager* display_manager = window_server()->display_manager();
|
| - ASSERT_EQ(1u, display_manager->displays().size());
|
| - Display* display = *display_manager->displays().begin();
|
| + ASSERT_EQ(1u, display_manager()->displays().size());
|
| + Display* display = display_manager()->GetDisplayById(display_id);
|
| WindowManagerState* wms_for_id2 =
|
| GetWindowManagerStateForUser(display, kTestId2);
|
| wms_for_id2->window_tree()->AddActivationParent(
|
| @@ -251,7 +354,8 @@ TEST_F(DisplayTest, FocusFailsForInactiveUser) {
|
|
|
| // Verifies a single tree is used for multiple displays.
|
| TEST_F(DisplayTest, MultipleDisplays) {
|
| - window_server_delegate()->CreateDisplays(2);
|
| + platform_screen().AddDisplay();
|
| + platform_screen().AddDisplay();
|
| AddWindowManager(window_server(), kTestId1);
|
| window_server()->user_id_tracker()->SetActiveUserId(kTestId1);
|
| ASSERT_EQ(1u, window_server_delegate()->bindings()->size());
|
| @@ -276,65 +380,17 @@ TEST_F(DisplayTest, MultipleDisplays) {
|
| EXPECT_EQ(display1_wms->window_tree(), display2_wms->window_tree());
|
| }
|
|
|
| -namespace {
|
| -
|
| -// Returns the first non-primary display.
|
| -Display* GetSecondaryDisplay(DisplayManager* display_manager) {
|
| - for (Display* display : display_manager->displays()) {
|
| - if (!display->platform_display()->IsPrimaryDisplay())
|
| - return display;
|
| - }
|
| - return nullptr;
|
| -}
|
| -
|
| -// Returns the root ServerWindow for the specified Display.
|
| -ServerWindow* GetRootOnDisplay(WindowTree* tree, Display* display) {
|
| - for (const ServerWindow* root : tree->roots()) {
|
| - if (tree->GetDisplay(root) == display)
|
| - return const_cast<ServerWindow*>(root);
|
| - }
|
| - return nullptr;
|
| -}
|
| -
|
| -// Tracks destruction of a ServerWindow, setting a bool* to true when
|
| -// OnWindowDestroyed() is called
|
| -class ServerWindowDestructionObserver : public ServerWindowObserver {
|
| - public:
|
| - ServerWindowDestructionObserver(ServerWindow* window, bool* destroyed)
|
| - : window_(window), destroyed_(destroyed) {
|
| - window_->AddObserver(this);
|
| - }
|
| - ~ServerWindowDestructionObserver() override {
|
| - if (window_)
|
| - window_->RemoveObserver(this);
|
| - }
|
| -
|
| - // ServerWindowObserver:
|
| - void OnWindowDestroyed(ServerWindow* window) override {
|
| - *destroyed_ = true;
|
| - window_->RemoveObserver(this);
|
| - window_ = nullptr;
|
| - }
|
| -
|
| - private:
|
| - ServerWindow* window_;
|
| - bool* destroyed_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(ServerWindowDestructionObserver);
|
| -};
|
| -
|
| -} // namespace
|
| -
|
| // Assertions around destroying a secondary display.
|
| TEST_F(DisplayTest, DestroyingDisplayDoesntDelete) {
|
| - window_server_delegate()->CreateDisplays(2);
|
| AddWindowManager(window_server(), kTestId1);
|
| + platform_screen().AddDisplay();
|
| + const int64_t secondary_display_id = platform_screen().AddDisplay();
|
| window_server()->user_id_tracker()->SetActiveUserId(kTestId1);
|
| ASSERT_EQ(1u, window_server_delegate()->bindings()->size());
|
| WindowTree* tree = (*window_server_delegate()->bindings())[0]->tree();
|
| ASSERT_EQ(2u, tree->roots().size());
|
| Display* secondary_display =
|
| - GetSecondaryDisplay(window_server()->display_manager());
|
| + display_manager()->GetDisplayById(secondary_display_id);
|
| ASSERT_TRUE(secondary_display);
|
| bool secondary_root_destroyed = false;
|
| ServerWindow* secondary_root = GetRootOnDisplay(tree, secondary_display);
|
| @@ -343,14 +399,13 @@ TEST_F(DisplayTest, DestroyingDisplayDoesntDelete) {
|
| &secondary_root_destroyed);
|
| ClientWindowId secondary_root_id =
|
| ClientWindowIdForWindow(tree, secondary_root);
|
| - const int64_t secondary_display_id = secondary_display->GetId();
|
| TestWindowTreeClient* tree_client =
|
| static_cast<TestWindowTreeClient*>(tree->client());
|
| tree_client->tracker()->changes()->clear();
|
| TestWindowManager* test_window_manager =
|
| window_server_delegate()->last_binding()->window_manager();
|
| EXPECT_FALSE(test_window_manager->got_display_removed());
|
| - window_server()->display_manager()->DestroyDisplay(secondary_display);
|
| + platform_screen().RemoveDisplay(secondary_display_id);
|
|
|
| // Destroying the display should result in the following:
|
| // . The WindowManager should be told it was removed with the right id.
|
|
|