| 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/shell/public/interfaces/connector.mojom.h" | 12 #include "services/shell/public/interfaces/connector.mojom.h" |
| 13 #include "services/ui/public/interfaces/cursor.mojom.h" |
| 13 #include "services/ui/surfaces/surfaces_state.h" | 14 #include "services/ui/surfaces/surfaces_state.h" |
| 14 #include "services/ui/ws/display_binding.h" | 15 #include "services/ui/ws/display_binding.h" |
| 15 #include "services/ui/ws/display_manager.h" | 16 #include "services/ui/ws/display_manager.h" |
| 16 #include "services/ui/ws/platform_display_init_params.h" | 17 #include "services/ui/ws/platform_display_init_params.h" |
| 17 #include "services/ui/ws/server_window_surface_manager_test_api.h" | 18 #include "services/ui/ws/server_window_surface_manager_test_api.h" |
| 18 #include "services/ui/ws/window_manager_access_policy.h" | 19 #include "services/ui/ws/window_manager_access_policy.h" |
| 19 #include "services/ui/ws/window_manager_window_tree_factory.h" | 20 #include "services/ui/ws/window_manager_window_tree_factory.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace ui { | 23 namespace ui { |
| 23 namespace ws { | 24 namespace ws { |
| 24 namespace test { | 25 namespace test { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // ----------------------------------------------------------------------------- | 28 // ----------------------------------------------------------------------------- |
| 28 // Empty implementation of PlatformDisplay. | 29 // Empty implementation of PlatformDisplay. |
| 29 class TestPlatformDisplay : public PlatformDisplay { | 30 class TestPlatformDisplay : public PlatformDisplay { |
| 30 public: | 31 public: |
| 31 explicit TestPlatformDisplay(int64_t id, | 32 explicit TestPlatformDisplay(int64_t id, |
| 32 bool is_primary, | 33 bool is_primary, |
| 33 int32_t* cursor_id_storage) | 34 mojom::Cursor* cursor_storage) |
| 34 : id_(id), | 35 : id_(id), |
| 35 is_primary_(is_primary), | 36 is_primary_(is_primary), |
| 36 cursor_id_storage_(cursor_id_storage) { | 37 cursor_storage_(cursor_storage) { |
| 37 display_metrics_.bounds = gfx::Rect(0, 0, 400, 300); | 38 display_metrics_.bounds = gfx::Rect(0, 0, 400, 300); |
| 38 display_metrics_.device_scale_factor = 1.f; | 39 display_metrics_.device_scale_factor = 1.f; |
| 39 } | 40 } |
| 40 ~TestPlatformDisplay() override {} | 41 ~TestPlatformDisplay() override {} |
| 41 | 42 |
| 42 // PlatformDisplay: | 43 // PlatformDisplay: |
| 43 void Init(PlatformDisplayDelegate* delegate) override { | 44 void Init(PlatformDisplayDelegate* delegate) override { |
| 44 delegate->CreateRootWindow(display_metrics_.bounds.size()); | 45 delegate->CreateRootWindow(display_metrics_.bounds.size()); |
| 45 } | 46 } |
| 46 int64_t GetId() const override { return id_; } | 47 int64_t GetId() const override { return id_; } |
| 47 void SchedulePaint(const ServerWindow* window, | 48 void SchedulePaint(const ServerWindow* window, |
| 48 const gfx::Rect& bounds) override {} | 49 const gfx::Rect& bounds) override {} |
| 49 void SetViewportSize(const gfx::Size& size) override {} | 50 void SetViewportSize(const gfx::Size& size) override {} |
| 50 void SetTitle(const base::string16& title) override {} | 51 void SetTitle(const base::string16& title) override {} |
| 51 void SetCapture() override {} | 52 void SetCapture() override {} |
| 52 void ReleaseCapture() override {} | 53 void ReleaseCapture() override {} |
| 53 void SetCursorById(int32_t cursor) override { *cursor_id_storage_ = cursor; } | 54 void SetCursorById(mojom::Cursor cursor) override { |
| 55 *cursor_storage_ = cursor; |
| 56 } |
| 54 display::Display::Rotation GetRotation() override { | 57 display::Display::Rotation GetRotation() override { |
| 55 return display::Display::Rotation::ROTATE_0; | 58 return display::Display::Rotation::ROTATE_0; |
| 56 } | 59 } |
| 57 float GetDeviceScaleFactor() override { | 60 float GetDeviceScaleFactor() override { |
| 58 return display_metrics_.device_scale_factor; | 61 return display_metrics_.device_scale_factor; |
| 59 } | 62 } |
| 60 void UpdateTextInputState(const ui::TextInputState& state) override {} | 63 void UpdateTextInputState(const ui::TextInputState& state) override {} |
| 61 void SetImeVisibility(bool visible) override {} | 64 void SetImeVisibility(bool visible) override {} |
| 62 bool IsFramePending() const override { return false; } | 65 bool IsFramePending() const override { return false; } |
| 63 void RequestCopyOfOutput( | 66 void RequestCopyOfOutput( |
| 64 std::unique_ptr<cc::CopyOutputRequest> output_request) override {} | 67 std::unique_ptr<cc::CopyOutputRequest> output_request) override {} |
| 65 gfx::Rect GetBounds() const override { return display_metrics_.bounds; } | 68 gfx::Rect GetBounds() const override { return display_metrics_.bounds; } |
| 66 bool IsPrimaryDisplay() const override { return is_primary_; } | 69 bool IsPrimaryDisplay() const override { return is_primary_; } |
| 67 void OnGpuChannelEstablished( | 70 void OnGpuChannelEstablished( |
| 68 scoped_refptr<gpu::GpuChannelHost> host) override {} | 71 scoped_refptr<gpu::GpuChannelHost> host) override {} |
| 69 | 72 |
| 70 private: | 73 private: |
| 71 ViewportMetrics display_metrics_; | 74 ViewportMetrics display_metrics_; |
| 72 | 75 |
| 73 int64_t id_; | 76 int64_t id_; |
| 74 bool is_primary_; | 77 bool is_primary_; |
| 75 int32_t* cursor_id_storage_; | 78 mojom::Cursor* cursor_storage_; |
| 76 | 79 |
| 77 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay); | 80 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay); |
| 78 }; | 81 }; |
| 79 | 82 |
| 80 ClientWindowId NextUnusedClientWindowId(WindowTree* tree) { | 83 ClientWindowId NextUnusedClientWindowId(WindowTree* tree) { |
| 81 ClientWindowId client_id; | 84 ClientWindowId client_id; |
| 82 for (ClientSpecificId id = 1;; ++id) { | 85 for (ClientSpecificId id = 1;; ++id) { |
| 83 // Used the id of the client in the upper bits to simplify things. | 86 // Used the id of the client in the upper bits to simplify things. |
| 84 const ClientWindowId client_id = | 87 const ClientWindowId client_id = |
| 85 ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id))); | 88 ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id))); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 106 WindowManagerWindowTreeFactory* factory = | 109 WindowManagerWindowTreeFactory* factory = |
| 107 window_manager_window_tree_factory_set_->Add(user_id, nullptr); | 110 window_manager_window_tree_factory_set_->Add(user_id, nullptr); |
| 108 factory->CreateWindowTree(nullptr, nullptr); | 111 factory->CreateWindowTree(nullptr, nullptr); |
| 109 } | 112 } |
| 110 | 113 |
| 111 // TestPlatformDisplayFactory ------------------------------------------------- | 114 // TestPlatformDisplayFactory ------------------------------------------------- |
| 112 | 115 |
| 113 const int64_t TestPlatformDisplayFactory::kFirstDisplayId = 1; | 116 const int64_t TestPlatformDisplayFactory::kFirstDisplayId = 1; |
| 114 | 117 |
| 115 TestPlatformDisplayFactory::TestPlatformDisplayFactory( | 118 TestPlatformDisplayFactory::TestPlatformDisplayFactory( |
| 116 int32_t* cursor_id_storage) | 119 mojom::Cursor* cursor_storage) |
| 117 : cursor_id_storage_(cursor_id_storage), | 120 : cursor_storage_(cursor_storage), |
| 118 next_display_id_(kFirstDisplayId) {} | 121 next_display_id_(kFirstDisplayId) {} |
| 119 | 122 |
| 120 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {} | 123 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {} |
| 121 | 124 |
| 122 PlatformDisplay* TestPlatformDisplayFactory::CreatePlatformDisplay() { | 125 PlatformDisplay* TestPlatformDisplayFactory::CreatePlatformDisplay() { |
| 123 bool is_primary = (next_display_id_ == kFirstDisplayId); | 126 bool is_primary = (next_display_id_ == kFirstDisplayId); |
| 124 return new TestPlatformDisplay(next_display_id_++, is_primary, | 127 return new TestPlatformDisplay(next_display_id_++, is_primary, |
| 125 cursor_id_storage_); | 128 cursor_storage_); |
| 126 } | 129 } |
| 127 | 130 |
| 128 // TestFrameGeneratorDelegate ------------------------------------------------- | 131 // TestFrameGeneratorDelegate ------------------------------------------------- |
| 129 | 132 |
| 130 TestFrameGeneratorDelegate::TestFrameGeneratorDelegate( | 133 TestFrameGeneratorDelegate::TestFrameGeneratorDelegate( |
| 131 std::unique_ptr<ServerWindow> root) | 134 std::unique_ptr<ServerWindow> root) |
| 132 : root_(std::move(root)) {} | 135 : root_(std::move(root)) {} |
| 133 | 136 |
| 134 TestFrameGeneratorDelegate::~TestFrameGeneratorDelegate() {} | 137 TestFrameGeneratorDelegate::~TestFrameGeneratorDelegate() {} |
| 135 | 138 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 AddDisplay(); | 460 AddDisplay(); |
| 458 } | 461 } |
| 459 | 462 |
| 460 bool TestWindowServerDelegate::IsTestConfig() const { | 463 bool TestWindowServerDelegate::IsTestConfig() const { |
| 461 return true; | 464 return true; |
| 462 } | 465 } |
| 463 | 466 |
| 464 // WindowServerTestHelper --------------------------------------------------- | 467 // WindowServerTestHelper --------------------------------------------------- |
| 465 | 468 |
| 466 WindowServerTestHelper::WindowServerTestHelper() | 469 WindowServerTestHelper::WindowServerTestHelper() |
| 467 : cursor_id_(0), platform_display_factory_(&cursor_id_) { | 470 : cursor_id_(mojom::Cursor::CURSOR_NULL), |
| 471 platform_display_factory_(&cursor_id_) { |
| 468 PlatformDisplay::set_factory_for_testing(&platform_display_factory_); | 472 PlatformDisplay::set_factory_for_testing(&platform_display_factory_); |
| 469 window_server_ = base::MakeUnique<WindowServer>(&window_server_delegate_); | 473 window_server_ = base::MakeUnique<WindowServer>(&window_server_delegate_); |
| 470 window_server_delegate_.set_window_server(window_server_.get()); | 474 window_server_delegate_.set_window_server(window_server_.get()); |
| 471 } | 475 } |
| 472 | 476 |
| 473 WindowServerTestHelper::~WindowServerTestHelper() { | 477 WindowServerTestHelper::~WindowServerTestHelper() { |
| 474 // Destroy |window_server_| while the message-loop is still alive. | 478 // Destroy |window_server_| while the message-loop is still alive. |
| 475 window_server_.reset(); | 479 window_server_.reset(); |
| 476 } | 480 } |
| 477 | 481 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 return nullptr; | 600 return nullptr; |
| 597 if (!tree->AddWindow(parent_client_id, client_window_id)) | 601 if (!tree->AddWindow(parent_client_id, client_window_id)) |
| 598 return nullptr; | 602 return nullptr; |
| 599 *client_id = client_window_id; | 603 *client_id = client_window_id; |
| 600 return tree->GetWindowByClientId(client_window_id); | 604 return tree->GetWindowByClientId(client_window_id); |
| 601 } | 605 } |
| 602 | 606 |
| 603 } // namespace test | 607 } // namespace test |
| 604 } // namespace ws | 608 } // namespace ws |
| 605 } // namespace ui | 609 } // namespace ui |
| OLD | NEW |