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

Side by Side Diff: services/ui/display/platform_screen_ozone_unittests.cc

Issue 2434923002: Handle modified displays in mustash. (Closed)
Patch Set: Fix PlatformScreenStub for tests. 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
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 <memory> 5 #include <memory>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "services/ui/display/platform_screen.h" 11 #include "services/ui/display/platform_screen.h"
12 #include "services/ui/display/platform_screen_ozone.h" 12 #include "services/ui/display/platform_screen_ozone.h"
13 #include "services/ui/display/viewport_metrics.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/display/chromeos/display_configurator.h" 16 #include "ui/display/chromeos/display_configurator.h"
16 #include "ui/display/display_switches.h" 17 #include "ui/display/display_switches.h"
17 #include "ui/display/fake_display_snapshot.h" 18 #include "ui/display/fake_display_snapshot.h"
18 #include "ui/display/types/display_constants.h" 19 #include "ui/display/types/display_constants.h"
19 #include "ui/display/types/display_mode.h" 20 #include "ui/display/types/display_mode.h"
20 #include "ui/display/types/display_snapshot.h" 21 #include "ui/display/types/display_snapshot.h"
21 #include "ui/ozone/public/ozone_platform.h" 22 #include "ui/ozone/public/ozone_platform.h"
22 23
23 namespace display { 24 namespace display {
24 25
25 using ui::DisplayConfigurator; 26 using ui::DisplayConfigurator;
26 using ui::DisplayMode; 27 using ui::DisplayMode;
27 using ui::DisplaySnapshot; 28 using ui::DisplaySnapshot;
28 using ui::DisplaySnapshotVirtual; 29 using ui::DisplaySnapshotVirtual;
29 using testing::IsEmpty; 30 using testing::IsEmpty;
30 using testing::SizeIs; 31 using testing::SizeIs;
31 32
32 namespace { 33 namespace {
33 34
34 // The ID of default "display" that gets added when running off device. 35 // The ID of default "display" that gets added when running off device.
35 const int64_t kDefaultDisplayId = 1; 36 const int64_t kDefaultDisplayId = 1;
36 37
37 // Holds info about the display state we want to test. 38 // Holds info about the display state we want to test.
38 struct DisplayState { 39 struct DisplayState {
39 int64_t id; 40 int64_t id;
40 gfx::Rect bounds; 41 ViewportMetrics metrics;
41 gfx::Size size;
42 float device_scale_factor;
43 }; 42 };
44 43
45 // Matchers that operate on DisplayState. 44 // Matchers that operate on DisplayState.
46 MATCHER_P(DisplayId, display_id, "") { 45 MATCHER_P(DisplayId, display_id, "") {
47 *result_listener << "has id " << arg.id; 46 *result_listener << "has id " << arg.id;
48 return arg.id == display_id; 47 return arg.id == display_id;
49 } 48 }
50 49
51 MATCHER_P(DisplaySize, size_string, "") { 50 MATCHER_P(DisplaySize, size_string, "") {
52 *result_listener << "has size " << arg.bounds.size().ToString(); 51 *result_listener << "has size " << arg.metrics.bounds.size().ToString();
53 return arg.bounds.size().ToString() == size_string; 52 return arg.metrics.bounds.size().ToString() == size_string;
54 } 53 }
55 54
56 MATCHER_P(DisplayOrigin, origin_string, "") { 55 MATCHER_P(DisplayOrigin, origin_string, "") {
57 *result_listener << "has origin " << arg.bounds.origin().ToString(); 56 *result_listener << "has origin " << arg.metrics.bounds.origin().ToString();
58 return arg.bounds.origin().ToString() == origin_string; 57 return arg.metrics.bounds.origin().ToString() == origin_string;
59 } 58 }
60 59
61 // Make a DisplaySnapshot with specified id and size. 60 // Make a DisplaySnapshot with specified id and size.
62 std::unique_ptr<DisplaySnapshot> MakeSnapshot(int64_t id, 61 std::unique_ptr<DisplaySnapshot> MakeSnapshot(int64_t id,
63 const gfx::Size& size) { 62 const gfx::Size& size) {
64 return FakeDisplaySnapshot::Builder() 63 return FakeDisplaySnapshot::Builder()
65 .SetId(id) 64 .SetId(id)
66 .SetNativeMode(size) 65 .SetNativeMode(size)
67 .SetCurrentMode(size) 66 .SetCurrentMode(size)
68 .Build(); 67 .Build();
69 } 68 }
70 69
71 // Test delegate to track what functions calls the delegate receives. 70 // Test delegate to track what functions calls the delegate receives.
72 class TestPlatformScreenDelegate : public PlatformScreenDelegate { 71 class TestPlatformScreenDelegate : public PlatformScreenDelegate {
73 public: 72 public:
74 TestPlatformScreenDelegate() {} 73 TestPlatformScreenDelegate() {}
75 ~TestPlatformScreenDelegate() override {} 74 ~TestPlatformScreenDelegate() override {}
76 75
77 std::vector<DisplayState> added() { return added_; } 76 std::vector<DisplayState> added() { return added_; }
78 std::vector<DisplayState> removed() { return removed_; } 77 std::vector<DisplayState> removed() { return removed_; }
79 std::vector<DisplayState> modified() { return modified_; } 78 std::vector<DisplayState> modified() { return modified_; }
80 79
81 void Reset() { 80 void Reset() {
82 added_.clear(); 81 added_.clear();
83 removed_.clear(); 82 removed_.clear();
84 modified_.clear(); 83 modified_.clear();
85 } 84 }
86 85
87 private: 86 private:
88 void OnDisplayAdded(int64_t id, 87 void OnDisplayAdded(int64_t id, const ViewportMetrics& metrics) override {
89 const gfx::Rect& bounds, 88 added_.push_back({id, metrics});
90 const gfx::Size& pixel_size,
91 float device_scale_factor) override {
92 added_.push_back({id, bounds, pixel_size, device_scale_factor});
93 } 89 }
94 90
95 void OnDisplayRemoved(int64_t id) override { 91 void OnDisplayRemoved(int64_t id) override {
96 removed_.push_back({id, gfx::Rect(), gfx::Size(), 1.0f}); 92 removed_.push_back({id, ViewportMetrics()});
97 } 93 }
98 94
99 void OnDisplayModified(int64_t id, 95 void OnDisplayModified(int64_t id, const ViewportMetrics& metrics) override {
100 const gfx::Rect& bounds, 96 modified_.push_back({id, metrics});
101 const gfx::Size& pixel_size,
102 float device_scale_factor) override {
103 modified_.push_back({id, bounds, pixel_size, device_scale_factor});
104 } 97 }
105 98
106 std::vector<DisplayState> added_; 99 std::vector<DisplayState> added_;
107 std::vector<DisplayState> removed_; 100 std::vector<DisplayState> removed_;
108 std::vector<DisplayState> modified_; 101 std::vector<DisplayState> modified_;
109 102
110 DISALLOW_COPY_AND_ASSIGN(TestPlatformScreenDelegate); 103 DISALLOW_COPY_AND_ASSIGN(TestPlatformScreenDelegate);
111 }; 104 };
112 105
113 // Test fixture with helpers to act like ui::DisplayConfigurator and send 106 // Test fixture with helpers to act like ui::DisplayConfigurator and send
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // Check that the default display was modified with a new size and display 2 321 // Check that the default display was modified with a new size and display 2
329 // was modified with a new origin. 322 // was modified with a new origin.
330 ASSERT_THAT(delegate()->modified(), SizeIs(2)); 323 ASSERT_THAT(delegate()->modified(), SizeIs(2));
331 EXPECT_THAT(delegate()->modified()[0], DisplayId(kDefaultDisplayId)); 324 EXPECT_THAT(delegate()->modified()[0], DisplayId(kDefaultDisplayId));
332 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString())); 325 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString()));
333 EXPECT_THAT(delegate()->modified()[1], DisplayId(2)); 326 EXPECT_THAT(delegate()->modified()[1], DisplayId(2));
334 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0")); 327 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0"));
335 } 328 }
336 329
337 } // namespace display 330 } // namespace display
OLDNEW
« no previous file with comments | « services/ui/display/platform_screen_ozone.cc ('k') | services/ui/display/platform_screen_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698