| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "content/common/cursors/webcursor.h" | 9 #include "content/common/cursors/webcursor.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 gfx::Point hotspot; | 298 gfx::Point hotspot; |
| 299 cursor.CreateScaledBitmapAndHotspotFromCustomData(&image_copy, &hotspot); | 299 cursor.CreateScaledBitmapAndHotspotFromCustomData(&image_copy, &hotspot); |
| 300 | 300 |
| 301 EXPECT_EQ(kBGRA_8888_SkColorType, image_copy.colorType()); | 301 EXPECT_EQ(kBGRA_8888_SkColorType, image_copy.colorType()); |
| 302 EXPECT_EQ(kUnpremul_SkAlphaType, image_copy.alphaType()); | 302 EXPECT_EQ(kUnpremul_SkAlphaType, image_copy.alphaType()); |
| 303 EXPECT_EQ(2, image_copy.width()); | 303 EXPECT_EQ(2, image_copy.width()); |
| 304 EXPECT_EQ(2, image_copy.height()); | 304 EXPECT_EQ(2, image_copy.height()); |
| 305 EXPECT_EQ(0, hotspot.x()); | 305 EXPECT_EQ(0, hotspot.x()); |
| 306 EXPECT_EQ(1, hotspot.y()); | 306 EXPECT_EQ(1, hotspot.y()); |
| 307 } | 307 } |
| 308 |
| 309 TEST(WebCursorTest, CopyDeviceScaleFactor) { |
| 310 WebCursor cursor1; |
| 311 EXPECT_EQ(1.f, cursor1.GetCursorScaleFactor()); |
| 312 |
| 313 display::Display display; |
| 314 display.set_device_scale_factor(19.333f); |
| 315 cursor1.SetDisplayInfo(display); |
| 316 WebCursor cursor2 = cursor1; |
| 317 EXPECT_EQ(19.333f, cursor2.GetCursorScaleFactor()); |
| 318 } |
| 308 #endif | 319 #endif |
| 309 | 320 |
| 310 #if defined(OS_WIN) | 321 #if defined(OS_WIN) |
| 311 void ScaleCursor(float scaleFactor, int hotspotX, int hotspotY) { | 322 namespace { |
| 323 |
| 324 void ScaleCursor(float scale_factor, int hotspot_x, int hotspot_y) { |
| 312 display::Display display; | 325 display::Display display; |
| 313 display.set_device_scale_factor(scaleFactor); | 326 display.set_device_scale_factor(scale_factor); |
| 314 | 327 |
| 315 WebCursor::CursorInfo info; | 328 WebCursor::CursorInfo info; |
| 316 info.type = WebCursorInfo::TypeCustom; | 329 info.type = WebCursorInfo::TypeCustom; |
| 317 info.hotspot = gfx::Point(hotspotX, hotspotY); | 330 info.hotspot = gfx::Point(hotspot_x, hotspot_y); |
| 318 | 331 |
| 319 info.custom_image = SkBitmap(); | 332 info.custom_image = SkBitmap(); |
| 320 info.custom_image.allocN32Pixels(10, 10); | 333 info.custom_image.allocN32Pixels(10, 10); |
| 321 info.custom_image.eraseColor(0); | 334 info.custom_image.eraseColor(0); |
| 322 | 335 |
| 323 WebCursor cursor; | 336 WebCursor cursor; |
| 324 cursor.SetDisplayInfo(display); | 337 cursor.SetDisplayInfo(display); |
| 325 cursor.InitFromCursorInfo(info); | 338 cursor.InitFromCursorInfo(info); |
| 326 | 339 |
| 327 HCURSOR windowsCursorHandle = cursor.GetPlatformCursor(); | 340 HCURSOR windows_cursor_handle = cursor.GetPlatformCursor(); |
| 328 EXPECT_NE(nullptr, windowsCursorHandle); | 341 EXPECT_NE(nullptr, windows_cursor_handle); |
| 329 ICONINFO windowsIconInfo; | 342 ICONINFO windows_icon_info; |
| 330 EXPECT_TRUE(GetIconInfo(windowsCursorHandle, &windowsIconInfo)); | 343 EXPECT_TRUE(GetIconInfo(windows_cursor_handle, &windows_icon_info)); |
| 331 EXPECT_FALSE(windowsIconInfo.fIcon); | 344 EXPECT_FALSE(windows_icon_info.fIcon); |
| 332 EXPECT_EQ(static_cast<DWORD>(scaleFactor * hotspotX), | 345 EXPECT_EQ(static_cast<DWORD>(scale_factor * hotspot_x), |
| 333 windowsIconInfo.xHotspot); | 346 windows_icon_info.xHotspot); |
| 334 EXPECT_EQ(static_cast<DWORD>(scaleFactor * hotspotY), | 347 EXPECT_EQ(static_cast<DWORD>(scale_factor * hotspot_y), |
| 335 windowsIconInfo.yHotspot); | 348 windows_icon_info.yHotspot); |
| 336 } | 349 } |
| 337 | 350 |
| 351 } // namespace |
| 352 |
| 338 TEST(WebCursorTest, WindowsCursorScaledAtHiDpi) { | 353 TEST(WebCursorTest, WindowsCursorScaledAtHiDpi) { |
| 339 ScaleCursor(2.0f, 4, 6); | 354 ScaleCursor(2.0f, 4, 6); |
| 340 ScaleCursor(1.5f, 2, 8); | 355 ScaleCursor(1.5f, 2, 8); |
| 341 ScaleCursor(1.25f, 3, 7); | 356 ScaleCursor(1.25f, 3, 7); |
| 342 } | 357 } |
| 343 #endif | 358 #endif |
| 344 | 359 |
| 345 } // namespace content | 360 } // namespace content |
| OLD | NEW |