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

Side by Side Diff: ui/views/mus/display_list_unittest.cc

Issue 2314203002: Move DisplayList to display; add ScreenBase. (Closed)
Patch Set: Update unit test namespace. Created 4 years, 3 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
« no previous file with comments | « ui/views/mus/display_list.cc ('k') | ui/views/mus/screen_mus.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/mus/display_list.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/strings/string_number_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/display/display.h"
13 #include "ui/display/display_observer.h"
14
15 using display::Display;
16
17 namespace views {
18 namespace {
19
20 class DisplayObserverImpl : public display::DisplayObserver {
21 public:
22 DisplayObserverImpl() {}
23 ~DisplayObserverImpl() override {}
24
25 std::string GetAndClearChanges() {
26 std::string changes;
27 std::swap(changes, changes_);
28 return changes;
29 }
30
31 private:
32 static void AddPartChange(uint32_t changed,
33 uint32_t part,
34 const std::string& description,
35 std::string* changed_string) {
36 if ((changed & part) != part)
37 return;
38
39 *changed_string += " ";
40 *changed_string += description;
41 }
42
43 void AddChange(const std::string& change) {
44 if (!changes_.empty())
45 changes_ += "\n";
46 changes_ += change;
47 }
48
49 void OnDisplayAdded(const Display& new_display) override {
50 AddChange("Added id=" + base::Int64ToString(new_display.id()));
51 }
52 void OnDisplayRemoved(const Display& old_display) override {
53 AddChange("Removed id=" + base::Int64ToString(old_display.id()));
54 }
55 void OnDisplayMetricsChanged(const Display& display,
56 uint32_t changed_metrics) override {
57 std::string parts;
58 AddPartChange(changed_metrics, DISPLAY_METRIC_BOUNDS, "bounds", &parts);
59 AddPartChange(changed_metrics, DISPLAY_METRIC_WORK_AREA, "work_area",
60 &parts);
61 AddPartChange(changed_metrics, DISPLAY_METRIC_DEVICE_SCALE_FACTOR,
62 "scale_factor", &parts);
63 AddPartChange(changed_metrics, DISPLAY_METRIC_ROTATION, "rotation", &parts);
64 AddPartChange(changed_metrics, DISPLAY_METRIC_PRIMARY, "primary", &parts);
65
66 AddChange("Changed id=" + base::Int64ToString(display.id()) + parts);
67 }
68
69 std::string changes_;
70
71 DISALLOW_COPY_AND_ASSIGN(DisplayObserverImpl);
72 };
73
74 TEST(DisplayListTest, AddUpdateRemove) {
75 DisplayList display_list;
76 DisplayObserverImpl observer;
77 display_list.AddObserver(&observer);
78 display_list.AddDisplay(display::Display(2, gfx::Rect(0, 0, 801, 802)),
79 DisplayList::Type::PRIMARY);
80 EXPECT_EQ("Added id=2", observer.GetAndClearChanges());
81
82 // Update the bounds.
83 {
84 display::Display updated_display = *(display_list.displays().begin());
85 updated_display.set_bounds(gfx::Rect(0, 0, 803, 802));
86 display_list.UpdateDisplay(updated_display, DisplayList::Type::PRIMARY);
87 EXPECT_EQ("Changed id=2 bounds", observer.GetAndClearChanges());
88 }
89
90 // Add another.
91 display_list.AddDisplay(display::Display(3, gfx::Rect(0, 0, 809, 802)),
92 DisplayList::Type::NOT_PRIMARY);
93 EXPECT_EQ("Added id=3", observer.GetAndClearChanges());
94 ASSERT_EQ(2u, display_list.displays().size());
95 EXPECT_EQ(2, display_list.displays()[0].id());
96 EXPECT_EQ(3, display_list.displays()[1].id());
97 EXPECT_EQ(2, display_list.GetPrimaryDisplayIterator()->id());
98
99 // Make the second the primary.
100 display_list.UpdateDisplay(display_list.displays()[1],
101 DisplayList::Type::PRIMARY);
102 EXPECT_EQ("Changed id=3 primary", observer.GetAndClearChanges());
103 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id());
104
105 // Delete the first.
106 display_list.RemoveDisplay(2);
107 ASSERT_EQ(1u, display_list.displays().size());
108 EXPECT_EQ("Removed id=2", observer.GetAndClearChanges());
109 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id());
110 }
111
112 } // namespace
113 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/display_list.cc ('k') | ui/views/mus/screen_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698