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/test_utils.h" | 5 #include "services/ui/ws/test_utils.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "cc/output/copy_output_request.h" | 10 #include "cc/output/copy_output_request.h" |
11 #include "gpu/ipc/client/gpu_channel_host.h" | 11 #include "gpu/ipc/client/gpu_channel_host.h" |
12 #include "services/service_manager/public/interfaces/connector.mojom.h" | 12 #include "services/service_manager/public/interfaces/connector.mojom.h" |
13 #include "services/ui/public/interfaces/cursor/cursor.mojom.h" | 13 #include "services/ui/public/interfaces/cursor/cursor.mojom.h" |
14 #include "services/ui/ws/display_binding.h" | 14 #include "services/ui/ws/display_binding.h" |
15 #include "services/ui/ws/display_manager.h" | 15 #include "services/ui/ws/display_manager.h" |
16 #include "services/ui/ws/window_manager_access_policy.h" | 16 #include "services/ui/ws/window_manager_access_policy.h" |
17 #include "services/ui/ws/window_manager_window_tree_factory.h" | 17 #include "services/ui/ws/window_manager_window_tree_factory.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/cursor/cursor.h" |
19 #include "ui/gfx/geometry/dip_util.h" | 20 #include "ui/gfx/geometry/dip_util.h" |
20 | 21 |
21 namespace ui { | 22 namespace ui { |
22 namespace ws { | 23 namespace ws { |
23 namespace test { | 24 namespace test { |
24 namespace { | 25 namespace { |
25 | 26 |
26 // ----------------------------------------------------------------------------- | 27 // ----------------------------------------------------------------------------- |
27 // Empty implementation of PlatformDisplay. | 28 // Empty implementation of PlatformDisplay. |
28 class TestPlatformDisplay : public PlatformDisplay { | 29 class TestPlatformDisplay : public PlatformDisplay { |
29 public: | 30 public: |
30 explicit TestPlatformDisplay(const display::ViewportMetrics& metrics, | 31 explicit TestPlatformDisplay(const display::ViewportMetrics& metrics, |
31 mojom::CursorType* cursor_storage) | 32 ui::CursorData* cursor_storage) |
32 : metrics_(metrics), cursor_storage_(cursor_storage) {} | 33 : metrics_(metrics), cursor_storage_(cursor_storage) {} |
33 ~TestPlatformDisplay() override {} | 34 ~TestPlatformDisplay() override {} |
34 | 35 |
35 // PlatformDisplay: | 36 // PlatformDisplay: |
36 void Init(PlatformDisplayDelegate* delegate) override { | 37 void Init(PlatformDisplayDelegate* delegate) override { |
37 delegate->OnAcceleratedWidgetAvailable(); | 38 delegate->OnAcceleratedWidgetAvailable(); |
38 } | 39 } |
39 void SetViewportSize(const gfx::Size& size) override {} | 40 void SetViewportSize(const gfx::Size& size) override {} |
40 void SetTitle(const base::string16& title) override {} | 41 void SetTitle(const base::string16& title) override {} |
41 void SetCapture() override {} | 42 void SetCapture() override {} |
42 void ReleaseCapture() override {} | 43 void ReleaseCapture() override {} |
43 void SetCursorById(mojom::CursorType cursor) override { | 44 void SetCursor(const ui::CursorData& cursor) override { |
44 *cursor_storage_ = cursor; | 45 *cursor_storage_ = cursor; |
45 } | 46 } |
46 void UpdateTextInputState(const ui::TextInputState& state) override {} | 47 void UpdateTextInputState(const ui::TextInputState& state) override {} |
47 void SetImeVisibility(bool visible) override {} | 48 void SetImeVisibility(bool visible) override {} |
48 void UpdateViewportMetrics(const display::ViewportMetrics& metrics) override { | 49 void UpdateViewportMetrics(const display::ViewportMetrics& metrics) override { |
49 metrics_ = metrics; | 50 metrics_ = metrics; |
50 } | 51 } |
51 gfx::AcceleratedWidget GetAcceleratedWidget() const override { | 52 gfx::AcceleratedWidget GetAcceleratedWidget() const override { |
52 return gfx::kNullAcceleratedWidget; | 53 return gfx::kNullAcceleratedWidget; |
53 } | 54 } |
54 FrameGenerator* GetFrameGenerator() override { return nullptr; } | 55 FrameGenerator* GetFrameGenerator() override { return nullptr; } |
55 EventSink* GetEventSink() override { return nullptr; } | 56 EventSink* GetEventSink() override { return nullptr; } |
56 | 57 |
57 private: | 58 private: |
58 display::ViewportMetrics metrics_; | 59 display::ViewportMetrics metrics_; |
59 mojom::CursorType* cursor_storage_; | 60 ui::CursorData* cursor_storage_; |
60 | 61 |
61 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay); | 62 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay); |
62 }; | 63 }; |
63 | 64 |
64 ClientWindowId NextUnusedClientWindowId(WindowTree* tree) { | 65 ClientWindowId NextUnusedClientWindowId(WindowTree* tree) { |
65 ClientWindowId client_id; | 66 ClientWindowId client_id; |
66 for (ClientSpecificId id = 1;; ++id) { | 67 for (ClientSpecificId id = 1;; ++id) { |
67 // Used the id of the client in the upper bits to simplify things. | 68 // Used the id of the client in the upper bits to simplify things. |
68 const ClientWindowId client_id = | 69 const ClientWindowId client_id = |
69 ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id))); | 70 ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id))); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 display::Screen::SetScreenInstance(screen_.get()); | 143 display::Screen::SetScreenInstance(screen_.get()); |
143 } | 144 } |
144 | 145 |
145 display::ScreenBase* TestScreenManager::GetScreen() { | 146 display::ScreenBase* TestScreenManager::GetScreen() { |
146 return screen_.get(); | 147 return screen_.get(); |
147 } | 148 } |
148 | 149 |
149 // TestPlatformDisplayFactory ------------------------------------------------- | 150 // TestPlatformDisplayFactory ------------------------------------------------- |
150 | 151 |
151 TestPlatformDisplayFactory::TestPlatformDisplayFactory( | 152 TestPlatformDisplayFactory::TestPlatformDisplayFactory( |
152 mojom::CursorType* cursor_storage) | 153 ui::CursorData* cursor_storage) |
153 : cursor_storage_(cursor_storage) {} | 154 : cursor_storage_(cursor_storage) {} |
154 | 155 |
155 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {} | 156 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {} |
156 | 157 |
157 std::unique_ptr<PlatformDisplay> | 158 std::unique_ptr<PlatformDisplay> |
158 TestPlatformDisplayFactory::CreatePlatformDisplay( | 159 TestPlatformDisplayFactory::CreatePlatformDisplay( |
159 ServerWindow* root_window, | 160 ServerWindow* root_window, |
160 const display::ViewportMetrics& metrics) { | 161 const display::ViewportMetrics& metrics) { |
161 return base::MakeUnique<TestPlatformDisplay>(metrics, cursor_storage_); | 162 return base::MakeUnique<TestPlatformDisplay>(metrics, cursor_storage_); |
162 } | 163 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 std::unique_ptr<ui::Event> event, | 417 std::unique_ptr<ui::Event> event, |
417 uint32_t window_id, | 418 uint32_t window_id, |
418 int64_t display_id) { | 419 int64_t display_id) { |
419 tracker_.OnPointerEventObserved(*event.get(), window_id); | 420 tracker_.OnPointerEventObserved(*event.get(), window_id); |
420 } | 421 } |
421 | 422 |
422 void TestWindowTreeClient::OnWindowFocused(uint32_t focused_window_id) { | 423 void TestWindowTreeClient::OnWindowFocused(uint32_t focused_window_id) { |
423 tracker_.OnWindowFocused(focused_window_id); | 424 tracker_.OnWindowFocused(focused_window_id); |
424 } | 425 } |
425 | 426 |
426 void TestWindowTreeClient::OnWindowPredefinedCursorChanged( | 427 void TestWindowTreeClient::OnWindowCursorChanged(uint32_t window_id, |
427 uint32_t window_id, | 428 ui::CursorData cursor) { |
428 mojom::CursorType cursor_id) { | 429 tracker_.OnWindowCursorChanged(window_id, cursor); |
429 tracker_.OnWindowPredefinedCursorChanged(window_id, cursor_id); | |
430 } | 430 } |
431 | 431 |
432 void TestWindowTreeClient::OnWindowSurfaceChanged( | 432 void TestWindowTreeClient::OnWindowSurfaceChanged( |
433 Id window_id, | 433 Id window_id, |
434 const cc::SurfaceInfo& surface_info) {} | 434 const cc::SurfaceInfo& surface_info) {} |
435 | 435 |
436 void TestWindowTreeClient::OnDragDropStart( | 436 void TestWindowTreeClient::OnDragDropStart( |
437 const std::unordered_map<std::string, std::vector<uint8_t>>& mime_data) {} | 437 const std::unordered_map<std::string, std::vector<uint8_t>>& mime_data) {} |
438 | 438 |
439 void TestWindowTreeClient::OnDragEnter(uint32_t window, | 439 void TestWindowTreeClient::OnDragEnter(uint32_t window, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 return std::move(binding); | 523 return std::move(binding); |
524 } | 524 } |
525 | 525 |
526 bool TestWindowServerDelegate::IsTestConfig() const { | 526 bool TestWindowServerDelegate::IsTestConfig() const { |
527 return true; | 527 return true; |
528 } | 528 } |
529 | 529 |
530 // WindowServerTestHelper --------------------------------------------------- | 530 // WindowServerTestHelper --------------------------------------------------- |
531 | 531 |
532 WindowServerTestHelper::WindowServerTestHelper() | 532 WindowServerTestHelper::WindowServerTestHelper() |
533 : cursor_id_(mojom::CursorType::kNull), | 533 : cursor_(ui::CursorType::kNull), platform_display_factory_(&cursor_) { |
534 platform_display_factory_(&cursor_id_) { | |
535 // Some tests create their own message loop, for example to add a task runner. | 534 // Some tests create their own message loop, for example to add a task runner. |
536 if (!base::MessageLoop::current()) | 535 if (!base::MessageLoop::current()) |
537 message_loop_ = base::MakeUnique<base::MessageLoop>(); | 536 message_loop_ = base::MakeUnique<base::MessageLoop>(); |
538 PlatformDisplay::set_factory_for_testing(&platform_display_factory_); | 537 PlatformDisplay::set_factory_for_testing(&platform_display_factory_); |
539 window_server_ = base::MakeUnique<WindowServer>(&window_server_delegate_); | 538 window_server_ = base::MakeUnique<WindowServer>(&window_server_delegate_); |
540 window_server_delegate_.set_window_server(window_server_.get()); | 539 window_server_delegate_.set_window_server(window_server_.get()); |
541 } | 540 } |
542 | 541 |
543 WindowServerTestHelper::~WindowServerTestHelper() { | 542 WindowServerTestHelper::~WindowServerTestHelper() { |
544 // Destroy |window_server_| while the message-loop is still alive. | 543 // Destroy |window_server_| while the message-loop is still alive. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 if (!tree->AddWindow(parent_client_id, client_window_id)) | 689 if (!tree->AddWindow(parent_client_id, client_window_id)) |
691 return nullptr; | 690 return nullptr; |
692 if (client_id) | 691 if (client_id) |
693 *client_id = client_window_id; | 692 *client_id = client_window_id; |
694 return tree->GetWindowByClientId(client_window_id); | 693 return tree->GetWindowByClientId(client_window_id); |
695 } | 694 } |
696 | 695 |
697 } // namespace test | 696 } // namespace test |
698 } // namespace ws | 697 } // namespace ws |
699 } // namespace ui | 698 } // namespace ui |
OLD | NEW |