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

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

Issue 2613493002: Fix namespace for src/ui/display/. (Closed)
Patch Set: Rebase. Created 3 years, 11 months 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"
(...skipping 10 matching lines...) Expand all
21 #include "ui/display/screen.h" 21 #include "ui/display/screen.h"
22 #include "ui/display/types/display_constants.h" 22 #include "ui/display/types/display_constants.h"
23 #include "ui/display/types/display_mode.h" 23 #include "ui/display/types/display_mode.h"
24 #include "ui/display/types/display_snapshot.h" 24 #include "ui/display/types/display_snapshot.h"
25 #include "ui/display/types/fake_display_controller.h" 25 #include "ui/display/types/fake_display_controller.h"
26 #include "ui/events/devices/device_data_manager.h" 26 #include "ui/events/devices/device_data_manager.h"
27 #include "ui/ozone/public/ozone_platform.h" 27 #include "ui/ozone/public/ozone_platform.h"
28 28
29 namespace display { 29 namespace display {
30 30
31 using ui::DisplayMode;
32 using ui::DisplaySnapshot;
33 using testing::IsEmpty; 31 using testing::IsEmpty;
34 using testing::SizeIs; 32 using testing::SizeIs;
35 33
36 namespace { 34 namespace {
37 35
38 // Holds info about the display state we want to test. 36 // Holds info about the display state we want to test.
39 struct DisplayState { 37 struct DisplayState {
40 int64_t id; 38 int64_t id;
41 ViewportMetrics metrics; 39 ViewportMetrics metrics;
42 }; 40 };
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 104
107 std::vector<DisplayState> added_; 105 std::vector<DisplayState> added_;
108 std::vector<DisplayState> modified_; 106 std::vector<DisplayState> modified_;
109 std::string changes_; 107 std::string changes_;
110 108
111 DISALLOW_COPY_AND_ASSIGN(TestScreenManagerDelegate); 109 DISALLOW_COPY_AND_ASSIGN(TestScreenManagerDelegate);
112 }; 110 };
113 111
114 } // namespace 112 } // namespace
115 113
116 // Test fixture with helpers to act like ui::DisplayConfigurator and send 114 // Test fixture with helpers to act like DisplayConfigurator and send
117 // OnDisplayModeChanged() to ScreenManagerOzone. 115 // OnDisplayModeChanged() to ScreenManagerOzone.
118 class ScreenManagerOzoneTest : public ui::TaskRunnerTestBase { 116 class ScreenManagerOzoneTest : public ui::TaskRunnerTestBase {
119 public: 117 public:
120 ScreenManagerOzoneTest() {} 118 ScreenManagerOzoneTest() {}
121 ~ScreenManagerOzoneTest() override {} 119 ~ScreenManagerOzoneTest() override {}
122 120
123 ScreenManagerOzone* screen_manager() { return screen_manager_.get(); } 121 ScreenManagerOzone* screen_manager() { return screen_manager_.get(); }
124 TestScreenManagerDelegate* delegate() { return &delegate_; } 122 TestScreenManagerDelegate* delegate() { return &delegate_; }
125 123
126 // Adds a display snapshot with specified ID and default size. 124 // Adds a display snapshot with specified ID and default size.
127 void AddDisplay(int64_t id) { 125 void AddDisplay(int64_t id) {
128 return AddDisplay(FakeDisplaySnapshot::Builder() 126 return AddDisplay(FakeDisplaySnapshot::Builder()
129 .SetId(id) 127 .SetId(id)
130 .SetNativeMode(gfx::Size(1024, 768)) 128 .SetNativeMode(gfx::Size(1024, 768))
131 .Build()); 129 .Build());
132 } 130 }
133 131
134 void AddDisplay(std::unique_ptr<ui::DisplaySnapshot> snapshot) { 132 void AddDisplay(std::unique_ptr<DisplaySnapshot> snapshot) {
135 EXPECT_TRUE(fake_display_controller_->AddDisplay(std::move(snapshot))); 133 EXPECT_TRUE(fake_display_controller_->AddDisplay(std::move(snapshot)));
136 RunAllTasks(); 134 RunAllTasks();
137 } 135 }
138 136
139 // Removes display snapshot with specified ID. 137 // Removes display snapshot with specified ID.
140 void RemoveDisplay(int64_t id) { 138 void RemoveDisplay(int64_t id) {
141 EXPECT_TRUE(fake_display_controller_->RemoveDisplay(id)); 139 EXPECT_TRUE(fake_display_controller_->RemoveDisplay(id));
142 RunAllTasks(); 140 RunAllTasks();
143 } 141 }
144 142
145 static void SetUpTestCase() { ui::DeviceDataManager::CreateInstance(); } 143 static void SetUpTestCase() { ui::DeviceDataManager::CreateInstance(); }
146 144
147 static void TearDownTestCase() { ui::DeviceDataManager::DeleteInstance(); } 145 static void TearDownTestCase() { ui::DeviceDataManager::DeleteInstance(); }
148 146
149 private: 147 private:
150 // testing::Test: 148 // testing::Test:
151 void SetUp() override { 149 void SetUp() override {
152 TaskRunnerTestBase::SetUp(); 150 TaskRunnerTestBase::SetUp();
153 151
154 base::CommandLine::ForCurrentProcess()->AppendSwitchNative( 152 base::CommandLine::ForCurrentProcess()->AppendSwitchNative(
155 switches::kScreenConfig, "none"); 153 switches::kScreenConfig, "none");
156 154
157 screen_manager_ = base::MakeUnique<ScreenManagerOzone>(); 155 screen_manager_ = base::MakeUnique<ScreenManagerOzone>();
158 156
159 // Create NDD for FakeDisplayController. 157 // Create NDD for FakeDisplayController.
160 std::unique_ptr<ui::NativeDisplayDelegate> ndd = 158 std::unique_ptr<NativeDisplayDelegate> ndd =
161 base::MakeUnique<FakeDisplayDelegate>(); 159 base::MakeUnique<FakeDisplayDelegate>();
162 fake_display_controller_ = ndd->GetFakeDisplayController(); 160 fake_display_controller_ = ndd->GetFakeDisplayController();
163 161
164 // Add NDD to ScreenManager so one isn't loaded from Ozone. 162 // Add NDD to ScreenManager so one isn't loaded from Ozone.
165 screen_manager_->native_display_delegate_ = std::move(ndd); 163 screen_manager_->native_display_delegate_ = std::move(ndd);
166 164
167 AddDisplay(FakeDisplaySnapshot::Builder() 165 AddDisplay(FakeDisplaySnapshot::Builder()
168 .SetId(1) 166 .SetId(1)
169 .SetNativeMode(gfx::Size(1024, 768)) 167 .SetNativeMode(gfx::Size(1024, 768))
170 .SetType(ui::DISPLAY_CONNECTION_TYPE_INTERNAL) 168 .SetType(DISPLAY_CONNECTION_TYPE_INTERNAL)
171 .Build()); 169 .Build());
172 170
173 screen_manager_->Init(&delegate_); 171 screen_manager_->Init(&delegate_);
174 RunAllTasks(); 172 RunAllTasks();
175 173
176 // Double check the expected display exists and clear counters. 174 // Double check the expected display exists and clear counters.
177 ASSERT_THAT(delegate()->added(), SizeIs(1)); 175 ASSERT_THAT(delegate()->added(), SizeIs(1));
178 ASSERT_THAT(delegate_.added()[0], DisplayIdIs(1)); 176 ASSERT_THAT(delegate_.added()[0], DisplayIdIs(1));
179 ASSERT_THAT(delegate_.added()[0], DisplayBoundsIs("0,0 1024x768")); 177 ASSERT_THAT(delegate_.added()[0], DisplayBoundsIs("0,0 1024x768"));
180 ASSERT_THAT(delegate_.added()[0], DisplayPixelSizeIs("1024x768")); 178 ASSERT_THAT(delegate_.added()[0], DisplayPixelSizeIs("1024x768"));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 242
245 // Check that display 3 was removed. 243 // Check that display 3 was removed.
246 RemoveDisplay(3); 244 RemoveDisplay(3);
247 EXPECT_EQ("Removed(3)", delegate()->changes()); 245 EXPECT_EQ("Removed(3)", delegate()->changes());
248 } 246 }
249 247
250 TEST_F(ScreenManagerOzoneTest, AddDisplay4k) { 248 TEST_F(ScreenManagerOzoneTest, AddDisplay4k) {
251 AddDisplay(FakeDisplaySnapshot::Builder() 249 AddDisplay(FakeDisplaySnapshot::Builder()
252 .SetId(2) 250 .SetId(2)
253 .SetNativeMode(gfx::Size(4096, 2160)) 251 .SetNativeMode(gfx::Size(4096, 2160))
254 .SetType(ui::DISPLAY_CONNECTION_TYPE_DVI) 252 .SetType(DISPLAY_CONNECTION_TYPE_DVI)
255 .Build()); 253 .Build());
256 254
257 // Check that display 2 has a device scale factor of 2 since it's a 4k 255 // Check that display 2 has a device scale factor of 2 since it's a 4k
258 // display. 256 // display.
259 EXPECT_EQ("Added(2)", delegate()->changes()); 257 EXPECT_EQ("Added(2)", delegate()->changes());
260 EXPECT_THAT(delegate()->added()[0], DisplayBoundsIs("1024,0 2048x1080")); 258 EXPECT_THAT(delegate()->added()[0], DisplayBoundsIs("1024,0 2048x1080"));
261 EXPECT_THAT(delegate()->added()[0], DisplayPixelSizeIs("4096x2160")); 259 EXPECT_THAT(delegate()->added()[0], DisplayPixelSizeIs("4096x2160"));
262 } 260 }
263 261
264 TEST_F(ScreenManagerOzoneTest, SwapPrimaryDisplay) { 262 TEST_F(ScreenManagerOzoneTest, SwapPrimaryDisplay) {
(...skipping 13 matching lines...) Expand all
278 276
279 // Swapping again should be similar and end up back with display 1 as primary. 277 // Swapping again should be similar and end up back with display 1 as primary.
280 screen_manager()->SwapPrimaryDisplay(); 278 screen_manager()->SwapPrimaryDisplay();
281 EXPECT_EQ("Modified(1);Modified(2);Primary(1)", delegate()->changes()); 279 EXPECT_EQ("Modified(1);Modified(2);Primary(1)", delegate()->changes());
282 EXPECT_THAT(delegate()->modified()[0], DisplayBoundsIs("0,0 1024x768")); 280 EXPECT_THAT(delegate()->modified()[0], DisplayBoundsIs("0,0 1024x768"));
283 EXPECT_THAT(delegate()->modified()[1], DisplayBoundsIs("1024,0 1024x768")); 281 EXPECT_THAT(delegate()->modified()[1], DisplayBoundsIs("1024,0 1024x768"));
284 EXPECT_EQ(1, Screen::GetScreen()->GetPrimaryDisplay().id()); 282 EXPECT_EQ(1, Screen::GetScreen()->GetPrimaryDisplay().id());
285 } 283 }
286 284
287 } // namespace display 285 } // namespace display
OLDNEW
« no previous file with comments | « services/ui/display/screen_manager_ozone.cc ('k') | services/ui/surfaces/display_output_surface_ozone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698