| Index: services/ui/public/interfaces/cursor/cursor_struct_traits_unittest.cc
|
| diff --git a/services/ui/public/interfaces/cursor/cursor_struct_traits_unittest.cc b/services/ui/public/interfaces/cursor/cursor_struct_traits_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5fbc244dc486f1693e59f1854da72980df9037e3
|
| --- /dev/null
|
| +++ b/services/ui/public/interfaces/cursor/cursor_struct_traits_unittest.cc
|
| @@ -0,0 +1,107 @@
|
| +// 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/message_loop/message_loop.h"
|
| +#include "mojo/public/cpp/bindings/binding_set.h"
|
| +#include "services/ui/public/interfaces/cursor/cursor_struct_traits_test.mojom.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/base/cursor/cursor.h"
|
| +#include "ui/base/cursor/cursor_data.h"
|
| +
|
| +namespace ui {
|
| +
|
| +namespace {
|
| +
|
| +class CursorStructTraitsTest : public testing::Test,
|
| + public mojom::CursorStructTraitsTest {
|
| + public:
|
| + CursorStructTraitsTest() {}
|
| +
|
| + protected:
|
| + mojom::CursorStructTraitsTestPtr GetTraitsTestProxy() {
|
| + return traits_test_bindings_.CreateInterfacePtrAndBind(this);
|
| + }
|
| +
|
| + private:
|
| + // mojom::CursorStructTraitsTest:
|
| + void EchoCursorData(ui::CursorData in,
|
| + const EchoCursorDataCallback& callback) override {
|
| + callback.Run(in);
|
| + }
|
| +
|
| + base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work.
|
| + mojo::BindingSet<mojom::CursorStructTraitsTest> traits_test_bindings_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CursorStructTraitsTest);
|
| +};
|
| +
|
| +std::vector<SkBitmap> CreateTestCursorFrames(const gfx::Size& size,
|
| + unsigned int count) {
|
| + std::vector<SkBitmap> frames(count);
|
| + for (size_t i = 0; i < count; ++i) {
|
| + SkBitmap& bitmap = frames[i];
|
| + bitmap.allocN32Pixels(size.width(), size.height());
|
| + bitmap.eraseColor(SK_ColorRED);
|
| + }
|
| + return frames;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// Tests numeric cursor ids.
|
| +TEST_F(CursorStructTraitsTest, TestBuiltIn) {
|
| + mojom::CursorStructTraitsTestPtr proxy = GetTraitsTestProxy();
|
| + for (int i = 0; i < 43; ++i) {
|
| + ui::CursorData input(i);
|
| +
|
| + ui::CursorData output;
|
| + ASSERT_TRUE(proxy->EchoCursorData(input, &output));
|
| + EXPECT_TRUE(output.IsType(i));
|
| + }
|
| +}
|
| +
|
| +// Test that we copy cursor bitmaps and metadata across the wire.
|
| +TEST_F(CursorStructTraitsTest, TestBitmapCursor) {
|
| + mojom::CursorStructTraitsTestPtr proxy = GetTraitsTestProxy();
|
| +
|
| + const uint32_t kFrameDelayMs = 14;
|
| + const gfx::Point kHotspot = gfx::Point(5, 2);
|
| +
|
| + ui::CursorData input(kHotspot, CreateTestCursorFrames(gfx::Size(10, 10), 3),
|
| + kFrameDelayMs);
|
| +
|
| + ui::CursorData output;
|
| + ASSERT_TRUE(proxy->EchoCursorData(input, &output));
|
| +
|
| + EXPECT_EQ(kCursorCustom, output.native_type());
|
| + EXPECT_EQ(kFrameDelayMs, output.frame_delay_ms());
|
| + EXPECT_EQ(kHotspot, output.hotspot());
|
| +
|
| + // Even if the pixel data is logically the same, expect that it has different
|
| + // generation ids.
|
| + EXPECT_FALSE(output.IsSameAs(input));
|
| +
|
| + // But make sure that the pixel data actually is equivalent.
|
| + ASSERT_EQ(input.cursor_frames().size(), output.cursor_frames().size());
|
| + for (size_t f = 0; f < input.cursor_frames().size(); ++f) {
|
| + ASSERT_EQ(input.cursor_frames()[f].width(),
|
| + output.cursor_frames()[f].width());
|
| + ASSERT_EQ(input.cursor_frames()[f].height(),
|
| + output.cursor_frames()[f].height());
|
| +
|
| + input.cursor_frames()[f].lockPixels();
|
| + output.cursor_frames()[f].lockPixels();
|
| + for (int x = 0; x < input.cursor_frames()[f].width(); ++x) {
|
| + for (int y = 0; y < input.cursor_frames()[f].height(); ++y) {
|
| + EXPECT_EQ(input.cursor_frames()[f].getColor(x, y),
|
| + output.cursor_frames()[f].getColor(x, y));
|
| + }
|
| + }
|
| +
|
| + output.cursor_frames()[f].unlockPixels();
|
| + input.cursor_frames()[f].unlockPixels();
|
| + }
|
| +}
|
| +
|
| +} // namespace ui
|
|
|