| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 // Custom Windows message. | 215 // Custom Windows message. |
| 216 ok_custom_pickle.WriteUInt32(0); | 216 ok_custom_pickle.WriteUInt32(0); |
| 217 base::PickleIterator iter(ok_custom_pickle); | 217 base::PickleIterator iter(ok_custom_pickle); |
| 218 EXPECT_TRUE(custom_cursor.Deserialize(&iter)); | 218 EXPECT_TRUE(custom_cursor.Deserialize(&iter)); |
| 219 } | 219 } |
| 220 | 220 |
| 221 TEST(WebCursorTest, AlphaConversion) { | 221 TEST(WebCursorTest, AlphaConversion) { |
| 222 SkBitmap bitmap; | 222 SkBitmap bitmap; |
| 223 SkPMColor testColor = SkPreMultiplyARGB(10, 255, 255, 255); | 223 SkPMColor testColor = SkPreMultiplyARGB(10, 255, 255, 255); |
| 224 bitmap.allocN32Pixels(1,1); | 224 bitmap.allocN32Pixels(1,1); |
| 225 SkAutoLockPixels bitmap_lock(bitmap); | |
| 226 *bitmap.getAddr32(0, 0) = testColor; | 225 *bitmap.getAddr32(0, 0) = testColor; |
| 227 CursorInfo cursor_info; | 226 CursorInfo cursor_info; |
| 228 cursor_info.type = WebCursorInfo::kTypeCustom; | 227 cursor_info.type = WebCursorInfo::kTypeCustom; |
| 229 cursor_info.custom_image = bitmap; | 228 cursor_info.custom_image = bitmap; |
| 230 cursor_info.image_scale_factor = 1; | 229 cursor_info.image_scale_factor = 1; |
| 231 WebCursor custom_cursor; | 230 WebCursor custom_cursor; |
| 232 | 231 |
| 233 // This round trip will convert the cursor to unpremultiplied form. | 232 // This round trip will convert the cursor to unpremultiplied form. |
| 234 custom_cursor.InitFromCursorInfo(cursor_info); | 233 custom_cursor.InitFromCursorInfo(cursor_info); |
| 235 custom_cursor.GetCursorInfo(&cursor_info); | 234 custom_cursor.GetCursorInfo(&cursor_info); |
| 236 { | 235 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); |
| 237 SkAutoLockPixels lock(cursor_info.custom_image); | 236 EXPECT_EQ(testColor, |
| 238 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); | 237 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0, 0))); |
| 239 EXPECT_EQ(testColor, | |
| 240 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); | |
| 241 } | |
| 242 | 238 |
| 243 // Second round trip should not do any conversion because data is already | 239 // Second round trip should not do any conversion because data is already |
| 244 // unpremultiplied. | 240 // unpremultiplied. |
| 245 custom_cursor.InitFromCursorInfo(cursor_info); | 241 custom_cursor.InitFromCursorInfo(cursor_info); |
| 246 custom_cursor.GetCursorInfo(&cursor_info); | 242 custom_cursor.GetCursorInfo(&cursor_info); |
| 247 { | 243 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); |
| 248 SkAutoLockPixels lock(cursor_info.custom_image); | 244 EXPECT_EQ(testColor, |
| 249 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); | 245 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0, 0))); |
| 250 EXPECT_EQ(testColor, | |
| 251 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); | |
| 252 } | |
| 253 | 246 |
| 254 #if defined(OS_MACOSX) | 247 #if defined(OS_MACOSX) |
| 255 // On MacOS, test roundtrip through NSCursor conversion. | 248 // On MacOS, test roundtrip through NSCursor conversion. |
| 256 WebCursor custom_cursor_copy; | 249 WebCursor custom_cursor_copy; |
| 257 custom_cursor_copy.InitFromNSCursor(custom_cursor.GetNativeCursor()); | 250 custom_cursor_copy.InitFromNSCursor(custom_cursor.GetNativeCursor()); |
| 258 custom_cursor_copy.GetCursorInfo(&cursor_info); | 251 custom_cursor_copy.GetCursorInfo(&cursor_info); |
| 259 { | 252 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); |
| 260 SkAutoLockPixels lock(cursor_info.custom_image); | 253 EXPECT_EQ(testColor, |
| 261 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); | 254 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0, 0))); |
| 262 EXPECT_EQ(testColor, | |
| 263 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); | |
| 264 } | |
| 265 #endif | 255 #endif |
| 266 } | 256 } |
| 267 | 257 |
| 268 #if defined(USE_AURA) | 258 #if defined(USE_AURA) |
| 269 TEST(WebCursorTest, CursorScaleFactor) { | 259 TEST(WebCursorTest, CursorScaleFactor) { |
| 270 display::Display display; | 260 display::Display display; |
| 271 display.set_device_scale_factor(80.2f); | 261 display.set_device_scale_factor(80.2f); |
| 272 | 262 |
| 273 CursorInfo info; | 263 CursorInfo info; |
| 274 info.image_scale_factor = 2.0f; | 264 info.image_scale_factor = 2.0f; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 } // namespace | 341 } // namespace |
| 352 | 342 |
| 353 TEST(WebCursorTest, WindowsCursorScaledAtHiDpi) { | 343 TEST(WebCursorTest, WindowsCursorScaledAtHiDpi) { |
| 354 ScaleCursor(2.0f, 4, 6); | 344 ScaleCursor(2.0f, 4, 6); |
| 355 ScaleCursor(1.5f, 2, 8); | 345 ScaleCursor(1.5f, 2, 8); |
| 356 ScaleCursor(1.25f, 3, 7); | 346 ScaleCursor(1.25f, 3, 7); |
| 357 } | 347 } |
| 358 #endif | 348 #endif |
| 359 | 349 |
| 360 } // namespace content | 350 } // namespace content |
| OLD | NEW |