Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: services/ui/ws/window_tree_unittest.cc

Issue 2904993003: chromeos: changes how DisplayManagerObservers are notified (Closed)
Patch Set: cleanup Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/ws/window_tree.cc ('k') | ui/aura/mus/window_manager_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/ws/window_tree.h" 5 #include "services/ui/ws/window_tree.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "services/service_manager/public/interfaces/connector.mojom.h" 16 #include "services/service_manager/public/interfaces/connector.mojom.h"
17 #include "services/ui/common/task_runner_test_base.h"
16 #include "services/ui/common/types.h" 18 #include "services/ui/common/types.h"
17 #include "services/ui/common/util.h" 19 #include "services/ui/common/util.h"
18 #include "services/ui/public/interfaces/window_tree.mojom.h" 20 #include "services/ui/public/interfaces/window_tree.mojom.h"
19 #include "services/ui/ws/default_access_policy.h" 21 #include "services/ui/ws/default_access_policy.h"
20 #include "services/ui/ws/display_manager.h" 22 #include "services/ui/ws/display_manager.h"
21 #include "services/ui/ws/ids.h" 23 #include "services/ui/ws/ids.h"
22 #include "services/ui/ws/platform_display.h" 24 #include "services/ui/ws/platform_display.h"
23 #include "services/ui/ws/platform_display_factory.h" 25 #include "services/ui/ws/platform_display_factory.h"
24 #include "services/ui/ws/server_window.h" 26 #include "services/ui/ws/server_window.h"
25 #include "services/ui/ws/test_change_tracker.h" 27 #include "services/ui/ws/test_change_tracker.h"
26 #include "services/ui/ws/test_server_window_delegate.h" 28 #include "services/ui/ws/test_server_window_delegate.h"
27 #include "services/ui/ws/test_utils.h" 29 #include "services/ui/ws/test_utils.h"
30 #include "services/ui/ws/user_display_manager.h"
28 #include "services/ui/ws/window_manager_access_policy.h" 31 #include "services/ui/ws/window_manager_access_policy.h"
29 #include "services/ui/ws/window_manager_display_root.h" 32 #include "services/ui/ws/window_manager_display_root.h"
30 #include "services/ui/ws/window_server.h" 33 #include "services/ui/ws/window_server.h"
31 #include "services/ui/ws/window_server_delegate.h" 34 #include "services/ui/ws/window_server_delegate.h"
32 #include "services/ui/ws/window_tree_binding.h" 35 #include "services/ui/ws/window_tree_binding.h"
33 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
34 #include "ui/base/cursor/cursor.h" 37 #include "ui/base/cursor/cursor.h"
35 #include "ui/events/event.h" 38 #include "ui/events/event.h"
36 #include "ui/events/event_utils.h" 39 #include "ui/events/event_utils.h"
37 #include "ui/gfx/geometry/rect.h" 40 #include "ui/gfx/geometry/rect.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 static_cast<mojom::WindowManagerClient*>(tree_)->WmResponse( 117 static_cast<mojom::WindowManagerClient*>(tree_)->WmResponse(
115 change_id, true); 118 change_id, true);
116 } 119 }
117 120
118 private: 121 private:
119 WindowTree* tree_; 122 WindowTree* tree_;
120 123
121 DISALLOW_COPY_AND_ASSIGN(TestMoveLoopWindowManager); 124 DISALLOW_COPY_AND_ASSIGN(TestMoveLoopWindowManager);
122 }; 125 };
123 126
127 // This creates a WindowTree similar to how connecting via WindowTreeFactory
128 // creates a tree.
129 WindowTree* CreateTreeViaFactory(WindowServer* window_server,
130 const UserId& user_id,
131 TestWindowTreeBinding** binding) {
132 WindowTree* tree = new WindowTree(window_server, user_id, nullptr,
133 base::MakeUnique<DefaultAccessPolicy>());
134 *binding = new TestWindowTreeBinding(tree);
135 window_server->AddTree(base::WrapUnique(tree), base::WrapUnique(*binding),
136 nullptr);
137 return tree;
138 }
139
124 } // namespace 140 } // namespace
125 141
126 // ----------------------------------------------------------------------------- 142 // -----------------------------------------------------------------------------
127 143
128 class WindowTreeTest : public testing::Test { 144 class WindowTreeTest : public testing::Test {
129 public: 145 public:
130 WindowTreeTest() {} 146 WindowTreeTest() {}
131 ~WindowTreeTest() override {} 147 ~WindowTreeTest() override {}
132 148
133 ui::CursorType cursor_type() { 149 ui::CursorType cursor_type() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 189
174 // Creates a new window from wm_tree() and embeds a new client in it. 190 // Creates a new window from wm_tree() and embeds a new client in it.
175 void SetupEventTargeting(TestWindowTreeClient** out_client, 191 void SetupEventTargeting(TestWindowTreeClient** out_client,
176 WindowTree** window_tree, 192 WindowTree** window_tree,
177 ServerWindow** window); 193 ServerWindow** window);
178 194
179 // Creates a new tree as the specified user. This does what creation via 195 // Creates a new tree as the specified user. This does what creation via
180 // a WindowTreeFactory does. 196 // a WindowTreeFactory does.
181 WindowTree* CreateNewTree(const UserId& user_id, 197 WindowTree* CreateNewTree(const UserId& user_id,
182 TestWindowTreeBinding** binding) { 198 TestWindowTreeBinding** binding) {
183 WindowTree* tree = 199 return CreateTreeViaFactory(window_server(), user_id, binding);
184 new WindowTree(window_server(), user_id, nullptr,
185 base::WrapUnique(new DefaultAccessPolicy));
186 *binding = new TestWindowTreeBinding(tree);
187 window_server()->AddTree(base::WrapUnique(tree), base::WrapUnique(*binding),
188 nullptr);
189 return tree;
190 } 200 }
191 201
192 protected: 202 protected:
193 WindowEventTargetingHelper window_event_targeting_helper_; 203 WindowEventTargetingHelper window_event_targeting_helper_;
194 204
195 private: 205 private:
196 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); 206 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest);
197 }; 207 };
198 208
199 // Creates a new window in wm_tree(), adds it to the root, embeds a 209 // Creates a new window in wm_tree(), adds it to the root, embeds a
(...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 // Release the client so that it survices shutdown. 1519 // Release the client so that it survices shutdown.
1510 client = test_binding->ReleaseClient(); 1520 client = test_binding->ReleaseClient();
1511 client->tracker()->changes()->clear(); 1521 client->tracker()->changes()->clear();
1512 } 1522 }
1513 1523
1514 // Client should not have got any messages after shutdown. 1524 // Client should not have got any messages after shutdown.
1515 EXPECT_TRUE(client->tracker()->changes()->empty()); 1525 EXPECT_TRUE(client->tracker()->changes()->empty());
1516 } 1526 }
1517 1527
1518 // Used to test the window manager configured to manually create displays roots. 1528 // Used to test the window manager configured to manually create displays roots.
1519 class WindowTreeManualDisplayTest : public testing::Test { 1529 class WindowTreeManualDisplayTest : public TaskRunnerTestBase {
1520 public: 1530 public:
1521 WindowTreeManualDisplayTest() {} 1531 WindowTreeManualDisplayTest() {}
1522 ~WindowTreeManualDisplayTest() override {} 1532 ~WindowTreeManualDisplayTest() override {}
1523 1533
1524 WindowServer* window_server() { return ws_test_helper_.window_server(); } 1534 WindowServer* window_server() { return ws_test_helper_.window_server(); }
1525 DisplayManager* display_manager() { 1535 DisplayManager* display_manager() {
1526 return window_server()->display_manager(); 1536 return window_server()->display_manager();
1527 } 1537 }
1528 TestWindowServerDelegate* window_server_delegate() { 1538 TestWindowServerDelegate* window_server_delegate() {
1529 return ws_test_helper_.window_server_delegate(); 1539 return ws_test_helper_.window_server_delegate();
1530 } 1540 }
1531 TestScreenManager& screen_manager() { return screen_manager_; } 1541 TestScreenManager& screen_manager() { return screen_manager_; }
1532 1542
1533 protected: 1543 protected:
1534 // testing::Test: 1544 // testing::Test:
1535 void SetUp() override { 1545 void SetUp() override {
1546 TaskRunnerTestBase::SetUp();
1536 screen_manager_.Init(window_server()->display_manager()); 1547 screen_manager_.Init(window_server()->display_manager());
1537 window_server()->user_id_tracker()->AddUserId(kTestUserId1); 1548 window_server()->user_id_tracker()->AddUserId(kTestUserId1);
1538 } 1549 }
1539 1550
1540 private: 1551 private:
1541 WindowServerTestHelper ws_test_helper_; 1552 WindowServerTestHelper ws_test_helper_;
1542 TestScreenManager screen_manager_; 1553 TestScreenManager screen_manager_;
1543 1554
1544 DISALLOW_COPY_AND_ASSIGN(WindowTreeManualDisplayTest); 1555 DISALLOW_COPY_AND_ASSIGN(WindowTreeManualDisplayTest);
1545 }; 1556 };
1546 1557
1547 TEST_F(WindowTreeManualDisplayTest, ClientCreatesDisplayRoot) { 1558 TEST_F(WindowTreeManualDisplayTest, ClientCreatesDisplayRoot) {
1548 const bool automatically_create_display_roots = false; 1559 const bool automatically_create_display_roots = false;
1549 AddWindowManager(window_server(), kTestUserId1, 1560 AddWindowManager(window_server(), kTestUserId1,
1550 automatically_create_display_roots); 1561 automatically_create_display_roots);
1562
1551 WindowManagerState* window_manager_state = 1563 WindowManagerState* window_manager_state =
1552 window_server()->GetWindowManagerStateForUser(kTestUserId1); 1564 window_server()->GetWindowManagerStateForUser(kTestUserId1);
1553 ASSERT_TRUE(window_manager_state); 1565 ASSERT_TRUE(window_manager_state);
1554 WindowTree* window_manager_tree = window_manager_state->window_tree(); 1566 WindowTree* window_manager_tree = window_manager_state->window_tree();
1555 EXPECT_TRUE(window_manager_tree->roots().empty()); 1567 EXPECT_TRUE(window_manager_tree->roots().empty());
1556 TestWindowManager* test_window_manager = 1568 TestWindowManager* test_window_manager =
1557 window_server_delegate()->last_binding()->window_manager(); 1569 window_server_delegate()->last_binding()->window_manager();
1558 EXPECT_EQ(1, test_window_manager->connect_count()); 1570 EXPECT_EQ(1, test_window_manager->connect_count());
1559 EXPECT_EQ(0, test_window_manager->display_added_count()); 1571 EXPECT_EQ(0, test_window_manager->display_added_count());
1560 1572
(...skipping 25 matching lines...) Expand all
1586 EXPECT_EQ(1u, window_manager_tree->roots().size()); 1598 EXPECT_EQ(1u, window_manager_tree->roots().size());
1587 1599
1588 // Delete the root, which should delete the WindowManagerDisplayRoot. 1600 // Delete the root, which should delete the WindowManagerDisplayRoot.
1589 EXPECT_TRUE(window_manager_tree->DeleteWindow(display_root_id)); 1601 EXPECT_TRUE(window_manager_tree->DeleteWindow(display_root_id));
1590 EXPECT_TRUE(window_manager_tree->roots().empty()); 1602 EXPECT_TRUE(window_manager_tree->roots().empty());
1591 EXPECT_TRUE(WindowManagerStateTestApi(window_manager_state) 1603 EXPECT_TRUE(WindowManagerStateTestApi(window_manager_state)
1592 .window_manager_display_roots() 1604 .window_manager_display_roots()
1593 .empty()); 1605 .empty());
1594 } 1606 }
1595 1607
1608 TEST_F(WindowTreeManualDisplayTest,
1609 DisplayManagerObserverNotifiedWithManualRoots) {
1610 const bool automatically_create_display_roots = false;
1611 AddWindowManager(window_server(), kTestUserId1,
1612 automatically_create_display_roots);
1613
1614 TestDisplayManagerObserver display_manager_observer;
1615 DisplayManager* display_manager = window_server()->display_manager();
1616 UserDisplayManager* user_display_manager =
1617 display_manager->GetUserDisplayManager(kTestUserId1);
1618 ASSERT_TRUE(user_display_manager);
1619 user_display_manager->AddObserver(display_manager_observer.GetPtr());
1620
1621 // Observer should not have been notified yet.
1622 //
1623 // NOTE: the RunUntilIdle() calls are necessary anytime the calls are checked
1624 // as the observer is called via mojo, which is async.
1625 RunUntilIdle();
1626 EXPECT_TRUE(display_manager_observer.GetAndClearObserverCalls().empty());
1627
1628 // Set frame decorations, again observer should not be notified.
1629 WindowManagerState* window_manager_state =
1630 window_server()->GetWindowManagerStateForUser(kTestUserId1);
1631 ASSERT_TRUE(window_manager_state);
1632 WindowTree* window_manager_tree = window_manager_state->window_tree();
1633 window_manager_state->SetFrameDecorationValues(
1634 mojom::FrameDecorationValues::New());
1635 RunUntilIdle();
1636 EXPECT_TRUE(display_manager_observer.GetAndClearObserverCalls().empty());
1637
1638 // Create a window for the windowmanager and set it as the root.
1639 ClientWindowId display_root_id = BuildClientWindowId(window_manager_tree, 10);
1640 ASSERT_TRUE(window_manager_tree->NewWindow(display_root_id,
1641 ServerWindow::Properties()));
1642 ServerWindow* display_root =
1643 window_manager_tree->GetWindowByClientId(display_root_id);
1644 ASSERT_TRUE(display_root);
1645 RunUntilIdle();
1646 EXPECT_TRUE(display_manager_observer.GetAndClearObserverCalls().empty());
1647
1648 // Add a new display.
1649 display::Display display1 = MakeDisplay(0, 0, 1024, 768, 1.0f);
1650 const int64_t display_id1 = 101;
1651 display1.set_id(display_id1);
1652 mojom::WmViewportMetrics metrics1;
1653 metrics1.bounds_in_pixels = display1.bounds();
1654 metrics1.device_scale_factor = 1.5;
1655 metrics1.ui_scale_factor = 2.5;
1656 const bool is_primary_display = true;
1657 ASSERT_TRUE(WindowTreeTestApi(window_manager_tree)
1658 .ProcessSetDisplayRoot(display1, metrics1, is_primary_display,
1659 display_root_id));
1660 RunUntilIdle();
1661 EXPECT_TRUE(display_manager_observer.GetAndClearObserverCalls().empty());
1662
1663 // Configure the displays.
1664 std::vector<display::Display> displays;
1665 displays.push_back(display1);
1666 std::vector<ui::mojom::WmViewportMetricsPtr> viewport_metrics;
1667 viewport_metrics.push_back(ui::mojom::WmViewportMetrics::New(metrics1));
1668 ASSERT_TRUE(display_manager->SetDisplayConfiguration(
1669 displays, std::move(viewport_metrics), display_id1));
1670 RunUntilIdle();
1671 EXPECT_EQ("OnDisplaysChanged " + std::to_string(display_id1),
1672 display_manager_observer.GetAndClearObserverCalls());
1673
1674 // Create a window for the windowmanager and set it as the root.
1675 ClientWindowId display_root_id2 =
1676 BuildClientWindowId(window_manager_tree, 11);
1677 ASSERT_TRUE(window_manager_tree->NewWindow(display_root_id2,
1678 ServerWindow::Properties()));
1679 ServerWindow* display_root2 =
1680 window_manager_tree->GetWindowByClientId(display_root_id);
1681 ASSERT_TRUE(display_root2);
1682 RunUntilIdle();
1683 EXPECT_TRUE(display_manager_observer.GetAndClearObserverCalls().empty());
1684
1685 // Add another display.
1686 display::Display display2 = MakeDisplay(0, 0, 1024, 768, 1.0f);
1687 const int64_t display_id2 = 102;
1688 display2.set_id(display_id2);
1689 mojom::WmViewportMetrics metrics2;
1690 metrics2.bounds_in_pixels = display2.bounds();
1691 metrics2.device_scale_factor = 1.5;
1692 metrics2.ui_scale_factor = 2.5;
1693 ASSERT_TRUE(
1694 WindowTreeTestApi(window_manager_tree)
1695 .ProcessSetDisplayRoot(display2, metrics2, false, display_root_id2));
1696 RunUntilIdle();
1697 EXPECT_TRUE(display_manager_observer.GetAndClearObserverCalls().empty());
1698
1699 // Make |display2| the default, and resize both displays.
1700 display1.set_bounds(gfx::Rect(0, 0, 1024, 1280));
1701 metrics1.bounds_in_pixels = display1.bounds();
1702 displays.clear();
1703 displays.push_back(display1);
1704
1705 display2.set_bounds(gfx::Rect(0, 0, 500, 600));
1706 metrics2.bounds_in_pixels = display2.bounds();
1707 displays.push_back(display2);
1708
1709 viewport_metrics.push_back(ui::mojom::WmViewportMetrics::New(metrics1));
1710 viewport_metrics.push_back(ui::mojom::WmViewportMetrics::New(metrics2));
1711 ASSERT_TRUE(display_manager->SetDisplayConfiguration(
1712 displays, std::move(viewport_metrics), display_id2));
1713 RunUntilIdle();
1714 EXPECT_EQ("OnDisplaysChanged " + std::to_string(display_id1) + " " +
1715 std::to_string(display_id2),
1716 display_manager_observer.GetAndClearObserverCalls());
1717
1718 // Delete the second display, no notification should be sent.
1719 EXPECT_TRUE(window_manager_tree->DeleteWindow(display_root_id2));
1720 RunUntilIdle();
1721 EXPECT_TRUE(display_manager_observer.GetAndClearObserverCalls().empty());
1722 EXPECT_FALSE(display_manager->GetDisplayById(display_id2));
1723
1724 // Set the config back to only the first.
1725 displays.clear();
1726 displays.push_back(display1);
1727
1728 viewport_metrics.push_back(ui::mojom::WmViewportMetrics::New(metrics1));
1729 ASSERT_TRUE(display_manager->SetDisplayConfiguration(
1730 displays, std::move(viewport_metrics), display_id1));
1731 RunUntilIdle();
1732 EXPECT_EQ("OnDisplaysChanged " + std::to_string(display_id1),
1733 display_manager_observer.GetAndClearObserverCalls());
1734
1735 // The display list should not have display2.
1736 display::DisplayList& display_list =
1737 display::ScreenManager::GetInstance()->GetScreen()->display_list();
1738 EXPECT_TRUE(display_list.FindDisplayById(display_id2) ==
1739 display_list.displays().end());
1740 ASSERT_TRUE(display_list.GetPrimaryDisplayIterator() !=
1741 display_list.displays().end());
1742 EXPECT_EQ(display_id1, display_list.GetPrimaryDisplayIterator()->id());
1743 }
1744
1596 } // namespace test 1745 } // namespace test
1597 } // namespace ws 1746 } // namespace ws
1598 } // namespace ui 1747 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/window_tree.cc ('k') | ui/aura/mus/window_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698