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

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

Issue 2897303002: chromeos: Changes DisplayManagerObserver to have a single function (Closed)
Patch Set: fix compile Created 3 years, 6 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/screen_mus.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/views/mus/screen_mus.h" 5 #include "ui/views/mus/screen_mus.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "ui/display/display_switches.h" 9 #include "ui/display/display_switches.h"
10 #include "ui/display/screen.h" 10 #include "ui/display/screen.h"
11 #include "ui/views/test/scoped_views_test_helper.h" 11 #include "ui/views/test/scoped_views_test_helper.h"
12 #include "ui/views/test/views_test_base.h" 12 #include "ui/views/test/views_test_base.h"
13 13
14 namespace views { 14 namespace views {
15
16 class ScreenMusTestApi {
17 public:
18 static void CallOnDisplaysChanged(
19 ScreenMus* screen,
20 std::vector<ui::mojom::WsDisplayPtr> ws_displays,
21 int64_t primary_display_id,
22 int64_t internal_display_id) {
23 screen->OnDisplaysChanged(std::move(ws_displays), primary_display_id,
24 internal_display_id);
25 }
26
27 private:
28 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenMusTestApi);
29 };
30
15 namespace { 31 namespace {
16 32
33 std::vector<ui::mojom::WsDisplayPtr> ConvertDisplayToWsDisplays(
34 const std::vector<display::Display>& displays) {
35 std::vector<ui::mojom::WsDisplayPtr> results;
36 for (const auto& display : displays) {
37 ui::mojom::WsDisplayPtr display_ptr = ui::mojom::WsDisplay::New();
38 display_ptr->display = display;
39 display_ptr->frame_decoration_values =
40 ui::mojom::FrameDecorationValues::New();
41 results.push_back(std::move(display_ptr));
42 }
43 return results;
44 }
45
17 TEST(ScreenMusTest, ConsistentDisplayInHighDPI) { 46 TEST(ScreenMusTest, ConsistentDisplayInHighDPI) {
18 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); 47 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
19 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 48 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
20 switches::kForceDeviceScaleFactor, "2"); 49 switches::kForceDeviceScaleFactor, "2");
21 ScopedViewsTestHelper test_helper; 50 ScopedViewsTestHelper test_helper;
22 display::Screen* screen = display::Screen::GetScreen(); 51 display::Screen* screen = display::Screen::GetScreen();
23 std::vector<display::Display> displays = screen->GetAllDisplays(); 52 std::vector<display::Display> displays = screen->GetAllDisplays();
24 ASSERT_FALSE(displays.empty()); 53 ASSERT_FALSE(displays.empty());
25 for (const display::Display& display : displays) { 54 for (const display::Display& display : displays) {
26 EXPECT_EQ(2.f, display.device_scale_factor()); 55 EXPECT_EQ(2.f, display.device_scale_factor());
27 EXPECT_EQ(display.work_area(), display.bounds()); 56 EXPECT_EQ(display.work_area(), display.bounds());
28 } 57 }
29 } 58 }
30 59
60 TEST(ScreenMusTest, PrimaryChangedToExisting) {
61 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
62 ScopedViewsTestHelper test_helper;
63 ScreenMus* screen = static_cast<ScreenMus*>(display::Screen::GetScreen());
64 std::vector<display::Display> displays = screen->GetAllDisplays();
65 ASSERT_FALSE(displays.empty());
66
67 // Convert to a single display with a different primary id.
68 displays.resize(1);
69 displays[0].set_id(displays[0].id() + 1);
70 ScreenMusTestApi::CallOnDisplaysChanged(
71 screen, ConvertDisplayToWsDisplays(displays), displays[0].id(), 0);
72 ASSERT_EQ(1u, screen->GetAllDisplays().size());
73 EXPECT_EQ(displays[0].id(), screen->GetAllDisplays()[0].id());
74 EXPECT_EQ(displays[0].id(), screen->GetPrimaryDisplay().id());
75 }
76
77 TEST(ScreenMusTest, AddAndUpdate) {
78 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
79 ScopedViewsTestHelper test_helper;
80 ScreenMus* screen = static_cast<ScreenMus*>(display::Screen::GetScreen());
81 std::vector<display::Display> displays = screen->GetAllDisplays();
82 ASSERT_FALSE(displays.empty());
83
84 // Update the bounds of display 1, and add a new display.
85 displays.resize(1);
86 gfx::Rect new_bounds = displays[0].bounds();
87 new_bounds.set_height(new_bounds.height() + 1);
88 displays[0].set_bounds(new_bounds);
89 displays.push_back(displays[0]);
90 displays[1].set_id(displays[0].id() + 1);
91 ScreenMusTestApi::CallOnDisplaysChanged(
92 screen, ConvertDisplayToWsDisplays(displays), displays[1].id(), 0);
93 ASSERT_EQ(2u, screen->GetAllDisplays().size());
94 ASSERT_TRUE(screen->display_list().FindDisplayById(displays[0].id()) !=
95 screen->display_list().displays().end());
96 EXPECT_EQ(new_bounds.height(), screen->display_list()
97 .FindDisplayById(displays[0].id())
98 ->bounds()
99 .height());
100 ASSERT_TRUE(screen->display_list().FindDisplayById(displays[1].id()) !=
101 screen->display_list().displays().end());
102 EXPECT_EQ(displays[1].id(), screen->GetPrimaryDisplay().id());
103 }
104
31 } // namespace 105 } // namespace
32 } // namespace views 106 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/screen_mus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698