Chromium Code Reviews| Index: ui/display/mojo/display_struct_traits_unittest.cc |
| diff --git a/ui/display/mojo/display_struct_traits_unittest.cc b/ui/display/mojo/display_struct_traits_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..52f57c5eeea24d497b8e16ea8ccbdce933a180a7 |
| --- /dev/null |
| +++ b/ui/display/mojo/display_struct_traits_unittest.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/logging.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/display/mojo/display_struct_traits_test.mojom.h" |
| +#include "ui/display/types/display_mode.h" |
| + |
| +namespace display { |
| + |
| +namespace { |
| + |
| +class DisplayStructTraitsTestImpl : public mojom::DisplayStructTraitsTest { |
| + public: |
| + explicit DisplayStructTraitsTestImpl( |
| + mojo::InterfaceRequest<mojom::DisplayStructTraitsTest> request) |
| + : binding_(this, std::move(request)) {} |
| + |
| + // DisplayStructTraitsTest: |
| + void EchoDisplayMode( |
| + const DisplayMode& input, |
| + const EchoDisplayModeCallback& callback) override { |
| + callback.Run(input); |
| + } |
| + |
| + private: |
| + mojo::Binding<DisplayStructTraitsTest> binding_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DisplayStructTraitsTestImpl); |
| +}; |
| + |
| +TEST(DisplayStructTraitsTest, Basic) { |
| + // A MessageLoop is needed for Mojo IPC to work. |
| + base::MessageLoop message_loop; |
| + |
| + mojom::DisplayStructTraitsTestPtr proxy; |
| + DisplayStructTraitsTestImpl impl(MakeRequest(&proxy)); |
| + |
| + // prepare sample input with random values |
| + DisplayMode input(gfx::Size(15, 29), true, 61.0); |
|
kylechar
2017/01/25 16:59:45
const DisplayMode input
thanhph1
2017/01/25 20:28:40
Done.
|
| + |
| + DisplayMode output; |
| + |
| + EXPECT_TRUE(proxy->EchoDisplayMode(input, &output)); |
| + |
| + // We want to test each component individually to make sure each data member |
| + // was correctly serialized and deserialized. |
| + EXPECT_EQ(input.size(), output.size()); |
| + EXPECT_EQ(input.is_interlaced(), output.is_interlaced()); |
| + EXPECT_EQ(input.refresh_rate(), output.refresh_rate()); |
| +} |
| + |
| +} // namespace |
| + |
| +} // namespace display |