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/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 Loading... |
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 " |
50 return arg.metrics.pixel_size.ToString() == size_string; | 50 << arg.metrics.bounds_in_pixels.size().ToString(); |
| 51 return arg.metrics.bounds_in_pixels.size().ToString() == size_string; |
51 } | 52 } |
52 | 53 |
53 MATCHER_P(DisplayBoundsIs, bounds_string, "") { | 54 MATCHER_P(DisplayBoundsIs, bounds_string, "") { |
54 *result_listener << "has size " << arg.metrics.bounds.ToString(); | 55 *result_listener << "has size " << arg.display.bounds().ToString(); |
55 return arg.metrics.bounds.ToString() == bounds_string; | 56 return arg.display.bounds().ToString() == bounds_string; |
56 } | 57 } |
57 | 58 |
58 // Test delegate to track what functions calls the delegate receives. | 59 // Test delegate to track what functions calls the delegate receives. |
59 class TestScreenManagerDelegate : public ScreenManagerDelegate { | 60 class TestScreenManagerDelegate : public ScreenManagerDelegate { |
60 public: | 61 public: |
61 TestScreenManagerDelegate() {} | 62 TestScreenManagerDelegate() {} |
62 ~TestScreenManagerDelegate() override {} | 63 ~TestScreenManagerDelegate() override {} |
63 | 64 |
64 const std::vector<DisplayState>& added() const { return added_; } | 65 const std::vector<DisplayState>& added() const { return added_; } |
65 const std::vector<DisplayState>& modified() const { return modified_; } | 66 const std::vector<DisplayState>& modified() const { return modified_; } |
(...skipping 11 matching lines...) Expand all Loading... |
77 changes_.clear(); | 78 changes_.clear(); |
78 } | 79 } |
79 | 80 |
80 private: | 81 private: |
81 void AddChange(const std::string& name, const std::string& value) { | 82 void AddChange(const std::string& name, const std::string& value) { |
82 if (!changes_.empty()) | 83 if (!changes_.empty()) |
83 changes_ += ";"; | 84 changes_ += ";"; |
84 changes_ += name + "(" + value + ")"; | 85 changes_ += name + "(" + value + ")"; |
85 } | 86 } |
86 | 87 |
87 void OnDisplayAdded(int64_t id, const ViewportMetrics& metrics) override { | 88 void OnDisplayAdded(const display::Display& display, |
88 added_.push_back({id, metrics}); | 89 const ViewportMetrics& metrics) override { |
89 AddChange("Added", base::Int64ToString(id)); | 90 added_.push_back({display, metrics}); |
| 91 AddChange("Added", base::Int64ToString(display.id())); |
90 } | 92 } |
91 | 93 |
92 void OnDisplayRemoved(int64_t id) override { | 94 void OnDisplayRemoved(int64_t id) override { |
93 AddChange("Removed", base::Int64ToString(id)); | 95 AddChange("Removed", base::Int64ToString(id)); |
94 } | 96 } |
95 | 97 |
96 void OnDisplayModified(int64_t id, const ViewportMetrics& metrics) override { | 98 void OnDisplayModified(const display::Display& display, |
97 modified_.push_back({id, metrics}); | 99 const ViewportMetrics& metrics) override { |
98 AddChange("Modified", base::Int64ToString(id)); | 100 modified_.push_back({display, metrics}); |
| 101 AddChange("Modified", base::Int64ToString(display.id())); |
99 } | 102 } |
100 | 103 |
101 void OnPrimaryDisplayChanged(int64_t primary_display_id) override { | 104 void OnPrimaryDisplayChanged(int64_t primary_display_id) override { |
102 AddChange("Primary", base::Int64ToString(primary_display_id)); | 105 AddChange("Primary", base::Int64ToString(primary_display_id)); |
103 } | 106 } |
104 | 107 |
105 std::vector<DisplayState> added_; | 108 std::vector<DisplayState> added_; |
106 std::vector<DisplayState> modified_; | 109 std::vector<DisplayState> modified_; |
107 std::string changes_; | 110 std::string changes_; |
108 | 111 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 279 |
277 // Swapping again should be similar and end up back with display 1 as primary. | 280 // Swapping again should be similar and end up back with display 1 as primary. |
278 screen_manager()->SwapPrimaryDisplay(); | 281 screen_manager()->SwapPrimaryDisplay(); |
279 EXPECT_EQ("Modified(1);Modified(2);Primary(1)", delegate()->changes()); | 282 EXPECT_EQ("Modified(1);Modified(2);Primary(1)", delegate()->changes()); |
280 EXPECT_THAT(delegate()->modified()[0], DisplayBoundsIs("0,0 1024x768")); | 283 EXPECT_THAT(delegate()->modified()[0], DisplayBoundsIs("0,0 1024x768")); |
281 EXPECT_THAT(delegate()->modified()[1], DisplayBoundsIs("1024,0 1024x768")); | 284 EXPECT_THAT(delegate()->modified()[1], DisplayBoundsIs("1024,0 1024x768")); |
282 EXPECT_EQ(1, Screen::GetScreen()->GetPrimaryDisplay().id()); | 285 EXPECT_EQ(1, Screen::GetScreen()->GetPrimaryDisplay().id()); |
283 } | 286 } |
284 | 287 |
285 } // namespace display | 288 } // namespace display |
OLD | NEW |