| OLD | NEW |
| 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 "services/ui/ws/user_display_manager.h" | 5 #include "services/ui/ws/user_display_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/atomicops.h" | 11 #include "base/atomicops.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "mojo/public/cpp/bindings/interface_request.h" | 16 #include "mojo/public/cpp/bindings/interface_request.h" |
| 17 #include "services/ui/common/task_runner_test_base.h" | 17 #include "services/ui/common/task_runner_test_base.h" |
| 18 #include "services/ui/common/types.h" | 18 #include "services/ui/common/types.h" |
| 19 #include "services/ui/common/util.h" | 19 #include "services/ui/common/util.h" |
| 20 #include "services/ui/display/platform_screen.h" | 20 #include "services/ui/display/screen_manager.h" |
| 21 #include "services/ui/ws/display_manager.h" | 21 #include "services/ui/ws/display_manager.h" |
| 22 #include "services/ui/ws/ids.h" | 22 #include "services/ui/ws/ids.h" |
| 23 #include "services/ui/ws/server_window.h" | 23 #include "services/ui/ws/server_window.h" |
| 24 #include "services/ui/ws/test_utils.h" | 24 #include "services/ui/ws/test_utils.h" |
| 25 #include "services/ui/ws/window_manager_state.h" | 25 #include "services/ui/ws/window_manager_state.h" |
| 26 #include "services/ui/ws/window_manager_window_tree_factory_set.h" | 26 #include "services/ui/ws/window_manager_window_tree_factory_set.h" |
| 27 #include "services/ui/ws/window_server.h" | 27 #include "services/ui/ws/window_server.h" |
| 28 #include "services/ui/ws/window_server_delegate.h" | 28 #include "services/ui/ws/window_server_delegate.h" |
| 29 #include "services/ui/ws/window_tree.h" | 29 #include "services/ui/ws/window_tree.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 class UserDisplayManagerTest : public TaskRunnerTestBase { | 103 class UserDisplayManagerTest : public TaskRunnerTestBase { |
| 104 public: | 104 public: |
| 105 UserDisplayManagerTest() {} | 105 UserDisplayManagerTest() {} |
| 106 ~UserDisplayManagerTest() override {} | 106 ~UserDisplayManagerTest() override {} |
| 107 | 107 |
| 108 WindowServer* window_server() { return ws_test_helper_.window_server(); } | 108 WindowServer* window_server() { return ws_test_helper_.window_server(); } |
| 109 TestWindowServerDelegate* window_server_delegate() { | 109 TestWindowServerDelegate* window_server_delegate() { |
| 110 return ws_test_helper_.window_server_delegate(); | 110 return ws_test_helper_.window_server_delegate(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 TestPlatformScreen& platform_screen() { return platform_screen_; } | 113 TestScreenManager& screen_manager() { return screen_manager_; } |
| 114 | 114 |
| 115 private: | 115 private: |
| 116 // testing::Test: | 116 // testing::Test: |
| 117 void SetUp() override { | 117 void SetUp() override { |
| 118 TaskRunnerTestBase::SetUp(); | 118 TaskRunnerTestBase::SetUp(); |
| 119 platform_screen_.Init(window_server()->display_manager()); | 119 screen_manager_.Init(window_server()->display_manager()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 WindowServerTestHelper ws_test_helper_; | 122 WindowServerTestHelper ws_test_helper_; |
| 123 TestPlatformScreen platform_screen_; | 123 TestScreenManager screen_manager_; |
| 124 DISALLOW_COPY_AND_ASSIGN(UserDisplayManagerTest); | 124 DISALLOW_COPY_AND_ASSIGN(UserDisplayManagerTest); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 TEST_F(UserDisplayManagerTest, OnlyNotifyWhenFrameDecorationsSet) { | 127 TEST_F(UserDisplayManagerTest, OnlyNotifyWhenFrameDecorationsSet) { |
| 128 platform_screen().AddDisplay(); | 128 screen_manager().AddDisplay(); |
| 129 | 129 |
| 130 TestDisplayManagerObserver display_manager_observer1; | 130 TestDisplayManagerObserver display_manager_observer1; |
| 131 DisplayManager* display_manager = window_server()->display_manager(); | 131 DisplayManager* display_manager = window_server()->display_manager(); |
| 132 AddWindowManager(window_server(), kUserId1); | 132 AddWindowManager(window_server(), kUserId1); |
| 133 UserDisplayManager* user_display_manager1 = | 133 UserDisplayManager* user_display_manager1 = |
| 134 display_manager->GetUserDisplayManager(kUserId1); | 134 display_manager->GetUserDisplayManager(kUserId1); |
| 135 ASSERT_TRUE(user_display_manager1); | 135 ASSERT_TRUE(user_display_manager1); |
| 136 user_display_manager1->AddObserver(display_manager_observer1.GetPtr()); | 136 user_display_manager1->AddObserver(display_manager_observer1.GetPtr()); |
| 137 RunUntilIdle(); | 137 RunUntilIdle(); |
| 138 | 138 |
| 139 // Observer should not have been notified yet. | 139 // Observer should not have been notified yet. |
| 140 EXPECT_EQ(std::string(), | 140 EXPECT_EQ(std::string(), |
| 141 display_manager_observer1.GetAndClearObserverCalls()); | 141 display_manager_observer1.GetAndClearObserverCalls()); |
| 142 | 142 |
| 143 // Set the frame decoration values, which should trigger sending immediately. | 143 // Set the frame decoration values, which should trigger sending immediately. |
| 144 ASSERT_EQ(1u, display_manager->displays().size()); | 144 ASSERT_EQ(1u, display_manager->displays().size()); |
| 145 window_server() | 145 window_server() |
| 146 ->window_manager_window_tree_factory_set() | 146 ->window_manager_window_tree_factory_set() |
| 147 ->GetWindowManagerStateForUser(kUserId1) | 147 ->GetWindowManagerStateForUser(kUserId1) |
| 148 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); | 148 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); |
| 149 RunUntilIdle(); | 149 RunUntilIdle(); |
| 150 | 150 |
| 151 EXPECT_EQ("OnDisplays 1", | 151 EXPECT_EQ("OnDisplays 1", |
| 152 display_manager_observer1.GetAndClearObserverCalls()); | 152 display_manager_observer1.GetAndClearObserverCalls()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST_F(UserDisplayManagerTest, AddObserverAfterFrameDecorationsSet) { | 155 TEST_F(UserDisplayManagerTest, AddObserverAfterFrameDecorationsSet) { |
| 156 platform_screen().AddDisplay(); | 156 screen_manager().AddDisplay(); |
| 157 | 157 |
| 158 TestDisplayManagerObserver display_manager_observer1; | 158 TestDisplayManagerObserver display_manager_observer1; |
| 159 DisplayManager* display_manager = window_server()->display_manager(); | 159 DisplayManager* display_manager = window_server()->display_manager(); |
| 160 AddWindowManager(window_server(), kUserId1); | 160 AddWindowManager(window_server(), kUserId1); |
| 161 UserDisplayManager* user_display_manager1 = | 161 UserDisplayManager* user_display_manager1 = |
| 162 display_manager->GetUserDisplayManager(kUserId1); | 162 display_manager->GetUserDisplayManager(kUserId1); |
| 163 ASSERT_TRUE(user_display_manager1); | 163 ASSERT_TRUE(user_display_manager1); |
| 164 ASSERT_EQ(1u, display_manager->displays().size()); | 164 ASSERT_EQ(1u, display_manager->displays().size()); |
| 165 window_server() | 165 window_server() |
| 166 ->window_manager_window_tree_factory_set() | 166 ->window_manager_window_tree_factory_set() |
| 167 ->GetWindowManagerStateForUser(kUserId1) | 167 ->GetWindowManagerStateForUser(kUserId1) |
| 168 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); | 168 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); |
| 169 | 169 |
| 170 user_display_manager1->AddObserver(display_manager_observer1.GetPtr()); | 170 user_display_manager1->AddObserver(display_manager_observer1.GetPtr()); |
| 171 RunUntilIdle(); | 171 RunUntilIdle(); |
| 172 | 172 |
| 173 EXPECT_EQ("OnDisplays 1", | 173 EXPECT_EQ("OnDisplays 1", |
| 174 display_manager_observer1.GetAndClearObserverCalls()); | 174 display_manager_observer1.GetAndClearObserverCalls()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST_F(UserDisplayManagerTest, AddRemoveDisplay) { | 177 TEST_F(UserDisplayManagerTest, AddRemoveDisplay) { |
| 178 platform_screen().AddDisplay(); | 178 screen_manager().AddDisplay(); |
| 179 | 179 |
| 180 TestDisplayManagerObserver display_manager_observer1; | 180 TestDisplayManagerObserver display_manager_observer1; |
| 181 DisplayManager* display_manager = window_server()->display_manager(); | 181 DisplayManager* display_manager = window_server()->display_manager(); |
| 182 AddWindowManager(window_server(), kUserId1); | 182 AddWindowManager(window_server(), kUserId1); |
| 183 UserDisplayManager* user_display_manager1 = | 183 UserDisplayManager* user_display_manager1 = |
| 184 display_manager->GetUserDisplayManager(kUserId1); | 184 display_manager->GetUserDisplayManager(kUserId1); |
| 185 ASSERT_TRUE(user_display_manager1); | 185 ASSERT_TRUE(user_display_manager1); |
| 186 ASSERT_EQ(1u, display_manager->displays().size()); | 186 ASSERT_EQ(1u, display_manager->displays().size()); |
| 187 window_server() | 187 window_server() |
| 188 ->window_manager_window_tree_factory_set() | 188 ->window_manager_window_tree_factory_set() |
| 189 ->GetWindowManagerStateForUser(kUserId1) | 189 ->GetWindowManagerStateForUser(kUserId1) |
| 190 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); | 190 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); |
| 191 user_display_manager1->AddObserver(display_manager_observer1.GetPtr()); | 191 user_display_manager1->AddObserver(display_manager_observer1.GetPtr()); |
| 192 RunUntilIdle(); | 192 RunUntilIdle(); |
| 193 | 193 |
| 194 EXPECT_EQ("OnDisplays 1", | 194 EXPECT_EQ("OnDisplays 1", |
| 195 display_manager_observer1.GetAndClearObserverCalls()); | 195 display_manager_observer1.GetAndClearObserverCalls()); |
| 196 | 196 |
| 197 // Add another display. | 197 // Add another display. |
| 198 const int64_t second_display_id = platform_screen().AddDisplay(); | 198 const int64_t second_display_id = screen_manager().AddDisplay(); |
| 199 RunUntilIdle(); | 199 RunUntilIdle(); |
| 200 | 200 |
| 201 // Observer should be notified immediately as frame decorations were set. | 201 // Observer should be notified immediately as frame decorations were set. |
| 202 EXPECT_EQ("OnDisplaysChanged 2", | 202 EXPECT_EQ("OnDisplaysChanged 2", |
| 203 display_manager_observer1.GetAndClearObserverCalls()); | 203 display_manager_observer1.GetAndClearObserverCalls()); |
| 204 | 204 |
| 205 // Remove the display and verify observer is notified. | 205 // Remove the display and verify observer is notified. |
| 206 platform_screen().RemoveDisplay(second_display_id); | 206 screen_manager().RemoveDisplay(second_display_id); |
| 207 RunUntilIdle(); | 207 RunUntilIdle(); |
| 208 | 208 |
| 209 EXPECT_EQ("OnDisplayRemoved 2", | 209 EXPECT_EQ("OnDisplayRemoved 2", |
| 210 display_manager_observer1.GetAndClearObserverCalls()); | 210 display_manager_observer1.GetAndClearObserverCalls()); |
| 211 } | 211 } |
| 212 | 212 |
| 213 TEST_F(UserDisplayManagerTest, NegativeCoordinates) { | 213 TEST_F(UserDisplayManagerTest, NegativeCoordinates) { |
| 214 platform_screen().AddDisplay(); | 214 screen_manager().AddDisplay(); |
| 215 | 215 |
| 216 TestDisplayManagerObserver display_manager_observer1; | 216 TestDisplayManagerObserver display_manager_observer1; |
| 217 DisplayManager* display_manager = window_server()->display_manager(); | 217 DisplayManager* display_manager = window_server()->display_manager(); |
| 218 AddWindowManager(window_server(), kUserId1); | 218 AddWindowManager(window_server(), kUserId1); |
| 219 UserDisplayManager* user_display_manager1 = | 219 UserDisplayManager* user_display_manager1 = |
| 220 display_manager->GetUserDisplayManager(kUserId1); | 220 display_manager->GetUserDisplayManager(kUserId1); |
| 221 ASSERT_TRUE(user_display_manager1); | 221 ASSERT_TRUE(user_display_manager1); |
| 222 | 222 |
| 223 user_display_manager1->OnMouseCursorLocationChanged(gfx::Point(-10, -11)); | 223 user_display_manager1->OnMouseCursorLocationChanged(gfx::Point(-10, -11)); |
| 224 | 224 |
| 225 base::subtle::Atomic32* cursor_location_memory = nullptr; | 225 base::subtle::Atomic32* cursor_location_memory = nullptr; |
| 226 mojo::ScopedSharedBufferHandle handle = | 226 mojo::ScopedSharedBufferHandle handle = |
| 227 user_display_manager1->GetCursorLocationMemory(); | 227 user_display_manager1->GetCursorLocationMemory(); |
| 228 mojo::ScopedSharedBufferMapping cursor_location_mapping = | 228 mojo::ScopedSharedBufferMapping cursor_location_mapping = |
| 229 handle->Map(sizeof(base::subtle::Atomic32)); | 229 handle->Map(sizeof(base::subtle::Atomic32)); |
| 230 ASSERT_TRUE(cursor_location_mapping); | 230 ASSERT_TRUE(cursor_location_mapping); |
| 231 cursor_location_memory = | 231 cursor_location_memory = |
| 232 reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get()); | 232 reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get()); |
| 233 | 233 |
| 234 base::subtle::Atomic32 location = | 234 base::subtle::Atomic32 location = |
| 235 base::subtle::NoBarrier_Load(cursor_location_memory); | 235 base::subtle::NoBarrier_Load(cursor_location_memory); |
| 236 EXPECT_EQ(gfx::Point(static_cast<int16_t>(location >> 16), | 236 EXPECT_EQ(gfx::Point(static_cast<int16_t>(location >> 16), |
| 237 static_cast<int16_t>(location & 0xFFFF)), | 237 static_cast<int16_t>(location & 0xFFFF)), |
| 238 gfx::Point(-10, -11)); | 238 gfx::Point(-10, -11)); |
| 239 } | 239 } |
| 240 | 240 |
| 241 } // namespace test | 241 } // namespace test |
| 242 } // namespace ws | 242 } // namespace ws |
| 243 } // namespace ui | 243 } // namespace ui |
| OLD | NEW |