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

Side by Side Diff: blimp/engine/app/ui/blimp_screen_unittest.cc

Issue 2629743003: Remove all blimp engine code (Closed)
Patch Set: Use consistent comment style in //chrome Created 3 years, 11 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
(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 "blimp/engine/app/ui/blimp_screen.h"
6
7 #include <memory>
8 #include <string>
9 #include <vector>
10
11 #include "base/command_line.h"
12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/ptr_util.h"
15 #include "base/strings/stringprintf.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/display/display.h"
19 #include "ui/display/display_observer.h"
20 #include "ui/display/screen.h"
21
22 using testing::InSequence;
23
24 namespace blimp {
25 namespace engine {
26 namespace {
27
28 // Checks if two display::Displays have the ID.
29 MATCHER_P(EqualsDisplay, display, "") {
30 return display.id() == arg.id();
31 }
32
33 class MockDisplayObserver : public display::DisplayObserver {
34 public:
35 MockDisplayObserver() {}
36 ~MockDisplayObserver() override {}
37
38 MOCK_METHOD1(OnDisplayAdded, void(const display::Display&));
39 MOCK_METHOD1(OnDisplayRemoved, void(const display::Display&));
40 MOCK_METHOD2(OnDisplayMetricsChanged,
41 void(const display::Display& display, uint32_t changed_metrics));
42 };
43
44 class BlimpScreenTest : public testing::Test {
45 protected:
46 void SetUp() override {
47 screen_ = base::WrapUnique(new BlimpScreen);
48 screen_->AddObserver(&observer1_);
49 screen_->AddObserver(&observer2_);
50 }
51
52 std::unique_ptr<BlimpScreen> screen_;
53 testing::StrictMock<MockDisplayObserver> observer1_;
54 testing::StrictMock<MockDisplayObserver> observer2_;
55 };
56
57 TEST_F(BlimpScreenTest, ObserversAreInfomed) {
58 auto display = screen_->GetPrimaryDisplay();
59 uint32_t changed_metrics =
60 display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
61 display::DisplayObserver::DISPLAY_METRIC_BOUNDS |
62 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
63
64 InSequence s;
65 EXPECT_CALL(observer1_,
66 OnDisplayMetricsChanged(EqualsDisplay(display), changed_metrics));
67 EXPECT_CALL(observer2_,
68 OnDisplayMetricsChanged(EqualsDisplay(display), changed_metrics));
69
70 changed_metrics = display::DisplayObserver::DISPLAY_METRIC_BOUNDS |
71 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
72 EXPECT_CALL(observer1_,
73 OnDisplayMetricsChanged(EqualsDisplay(display), changed_metrics));
74 EXPECT_CALL(observer2_,
75 OnDisplayMetricsChanged(EqualsDisplay(display), changed_metrics));
76
77 changed_metrics =
78 display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
79 display::DisplayObserver::DISPLAY_METRIC_BOUNDS |
80 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
81 EXPECT_CALL(observer1_,
82 OnDisplayMetricsChanged(EqualsDisplay(display), changed_metrics));
83 EXPECT_CALL(observer2_,
84 OnDisplayMetricsChanged(EqualsDisplay(display), changed_metrics));
85
86 gfx::Size size1(100, 200);
87 screen_->UpdateDisplayScaleAndSize(2.0f, size1);
88 EXPECT_EQ(size1, screen_->GetPrimaryDisplay().GetSizeInPixel());
89 EXPECT_EQ(2.0f, screen_->GetPrimaryDisplay().device_scale_factor());
90
91 screen_->UpdateDisplayScaleAndSize(2.0f, size1);
92
93 gfx::Size size2(200, 100);
94 screen_->UpdateDisplayScaleAndSize(2.0f, size2);
95 EXPECT_EQ(size2, screen_->GetPrimaryDisplay().GetSizeInPixel());
96 EXPECT_EQ(2.0f, screen_->GetPrimaryDisplay().device_scale_factor());
97
98 screen_->UpdateDisplayScaleAndSize(3.0f, size2);
99 EXPECT_EQ(3.0f, screen_->GetPrimaryDisplay().device_scale_factor());
100 }
101
102 TEST_F(BlimpScreenTest, RemoveObserver) {
103 screen_->RemoveObserver(&observer2_);
104 auto display = screen_->GetPrimaryDisplay();
105 uint32_t changed_metrics =
106 display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
107 display::DisplayObserver::DISPLAY_METRIC_BOUNDS |
108 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
109 EXPECT_CALL(observer1_,
110 OnDisplayMetricsChanged(EqualsDisplay(display), changed_metrics));
111
112 gfx::Size size1(100, 100);
113 screen_->UpdateDisplayScaleAndSize(2.0f, size1);
114 EXPECT_EQ(size1, screen_->GetPrimaryDisplay().GetSizeInPixel());
115 }
116
117 } // namespace
118 } // namespace engine
119 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/engine/app/ui/blimp_screen.cc ('k') | blimp/engine/app/ui/blimp_window_parenting_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698