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

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

Issue 2736943003: Start to decouple display::Display from ws::PlatformDisplay. (Closed)
Patch Set: Missing statement. Created 3 years, 9 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 17 matching lines...) Expand all
28 28
29 namespace display { 29 namespace display {
30 30
31 using testing::IsEmpty; 31 using testing::IsEmpty;
32 using testing::SizeIs; 32 using testing::SizeIs;
33 33
34 namespace { 34 namespace {
35 35
36 // Holds info about the display state we want to test. 36 // Holds info about the display state we want to test.
37 struct DisplayState { 37 struct DisplayState {
38 int64_t id; 38 Display display;
39 ViewportMetrics metrics; 39 ViewportMetrics metrics;
40 }; 40 };
41 41
42 // Matchers that operate on DisplayState. 42 // Matchers that operate on DisplayState.
43 MATCHER_P(DisplayIdIs, display_id, "") { 43 MATCHER_P(DisplayIdIs, display_id, "") {
44 *result_listener << "has id " << arg.id; 44 *result_listener << "has id " << arg.display.id();
45 return arg.id == display_id; 45 return arg.display.id() == display_id;
46 } 46 }
47 47
48 MATCHER_P(DisplayPixelSizeIs, size_string, "") { 48 MATCHER_P(DisplayPixelSizeIs, size_string, "") {
49 *result_listener << "has size " << arg.metrics.pixel_size.ToString(); 49 *result_listener << "has size " << arg.metrics.bounds.size().ToString();
50 return arg.metrics.pixel_size.ToString() == size_string; 50 return arg.metrics.bounds.size().ToString() == size_string;
51 } 51 }
52 52
53 MATCHER_P(DisplayBoundsIs, bounds_string, "") { 53 MATCHER_P(DisplayBoundsIs, bounds_string, "") {
54 *result_listener << "has size " << arg.metrics.bounds.ToString(); 54 *result_listener << "has size " << arg.display.bounds().ToString();
55 return arg.metrics.bounds.ToString() == bounds_string; 55 return arg.display.bounds().ToString() == bounds_string;
56 } 56 }
57 57
58 // Test delegate to track what functions calls the delegate receives. 58 // Test delegate to track what functions calls the delegate receives.
59 class TestScreenManagerDelegate : public ScreenManagerDelegate { 59 class TestScreenManagerDelegate : public ScreenManagerDelegate {
60 public: 60 public:
61 TestScreenManagerDelegate() {} 61 TestScreenManagerDelegate() {}
62 ~TestScreenManagerDelegate() override {} 62 ~TestScreenManagerDelegate() override {}
63 63
64 const std::vector<DisplayState>& added() const { return added_; } 64 const std::vector<DisplayState>& added() const { return added_; }
65 const std::vector<DisplayState>& modified() const { return modified_; } 65 const std::vector<DisplayState>& modified() const { return modified_; }
(...skipping 11 matching lines...) Expand all
77 changes_.clear(); 77 changes_.clear();
78 } 78 }
79 79
80 private: 80 private:
81 void AddChange(const std::string& name, const std::string& value) { 81 void AddChange(const std::string& name, const std::string& value) {
82 if (!changes_.empty()) 82 if (!changes_.empty())
83 changes_ += ";"; 83 changes_ += ";";
84 changes_ += name + "(" + value + ")"; 84 changes_ += name + "(" + value + ")";
85 } 85 }
86 86
87 void OnDisplayAdded(int64_t id, const ViewportMetrics& metrics) override { 87 void OnDisplayAdded(const display::Display& display,
88 added_.push_back({id, metrics}); 88 const ViewportMetrics& metrics) override {
89 AddChange("Added", base::Int64ToString(id)); 89 added_.push_back({display, metrics});
90 AddChange("Added", base::Int64ToString(display.id()));
90 } 91 }
91 92
92 void OnDisplayRemoved(int64_t id) override { 93 void OnDisplayRemoved(int64_t id) override {
93 AddChange("Removed", base::Int64ToString(id)); 94 AddChange("Removed", base::Int64ToString(id));
94 } 95 }
95 96
96 void OnDisplayModified(int64_t id, const ViewportMetrics& metrics) override { 97 void OnDisplayModified(const display::Display& display,
97 modified_.push_back({id, metrics}); 98 const ViewportMetrics& metrics) override {
98 AddChange("Modified", base::Int64ToString(id)); 99 modified_.push_back({display, metrics});
100 AddChange("Modified", base::Int64ToString(display.id()));
99 } 101 }
100 102
101 void OnPrimaryDisplayChanged(int64_t primary_display_id) override { 103 void OnPrimaryDisplayChanged(int64_t primary_display_id) override {
102 AddChange("Primary", base::Int64ToString(primary_display_id)); 104 AddChange("Primary", base::Int64ToString(primary_display_id));
103 } 105 }
104 106
105 std::vector<DisplayState> added_; 107 std::vector<DisplayState> added_;
106 std::vector<DisplayState> modified_; 108 std::vector<DisplayState> modified_;
107 std::string changes_; 109 std::string changes_;
108 110
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 278
277 // Swapping again should be similar and end up back with display 1 as primary. 279 // Swapping again should be similar and end up back with display 1 as primary.
278 screen_manager()->SwapPrimaryDisplay(); 280 screen_manager()->SwapPrimaryDisplay();
279 EXPECT_EQ("Modified(1);Modified(2);Primary(1)", delegate()->changes()); 281 EXPECT_EQ("Modified(1);Modified(2);Primary(1)", delegate()->changes());
280 EXPECT_THAT(delegate()->modified()[0], DisplayBoundsIs("0,0 1024x768")); 282 EXPECT_THAT(delegate()->modified()[0], DisplayBoundsIs("0,0 1024x768"));
281 EXPECT_THAT(delegate()->modified()[1], DisplayBoundsIs("1024,0 1024x768")); 283 EXPECT_THAT(delegate()->modified()[1], DisplayBoundsIs("1024,0 1024x768"));
282 EXPECT_EQ(1, Screen::GetScreen()->GetPrimaryDisplay().id()); 284 EXPECT_EQ(1, Screen::GetScreen()->GetPrimaryDisplay().id());
283 } 285 }
284 286
285 } // namespace display 287 } // namespace display
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698