| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "services/ui/display/platform_screen.h" | 10 #include "services/ui/display/platform_screen.h" |
| 11 #include "services/ui/display/platform_screen_impl_ozone.h" | 11 #include "services/ui/display/platform_screen_ozone.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/display/chromeos/display_configurator.h" | 14 #include "ui/display/chromeos/display_configurator.h" |
| 15 #include "ui/display/chromeos/display_snapshot_virtual.h" | 15 #include "ui/display/chromeos/display_snapshot_virtual.h" |
| 16 #include "ui/display/types/display_constants.h" | 16 #include "ui/display/types/display_constants.h" |
| 17 #include "ui/display/types/display_mode.h" | 17 #include "ui/display/types/display_mode.h" |
| 18 #include "ui/display/types/display_snapshot.h" | 18 #include "ui/display/types/display_snapshot.h" |
| 19 #include "ui/ozone/public/ozone_platform.h" | 19 #include "ui/ozone/public/ozone_platform.h" |
| 20 | 20 |
| 21 namespace display { | 21 namespace display { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 | 95 |
| 96 std::vector<DisplayState> added_; | 96 std::vector<DisplayState> added_; |
| 97 std::vector<DisplayState> removed_; | 97 std::vector<DisplayState> removed_; |
| 98 std::vector<DisplayState> modified_; | 98 std::vector<DisplayState> modified_; |
| 99 | 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(TestPlatformScreenDelegate); | 100 DISALLOW_COPY_AND_ASSIGN(TestPlatformScreenDelegate); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 // Test fixture with helpers to act like ui::DisplayConfigurator and send | 103 // Test fixture with helpers to act like ui::DisplayConfigurator and send |
| 104 // OnDisplayModeChanged() to PlatformScreenImplOzone. | 104 // OnDisplayModeChanged() to PlatformScreenOzone. |
| 105 class PlatformScreenOzoneTest : public testing::Test { | 105 class PlatformScreenOzoneTest : public testing::Test { |
| 106 public: | 106 public: |
| 107 PlatformScreenOzoneTest() {} | 107 PlatformScreenOzoneTest() {} |
| 108 ~PlatformScreenOzoneTest() override {} | 108 ~PlatformScreenOzoneTest() override {} |
| 109 | 109 |
| 110 PlatformScreen* platform_screen() { return platform_screen_.get(); } | 110 PlatformScreen* platform_screen() { return platform_screen_.get(); } |
| 111 TestPlatformScreenDelegate* delegate() { return &delegate_; } | 111 TestPlatformScreenDelegate* delegate() { return &delegate_; } |
| 112 | 112 |
| 113 // Adds a display snapshot with specified ID and default size. | 113 // Adds a display snapshot with specified ID and default size. |
| 114 void AddDisplay(int64_t id) { return AddDisplay(id, gfx::Size(1024, 768)); } | 114 void AddDisplay(int64_t id) { return AddDisplay(id, gfx::Size(1024, 768)); } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (snapshot->display_id() == id) | 163 if (snapshot->display_id() == id) |
| 164 return snapshot.get(); | 164 return snapshot.get(); |
| 165 } | 165 } |
| 166 return nullptr; | 166 return nullptr; |
| 167 } | 167 } |
| 168 | 168 |
| 169 // testing::Test: | 169 // testing::Test: |
| 170 void SetUp() override { | 170 void SetUp() override { |
| 171 testing::Test::SetUp(); | 171 testing::Test::SetUp(); |
| 172 ui::OzonePlatform::InitializeForUI(); | 172 ui::OzonePlatform::InitializeForUI(); |
| 173 platform_screen_ = base::MakeUnique<PlatformScreenImplOzone>(); | 173 platform_screen_ = base::MakeUnique<PlatformScreenOzone>(); |
| 174 platform_screen_->Init(&delegate_); | 174 platform_screen_->Init(&delegate_); |
| 175 | 175 |
| 176 // Double check the expected display exists and clear counters. | 176 // Double check the expected display exists and clear counters. |
| 177 ASSERT_THAT(delegate()->added(), SizeIs(1)); | 177 ASSERT_THAT(delegate()->added(), SizeIs(1)); |
| 178 ASSERT_THAT(delegate_.added()[0], DisplayId(kDefaultDisplayId)); | 178 ASSERT_THAT(delegate_.added()[0], DisplayId(kDefaultDisplayId)); |
| 179 ASSERT_THAT(delegate_.added()[0], DisplayOrigin("0,0")); | 179 ASSERT_THAT(delegate_.added()[0], DisplayOrigin("0,0")); |
| 180 ASSERT_THAT(delegate_.added()[0], DisplaySize("1024x768")); | 180 ASSERT_THAT(delegate_.added()[0], DisplaySize("1024x768")); |
| 181 delegate_.Reset(); | 181 delegate_.Reset(); |
| 182 | 182 |
| 183 // Make the initial list of snapshots match what exists. | 183 // Make the initial list of snapshots match what exists. |
| 184 AddDisplay(kDefaultDisplayId); | 184 AddDisplay(kDefaultDisplayId); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void TearDown() override { | 187 void TearDown() override { |
| 188 snapshots_.clear(); | 188 snapshots_.clear(); |
| 189 delegate_.Reset(); | 189 delegate_.Reset(); |
| 190 platform_screen_.reset(); | 190 platform_screen_.reset(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 TestPlatformScreenDelegate delegate_; | 193 TestPlatformScreenDelegate delegate_; |
| 194 std::unique_ptr<PlatformScreenImplOzone> platform_screen_; | 194 std::unique_ptr<PlatformScreenOzone> platform_screen_; |
| 195 std::vector<std::unique_ptr<DisplaySnapshot>> snapshots_; | 195 std::vector<std::unique_ptr<DisplaySnapshot>> snapshots_; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 } // namespace | 198 } // namespace |
| 199 | 199 |
| 200 TEST_F(PlatformScreenOzoneTest, AddDisplay) { | 200 TEST_F(PlatformScreenOzoneTest, AddDisplay) { |
| 201 AddDisplay(2); | 201 AddDisplay(2); |
| 202 TriggerOnDisplayModeChanged(); | 202 TriggerOnDisplayModeChanged(); |
| 203 | 203 |
| 204 // Check that display 2 was added. | 204 // Check that display 2 was added. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // Check that the default display was modified with a new size and display 2 | 314 // Check that the default display was modified with a new size and display 2 |
| 315 // was modified with a new origin. | 315 // was modified with a new origin. |
| 316 ASSERT_THAT(delegate()->modified(), SizeIs(2)); | 316 ASSERT_THAT(delegate()->modified(), SizeIs(2)); |
| 317 EXPECT_THAT(delegate()->modified()[0], DisplayId(kDefaultDisplayId)); | 317 EXPECT_THAT(delegate()->modified()[0], DisplayId(kDefaultDisplayId)); |
| 318 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString())); | 318 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString())); |
| 319 EXPECT_THAT(delegate()->modified()[1], DisplayId(2)); | 319 EXPECT_THAT(delegate()->modified()[1], DisplayId(2)); |
| 320 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0")); | 320 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0")); |
| 321 } | 321 } |
| 322 | 322 |
| 323 } // namespace display | 323 } // namespace display |
| OLD | NEW |