OLD | NEW |
(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 "base/message_loop/message_loop.h" |
| 6 #include "mojo/public/cpp/bindings/binding_set.h" |
| 7 #include "services/ui/public/interfaces/display/display_struct_traits_test.mojom
.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/display/display.h" |
| 10 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/geometry/size.h" |
| 12 |
| 13 namespace display { |
| 14 |
| 15 namespace { |
| 16 |
| 17 class DisplayStructTraitsTest : public testing::Test, |
| 18 public mojom::DisplayStructTraitsTest { |
| 19 public: |
| 20 DisplayStructTraitsTest() {} |
| 21 |
| 22 protected: |
| 23 mojom::DisplayStructTraitsTestPtr GetTraitsTestProxy() { |
| 24 return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
| 25 } |
| 26 |
| 27 private: |
| 28 // mojom::DisplayStructTraitsTest: |
| 29 void EchoDisplay(const Display& in, |
| 30 const EchoDisplayCallback& callback) override { |
| 31 callback.Run(in); |
| 32 } |
| 33 |
| 34 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. |
| 35 mojo::BindingSet<mojom::DisplayStructTraitsTest> traits_test_bindings_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(DisplayStructTraitsTest); |
| 38 }; |
| 39 |
| 40 void CheckDisplaysEqual(const Display& input, const Display& output) { |
| 41 EXPECT_NE(&input, &output); // Make sure they aren't the same object. |
| 42 EXPECT_EQ(input.id(), output.id()); |
| 43 EXPECT_EQ(input.bounds(), output.bounds()); |
| 44 EXPECT_EQ(input.work_area(), output.work_area()); |
| 45 EXPECT_EQ(input.device_scale_factor(), output.device_scale_factor()); |
| 46 EXPECT_EQ(input.rotation(), output.rotation()); |
| 47 EXPECT_EQ(input.touch_support(), output.touch_support()); |
| 48 EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size()); |
| 49 } |
| 50 |
| 51 } // namespace |
| 52 |
| 53 TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { |
| 54 Display input(5); |
| 55 |
| 56 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
| 57 Display output; |
| 58 proxy->EchoDisplay(input, &output); |
| 59 |
| 60 CheckDisplaysEqual(input, output); |
| 61 } |
| 62 |
| 63 TEST_F(DisplayStructTraitsTest, SetAllDisplayValues) { |
| 64 const gfx::Rect bounds(100, 200, 500, 600); |
| 65 const gfx::Rect work_area(150, 250, 400, 500); |
| 66 const gfx::Size maximum_cursor_size(64, 64); |
| 67 |
| 68 Display input(246345234, bounds); |
| 69 input.set_work_area(work_area); |
| 70 input.set_device_scale_factor(2.0f); |
| 71 input.set_rotation(Display::ROTATE_270); |
| 72 input.set_touch_support(Display::TOUCH_SUPPORT_AVAILABLE); |
| 73 input.set_maximum_cursor_size(maximum_cursor_size); |
| 74 |
| 75 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
| 76 Display output; |
| 77 proxy->EchoDisplay(input, &output); |
| 78 |
| 79 CheckDisplaysEqual(input, output); |
| 80 } |
| 81 |
| 82 } // namespace display |
OLD | NEW |