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

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

Issue 1766943002: Refators display related functionality into own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "components/mus/common/types.h" 11 #include "components/mus/common/types.h"
12 #include "components/mus/common/util.h" 12 #include "components/mus/common/util.h"
13 #include "components/mus/public/interfaces/window_tree.mojom.h" 13 #include "components/mus/public/interfaces/window_tree.mojom.h"
14 #include "components/mus/surfaces/surfaces_state.h" 14 #include "components/mus/surfaces/surfaces_state.h"
15 #include "components/mus/ws/connection_manager.h" 15 #include "components/mus/ws/connection_manager.h"
16 #include "components/mus/ws/connection_manager_delegate.h" 16 #include "components/mus/ws/connection_manager_delegate.h"
17 #include "components/mus/ws/display_manager.h"
17 #include "components/mus/ws/ids.h" 18 #include "components/mus/ws/ids.h"
18 #include "components/mus/ws/platform_display.h" 19 #include "components/mus/ws/platform_display.h"
19 #include "components/mus/ws/platform_display_factory.h" 20 #include "components/mus/ws/platform_display_factory.h"
20 #include "components/mus/ws/server_window.h" 21 #include "components/mus/ws/server_window.h"
21 #include "components/mus/ws/test_utils.h" 22 #include "components/mus/ws/test_utils.h"
22 #include "components/mus/ws/window_manager_state.h" 23 #include "components/mus/ws/window_manager_state.h"
23 #include "components/mus/ws/window_tree.h" 24 #include "components/mus/ws/window_tree.h"
24 #include "components/mus/ws/window_tree_binding.h" 25 #include "components/mus/ws/window_tree_binding.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gfx/geometry/rect.h" 27 #include "ui/gfx/geometry/rect.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 74
74 DISALLOW_COPY_AND_ASSIGN(DisplayTest); 75 DISALLOW_COPY_AND_ASSIGN(DisplayTest);
75 }; 76 };
76 77
77 TEST_F(DisplayTest, CallsCreateDefaultDisplays) { 78 TEST_F(DisplayTest, CallsCreateDefaultDisplays) {
78 const int kNumHostsToCreate = 2; 79 const int kNumHostsToCreate = 2;
79 connection_manager_delegate_.set_num_displays_to_create(kNumHostsToCreate); 80 connection_manager_delegate_.set_num_displays_to_create(kNumHostsToCreate);
80 81
81 const UserId kTestId1 = "2"; 82 const UserId kTestId1 = "2";
82 const UserId kTestId2 = "21"; 83 const UserId kTestId2 = "21";
84 DisplayManager* display_manager = connection_manager_->display_manager();
83 WindowManagerFactoryRegistryTestApi( 85 WindowManagerFactoryRegistryTestApi(
84 connection_manager_->window_manager_factory_registry()) 86 connection_manager_->window_manager_factory_registry())
85 .AddService(kTestId1, &test_window_manager_factory_); 87 .AddService(kTestId1, &test_window_manager_factory_);
86 // The first register should trigger creation of the default 88 // The first register should trigger creation of the default
87 // Displays. There should be kNumHostsToCreate Displays. 89 // Displays. There should be kNumHostsToCreate Displays.
88 EXPECT_EQ(static_cast<size_t>(kNumHostsToCreate), 90 EXPECT_EQ(static_cast<size_t>(kNumHostsToCreate),
89 connection_manager_->displays().size()); 91 display_manager->displays().size());
90 92
91 // Each host should have a WindowManagerState for kTestId1. 93 // Each host should have a WindowManagerState for kTestId1.
92 for (Display* display : connection_manager_->displays()) { 94 for (Display* display : display_manager->displays()) {
93 EXPECT_EQ(1u, display->num_window_manger_states()); 95 EXPECT_EQ(1u, display->num_window_manger_states());
94 EXPECT_TRUE(display->GetWindowManagerStateForUser(kTestId1)); 96 EXPECT_TRUE(display->GetWindowManagerStateForUser(kTestId1));
95 EXPECT_FALSE(display->GetWindowManagerStateForUser(kTestId2)); 97 EXPECT_FALSE(display->GetWindowManagerStateForUser(kTestId2));
96 } 98 }
97 99
98 // Add another registry, should trigger creation of another wm. 100 // Add another registry, should trigger creation of another wm.
99 WindowManagerFactoryRegistryTestApi( 101 WindowManagerFactoryRegistryTestApi(
100 connection_manager_->window_manager_factory_registry()) 102 connection_manager_->window_manager_factory_registry())
101 .AddService(kTestId2, &test_window_manager_factory_); 103 .AddService(kTestId2, &test_window_manager_factory_);
102 for (Display* display : connection_manager_->displays()) { 104 for (Display* display : display_manager->displays()) {
103 ASSERT_EQ(2u, display->num_window_manger_states()); 105 ASSERT_EQ(2u, display->num_window_manger_states());
104 WindowManagerState* state1 = 106 WindowManagerState* state1 =
105 display->GetWindowManagerStateForUser(kTestId1); 107 display->GetWindowManagerStateForUser(kTestId1);
106 ASSERT_TRUE(state1); 108 ASSERT_TRUE(state1);
107 WindowManagerState* state2 = 109 WindowManagerState* state2 =
108 display->GetWindowManagerStateForUser(kTestId2); 110 display->GetWindowManagerStateForUser(kTestId2);
109 ASSERT_TRUE(state2); 111 ASSERT_TRUE(state2);
110 // Verify the two states have different roots. 112 // Verify the two states have different roots.
111 EXPECT_NE(state1, state2); 113 EXPECT_NE(state1, state2);
112 EXPECT_NE(state1->root(), state2->root()); 114 EXPECT_NE(state1->root(), state2->root());
113 } 115 }
114 } 116 }
115 117
116 TEST_F(DisplayTest, Destruction) { 118 TEST_F(DisplayTest, Destruction) {
117 connection_manager_delegate_.set_num_displays_to_create(1); 119 connection_manager_delegate_.set_num_displays_to_create(1);
118 120
119 const UserId kTestId1 = "2"; 121 const UserId kTestId1 = "2";
120 const UserId kTestId2 = "21"; 122 const UserId kTestId2 = "21";
121 WindowManagerFactoryRegistryTestApi( 123 WindowManagerFactoryRegistryTestApi(
122 connection_manager_->window_manager_factory_registry()) 124 connection_manager_->window_manager_factory_registry())
123 .AddService(kTestId1, &test_window_manager_factory_); 125 .AddService(kTestId1, &test_window_manager_factory_);
124 126
125 // Add another registry, should trigger creation of another wm. 127 // Add another registry, should trigger creation of another wm.
128 DisplayManager* display_manager = connection_manager_->display_manager();
126 WindowManagerFactoryRegistryTestApi( 129 WindowManagerFactoryRegistryTestApi(
127 connection_manager_->window_manager_factory_registry()) 130 connection_manager_->window_manager_factory_registry())
128 .AddService(kTestId2, &test_window_manager_factory_); 131 .AddService(kTestId2, &test_window_manager_factory_);
129 ASSERT_EQ(1u, connection_manager_->displays().size()); 132 ASSERT_EQ(1u, display_manager->displays().size());
130 Display* display = *connection_manager_->displays().begin(); 133 Display* display = *display_manager->displays().begin();
131 ASSERT_EQ(2u, display->num_window_manger_states()); 134 ASSERT_EQ(2u, display->num_window_manger_states());
132 // There should be two trees, one for each windowmanager. 135 // There should be two trees, one for each windowmanager.
133 EXPECT_EQ(2u, connection_manager_->num_trees()); 136 EXPECT_EQ(2u, connection_manager_->num_trees());
134 137
135 { 138 {
136 WindowManagerState* state = display->GetWindowManagerStateForUser(kTestId1); 139 WindowManagerState* state = display->GetWindowManagerStateForUser(kTestId1);
137 // Destroy the tree associated with |state|. Should result in deleting 140 // Destroy the tree associated with |state|. Should result in deleting
138 // |state|. 141 // |state|.
139 connection_manager_->DestroyTree(state->tree()); 142 connection_manager_->DestroyTree(state->tree());
140 ASSERT_EQ(1u, display->num_window_manger_states()); 143 ASSERT_EQ(1u, display->num_window_manger_states());
141 EXPECT_FALSE(display->GetWindowManagerStateForUser(kTestId1)); 144 EXPECT_FALSE(display->GetWindowManagerStateForUser(kTestId1));
142 EXPECT_EQ(1u, connection_manager_->displays().size()); 145 EXPECT_EQ(1u, display_manager->displays().size());
143 EXPECT_EQ(1u, connection_manager_->num_trees()); 146 EXPECT_EQ(1u, connection_manager_->num_trees());
144 } 147 }
145 148
146 EXPECT_FALSE(connection_manager_delegate_.got_on_no_more_connections()); 149 EXPECT_FALSE(connection_manager_delegate_.got_on_no_more_displays());
147 // Destroy the Display, which should shutdown the trees. 150 // Destroy the Display, which should shutdown the trees.
148 connection_manager_->DestroyDisplay(display); 151 connection_manager_->display_manager()->DestroyDisplay(display);
149 EXPECT_EQ(0u, connection_manager_->num_trees()); 152 EXPECT_EQ(0u, connection_manager_->num_trees());
150 EXPECT_TRUE(connection_manager_delegate_.got_on_no_more_connections()); 153 EXPECT_TRUE(connection_manager_delegate_.got_on_no_more_displays());
151 } 154 }
152 155
153 } // namespace test 156 } // namespace test
154 } // namespace ws 157 } // namespace ws
155 } // namespace mus 158 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/display_manager_delegate.h ('k') | components/mus/ws/server_window_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698