Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: services/ui/ws/test_utils.cc

Issue 2512593003: Cleanup display creation in mus tests. (Closed)
Patch Set: Cleanup. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/ws/test_utils.h ('k') | services/ui/ws/user_display_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 16 #include "services/ui/ws/platform_display_init_params.h"
17 #include "services/ui/ws/server_window_compositor_frame_sink_manager_test_api.h" 17 #include "services/ui/ws/server_window_compositor_frame_sink_manager_test_api.h"
18 #include "services/ui/ws/window_manager_access_policy.h" 18 #include "services/ui/ws/window_manager_access_policy.h"
19 #include "services/ui/ws/window_manager_window_tree_factory.h" 19 #include "services/ui/ws/window_manager_window_tree_factory.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/gfx/geometry/dip_util.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(const PlatformDisplayInitParams& params,
32 bool is_primary,
33 mojom::Cursor* cursor_storage) 33 mojom::Cursor* cursor_storage)
34 : id_(id), 34 : id_(params.display_id),
35 is_primary_(is_primary), 35 display_metrics_(params.metrics),
36 cursor_storage_(cursor_storage) { 36 cursor_storage_(cursor_storage) {
37 display_metrics_.bounds = gfx::Rect(0, 0, 400, 300); 37 display_metrics_.bounds = gfx::Rect(0, 0, 400, 300);
38 display_metrics_.device_scale_factor = 1.f; 38 display_metrics_.device_scale_factor = 1.f;
39 } 39 }
40 ~TestPlatformDisplay() override {} 40 ~TestPlatformDisplay() override {}
41 41
42 // PlatformDisplay: 42 // PlatformDisplay:
43 void Init(PlatformDisplayDelegate* delegate) override { 43 void Init(PlatformDisplayDelegate* delegate) override {
44 delegate->OnAcceleratedWidgetAvailable(); 44 delegate->OnAcceleratedWidgetAvailable();
45 } 45 }
(...skipping 10 matching lines...) Expand all
56 gfx::Rect GetBounds() const override { return display_metrics_.bounds; } 56 gfx::Rect GetBounds() const override { return display_metrics_.bounds; }
57 bool UpdateViewportMetrics(const display::ViewportMetrics& metrics) override { 57 bool UpdateViewportMetrics(const display::ViewportMetrics& metrics) override {
58 if (display_metrics_ == metrics) 58 if (display_metrics_ == metrics)
59 return false; 59 return false;
60 display_metrics_ = metrics; 60 display_metrics_ = metrics;
61 return true; 61 return true;
62 } 62 }
63 const display::ViewportMetrics& GetViewportMetrics() const override { 63 const display::ViewportMetrics& GetViewportMetrics() const override {
64 return display_metrics_; 64 return display_metrics_;
65 } 65 }
66 bool IsPrimaryDisplay() const override { return is_primary_; }
67 void OnGpuChannelEstablished( 66 void OnGpuChannelEstablished(
68 scoped_refptr<gpu::GpuChannelHost> host) override {} 67 scoped_refptr<gpu::GpuChannelHost> host) override {}
69 68
70 private: 69 private:
70 int64_t id_;
sky 2016/11/18 16:57:39 const if you can.
kylechar 2016/11/18 17:27:07 Done.
71 display::ViewportMetrics display_metrics_; 71 display::ViewportMetrics display_metrics_;
72
73 int64_t id_;
74 bool is_primary_;
75 mojom::Cursor* cursor_storage_; 72 mojom::Cursor* cursor_storage_;
76 73
77 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay); 74 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay);
78 }; 75 };
79 76
80 ClientWindowId NextUnusedClientWindowId(WindowTree* tree) { 77 ClientWindowId NextUnusedClientWindowId(WindowTree* tree) {
81 ClientWindowId client_id; 78 ClientWindowId client_id;
82 for (ClientSpecificId id = 1;; ++id) { 79 for (ClientSpecificId id = 1;; ++id) {
83 // Used the id of the client in the upper bits to simplify things. 80 // Used the id of the client in the upper bits to simplify things.
84 const ClientWindowId client_id = 81 const ClientWindowId client_id =
85 ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id))); 82 ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id)));
86 if (!tree->GetWindowByClientId(client_id)) 83 if (!tree->GetWindowByClientId(client_id))
87 return client_id; 84 return client_id;
88 } 85 }
89 } 86 }
90 87
91 } // namespace 88 } // namespace
92 89
90 // TestPlatformScreen -------------------------------------------------
91
92 TestPlatformScreen::TestPlatformScreen() {}
93
94 TestPlatformScreen::~TestPlatformScreen() {}
95
96 int64_t TestPlatformScreen::AddDisplay() {
97 return AddDisplay(MakeViewportMetrics(0, 0, 100, 100, 1.0f));
98 }
99
100 int64_t TestPlatformScreen::AddDisplay(
101 const display::ViewportMetrics& metrics) {
102 // Generate a unique display id.
103 int64_t display_id = display_ids_.empty() ? 1 : *display_ids_.rbegin() + 1;
104 display_ids_.insert(display_id);
105
106 delegate_->OnDisplayAdded(display_id, metrics);
107
108 // First display added will be the primary display.
109 if (primary_display_id_ == display::Display::kInvalidDisplayID) {
110 primary_display_id_ = display_id;
111 delegate_->OnPrimaryDisplayChanged(display_id);
112 }
113
114 return display_id;
115 }
116
117 void TestPlatformScreen::ModifyDisplay(
118 int64_t id,
119 const display::ViewportMetrics& metrics) {
120 DCHECK(display_ids_.count(id) == 1);
121 delegate_->OnDisplayModified(id, metrics);
122 }
123
124 void TestPlatformScreen::RemoveDisplay(int64_t id) {
125 DCHECK(display_ids_.count(id) == 1);
126 delegate_->OnDisplayRemoved(id);
127 display_ids_.erase(id);
128 }
129
130 void TestPlatformScreen::Init(display::PlatformScreenDelegate* delegate) {
131 // Reset
132 delegate_ = delegate;
133 display_ids_.clear();
134 primary_display_id_ = display::Display::kInvalidDisplayID;
135 }
136
137 int64_t TestPlatformScreen::GetPrimaryDisplayId() const {
138 return primary_display_id_;
139 }
140
93 // TestPlatformDisplayFactory ------------------------------------------------- 141 // TestPlatformDisplayFactory -------------------------------------------------
94 142
95 const int64_t TestPlatformDisplayFactory::kFirstDisplayId = 1;
96
97 TestPlatformDisplayFactory::TestPlatformDisplayFactory( 143 TestPlatformDisplayFactory::TestPlatformDisplayFactory(
98 mojom::Cursor* cursor_storage) 144 mojom::Cursor* cursor_storage)
99 : cursor_storage_(cursor_storage), 145 : cursor_storage_(cursor_storage) {}
100 next_display_id_(kFirstDisplayId) {}
101 146
102 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {} 147 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {}
103 148
104 std::unique_ptr<PlatformDisplay> 149 std::unique_ptr<PlatformDisplay>
105 TestPlatformDisplayFactory::CreatePlatformDisplay() { 150 TestPlatformDisplayFactory::CreatePlatformDisplay(
106 bool is_primary = (next_display_id_ == kFirstDisplayId); 151 const PlatformDisplayInitParams& init_params) {
107 return base::MakeUnique<TestPlatformDisplay>(next_display_id_++, is_primary, 152 return base::MakeUnique<TestPlatformDisplay>(init_params, cursor_storage_);
108 cursor_storage_);
109 } 153 }
110 154
111 // TestFrameGeneratorDelegate ------------------------------------------------- 155 // TestFrameGeneratorDelegate -------------------------------------------------
112 156
113 TestFrameGeneratorDelegate::TestFrameGeneratorDelegate() {} 157 TestFrameGeneratorDelegate::TestFrameGeneratorDelegate() {}
114 158
115 TestFrameGeneratorDelegate::~TestFrameGeneratorDelegate() {} 159 TestFrameGeneratorDelegate::~TestFrameGeneratorDelegate() {}
116 160
117 bool TestFrameGeneratorDelegate::IsInHighContrastMode() { 161 bool TestFrameGeneratorDelegate::IsInHighContrastMode() {
118 return false; 162 return false;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 DCHECK(!client_after_reset_); 442 DCHECK(!client_after_reset_);
399 client_after_reset_ = base::MakeUnique<TestWindowTreeClient>(); 443 client_after_reset_ = base::MakeUnique<TestWindowTreeClient>();
400 return client_after_reset_.get(); 444 return client_after_reset_.get();
401 } 445 }
402 446
403 // TestWindowServerDelegate ---------------------------------------------- 447 // TestWindowServerDelegate ----------------------------------------------
404 448
405 TestWindowServerDelegate::TestWindowServerDelegate() {} 449 TestWindowServerDelegate::TestWindowServerDelegate() {}
406 TestWindowServerDelegate::~TestWindowServerDelegate() {} 450 TestWindowServerDelegate::~TestWindowServerDelegate() {}
407 451
408 void TestWindowServerDelegate::CreateDisplays(int num_displays) {
409 DCHECK_GT(num_displays, 0);
410 DCHECK(window_server_);
411
412 for (int i = 0; i < num_displays; ++i)
413 AddDisplay();
414 }
415
416 Display* TestWindowServerDelegate::AddDisplay() {
417 // Display manages its own lifetime.
418 Display* display = new Display(window_server_);
419 display->Init(PlatformDisplayInitParams(), nullptr);
420 return display;
421 }
422
423 void TestWindowServerDelegate::StartDisplayInit() {} 452 void TestWindowServerDelegate::StartDisplayInit() {}
424 453
425 void TestWindowServerDelegate::OnNoMoreDisplays() { 454 void TestWindowServerDelegate::OnNoMoreDisplays() {
426 got_on_no_more_displays_ = true; 455 got_on_no_more_displays_ = true;
427 } 456 }
428 457
429 std::unique_ptr<WindowTreeBinding> 458 std::unique_ptr<WindowTreeBinding>
430 TestWindowServerDelegate::CreateWindowTreeBinding( 459 TestWindowServerDelegate::CreateWindowTreeBinding(
431 BindingType type, 460 BindingType type,
432 ws::WindowServer* window_server, 461 ws::WindowServer* window_server,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 563 }
535 564
536 // ---------------------------------------------------------------------------- 565 // ----------------------------------------------------------------------------
537 566
538 void AddWindowManager(WindowServer* window_server, const UserId& user_id) { 567 void AddWindowManager(WindowServer* window_server, const UserId& user_id) {
539 window_server->window_manager_window_tree_factory_set() 568 window_server->window_manager_window_tree_factory_set()
540 ->Add(user_id, nullptr) 569 ->Add(user_id, nullptr)
541 ->CreateWindowTree(nullptr, nullptr); 570 ->CreateWindowTree(nullptr, nullptr);
542 } 571 }
543 572
573 display::ViewportMetrics MakeViewportMetrics(int origin_x,
574 int origin_y,
575 int width_pixels,
576 int height_pixels,
577 float scale_factor) {
578 display::ViewportMetrics metrics;
579 gfx::Size scaled_size = gfx::ConvertSizeToDIP(
580 scale_factor, gfx::Size(width_pixels, height_pixels));
581 metrics.bounds = gfx::Rect(gfx::Point(origin_x, origin_y), scaled_size);
582 metrics.work_area = metrics.bounds;
583 metrics.pixel_size = gfx::Size(width_pixels, height_pixels);
584 metrics.device_scale_factor = scale_factor;
585 return metrics;
586 }
587
544 ServerWindow* FirstRoot(WindowTree* tree) { 588 ServerWindow* FirstRoot(WindowTree* tree) {
545 return tree->roots().size() == 1u 589 return tree->roots().size() == 1u
546 ? tree->GetWindow((*tree->roots().begin())->id()) 590 ? tree->GetWindow((*tree->roots().begin())->id())
547 : nullptr; 591 : nullptr;
548 } 592 }
549 593
550 ClientWindowId FirstRootId(WindowTree* tree) { 594 ClientWindowId FirstRootId(WindowTree* tree) {
551 ServerWindow* first_root = FirstRoot(tree); 595 ServerWindow* first_root = FirstRoot(tree);
552 return first_root ? ClientWindowIdForWindow(tree, first_root) 596 return first_root ? ClientWindowIdForWindow(tree, first_root)
553 : ClientWindowId(); 597 : ClientWindowId();
(...skipping 26 matching lines...) Expand all
580 return nullptr; 624 return nullptr;
581 if (!tree->AddWindow(parent_client_id, client_window_id)) 625 if (!tree->AddWindow(parent_client_id, client_window_id))
582 return nullptr; 626 return nullptr;
583 *client_id = client_window_id; 627 *client_id = client_window_id;
584 return tree->GetWindowByClientId(client_window_id); 628 return tree->GetWindowByClientId(client_window_id);
585 } 629 }
586 630
587 } // namespace test 631 } // namespace test
588 } // namespace ws 632 } // namespace ws
589 } // namespace ui 633 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/test_utils.h ('k') | services/ui/ws/user_display_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698