Chromium Code Reviews| 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 "webkit/glue/webcursor.h" | 8 #include "webkit/glue/webcursor.h" |
| 8 #include "webkit/tools/test_shell/test_shell_test.h" | 9 #include "webkit/tools/test_shell/test_shell_test.h" |
| 9 | 10 |
| 11 using WebKit::WebCursorInfo; | |
| 12 | |
| 10 TEST(WebCursorTest, CursorSerialization) { | 13 TEST(WebCursorTest, CursorSerialization) { |
| 11 WebCursor custom_cursor; | 14 WebCursor custom_cursor; |
| 12 // This is a valid custom cursor. | 15 // This is a valid custom cursor. |
| 13 Pickle ok_custom_pickle; | 16 Pickle ok_custom_pickle; |
| 14 // Type and hotspots. | 17 // Type and hotspots. |
| 15 ok_custom_pickle.WriteInt(0); | 18 ok_custom_pickle.WriteInt(0); |
| 16 ok_custom_pickle.WriteInt(0); | 19 ok_custom_pickle.WriteInt(0); |
| 17 ok_custom_pickle.WriteInt(0); | 20 ok_custom_pickle.WriteInt(0); |
| 18 // X & Y | 21 // X & Y |
| 19 ok_custom_pickle.WriteInt(1); | 22 ok_custom_pickle.WriteInt(1); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 neg_custom_pickle.WriteInt(-1); | 76 neg_custom_pickle.WriteInt(-1); |
| 74 // Data len including enough data for a 1x1 image. | 77 // Data len including enough data for a 1x1 image. |
| 75 neg_custom_pickle.WriteInt(4); | 78 neg_custom_pickle.WriteInt(4); |
| 76 neg_custom_pickle.WriteUInt32(0); | 79 neg_custom_pickle.WriteUInt32(0); |
| 77 // Custom Windows message. | 80 // Custom Windows message. |
| 78 neg_custom_pickle.WriteUInt32(0); | 81 neg_custom_pickle.WriteUInt32(0); |
| 79 iter = NULL; | 82 iter = NULL; |
| 80 EXPECT_FALSE(custom_cursor.Deserialize(&neg_custom_pickle, &iter)); | 83 EXPECT_FALSE(custom_cursor.Deserialize(&neg_custom_pickle, &iter)); |
| 81 } | 84 } |
| 82 | 85 |
| 86 TEST(WebCursorTest, ClampHotspot) { | |
| 87 WebCursor custom_cursor; | |
| 88 // This is a valid custom cursor. | |
| 89 Pickle ok_custom_pickle; | |
| 90 // Type and hotspots. | |
| 91 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); | |
| 92 // Hotspot is invalid --- outside the bounds of the image. | |
| 93 ok_custom_pickle.WriteInt(5); | |
| 94 ok_custom_pickle.WriteInt(5); | |
| 95 // X & Y | |
| 96 ok_custom_pickle.WriteInt(2); | |
| 97 ok_custom_pickle.WriteInt(2); | |
| 98 // Data len including enough data for a 2x2 image. | |
| 99 ok_custom_pickle.WriteInt(4 * 4); | |
| 100 for (size_t i = 0; i < 4; i++) | |
| 101 ok_custom_pickle.WriteUInt32(0); | |
| 102 // Custom Windows message. | |
| 103 ok_custom_pickle.WriteUInt32(0); | |
| 104 void* iter = NULL; | |
| 105 ASSERT_TRUE(custom_cursor.Deserialize(&ok_custom_pickle, &iter)); | |
|
Evan Martin
2010/08/11 00:01:58
yay correct usage of assert
| |
| 106 | |
| 107 // Convert to WebCursorInfo, make sure the hotspot got clamped. | |
| 108 WebCursorInfo info; | |
| 109 custom_cursor.GetCursorInfo(&info); | |
| 110 EXPECT_EQ(gfx::Point(1, 1), gfx::Point(info.hotSpot)); | |
| 111 | |
| 112 // Set hotspot to an invalid point again, pipe back through WebCursor, | |
| 113 // and make sure the hotspot got clamped again. | |
| 114 info.hotSpot = gfx::Point(-1, -1); | |
| 115 custom_cursor.InitFromCursorInfo(info); | |
| 116 custom_cursor.GetCursorInfo(&info); | |
| 117 EXPECT_EQ(gfx::Point(0, 0), gfx::Point(info.hotSpot)); | |
| 118 } | |
| OLD | NEW |