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

Side by Side Diff: components/mus/ws/window_tree_host_unittest.cc

Issue 1757403002: More user id tracking for mus: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweaks Created 4 years, 9 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 | « components/mus/ws/window_tree_host_impl.cc ('k') | components/mus/ws/window_tree_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdint.h>
6
7 #include <string>
8
9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h"
11 #include "components/mus/common/types.h"
12 #include "components/mus/common/util.h"
13 #include "components/mus/public/interfaces/window_tree.mojom.h"
14 #include "components/mus/surfaces/surfaces_state.h"
15 #include "components/mus/ws/client_connection.h"
16 #include "components/mus/ws/connection_manager.h"
17 #include "components/mus/ws/connection_manager_delegate.h"
18 #include "components/mus/ws/display_manager.h"
19 #include "components/mus/ws/display_manager_factory.h"
20 #include "components/mus/ws/ids.h"
21 #include "components/mus/ws/server_window.h"
22 #include "components/mus/ws/test_utils.h"
23 #include "components/mus/ws/window_manager_state.h"
24 #include "components/mus/ws/window_tree_impl.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gfx/geometry/rect.h"
27
28 namespace mus {
29 namespace ws {
30 namespace test {
31 namespace {
32
33 class TestWindowManagerFactory : public mojom::WindowManagerFactory {
34 public:
35 TestWindowManagerFactory() {}
36 ~TestWindowManagerFactory() override {}
37
38 // mojom::WindowManagerFactory:
39 void CreateWindowManager(
40 mus::mojom::DisplayPtr display,
41 mus::mojom::WindowTreeClientRequest client) override {}
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerFactory);
45 };
46
47 } // namespace
48
49 // -----------------------------------------------------------------------------
50
51 class WindowTreeHostTest : public testing::Test {
52 public:
53 WindowTreeHostTest() : cursor_id_(0), display_manager_factory_(&cursor_id_) {}
54 ~WindowTreeHostTest() override {}
55
56 // WindowTreeImpl for the window manager.
57 WindowTreeImpl* wm_connection() {
58 return connection_manager_->GetConnection(1);
59 }
60
61 TestWindowTreeClient* last_window_tree_client() {
62 return connection_manager_delegate_.last_client();
63 }
64
65 TestClientConnection* last_client_connection() {
66 return connection_manager_delegate_.last_connection();
67 }
68
69 ConnectionManager* connection_manager() { return connection_manager_.get(); }
70
71 ServerWindow* GetWindowById(const WindowId& id) {
72 return connection_manager_->GetWindow(id);
73 }
74
75 mus::mojom::Cursor cursor_id() {
76 return static_cast<mus::mojom::Cursor>(cursor_id_);
77 }
78
79 void set_window_manager_internal(WindowTreeImpl* connection,
80 mojom::WindowManager* wm_internal) {
81 WindowTreeTestApi(connection).set_window_manager_internal(wm_internal);
82 }
83
84 protected:
85 // testing::Test:
86 void SetUp() override {
87 DisplayManager::set_factory_for_testing(&display_manager_factory_);
88 connection_manager_.reset(new ConnectionManager(
89 &connection_manager_delegate_, scoped_refptr<SurfacesState>()));
90 connection_manager_delegate_.set_connection_manager(
91 connection_manager_.get());
92 }
93
94 protected:
95 int32_t cursor_id_;
96 TestDisplayManagerFactory display_manager_factory_;
97 TestConnectionManagerDelegate connection_manager_delegate_;
98 scoped_ptr<ConnectionManager> connection_manager_;
99 base::MessageLoop message_loop_;
100 TestWindowManagerFactory test_window_manager_factory_;
101
102 DISALLOW_COPY_AND_ASSIGN(WindowTreeHostTest);
103 };
104
105 TEST_F(WindowTreeHostTest, CallsCreateDefaultWindowTreeHosts) {
106 const int kNumHostsToCreate = 2;
107 connection_manager_delegate_.set_num_tree_hosts_to_create(kNumHostsToCreate);
108
109 const UserId kTestId1 = 2;
110 const UserId kTestId2 = 21;
111 WindowManagerFactoryRegistryTestApi(
112 connection_manager_->window_manager_factory_registry())
113 .AddService(kTestId1, &test_window_manager_factory_);
114 // The first register should trigger creation of the default
115 // WindowTreeHosts. There should be kNumHostsToCreate WindowTreeHosts.
116 EXPECT_EQ(static_cast<size_t>(kNumHostsToCreate),
117 connection_manager_->hosts().size());
118
119 // Each host should have a WindowManagerState for kTestId1.
120 for (WindowTreeHostImpl* tree_host : connection_manager_->hosts()) {
121 EXPECT_EQ(1u, tree_host->num_window_manger_states());
122 EXPECT_TRUE(tree_host->GetWindowManagerStateForUser(kTestId1));
123 EXPECT_FALSE(tree_host->GetWindowManagerStateForUser(kTestId2));
124 }
125
126 // Add another registry, should trigger creation of another wm.
127 WindowManagerFactoryRegistryTestApi(
128 connection_manager_->window_manager_factory_registry())
129 .AddService(kTestId2, &test_window_manager_factory_);
130 for (WindowTreeHostImpl* tree_host : connection_manager_->hosts()) {
131 ASSERT_EQ(2u, tree_host->num_window_manger_states());
132 WindowManagerState* state1 =
133 tree_host->GetWindowManagerStateForUser(kTestId1);
134 ASSERT_TRUE(state1);
135 WindowManagerState* state2 =
136 tree_host->GetWindowManagerStateForUser(kTestId2);
137 ASSERT_TRUE(state2);
138 // Verify the two states have different roots.
139 EXPECT_NE(state1, state2);
140 EXPECT_NE(state1->root(), state2->root());
141 }
142 }
143
144 TEST_F(WindowTreeHostTest, Destruction) {
145 connection_manager_delegate_.set_num_tree_hosts_to_create(1);
146
147 const UserId kTestId1 = 2;
148 const UserId kTestId2 = 21;
149 WindowManagerFactoryRegistryTestApi(
150 connection_manager_->window_manager_factory_registry())
151 .AddService(kTestId1, &test_window_manager_factory_);
152
153 // Add another registry, should trigger creation of another wm.
154 WindowManagerFactoryRegistryTestApi(
155 connection_manager_->window_manager_factory_registry())
156 .AddService(kTestId2, &test_window_manager_factory_);
157 ASSERT_EQ(1u, connection_manager_->hosts().size());
158 WindowTreeHostImpl* tree_host = *connection_manager_->hosts().begin();
159 ASSERT_EQ(2u, tree_host->num_window_manger_states());
160 // There should be two trees, one for each windowmanager.
161 EXPECT_EQ(2u, connection_manager_->num_trees());
162
163 {
164 WindowManagerState* state =
165 tree_host->GetWindowManagerStateForUser(kTestId1);
166 // Destroy the tree associated with |state|. Should result in deleting
167 // |state|.
168 connection_manager_->DestroyTree(state->tree());
169 ASSERT_EQ(1u, tree_host->num_window_manger_states());
170 EXPECT_FALSE(tree_host->GetWindowManagerStateForUser(kTestId1));
171 EXPECT_EQ(1u, connection_manager_->hosts().size());
172 EXPECT_EQ(1u, connection_manager_->num_trees());
173 }
174
175 EXPECT_FALSE(connection_manager_delegate_.got_on_no_more_connections());
176 // Destroy the WindowTreeHost, which should shutdown the trees.
177 connection_manager_->DestroyHost(tree_host);
178 EXPECT_EQ(0u, connection_manager_->num_trees());
179 EXPECT_TRUE(connection_manager_delegate_.got_on_no_more_connections());
180 }
181
182 } // namespace test
183 } // namespace ws
184 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_tree_host_impl.cc ('k') | components/mus/ws/window_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698