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 <memory> | 5 #include <memory> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
| 8 #include "base/command_line.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
10 #include "services/ui/display/platform_screen.h" | 11 #include "services/ui/display/platform_screen.h" |
11 #include "services/ui/display/platform_screen_ozone.h" | 12 #include "services/ui/display/platform_screen_ozone.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "ui/display/chromeos/display_configurator.h" | 15 #include "ui/display/chromeos/display_configurator.h" |
15 #include "ui/display/chromeos/display_snapshot_virtual.h" | 16 #include "ui/display/display_switches.h" |
| 17 #include "ui/display/fake_display_snapshot.h" |
16 #include "ui/display/types/display_constants.h" | 18 #include "ui/display/types/display_constants.h" |
17 #include "ui/display/types/display_mode.h" | 19 #include "ui/display/types/display_mode.h" |
18 #include "ui/display/types/display_snapshot.h" | 20 #include "ui/display/types/display_snapshot.h" |
19 #include "ui/ozone/public/ozone_platform.h" | 21 #include "ui/ozone/public/ozone_platform.h" |
20 | 22 |
21 namespace display { | 23 namespace display { |
22 | 24 |
23 using ui::DisplayConfigurator; | 25 using ui::DisplayConfigurator; |
24 using ui::DisplayMode; | 26 using ui::DisplayMode; |
25 using ui::DisplaySnapshot; | 27 using ui::DisplaySnapshot; |
26 using ui::DisplaySnapshotVirtual; | 28 using ui::DisplaySnapshotVirtual; |
27 using testing::IsEmpty; | 29 using testing::IsEmpty; |
28 using testing::SizeIs; | 30 using testing::SizeIs; |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 // The ID of default "display" that gets added when running off device. | 34 // The ID of default "display" that gets added when running off device. |
33 const int64_t kDefaultDisplayId = 36029742295586049; | 35 const int64_t kDefaultDisplayId = 1; |
34 | 36 |
35 // Holds info about the display state we want to test. | 37 // Holds info about the display state we want to test. |
36 struct DisplayState { | 38 struct DisplayState { |
37 int64_t id; | 39 int64_t id; |
38 gfx::Rect bounds; | 40 gfx::Rect bounds; |
39 }; | 41 }; |
40 | 42 |
41 // Matchers that operate on DisplayState. | 43 // Matchers that operate on DisplayState. |
42 MATCHER_P(DisplayId, display_id, "") { | 44 MATCHER_P(DisplayId, display_id, "") { |
43 *result_listener << "has id " << arg.id; | 45 *result_listener << "has id " << arg.id; |
44 return arg.id == display_id; | 46 return arg.id == display_id; |
45 } | 47 } |
46 | 48 |
47 MATCHER_P(DisplaySize, size_string, "") { | 49 MATCHER_P(DisplaySize, size_string, "") { |
48 *result_listener << "has size " << arg.bounds.size().ToString(); | 50 *result_listener << "has size " << arg.bounds.size().ToString(); |
49 return arg.bounds.size().ToString() == size_string; | 51 return arg.bounds.size().ToString() == size_string; |
50 } | 52 } |
51 | 53 |
52 MATCHER_P(DisplayOrigin, origin_string, "") { | 54 MATCHER_P(DisplayOrigin, origin_string, "") { |
53 *result_listener << "has origin " << arg.bounds.origin().ToString(); | 55 *result_listener << "has origin " << arg.bounds.origin().ToString(); |
54 return arg.bounds.origin().ToString() == origin_string; | 56 return arg.bounds.origin().ToString() == origin_string; |
55 } | 57 } |
56 | 58 |
57 // Make a DisplaySnapshot with specified id and size. | 59 // Make a DisplaySnapshot with specified id and size. |
58 std::unique_ptr<DisplaySnapshot> MakeSnapshot(int64_t id, | 60 std::unique_ptr<DisplaySnapshot> MakeSnapshot(int64_t id, |
59 const gfx::Size& size) { | 61 const gfx::Size& size) { |
60 auto snapshot = base::MakeUnique<DisplaySnapshotVirtual>(id, size); | 62 return FakeDisplaySnapshot::Builder() |
61 snapshot->set_current_mode(snapshot->modes()[0].get()); | 63 .SetId(id) |
62 return snapshot; | 64 .SetNativeMode(size) |
| 65 .SetCurrentMode(size) |
| 66 .Build(); |
63 } | 67 } |
64 | 68 |
65 // Test delegate to track what functions calls the delegate receives. | 69 // Test delegate to track what functions calls the delegate receives. |
66 class TestPlatformScreenDelegate : public PlatformScreenDelegate { | 70 class TestPlatformScreenDelegate : public PlatformScreenDelegate { |
67 public: | 71 public: |
68 TestPlatformScreenDelegate() {} | 72 TestPlatformScreenDelegate() {} |
69 ~TestPlatformScreenDelegate() override {} | 73 ~TestPlatformScreenDelegate() override {} |
70 | 74 |
71 std::vector<DisplayState> added() { return added_; } | 75 std::vector<DisplayState> added() { return added_; } |
72 std::vector<DisplayState> removed() { return removed_; } | 76 std::vector<DisplayState> removed() { return removed_; } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 DisplaySnapshot* GetSnapshotById(int64_t id) { | 163 DisplaySnapshot* GetSnapshotById(int64_t id) { |
160 for (auto& snapshot : snapshots_) { | 164 for (auto& snapshot : snapshots_) { |
161 if (snapshot->display_id() == id) | 165 if (snapshot->display_id() == id) |
162 return snapshot.get(); | 166 return snapshot.get(); |
163 } | 167 } |
164 return nullptr; | 168 return nullptr; |
165 } | 169 } |
166 | 170 |
167 // testing::Test: | 171 // testing::Test: |
168 void SetUp() override { | 172 void SetUp() override { |
| 173 base::CommandLine::ForCurrentProcess()->AppendSwitchNative( |
| 174 switches::kScreenConfig, "none"); |
| 175 |
169 testing::Test::SetUp(); | 176 testing::Test::SetUp(); |
170 ui::OzonePlatform::InitializeForUI(); | 177 ui::OzonePlatform::InitializeForUI(); |
171 platform_screen_ = base::MakeUnique<PlatformScreenOzone>(); | 178 platform_screen_ = base::MakeUnique<PlatformScreenOzone>(); |
172 platform_screen_->Init(&delegate_); | 179 platform_screen_->Init(&delegate_); |
173 | 180 |
| 181 // Have all tests start with a 1024x768 display by default. |
| 182 AddDisplay(kDefaultDisplayId, gfx::Size(1024, 768)); |
| 183 TriggerOnDisplayModeChanged(); |
| 184 |
174 // Double check the expected display exists and clear counters. | 185 // Double check the expected display exists and clear counters. |
175 ASSERT_THAT(delegate()->added(), SizeIs(1)); | 186 ASSERT_THAT(delegate()->added(), SizeIs(1)); |
176 ASSERT_THAT(delegate_.added()[0], DisplayId(kDefaultDisplayId)); | 187 ASSERT_THAT(delegate_.added()[0], DisplayId(kDefaultDisplayId)); |
177 ASSERT_THAT(delegate_.added()[0], DisplayOrigin("0,0")); | 188 ASSERT_THAT(delegate_.added()[0], DisplayOrigin("0,0")); |
178 ASSERT_THAT(delegate_.added()[0], DisplaySize("1024x768")); | 189 ASSERT_THAT(delegate_.added()[0], DisplaySize("1024x768")); |
179 delegate_.Reset(); | 190 delegate_.Reset(); |
180 | |
181 // Make the initial list of snapshots match what exists. | |
182 AddDisplay(kDefaultDisplayId); | |
183 } | 191 } |
184 | 192 |
185 void TearDown() override { | 193 void TearDown() override { |
186 snapshots_.clear(); | 194 snapshots_.clear(); |
187 delegate_.Reset(); | 195 delegate_.Reset(); |
188 platform_screen_.reset(); | 196 platform_screen_.reset(); |
189 } | 197 } |
190 | 198 |
191 TestPlatformScreenDelegate delegate_; | 199 TestPlatformScreenDelegate delegate_; |
192 std::unique_ptr<PlatformScreenOzone> platform_screen_; | 200 std::unique_ptr<PlatformScreenOzone> platform_screen_; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // Check that the default display was modified with a new size and display 2 | 320 // Check that the default display was modified with a new size and display 2 |
313 // was modified with a new origin. | 321 // was modified with a new origin. |
314 ASSERT_THAT(delegate()->modified(), SizeIs(2)); | 322 ASSERT_THAT(delegate()->modified(), SizeIs(2)); |
315 EXPECT_THAT(delegate()->modified()[0], DisplayId(kDefaultDisplayId)); | 323 EXPECT_THAT(delegate()->modified()[0], DisplayId(kDefaultDisplayId)); |
316 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString())); | 324 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString())); |
317 EXPECT_THAT(delegate()->modified()[1], DisplayId(2)); | 325 EXPECT_THAT(delegate()->modified()[1], DisplayId(2)); |
318 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0")); | 326 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0")); |
319 } | 327 } |
320 | 328 |
321 } // namespace display | 329 } // namespace display |
OLD | NEW |