Commit 71fc6b80 authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Test that a kNone ui::Cursor works as expected

The cursor type mojom::CursorType::kNone is used to hide the cursor.
Therefore, CursorLoader::SetPlatformCursor() should create an invisible
platform cursor for that type.

This CL adds a test that checks that that's the case for the different
implementations of platform cursors.

Bug: 1139157
Change-Id: If9cde827f820e6420d0298dcdf6df3b1dbaafd49
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485101Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Cr-Commit-Position: refs/heads/master@{#819316}
parent a998f007
...@@ -106,26 +106,39 @@ if (use_aura) { ...@@ -106,26 +106,39 @@ if (use_aura) {
source_set("unittests") { source_set("unittests") {
testonly = true testonly = true
sources = [] sources = []
deps = [ "//testing/gtest" ] deps = [
":cursor_base",
"//testing/gtest",
"//ui/base/cursor/mojom:cursor_type",
]
if (!is_ios) { if (!is_ios) {
sources += [ "cursor_unittest.cc" ] sources += [ "cursor_unittest.cc" ]
deps += [ deps += [
":cursor_base",
"//skia", "//skia",
"//ui/base/cursor/mojom:cursor_type",
"//ui/gfx:geometry_skia", "//ui/gfx:geometry_skia",
"//ui/gfx/geometry", "//ui/gfx/geometry",
] ]
} }
if (use_aura) { if (use_aura) {
sources += [ "cursor_util_unittest.cc" ] sources += [
"cursor_loader_unittest.cc",
"cursor_util_unittest.cc",
]
deps += [ deps += [
":cursor", ":cursor",
"//skia", "//skia",
"//ui/gfx/geometry", "//ui/gfx/geometry",
] ]
if (use_x11) {
deps += [
"//skia",
"//ui/base/x",
"//ui/gfx/geometry",
]
}
} }
if (use_ozone) { if (use_ozone) {
...@@ -133,7 +146,6 @@ source_set("unittests") { ...@@ -133,7 +146,6 @@ source_set("unittests") {
deps += [ deps += [
":cursor", ":cursor",
"//base", "//base",
"//ui/base/cursor/mojom:cursor_type",
] ]
} }
} }
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef UI_BASE_CURSOR_CURSOR_LOADER_H_ #ifndef UI_BASE_CURSOR_CURSOR_LOADER_H_
#define UI_BASE_CURSOR_CURSOR_LOADER_H_ #define UI_BASE_CURSOR_CURSOR_LOADER_H_
#include <memory>
#include "base/component_export.h" #include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" #include "ui/base/cursor/mojom/cursor_type.mojom-forward.h"
...@@ -60,7 +62,7 @@ class COMPONENT_EXPORT(UI_BASE_CURSOR) CursorLoader { ...@@ -60,7 +62,7 @@ class COMPONENT_EXPORT(UI_BASE_CURSOR) CursorLoader {
virtual void SetPlatformCursor(gfx::NativeCursor* cursor) = 0; virtual void SetPlatformCursor(gfx::NativeCursor* cursor) = 0;
// Creates a CursorLoader. // Creates a CursorLoader.
static CursorLoader* Create(); static std::unique_ptr<CursorLoader> Create();
private: private:
// The current scale of the mouse cursor icon. // The current scale of the mouse cursor icon.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ui/base/cursor/cursor_loader_ozone.h" #include "ui/base/cursor/cursor_loader_ozone.h"
#include <memory>
#include <vector> #include <vector>
#include "ui/base/cursor/cursor_factory.h" #include "ui/base/cursor/cursor_factory.h"
...@@ -98,8 +99,8 @@ PlatformCursor CursorLoaderOzone::CreateFallbackCursor(mojom::CursorType type) { ...@@ -98,8 +99,8 @@ PlatformCursor CursorLoaderOzone::CreateFallbackCursor(mojom::CursorType type) {
return nullptr; return nullptr;
} }
CursorLoader* CursorLoader::Create() { std::unique_ptr<CursorLoader> CursorLoader::Create() {
return new CursorLoaderOzone(); return std::make_unique<CursorLoaderOzone>();
} }
} // namespace ui } // namespace ui
// Copyright 2020 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 "ui/base/cursor/cursor_loader.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
#if defined(USE_OZONE)
#include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
#endif
#if defined(USE_X11)
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/x/x11_cursor_factory.h" // nogncheck
#include "ui/gfx/geometry/point.h"
#endif
namespace ui {
namespace {
PlatformCursor LoadInvisibleCursor() {
auto cursor_loader = CursorLoader::Create();
Cursor cursor(mojom::CursorType::kNone);
cursor_loader->SetPlatformCursor(&cursor);
return cursor.platform();
}
} // namespace
#if !defined(USE_X11)
TEST(CursorLoaderTest, InvisibleCursorOnNotX11) {
#if defined(USE_OZONE)
BitmapCursorFactoryOzone cursor_factory;
#endif
EXPECT_EQ(LoadInvisibleCursor(), nullptr);
}
#endif
#if defined(USE_X11)
TEST(CursorLoaderTest, InvisibleCursorOnX11) {
X11CursorFactory cursor_factory;
// Building an image cursor with an invalid SkBitmap should return the
// invisible cursor in X11.
auto* invisible_cursor =
cursor_factory.CreateImageCursor(SkBitmap(), gfx::Point());
EXPECT_EQ(LoadInvisibleCursor(), invisible_cursor);
// Release our refcount on the cursor
cursor_factory.UnrefImageCursor(invisible_cursor);
}
#endif
} // namespace ui
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <windows.h> #include <windows.h>
#include <memory>
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor.h"
...@@ -122,8 +124,8 @@ const wchar_t* GetCursorId(gfx::NativeCursor native_cursor) { ...@@ -122,8 +124,8 @@ const wchar_t* GetCursorId(gfx::NativeCursor native_cursor) {
} // namespace } // namespace
CursorLoader* CursorLoader::Create() { std::unique_ptr<CursorLoader> CursorLoader::Create() {
return new CursorLoaderWin; return std::make_unique<CursorLoaderWin>();
} }
CursorLoaderWin::CursorLoaderWin() { CursorLoaderWin::CursorLoaderWin() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment