OLD | NEW |
| (Empty) |
1 // Copyright 2015 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/client/core/contents/tab_control_feature.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/memory/ptr_util.h" | |
11 #include "blimp/common/proto/blimp_message.pb.h" | |
12 #include "blimp/common/proto/tab_control.pb.h" | |
13 #include "blimp/net/test_common.h" | |
14 #include "net/base/net_errors.h" | |
15 #include "testing/gmock/include/gmock/gmock.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 #include "ui/gfx/geometry/size.h" | |
18 | |
19 using testing::_; | |
20 | |
21 namespace blimp { | |
22 namespace client { | |
23 | |
24 MATCHER_P3(EqualsSizeMessage, width, height, dp_to_px, "") { | |
25 return arg.tab_control().tab_control_case() == TabControlMessage::kSize && | |
26 arg.tab_control().size().width() == width && | |
27 arg.tab_control().size().height() == height && | |
28 arg.tab_control().size().device_pixel_ratio() == dp_to_px; | |
29 } | |
30 | |
31 class TabControlFeatureTest : public testing::Test { | |
32 public: | |
33 TabControlFeatureTest() : out_processor_(nullptr) {} | |
34 | |
35 void SetUp() override { | |
36 out_processor_ = new MockBlimpMessageProcessor(); | |
37 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_)); | |
38 } | |
39 | |
40 protected: | |
41 // This is a raw pointer to a class that is owned by the ControlFeature. | |
42 MockBlimpMessageProcessor* out_processor_; | |
43 | |
44 TabControlFeature feature_; | |
45 }; | |
46 | |
47 TEST_F(TabControlFeatureTest, CreatesCorrectSizeMessage) { | |
48 uint64_t width = 10; | |
49 uint64_t height = 15; | |
50 float dp_to_px = 1.23f; | |
51 | |
52 EXPECT_CALL( | |
53 *out_processor_, | |
54 MockableProcessMessage(EqualsSizeMessage(width, height, dp_to_px), _)) | |
55 .Times(1); | |
56 feature_.SetSizeAndScale(gfx::Size(width, height), dp_to_px); | |
57 } | |
58 | |
59 TEST_F(TabControlFeatureTest, EnsureDuplicateSizeMessageAllowed) { | |
60 uint64_t width = 10; | |
61 uint64_t height = 15; | |
62 float dp_to_px = 1.23f; | |
63 | |
64 EXPECT_CALL( | |
65 *out_processor_, | |
66 MockableProcessMessage(EqualsSizeMessage(width, height, dp_to_px), _)) | |
67 .Times(2) | |
68 .RetiresOnSaturation(); | |
69 EXPECT_CALL( | |
70 *out_processor_, | |
71 MockableProcessMessage(EqualsSizeMessage(width, height, dp_to_px + 1), _)) | |
72 .Times(2) | |
73 .RetiresOnSaturation(); | |
74 EXPECT_CALL(*out_processor_, | |
75 MockableProcessMessage( | |
76 EqualsSizeMessage(width + 1, height, dp_to_px + 1), _)) | |
77 .Times(2) | |
78 .RetiresOnSaturation(); | |
79 EXPECT_CALL(*out_processor_, | |
80 MockableProcessMessage( | |
81 EqualsSizeMessage(width + 1, height + 1, dp_to_px + 1), _)) | |
82 .Times(2) | |
83 .RetiresOnSaturation(); | |
84 | |
85 feature_.SetSizeAndScale(gfx::Size(width, height), dp_to_px); | |
86 feature_.SetSizeAndScale(gfx::Size(width, height), dp_to_px); | |
87 feature_.SetSizeAndScale(gfx::Size(width, height), dp_to_px + 1); | |
88 feature_.SetSizeAndScale(gfx::Size(width, height), dp_to_px + 1); | |
89 feature_.SetSizeAndScale(gfx::Size(width + 1, height), dp_to_px + 1); | |
90 feature_.SetSizeAndScale(gfx::Size(width + 1, height), dp_to_px + 1); | |
91 feature_.SetSizeAndScale(gfx::Size(width + 1, height + 1), dp_to_px + 1); | |
92 feature_.SetSizeAndScale(gfx::Size(width + 1, height + 1), dp_to_px + 1); | |
93 } | |
94 | |
95 } // namespace client | |
96 } // namespace blimp | |
OLD | NEW |