| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 WindowServerTestHelper ws_test_helper_; | 126 WindowServerTestHelper ws_test_helper_; |
| 127 DISALLOW_COPY_AND_ASSIGN(UserDisplayManagerTest); | 127 DISALLOW_COPY_AND_ASSIGN(UserDisplayManagerTest); |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 TEST_F(UserDisplayManagerTest, OnlyNotifyWhenFrameDecorationsSet) { | 130 TEST_F(UserDisplayManagerTest, OnlyNotifyWhenFrameDecorationsSet) { |
| 131 window_server_delegate()->CreateDisplays(1); | 131 window_server_delegate()->CreateDisplays(1); |
| 132 | 132 |
| 133 const UserId kUserId1 = "2"; | 133 const UserId kUserId1 = "2"; |
| 134 TestDisplayManagerObserver display_manager_observer1; | 134 TestDisplayManagerObserver display_manager_observer1; |
| 135 DisplayManager* display_manager = window_server()->display_manager(); | 135 DisplayManager* display_manager = window_server()->display_manager(); |
| 136 WindowManagerWindowTreeFactorySetTestApi( | 136 AddWindowManager(window_server(), kUserId1); |
| 137 window_server()->window_manager_window_tree_factory_set()) | |
| 138 .Add(kUserId1); | |
| 139 UserDisplayManager* user_display_manager1 = | 137 UserDisplayManager* user_display_manager1 = |
| 140 display_manager->GetUserDisplayManager(kUserId1); | 138 display_manager->GetUserDisplayManager(kUserId1); |
| 141 ASSERT_TRUE(user_display_manager1); | 139 ASSERT_TRUE(user_display_manager1); |
| 142 UserDisplayManagerTestApi(user_display_manager1) | 140 UserDisplayManagerTestApi(user_display_manager1) |
| 143 .SetTestObserver(&display_manager_observer1); | 141 .SetTestObserver(&display_manager_observer1); |
| 144 // Observer should not have been notified yet. | 142 // Observer should not have been notified yet. |
| 145 EXPECT_EQ(std::string(), | 143 EXPECT_EQ(std::string(), |
| 146 display_manager_observer1.GetAndClearObserverCalls()); | 144 display_manager_observer1.GetAndClearObserverCalls()); |
| 147 | 145 |
| 148 // Set the frame decoration values, which should trigger sending immediately. | 146 // Set the frame decoration values, which should trigger sending immediately. |
| 149 ASSERT_EQ(1u, display_manager->displays().size()); | 147 ASSERT_EQ(1u, display_manager->displays().size()); |
| 150 window_server() | 148 window_server() |
| 151 ->window_manager_window_tree_factory_set() | 149 ->window_manager_window_tree_factory_set() |
| 152 ->GetWindowManagerStateForUser(kUserId1) | 150 ->GetWindowManagerStateForUser(kUserId1) |
| 153 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); | 151 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); |
| 154 EXPECT_EQ("OnDisplays 1", | 152 EXPECT_EQ("OnDisplays 1", |
| 155 display_manager_observer1.GetAndClearObserverCalls()); | 153 display_manager_observer1.GetAndClearObserverCalls()); |
| 156 | 154 |
| 157 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); | 155 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); |
| 158 } | 156 } |
| 159 | 157 |
| 160 TEST_F(UserDisplayManagerTest, AddObserverAfterFrameDecorationsSet) { | 158 TEST_F(UserDisplayManagerTest, AddObserverAfterFrameDecorationsSet) { |
| 161 window_server_delegate()->CreateDisplays(1); | 159 window_server_delegate()->CreateDisplays(1); |
| 162 | 160 |
| 163 const UserId kUserId1 = "2"; | 161 const UserId kUserId1 = "2"; |
| 164 TestDisplayManagerObserver display_manager_observer1; | 162 TestDisplayManagerObserver display_manager_observer1; |
| 165 DisplayManager* display_manager = window_server()->display_manager(); | 163 DisplayManager* display_manager = window_server()->display_manager(); |
| 166 WindowManagerWindowTreeFactorySetTestApi( | 164 AddWindowManager(window_server(), kUserId1); |
| 167 window_server()->window_manager_window_tree_factory_set()) | |
| 168 .Add(kUserId1); | |
| 169 UserDisplayManager* user_display_manager1 = | 165 UserDisplayManager* user_display_manager1 = |
| 170 display_manager->GetUserDisplayManager(kUserId1); | 166 display_manager->GetUserDisplayManager(kUserId1); |
| 171 ASSERT_TRUE(user_display_manager1); | 167 ASSERT_TRUE(user_display_manager1); |
| 172 ASSERT_EQ(1u, display_manager->displays().size()); | 168 ASSERT_EQ(1u, display_manager->displays().size()); |
| 173 window_server() | 169 window_server() |
| 174 ->window_manager_window_tree_factory_set() | 170 ->window_manager_window_tree_factory_set() |
| 175 ->GetWindowManagerStateForUser(kUserId1) | 171 ->GetWindowManagerStateForUser(kUserId1) |
| 176 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); | 172 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); |
| 177 | 173 |
| 178 UserDisplayManagerTestApi(user_display_manager1) | 174 UserDisplayManagerTestApi(user_display_manager1) |
| 179 .SetTestObserver(&display_manager_observer1); | 175 .SetTestObserver(&display_manager_observer1); |
| 180 EXPECT_EQ("OnDisplays 1", | 176 EXPECT_EQ("OnDisplays 1", |
| 181 display_manager_observer1.GetAndClearObserverCalls()); | 177 display_manager_observer1.GetAndClearObserverCalls()); |
| 182 | 178 |
| 183 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); | 179 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); |
| 184 } | 180 } |
| 185 | 181 |
| 186 TEST_F(UserDisplayManagerTest, AddRemoveDisplay) { | 182 TEST_F(UserDisplayManagerTest, AddRemoveDisplay) { |
| 187 window_server_delegate()->CreateDisplays(1); | 183 window_server_delegate()->CreateDisplays(1); |
| 188 | 184 |
| 189 const UserId kUserId1 = "2"; | 185 const UserId kUserId1 = "2"; |
| 190 TestDisplayManagerObserver display_manager_observer1; | 186 TestDisplayManagerObserver display_manager_observer1; |
| 191 DisplayManager* display_manager = window_server()->display_manager(); | 187 DisplayManager* display_manager = window_server()->display_manager(); |
| 192 WindowManagerWindowTreeFactorySetTestApi( | 188 AddWindowManager(window_server(), kUserId1); |
| 193 window_server()->window_manager_window_tree_factory_set()) | |
| 194 .Add(kUserId1); | |
| 195 UserDisplayManager* user_display_manager1 = | 189 UserDisplayManager* user_display_manager1 = |
| 196 display_manager->GetUserDisplayManager(kUserId1); | 190 display_manager->GetUserDisplayManager(kUserId1); |
| 197 ASSERT_TRUE(user_display_manager1); | 191 ASSERT_TRUE(user_display_manager1); |
| 198 ASSERT_EQ(1u, display_manager->displays().size()); | 192 ASSERT_EQ(1u, display_manager->displays().size()); |
| 199 window_server() | 193 window_server() |
| 200 ->window_manager_window_tree_factory_set() | 194 ->window_manager_window_tree_factory_set() |
| 201 ->GetWindowManagerStateForUser(kUserId1) | 195 ->GetWindowManagerStateForUser(kUserId1) |
| 202 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); | 196 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); |
| 203 UserDisplayManagerTestApi(user_display_manager1) | 197 UserDisplayManagerTestApi(user_display_manager1) |
| 204 .SetTestObserver(&display_manager_observer1); | 198 .SetTestObserver(&display_manager_observer1); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 221 | 215 |
| 222 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); | 216 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); |
| 223 } | 217 } |
| 224 | 218 |
| 225 TEST_F(UserDisplayManagerTest, NegativeCoordinates) { | 219 TEST_F(UserDisplayManagerTest, NegativeCoordinates) { |
| 226 window_server_delegate()->CreateDisplays(1); | 220 window_server_delegate()->CreateDisplays(1); |
| 227 | 221 |
| 228 const UserId kUserId1 = "2"; | 222 const UserId kUserId1 = "2"; |
| 229 TestDisplayManagerObserver display_manager_observer1; | 223 TestDisplayManagerObserver display_manager_observer1; |
| 230 DisplayManager* display_manager = window_server()->display_manager(); | 224 DisplayManager* display_manager = window_server()->display_manager(); |
| 231 WindowManagerWindowTreeFactorySetTestApi( | 225 AddWindowManager(window_server(), kUserId1); |
| 232 window_server()->window_manager_window_tree_factory_set()) | |
| 233 .Add(kUserId1); | |
| 234 UserDisplayManager* user_display_manager1 = | 226 UserDisplayManager* user_display_manager1 = |
| 235 display_manager->GetUserDisplayManager(kUserId1); | 227 display_manager->GetUserDisplayManager(kUserId1); |
| 236 ASSERT_TRUE(user_display_manager1); | 228 ASSERT_TRUE(user_display_manager1); |
| 237 | 229 |
| 238 user_display_manager1->OnMouseCursorLocationChanged(gfx::Point(-10, -11)); | 230 user_display_manager1->OnMouseCursorLocationChanged(gfx::Point(-10, -11)); |
| 239 | 231 |
| 240 base::subtle::Atomic32* cursor_location_memory = nullptr; | 232 base::subtle::Atomic32* cursor_location_memory = nullptr; |
| 241 mojo::ScopedSharedBufferHandle handle = | 233 mojo::ScopedSharedBufferHandle handle = |
| 242 user_display_manager1->GetCursorLocationMemory(); | 234 user_display_manager1->GetCursorLocationMemory(); |
| 243 mojo::ScopedSharedBufferMapping cursor_location_mapping = | 235 mojo::ScopedSharedBufferMapping cursor_location_mapping = |
| 244 handle->Map(sizeof(base::subtle::Atomic32)); | 236 handle->Map(sizeof(base::subtle::Atomic32)); |
| 245 ASSERT_TRUE(cursor_location_mapping); | 237 ASSERT_TRUE(cursor_location_mapping); |
| 246 cursor_location_memory = | 238 cursor_location_memory = |
| 247 reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get()); | 239 reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get()); |
| 248 | 240 |
| 249 base::subtle::Atomic32 location = | 241 base::subtle::Atomic32 location = |
| 250 base::subtle::NoBarrier_Load(cursor_location_memory); | 242 base::subtle::NoBarrier_Load(cursor_location_memory); |
| 251 EXPECT_EQ(gfx::Point(static_cast<int16_t>(location >> 16), | 243 EXPECT_EQ(gfx::Point(static_cast<int16_t>(location >> 16), |
| 252 static_cast<int16_t>(location & 0xFFFF)), | 244 static_cast<int16_t>(location & 0xFFFF)), |
| 253 gfx::Point(-10, -11)); | 245 gfx::Point(-10, -11)); |
| 254 } | 246 } |
| 255 | 247 |
| 256 } // namespace test | 248 } // namespace test |
| 257 } // namespace ws | 249 } // namespace ws |
| 258 } // namespace ui | 250 } // namespace ui |
| OLD | NEW |