| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  154   // Data len including enough data for a 2x2 image. |  154   // Data len including enough data for a 2x2 image. | 
|  155   ok_custom_pickle.WriteInt(4 * 4); |  155   ok_custom_pickle.WriteInt(4 * 4); | 
|  156   for (size_t i = 0; i < 4; i++) |  156   for (size_t i = 0; i < 4; i++) | 
|  157     ok_custom_pickle.WriteUInt32(0); |  157     ok_custom_pickle.WriteUInt32(0); | 
|  158   // Custom Windows message. |  158   // Custom Windows message. | 
|  159   ok_custom_pickle.WriteUInt32(0); |  159   ok_custom_pickle.WriteUInt32(0); | 
|  160   base::PickleIterator iter(ok_custom_pickle); |  160   base::PickleIterator iter(ok_custom_pickle); | 
|  161   EXPECT_TRUE(custom_cursor.Deserialize(&iter)); |  161   EXPECT_TRUE(custom_cursor.Deserialize(&iter)); | 
|  162  |  162  | 
|  163   // Convert to WebCursorInfo, make sure the hotspot got clamped. |  163   // Convert to WebCursorInfo, make sure the hotspot got clamped. | 
|  164   WebCursor::CursorInfo info; |  164   CursorInfo info; | 
|  165   custom_cursor.GetCursorInfo(&info); |  165   custom_cursor.GetCursorInfo(&info); | 
|  166   EXPECT_EQ(gfx::Point(1, 1), info.hotspot); |  166   EXPECT_EQ(gfx::Point(1, 1), info.hotspot); | 
|  167  |  167  | 
|  168   // Set hotspot to an invalid point again, pipe back through WebCursor, |  168   // Set hotspot to an invalid point again, pipe back through WebCursor, | 
|  169   // and make sure the hotspot got clamped again. |  169   // and make sure the hotspot got clamped again. | 
|  170   info.hotspot = gfx::Point(-1, -1); |  170   info.hotspot = gfx::Point(-1, -1); | 
|  171   custom_cursor.InitFromCursorInfo(info); |  171   custom_cursor.InitFromCursorInfo(info); | 
|  172   custom_cursor.GetCursorInfo(&info); |  172   custom_cursor.GetCursorInfo(&info); | 
|  173   EXPECT_EQ(gfx::Point(0, 0), info.hotspot); |  173   EXPECT_EQ(gfx::Point(0, 0), info.hotspot); | 
|  174 } |  174 } | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  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); |  225   SkAutoLockPixels bitmap_lock(bitmap); | 
|  226   *bitmap.getAddr32(0, 0) = testColor; |  226   *bitmap.getAddr32(0, 0) = testColor; | 
|  227   WebCursor::CursorInfo cursor_info; |  227   CursorInfo cursor_info; | 
|  228   cursor_info.type = WebCursorInfo::kTypeCustom; |  228   cursor_info.type = WebCursorInfo::kTypeCustom; | 
|  229   cursor_info.custom_image = bitmap; |  229   cursor_info.custom_image = bitmap; | 
|  230   cursor_info.image_scale_factor = 1; |  230   cursor_info.image_scale_factor = 1; | 
|  231   WebCursor custom_cursor; |  231   WebCursor custom_cursor; | 
|  232  |  232  | 
|  233   // This round trip will convert the cursor to unpremultiplied form. |  233   // This round trip will convert the cursor to unpremultiplied form. | 
|  234   custom_cursor.InitFromCursorInfo(cursor_info); |  234   custom_cursor.InitFromCursorInfo(cursor_info); | 
|  235   custom_cursor.GetCursorInfo(&cursor_info); |  235   custom_cursor.GetCursorInfo(&cursor_info); | 
|  236   { |  236   { | 
|  237     SkAutoLockPixels lock(cursor_info.custom_image); |  237     SkAutoLockPixels lock(cursor_info.custom_image); | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  263               SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); |  263               SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); | 
|  264   } |  264   } | 
|  265 #endif |  265 #endif | 
|  266 } |  266 } | 
|  267  |  267  | 
|  268 #if defined(USE_AURA) |  268 #if defined(USE_AURA) | 
|  269 TEST(WebCursorTest, CursorScaleFactor) { |  269 TEST(WebCursorTest, CursorScaleFactor) { | 
|  270   display::Display display; |  270   display::Display display; | 
|  271   display.set_device_scale_factor(80.2f); |  271   display.set_device_scale_factor(80.2f); | 
|  272  |  272  | 
|  273   WebCursor::CursorInfo info; |  273   CursorInfo info; | 
|  274   info.image_scale_factor = 2.0f; |  274   info.image_scale_factor = 2.0f; | 
|  275  |  275  | 
|  276   WebCursor cursor; |  276   WebCursor cursor; | 
|  277   cursor.InitFromCursorInfo(info); |  277   cursor.InitFromCursorInfo(info); | 
|  278   cursor.SetDisplayInfo(display); |  278   cursor.SetDisplayInfo(display); | 
|  279  |  279  | 
|  280   EXPECT_EQ(40.1f, cursor.GetCursorScaleFactor()); |  280   EXPECT_EQ(40.1f, cursor.GetCursorScaleFactor()); | 
|  281 } |  281 } | 
|  282  |  282  | 
|  283 TEST(WebCursorTest, UnscaledImageCopy) { |  283 TEST(WebCursorTest, UnscaledImageCopy) { | 
|  284   WebCursor::CursorInfo info; |  284   CursorInfo info; | 
|  285   info.type = WebCursorInfo::kTypeCustom; |  285   info.type = WebCursorInfo::kTypeCustom; | 
|  286   info.hotspot = gfx::Point(0, 1); |  286   info.hotspot = gfx::Point(0, 1); | 
|  287  |  287  | 
|  288   SkImageInfo image_info = SkImageInfo::MakeN32(2, 2, kUnpremul_SkAlphaType); |  288   SkImageInfo image_info = SkImageInfo::MakeN32(2, 2, kUnpremul_SkAlphaType); | 
|  289   info.custom_image = SkBitmap(); |  289   info.custom_image = SkBitmap(); | 
|  290   info.custom_image.setInfo(image_info); |  290   info.custom_image.setInfo(image_info); | 
|  291   info.custom_image.allocN32Pixels(2, 2); |  291   info.custom_image.allocN32Pixels(2, 2); | 
|  292   info.custom_image.eraseColor(0xFFFFFFFF); |  292   info.custom_image.eraseColor(0xFFFFFFFF); | 
|  293  |  293  | 
|  294   WebCursor cursor; |  294   WebCursor cursor; | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  318 } |  318 } | 
|  319 #endif |  319 #endif | 
|  320  |  320  | 
|  321 #if defined(OS_WIN) |  321 #if defined(OS_WIN) | 
|  322 namespace { |  322 namespace { | 
|  323  |  323  | 
|  324 void ScaleCursor(float scale_factor, int hotspot_x, int hotspot_y) { |  324 void ScaleCursor(float scale_factor, int hotspot_x, int hotspot_y) { | 
|  325   display::Display display; |  325   display::Display display; | 
|  326   display.set_device_scale_factor(scale_factor); |  326   display.set_device_scale_factor(scale_factor); | 
|  327  |  327  | 
|  328   WebCursor::CursorInfo info; |  328   CursorInfo info; | 
|  329   info.type = WebCursorInfo::kTypeCustom; |  329   info.type = WebCursorInfo::kTypeCustom; | 
|  330   info.hotspot = gfx::Point(hotspot_x, hotspot_y); |  330   info.hotspot = gfx::Point(hotspot_x, hotspot_y); | 
|  331  |  331  | 
|  332   info.custom_image = SkBitmap(); |  332   info.custom_image = SkBitmap(); | 
|  333   info.custom_image.allocN32Pixels(10, 10); |  333   info.custom_image.allocN32Pixels(10, 10); | 
|  334   info.custom_image.eraseColor(0); |  334   info.custom_image.eraseColor(0); | 
|  335  |  335  | 
|  336   WebCursor cursor; |  336   WebCursor cursor; | 
|  337   cursor.SetDisplayInfo(display); |  337   cursor.SetDisplayInfo(display); | 
|  338   cursor.InitFromCursorInfo(info); |  338   cursor.InitFromCursorInfo(info); | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  351 }  // namespace |  351 }  // namespace | 
|  352  |  352  | 
|  353 TEST(WebCursorTest, WindowsCursorScaledAtHiDpi) { |  353 TEST(WebCursorTest, WindowsCursorScaledAtHiDpi) { | 
|  354   ScaleCursor(2.0f, 4, 6); |  354   ScaleCursor(2.0f, 4, 6); | 
|  355   ScaleCursor(1.5f, 2, 8); |  355   ScaleCursor(1.5f, 2, 8); | 
|  356   ScaleCursor(1.25f, 3, 7); |  356   ScaleCursor(1.25f, 3, 7); | 
|  357 } |  357 } | 
|  358 #endif |  358 #endif | 
|  359  |  359  | 
|  360 }  // namespace content |  360 }  // namespace content | 
| OLD | NEW |