| 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.mojom.h" | 13 #include "services/ui/public/interfaces/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/platform_display_init_params.h" |  | 
| 17 #include "services/ui/ws/window_manager_access_policy.h" | 16 #include "services/ui/ws/window_manager_access_policy.h" | 
| 18 #include "services/ui/ws/window_manager_window_tree_factory.h" | 17 #include "services/ui/ws/window_manager_window_tree_factory.h" | 
| 19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" | 
| 20 #include "ui/gfx/geometry/dip_util.h" | 19 #include "ui/gfx/geometry/dip_util.h" | 
| 21 | 20 | 
| 22 namespace ui { | 21 namespace ui { | 
| 23 namespace ws { | 22 namespace ws { | 
| 24 namespace test { | 23 namespace test { | 
| 25 namespace { | 24 namespace { | 
| 26 | 25 | 
| 27 // ----------------------------------------------------------------------------- | 26 // ----------------------------------------------------------------------------- | 
| 28 // Empty implementation of PlatformDisplay. | 27 // Empty implementation of PlatformDisplay. | 
| 29 class TestPlatformDisplay : public PlatformDisplay { | 28 class TestPlatformDisplay : public PlatformDisplay { | 
| 30  public: | 29  public: | 
| 31   explicit TestPlatformDisplay(const PlatformDisplayInitParams& params, | 30   explicit TestPlatformDisplay(const display::ViewportMetrics& metrics, | 
| 32                                mojom::Cursor* cursor_storage) | 31                                mojom::Cursor* cursor_storage) | 
| 33       : id_(params.display_id), | 32       : metrics_(metrics), cursor_storage_(cursor_storage) {} | 
| 34         display_metrics_(params.metrics), |  | 
| 35         cursor_storage_(cursor_storage) { |  | 
| 36     display_metrics_.bounds = gfx::Rect(0, 0, 400, 300); |  | 
| 37     display_metrics_.device_scale_factor = 1.f; |  | 
| 38   } |  | 
| 39   ~TestPlatformDisplay() override {} | 33   ~TestPlatformDisplay() override {} | 
| 40 | 34 | 
| 41   // PlatformDisplay: | 35   // PlatformDisplay: | 
| 42   void Init(PlatformDisplayDelegate* delegate) override { | 36   void Init(PlatformDisplayDelegate* delegate) override { | 
| 43     delegate->OnAcceleratedWidgetAvailable(); | 37     delegate->OnAcceleratedWidgetAvailable(); | 
| 44   } | 38   } | 
| 45   int64_t GetId() const override { return id_; } |  | 
| 46   void SetViewportSize(const gfx::Size& size) override {} | 39   void SetViewportSize(const gfx::Size& size) override {} | 
| 47   void SetTitle(const base::string16& title) override {} | 40   void SetTitle(const base::string16& title) override {} | 
| 48   void SetCapture() override {} | 41   void SetCapture() override {} | 
| 49   void ReleaseCapture() override {} | 42   void ReleaseCapture() override {} | 
| 50   void SetCursorById(mojom::Cursor cursor) override { | 43   void SetCursorById(mojom::Cursor cursor) override { | 
| 51     *cursor_storage_ = cursor; | 44     *cursor_storage_ = cursor; | 
| 52   } | 45   } | 
| 53   void UpdateTextInputState(const ui::TextInputState& state) override {} | 46   void UpdateTextInputState(const ui::TextInputState& state) override {} | 
| 54   void SetImeVisibility(bool visible) override {} | 47   void SetImeVisibility(bool visible) override {} | 
| 55   gfx::Rect GetBounds() const override { return display_metrics_.bounds; } |  | 
| 56   bool UpdateViewportMetrics(const display::ViewportMetrics& metrics) override { | 48   bool UpdateViewportMetrics(const display::ViewportMetrics& metrics) override { | 
| 57     if (display_metrics_ == metrics) | 49     if (metrics_ == metrics) | 
| 58       return false; | 50       return false; | 
| 59     display_metrics_ = metrics; | 51     metrics_ = metrics; | 
| 60     return true; | 52     return true; | 
| 61   } | 53   } | 
| 62   const display::ViewportMetrics& GetViewportMetrics() const override { |  | 
| 63     return display_metrics_; |  | 
| 64   } |  | 
| 65   gfx::AcceleratedWidget GetAcceleratedWidget() const override { | 54   gfx::AcceleratedWidget GetAcceleratedWidget() const override { | 
| 66     return gfx::kNullAcceleratedWidget; | 55     return gfx::kNullAcceleratedWidget; | 
| 67   } | 56   } | 
| 68   FrameGenerator* GetFrameGenerator() override { return nullptr; } | 57   FrameGenerator* GetFrameGenerator() override { return nullptr; } | 
| 69 | 58 | 
| 70  private: | 59  private: | 
| 71   const int64_t id_; | 60   display::ViewportMetrics metrics_; | 
| 72   display::ViewportMetrics display_metrics_; |  | 
| 73   mojom::Cursor* cursor_storage_; | 61   mojom::Cursor* cursor_storage_; | 
| 74 | 62 | 
| 75   DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay); | 63   DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay); | 
| 76 }; | 64 }; | 
| 77 | 65 | 
| 78 ClientWindowId NextUnusedClientWindowId(WindowTree* tree) { | 66 ClientWindowId NextUnusedClientWindowId(WindowTree* tree) { | 
| 79   ClientWindowId client_id; | 67   ClientWindowId client_id; | 
| 80   for (ClientSpecificId id = 1;; ++id) { | 68   for (ClientSpecificId id = 1;; ++id) { | 
| 81     // Used the id of the client in the upper bits to simplify things. | 69     // Used the id of the client in the upper bits to simplify things. | 
| 82     const ClientWindowId client_id = | 70     const ClientWindowId client_id = | 
| 83         ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id))); | 71         ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id))); | 
| 84     if (!tree->GetWindowByClientId(client_id)) | 72     if (!tree->GetWindowByClientId(client_id)) | 
| 85       return client_id; | 73       return client_id; | 
| 86   } | 74   } | 
| 87 } | 75 } | 
| 88 | 76 | 
| 89 // Creates a Display with |id| and same attributes as |metrics|. | 77 display::ViewportMetrics MakeViewportMetrics(const display::Display& display) { | 
| 90 display::Display CreateDisplay(int64_t id, | 78   gfx::Size pixel_size = gfx::ConvertSizeToPixel(display.device_scale_factor(), | 
| 91                                const display::ViewportMetrics& metrics) { | 79                                                  display.bounds().size()); | 
| 92   display::Display display(id); | 80 | 
| 93   display.set_bounds(metrics.bounds); | 81   display::ViewportMetrics metrics; | 
| 94   display.set_work_area(metrics.work_area); | 82   metrics.bounds_in_pixels.set_size(pixel_size); | 
| 95   display.set_device_scale_factor(metrics.device_scale_factor); | 83   metrics.device_scale_factor = display.device_scale_factor(); | 
| 96   display.set_rotation(metrics.rotation); | 84   return metrics; | 
| 97   display.set_touch_support(metrics.touch_support); |  | 
| 98   return display; |  | 
| 99 } | 85 } | 
| 100 | 86 | 
| 101 }  // namespace | 87 }  // namespace | 
| 102 | 88 | 
| 103 // TestScreenManager  ------------------------------------------------- | 89 // TestScreenManager  ------------------------------------------------- | 
| 104 | 90 | 
| 105 TestScreenManager::TestScreenManager() {} | 91 TestScreenManager::TestScreenManager() {} | 
| 106 | 92 | 
| 107 TestScreenManager::~TestScreenManager() { | 93 TestScreenManager::~TestScreenManager() { | 
| 108   display::Screen::SetScreenInstance(nullptr); | 94   display::Screen::SetScreenInstance(nullptr); | 
| 109 } | 95 } | 
| 110 | 96 | 
| 111 int64_t TestScreenManager::AddDisplay() { | 97 int64_t TestScreenManager::AddDisplay() { | 
| 112   return AddDisplay(MakeViewportMetrics(0, 0, 100, 100, 1.0f)); | 98   return AddDisplay( | 
|  | 99       display::Display(display::kInvalidDisplayId, gfx::Rect(100, 100))); | 
| 113 } | 100 } | 
| 114 | 101 | 
| 115 int64_t TestScreenManager::AddDisplay(const display::ViewportMetrics& metrics) { | 102 int64_t TestScreenManager::AddDisplay(const display::Display& input_display) { | 
| 116   // Generate a unique display id. | 103   // Generate a unique display id. | 
| 117   int64_t display_id = display_ids_.empty() ? 1 : *display_ids_.rbegin() + 1; | 104   int64_t display_id = display_ids_.empty() ? 1 : *display_ids_.rbegin() + 1; | 
| 118   display_ids_.insert(display_id); | 105   display_ids_.insert(display_id); | 
| 119 | 106 | 
|  | 107   display::Display display = input_display; | 
|  | 108   display.set_id(display_id); | 
|  | 109 | 
| 120   // First display added will be the primary display. | 110   // First display added will be the primary display. | 
| 121   display::DisplayList::Type type = display::DisplayList::Type::NOT_PRIMARY; | 111   display::DisplayList::Type type = display::DisplayList::Type::NOT_PRIMARY; | 
| 122   if (display_ids_.size() == 1) | 112   if (display_ids_.size() == 1) | 
| 123     type = display::DisplayList::Type::PRIMARY; | 113     type = display::DisplayList::Type::PRIMARY; | 
| 124 | 114 | 
| 125   screen_->display_list().AddDisplay(CreateDisplay(display_id, metrics), type); | 115   screen_->display_list().AddDisplay(display, type); | 
| 126   delegate_->OnDisplayAdded(display_id, metrics); | 116   delegate_->OnDisplayAdded(display, MakeViewportMetrics(display)); | 
| 127 | 117 | 
| 128   if (type == display::DisplayList::Type::PRIMARY) | 118   if (type == display::DisplayList::Type::PRIMARY) | 
| 129     delegate_->OnPrimaryDisplayChanged(display_id); | 119     delegate_->OnPrimaryDisplayChanged(display_id); | 
| 130 | 120 | 
| 131   return display_id; | 121   return display_id; | 
| 132 } | 122 } | 
| 133 | 123 | 
| 134 void TestScreenManager::ModifyDisplay(int64_t display_id, | 124 void TestScreenManager::ModifyDisplay(const display::Display& display) { | 
| 135                                       const display::ViewportMetrics& metrics) { | 125   DCHECK(display_ids_.count(display.id()) == 1); | 
| 136   DCHECK(display_ids_.count(display_id) == 1); | 126   screen_->display_list().UpdateDisplay(display); | 
| 137   screen_->display_list().UpdateDisplay(CreateDisplay(display_id, metrics)); | 127   delegate_->OnDisplayModified(display, MakeViewportMetrics(display)); | 
| 138   delegate_->OnDisplayModified(display_id, metrics); |  | 
| 139 } | 128 } | 
| 140 | 129 | 
| 141 void TestScreenManager::RemoveDisplay(int64_t display_id) { | 130 void TestScreenManager::RemoveDisplay(int64_t display_id) { | 
| 142   DCHECK(display_ids_.count(display_id) == 1); | 131   DCHECK(display_ids_.count(display_id) == 1); | 
| 143   screen_->display_list().RemoveDisplay(display_id); | 132   screen_->display_list().RemoveDisplay(display_id); | 
| 144   delegate_->OnDisplayRemoved(display_id); | 133   delegate_->OnDisplayRemoved(display_id); | 
| 145   display_ids_.erase(display_id); | 134   display_ids_.erase(display_id); | 
| 146 } | 135 } | 
| 147 | 136 | 
| 148 void TestScreenManager::Init(display::ScreenManagerDelegate* delegate) { | 137 void TestScreenManager::Init(display::ScreenManagerDelegate* delegate) { | 
| 149   delegate_ = delegate; | 138   delegate_ = delegate; | 
| 150 | 139 | 
| 151   // Reset everything. | 140   // Reset everything. | 
| 152   display_ids_.clear(); | 141   display_ids_.clear(); | 
| 153   display::Screen::SetScreenInstance(nullptr); | 142   display::Screen::SetScreenInstance(nullptr); | 
| 154   screen_ = base::MakeUnique<display::ScreenBase>(); | 143   screen_ = base::MakeUnique<display::ScreenBase>(); | 
| 155   display::Screen::SetScreenInstance(screen_.get()); | 144   display::Screen::SetScreenInstance(screen_.get()); | 
| 156 } | 145 } | 
| 157 | 146 | 
| 158 // TestPlatformDisplayFactory  ------------------------------------------------- | 147 // TestPlatformDisplayFactory  ------------------------------------------------- | 
| 159 | 148 | 
| 160 TestPlatformDisplayFactory::TestPlatformDisplayFactory( | 149 TestPlatformDisplayFactory::TestPlatformDisplayFactory( | 
| 161     mojom::Cursor* cursor_storage) | 150     mojom::Cursor* cursor_storage) | 
| 162     : cursor_storage_(cursor_storage) {} | 151     : cursor_storage_(cursor_storage) {} | 
| 163 | 152 | 
| 164 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {} | 153 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {} | 
| 165 | 154 | 
| 166 std::unique_ptr<PlatformDisplay> | 155 std::unique_ptr<PlatformDisplay> | 
| 167 TestPlatformDisplayFactory::CreatePlatformDisplay( | 156 TestPlatformDisplayFactory::CreatePlatformDisplay( | 
| 168     const PlatformDisplayInitParams& init_params) { | 157     ServerWindow* root_window, | 
| 169   return base::MakeUnique<TestPlatformDisplay>(init_params, cursor_storage_); | 158     const display::ViewportMetrics& metrics) { | 
|  | 159   return base::MakeUnique<TestPlatformDisplay>(metrics, cursor_storage_); | 
| 170 } | 160 } | 
| 171 | 161 | 
| 172 // TestFrameGeneratorDelegate ------------------------------------------------- | 162 // TestFrameGeneratorDelegate ------------------------------------------------- | 
| 173 | 163 | 
| 174 TestFrameGeneratorDelegate::TestFrameGeneratorDelegate() {} | 164 TestFrameGeneratorDelegate::TestFrameGeneratorDelegate() {} | 
| 175 | 165 | 
| 176 TestFrameGeneratorDelegate::~TestFrameGeneratorDelegate() {} | 166 TestFrameGeneratorDelegate::~TestFrameGeneratorDelegate() {} | 
| 177 | 167 | 
| 178 bool TestFrameGeneratorDelegate::IsInHighContrastMode() { | 168 bool TestFrameGeneratorDelegate::IsInHighContrastMode() { | 
| 179   return false; | 169   return false; | 
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 515 WindowServerTestHelper::~WindowServerTestHelper() { | 505 WindowServerTestHelper::~WindowServerTestHelper() { | 
| 516   // Destroy |window_server_| while the message-loop is still alive. | 506   // Destroy |window_server_| while the message-loop is still alive. | 
| 517   window_server_.reset(); | 507   window_server_.reset(); | 
| 518 } | 508 } | 
| 519 | 509 | 
| 520 // WindowEventTargetingHelper ------------------------------------------------ | 510 // WindowEventTargetingHelper ------------------------------------------------ | 
| 521 | 511 | 
| 522 WindowEventTargetingHelper::WindowEventTargetingHelper() { | 512 WindowEventTargetingHelper::WindowEventTargetingHelper() { | 
| 523   display_ = new Display(window_server()); | 513   display_ = new Display(window_server()); | 
| 524   display_binding_ = new TestDisplayBinding(window_server()); | 514   display_binding_ = new TestDisplayBinding(window_server()); | 
| 525   display_->Init(PlatformDisplayInitParams(), | 515   display_->Init(display::ViewportMetrics(), | 
| 526                  base::WrapUnique(display_binding_)); | 516                  base::WrapUnique(display_binding_)); | 
| 527   wm_client_ = ws_test_helper_.window_server_delegate()->last_client(); | 517   wm_client_ = ws_test_helper_.window_server_delegate()->last_client(); | 
| 528   wm_client_->tracker()->changes()->clear(); | 518   wm_client_->tracker()->changes()->clear(); | 
| 529 } | 519 } | 
| 530 | 520 | 
| 531 WindowEventTargetingHelper::~WindowEventTargetingHelper() {} | 521 WindowEventTargetingHelper::~WindowEventTargetingHelper() {} | 
| 532 | 522 | 
| 533 ServerWindow* WindowEventTargetingHelper::CreatePrimaryTree( | 523 ServerWindow* WindowEventTargetingHelper::CreatePrimaryTree( | 
| 534     const gfx::Rect& root_window_bounds, | 524     const gfx::Rect& root_window_bounds, | 
| 535     const gfx::Rect& window_bounds) { | 525     const gfx::Rect& window_bounds) { | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 595 } | 585 } | 
| 596 | 586 | 
| 597 // ---------------------------------------------------------------------------- | 587 // ---------------------------------------------------------------------------- | 
| 598 | 588 | 
| 599 void AddWindowManager(WindowServer* window_server, const UserId& user_id) { | 589 void AddWindowManager(WindowServer* window_server, const UserId& user_id) { | 
| 600   window_server->window_manager_window_tree_factory_set() | 590   window_server->window_manager_window_tree_factory_set() | 
| 601       ->Add(user_id, nullptr) | 591       ->Add(user_id, nullptr) | 
| 602       ->CreateWindowTree(nullptr, nullptr); | 592       ->CreateWindowTree(nullptr, nullptr); | 
| 603 } | 593 } | 
| 604 | 594 | 
| 605 display::ViewportMetrics MakeViewportMetrics(int origin_x, | 595 display::Display MakeDisplay(int origin_x, | 
| 606                                              int origin_y, | 596                              int origin_y, | 
| 607                                              int width_pixels, | 597                              int width_pixels, | 
| 608                                              int height_pixels, | 598                              int height_pixels, | 
| 609                                              float scale_factor) { | 599                              float scale_factor) { | 
| 610   display::ViewportMetrics metrics; |  | 
| 611   gfx::Size scaled_size = gfx::ConvertSizeToDIP( | 600   gfx::Size scaled_size = gfx::ConvertSizeToDIP( | 
| 612       scale_factor, gfx::Size(width_pixels, height_pixels)); | 601       scale_factor, gfx::Size(width_pixels, height_pixels)); | 
| 613   metrics.bounds = gfx::Rect(gfx::Point(origin_x, origin_y), scaled_size); | 602   gfx::Rect bounds(gfx::Point(origin_x, origin_y), scaled_size); | 
| 614   metrics.work_area = metrics.bounds; | 603 | 
| 615   metrics.pixel_size = gfx::Size(width_pixels, height_pixels); | 604   display::Display display; | 
| 616   metrics.device_scale_factor = scale_factor; | 605   display.set_bounds(bounds); | 
| 617   return metrics; | 606   display.set_work_area(bounds); | 
|  | 607   display.set_device_scale_factor(scale_factor); | 
|  | 608   return display; | 
| 618 } | 609 } | 
| 619 | 610 | 
| 620 ServerWindow* FirstRoot(WindowTree* tree) { | 611 ServerWindow* FirstRoot(WindowTree* tree) { | 
| 621   return tree->roots().size() == 1u | 612   return tree->roots().size() == 1u | 
| 622              ? tree->GetWindow((*tree->roots().begin())->id()) | 613              ? tree->GetWindow((*tree->roots().begin())->id()) | 
| 623              : nullptr; | 614              : nullptr; | 
| 624 } | 615 } | 
| 625 | 616 | 
| 626 ClientWindowId FirstRootId(WindowTree* tree) { | 617 ClientWindowId FirstRootId(WindowTree* tree) { | 
| 627   ServerWindow* first_root = FirstRoot(tree); | 618   ServerWindow* first_root = FirstRoot(tree); | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 657   if (!tree->AddWindow(parent_client_id, client_window_id)) | 648   if (!tree->AddWindow(parent_client_id, client_window_id)) | 
| 658     return nullptr; | 649     return nullptr; | 
| 659   if (client_id) | 650   if (client_id) | 
| 660     *client_id = client_window_id; | 651     *client_id = client_window_id; | 
| 661   return tree->GetWindowByClientId(client_window_id); | 652   return tree->GetWindowByClientId(client_window_id); | 
| 662 } | 653 } | 
| 663 | 654 | 
| 664 }  // namespace test | 655 }  // namespace test | 
| 665 }  // namespace ws | 656 }  // namespace ws | 
| 666 }  // namespace ui | 657 }  // namespace ui | 
| OLD | NEW | 
|---|