Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: content/common/cursors/webcursor_unittest.cc

Issue 1975033002: Minor cleanup to webcursors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: forgot one thing Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 {
scottmg 2016/05/13 00:27:21 \n after { (make opening and closing match)
Bret 2016/05/13 00:53:16 Done.
323 void ScaleCursor(float scale_factor, int hotspot_x, int hotspot_y) {
312 display::Display display; 324 display::Display display;
313 display.set_device_scale_factor(scaleFactor); 325 display.set_device_scale_factor(scale_factor);
314 326
315 WebCursor::CursorInfo info; 327 WebCursor::CursorInfo info;
316 info.type = WebCursorInfo::TypeCustom; 328 info.type = WebCursorInfo::TypeCustom;
317 info.hotspot = gfx::Point(hotspotX, hotspotY); 329 info.hotspot = gfx::Point(hotspot_x, hotspot_y);
318 330
319 info.custom_image = SkBitmap(); 331 info.custom_image = SkBitmap();
320 info.custom_image.allocN32Pixels(10, 10); 332 info.custom_image.allocN32Pixels(10, 10);
321 info.custom_image.eraseColor(0); 333 info.custom_image.eraseColor(0);
322 334
323 WebCursor cursor; 335 WebCursor cursor;
324 cursor.SetDisplayInfo(display); 336 cursor.SetDisplayInfo(display);
325 cursor.InitFromCursorInfo(info); 337 cursor.InitFromCursorInfo(info);
326 338
327 HCURSOR windowsCursorHandle = cursor.GetPlatformCursor(); 339 HCURSOR windows_cursor_handle = cursor.GetPlatformCursor();
328 EXPECT_NE(nullptr, windowsCursorHandle); 340 EXPECT_NE(nullptr, windows_cursor_handle);
329 ICONINFO windowsIconInfo; 341 ICONINFO windows_icon_info;
330 EXPECT_TRUE(GetIconInfo(windowsCursorHandle, &windowsIconInfo)); 342 EXPECT_TRUE(GetIconInfo(windows_cursor_handle, &windows_icon_info));
331 EXPECT_FALSE(windowsIconInfo.fIcon); 343 EXPECT_FALSE(windows_icon_info.fIcon);
332 EXPECT_EQ(static_cast<DWORD>(scaleFactor * hotspotX), 344 EXPECT_EQ(static_cast<DWORD>(scale_factor * hotspot_x),
333 windowsIconInfo.xHotspot); 345 windows_icon_info.xHotspot);
334 EXPECT_EQ(static_cast<DWORD>(scaleFactor * hotspotY), 346 EXPECT_EQ(static_cast<DWORD>(scale_factor * hotspot_y),
335 windowsIconInfo.yHotspot); 347 windows_icon_info.yHotspot);
336 } 348 }
337 349
350 } // namespace
351
338 TEST(WebCursorTest, WindowsCursorScaledAtHiDpi) { 352 TEST(WebCursorTest, WindowsCursorScaledAtHiDpi) {
339 ScaleCursor(2.0f, 4, 6); 353 ScaleCursor(2.0f, 4, 6);
340 ScaleCursor(1.5f, 2, 8); 354 ScaleCursor(1.5f, 2, 8);
341 ScaleCursor(1.25f, 3, 7); 355 ScaleCursor(1.25f, 3, 7);
342 } 356 }
343 #endif 357 #endif
344 358
345 } // namespace content 359 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698