| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/pickle.h" | 5 #include "base/pickle.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" | 7 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
| 8 #include "webkit/glue/webcursor.h" | 8 #include "webkit/glue/webcursor.h" |
| 9 #include "webkit/tools/test_shell/test_shell_test.h" | 9 #include "webkit/tools/test_shell/test_shell_test.h" |
| 10 | 10 |
| 11 using WebKit::WebCursorInfo; | 11 using WebKit::WebCursorInfo; |
| 12 | 12 |
| 13 TEST(WebCursorTest, CursorSerialization) { | 13 TEST(WebCursorTest, CursorSerialization) { |
| 14 WebCursor custom_cursor; | 14 WebCursor custom_cursor; |
| 15 // This is a valid custom cursor. | 15 // This is a valid custom cursor. |
| 16 Pickle ok_custom_pickle; | 16 Pickle ok_custom_pickle; |
| 17 // Type and hotspots. | 17 // Type and hotspots. |
| 18 ok_custom_pickle.WriteInt(0); | 18 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); |
| 19 ok_custom_pickle.WriteInt(0); | 19 ok_custom_pickle.WriteInt(0); |
| 20 ok_custom_pickle.WriteInt(0); | 20 ok_custom_pickle.WriteInt(0); |
| 21 // X & Y | 21 // X & Y |
| 22 ok_custom_pickle.WriteInt(1); | 22 ok_custom_pickle.WriteInt(1); |
| 23 ok_custom_pickle.WriteInt(1); | 23 ok_custom_pickle.WriteInt(1); |
| 24 // Data len including enough data for a 1x1 image. | 24 // Data len including enough data for a 1x1 image. |
| 25 ok_custom_pickle.WriteInt(4); | 25 ok_custom_pickle.WriteInt(4); |
| 26 ok_custom_pickle.WriteUInt32(0); | 26 ok_custom_pickle.WriteUInt32(0); |
| 27 // Custom Windows message. | 27 // Custom Windows message. |
| 28 ok_custom_pickle.WriteUInt32(0); | 28 ok_custom_pickle.WriteUInt32(0); |
| 29 void* iter = NULL; | 29 void* iter = NULL; |
| 30 EXPECT_TRUE(custom_cursor.Deserialize(&ok_custom_pickle, &iter)); | 30 EXPECT_TRUE(custom_cursor.Deserialize(&ok_custom_pickle, &iter)); |
| 31 | 31 |
| 32 // This custom cursor has not been send with enough data. | 32 // This custom cursor has not been send with enough data. |
| 33 Pickle short_custom_pickle; | 33 Pickle short_custom_pickle; |
| 34 // Type and hotspots. | 34 // Type and hotspots. |
| 35 short_custom_pickle.WriteInt(0); | 35 short_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); |
| 36 short_custom_pickle.WriteInt(0); | 36 short_custom_pickle.WriteInt(0); |
| 37 short_custom_pickle.WriteInt(0); | 37 short_custom_pickle.WriteInt(0); |
| 38 // X & Y | 38 // X & Y |
| 39 short_custom_pickle.WriteInt(1); | 39 short_custom_pickle.WriteInt(1); |
| 40 short_custom_pickle.WriteInt(1); | 40 short_custom_pickle.WriteInt(1); |
| 41 // Data len not including enough data for a 1x1 image. | 41 // Data len not including enough data for a 1x1 image. |
| 42 short_custom_pickle.WriteInt(3); | 42 short_custom_pickle.WriteInt(3); |
| 43 short_custom_pickle.WriteUInt32(0); | 43 short_custom_pickle.WriteUInt32(0); |
| 44 // Custom Windows message. | 44 // Custom Windows message. |
| 45 ok_custom_pickle.WriteUInt32(0); | 45 ok_custom_pickle.WriteUInt32(0); |
| 46 iter = NULL; | 46 iter = NULL; |
| 47 EXPECT_FALSE(custom_cursor.Deserialize(&short_custom_pickle, &iter)); | 47 EXPECT_FALSE(custom_cursor.Deserialize(&short_custom_pickle, &iter)); |
| 48 | 48 |
| 49 // This custom cursor has enough data but is too big. | 49 // This custom cursor has enough data but is too big. |
| 50 Pickle large_custom_pickle; | 50 Pickle large_custom_pickle; |
| 51 // Type and hotspots. | 51 // Type and hotspots. |
| 52 large_custom_pickle.WriteInt(0); | 52 large_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); |
| 53 large_custom_pickle.WriteInt(0); | 53 large_custom_pickle.WriteInt(0); |
| 54 large_custom_pickle.WriteInt(0); | 54 large_custom_pickle.WriteInt(0); |
| 55 // X & Y | 55 // X & Y |
| 56 static const int kTooBigSize = 4096 + 1; | 56 static const int kTooBigSize = 4096 + 1; |
| 57 large_custom_pickle.WriteInt(kTooBigSize); | 57 large_custom_pickle.WriteInt(kTooBigSize); |
| 58 large_custom_pickle.WriteInt(1); | 58 large_custom_pickle.WriteInt(1); |
| 59 // Data len including enough data for a 4097x1 image. | 59 // Data len including enough data for a 4097x1 image. |
| 60 large_custom_pickle.WriteInt(kTooBigSize * 4); | 60 large_custom_pickle.WriteInt(kTooBigSize * 4); |
| 61 for (int i = 0; i < kTooBigSize; ++i) | 61 for (int i = 0; i < kTooBigSize; ++i) |
| 62 large_custom_pickle.WriteUInt32(0); | 62 large_custom_pickle.WriteUInt32(0); |
| 63 // Custom Windows message. | 63 // Custom Windows message. |
| 64 ok_custom_pickle.WriteUInt32(0); | 64 ok_custom_pickle.WriteUInt32(0); |
| 65 iter = NULL; | 65 iter = NULL; |
| 66 EXPECT_FALSE(custom_cursor.Deserialize(&large_custom_pickle, &iter)); | 66 EXPECT_FALSE(custom_cursor.Deserialize(&large_custom_pickle, &iter)); |
| 67 | 67 |
| 68 // This custom cursor uses negative lengths. | 68 // This custom cursor uses negative lengths. |
| 69 Pickle neg_custom_pickle; | 69 Pickle neg_custom_pickle; |
| 70 // Type and hotspots. | 70 // Type and hotspots. |
| 71 neg_custom_pickle.WriteInt(0); | 71 neg_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); |
| 72 neg_custom_pickle.WriteInt(0); | 72 neg_custom_pickle.WriteInt(0); |
| 73 neg_custom_pickle.WriteInt(0); | 73 neg_custom_pickle.WriteInt(0); |
| 74 // X & Y | 74 // X & Y |
| 75 neg_custom_pickle.WriteInt(-1); | 75 neg_custom_pickle.WriteInt(-1); |
| 76 neg_custom_pickle.WriteInt(-1); | 76 neg_custom_pickle.WriteInt(-1); |
| 77 // Data len including enough data for a 1x1 image. | 77 // Data len including enough data for a 1x1 image. |
| 78 neg_custom_pickle.WriteInt(4); | 78 neg_custom_pickle.WriteInt(4); |
| 79 neg_custom_pickle.WriteUInt32(0); | 79 neg_custom_pickle.WriteUInt32(0); |
| 80 // Custom Windows message. | 80 // Custom Windows message. |
| 81 neg_custom_pickle.WriteUInt32(0); | 81 neg_custom_pickle.WriteUInt32(0); |
| 82 iter = NULL; | 82 iter = NULL; |
| 83 EXPECT_FALSE(custom_cursor.Deserialize(&neg_custom_pickle, &iter)); | 83 EXPECT_FALSE(custom_cursor.Deserialize(&neg_custom_pickle, &iter)); |
| 84 |
| 85 #if defined(OS_WIN) |
| 86 Pickle win32_custom_pickle; |
| 87 WebCursor win32_custom_cursor; |
| 88 win32_custom_cursor.InitFromExternalCursor( |
| 89 reinterpret_cast<HCURSOR>(1000)); |
| 90 EXPECT_TRUE(win32_custom_cursor.Serialize(&win32_custom_pickle)); |
| 91 iter = NULL; |
| 92 EXPECT_TRUE(custom_cursor.Deserialize(&win32_custom_pickle, &iter)); |
| 93 EXPECT_EQ(reinterpret_cast<HCURSOR>(1000), custom_cursor.GetCursor(NULL)); |
| 94 #endif // OS_WIN |
| 84 } | 95 } |
| 85 | 96 |
| 86 TEST(WebCursorTest, ClampHotspot) { | 97 TEST(WebCursorTest, ClampHotspot) { |
| 87 WebCursor custom_cursor; | 98 WebCursor custom_cursor; |
| 88 // This is a valid custom cursor. | 99 // This is a valid custom cursor. |
| 89 Pickle ok_custom_pickle; | 100 Pickle ok_custom_pickle; |
| 90 // Type and hotspots. | 101 // Type and hotspots. |
| 91 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); | 102 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); |
| 92 // Hotspot is invalid --- outside the bounds of the image. | 103 // Hotspot is invalid --- outside the bounds of the image. |
| 93 ok_custom_pickle.WriteInt(5); | 104 ok_custom_pickle.WriteInt(5); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 custom_cursor.GetCursorInfo(&info); | 120 custom_cursor.GetCursorInfo(&info); |
| 110 EXPECT_EQ(gfx::Point(1, 1), gfx::Point(info.hotSpot)); | 121 EXPECT_EQ(gfx::Point(1, 1), gfx::Point(info.hotSpot)); |
| 111 | 122 |
| 112 // Set hotspot to an invalid point again, pipe back through WebCursor, | 123 // Set hotspot to an invalid point again, pipe back through WebCursor, |
| 113 // and make sure the hotspot got clamped again. | 124 // and make sure the hotspot got clamped again. |
| 114 info.hotSpot = gfx::Point(-1, -1); | 125 info.hotSpot = gfx::Point(-1, -1); |
| 115 custom_cursor.InitFromCursorInfo(info); | 126 custom_cursor.InitFromCursorInfo(info); |
| 116 custom_cursor.GetCursorInfo(&info); | 127 custom_cursor.GetCursorInfo(&info); |
| 117 EXPECT_EQ(gfx::Point(0, 0), gfx::Point(info.hotSpot)); | 128 EXPECT_EQ(gfx::Point(0, 0), gfx::Point(info.hotSpot)); |
| 118 } | 129 } |
| OLD | NEW |