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

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

Issue 1149113006: Move Pickle to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « content/common/cursors/webcursor_ozone.cc ('k') | content/common/gamepad_param_traits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/pickle.h" 5 #include "base/pickle.h"
6 #include "content/common/cursors/webcursor.h" 6 #include "content/common/cursors/webcursor.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/WebKit/public/platform/WebCursorInfo.h" 8 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
9 9
10 using blink::WebCursorInfo; 10 using blink::WebCursorInfo;
11 11
12 namespace content { 12 namespace content {
13 13
14 TEST(WebCursorTest, OKCursorSerialization) { 14 TEST(WebCursorTest, OKCursorSerialization) {
15 WebCursor custom_cursor; 15 WebCursor custom_cursor;
16 // This is a valid custom cursor. 16 // This is a valid custom cursor.
17 Pickle ok_custom_pickle; 17 base::Pickle ok_custom_pickle;
18 // Type and hotspots. 18 // Type and hotspots.
19 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 19 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
20 ok_custom_pickle.WriteInt(0); 20 ok_custom_pickle.WriteInt(0);
21 ok_custom_pickle.WriteInt(0); 21 ok_custom_pickle.WriteInt(0);
22 // X & Y 22 // X & Y
23 ok_custom_pickle.WriteInt(1); 23 ok_custom_pickle.WriteInt(1);
24 ok_custom_pickle.WriteInt(1); 24 ok_custom_pickle.WriteInt(1);
25 // Scale 25 // Scale
26 ok_custom_pickle.WriteFloat(1.0); 26 ok_custom_pickle.WriteFloat(1.0);
27 // Data len including enough data for a 1x1 image. 27 // Data len including enough data for a 1x1 image.
28 ok_custom_pickle.WriteInt(4); 28 ok_custom_pickle.WriteInt(4);
29 ok_custom_pickle.WriteUInt32(0); 29 ok_custom_pickle.WriteUInt32(0);
30 // Custom Windows message. 30 // Custom Windows message.
31 ok_custom_pickle.WriteUInt32(0); 31 ok_custom_pickle.WriteUInt32(0);
32 PickleIterator iter(ok_custom_pickle); 32 base::PickleIterator iter(ok_custom_pickle);
33 EXPECT_TRUE(custom_cursor.Deserialize(&iter)); 33 EXPECT_TRUE(custom_cursor.Deserialize(&iter));
34 } 34 }
35 35
36 TEST(WebCursorTest, BrokenCursorSerialization) { 36 TEST(WebCursorTest, BrokenCursorSerialization) {
37 WebCursor custom_cursor; 37 WebCursor custom_cursor;
38 // This custom cursor has not been send with enough data. 38 // This custom cursor has not been send with enough data.
39 Pickle short_custom_pickle; 39 base::Pickle short_custom_pickle;
40 // Type and hotspots. 40 // Type and hotspots.
41 short_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 41 short_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
42 short_custom_pickle.WriteInt(0); 42 short_custom_pickle.WriteInt(0);
43 short_custom_pickle.WriteInt(0); 43 short_custom_pickle.WriteInt(0);
44 // X & Y 44 // X & Y
45 short_custom_pickle.WriteInt(1); 45 short_custom_pickle.WriteInt(1);
46 short_custom_pickle.WriteInt(1); 46 short_custom_pickle.WriteInt(1);
47 // Scale 47 // Scale
48 short_custom_pickle.WriteFloat(1.0); 48 short_custom_pickle.WriteFloat(1.0);
49 // Data len not including enough data for a 1x1 image. 49 // Data len not including enough data for a 1x1 image.
50 short_custom_pickle.WriteInt(3); 50 short_custom_pickle.WriteInt(3);
51 short_custom_pickle.WriteUInt32(0); 51 short_custom_pickle.WriteUInt32(0);
52 PickleIterator iter(short_custom_pickle); 52 base::PickleIterator iter(short_custom_pickle);
53 EXPECT_FALSE(custom_cursor.Deserialize(&iter)); 53 EXPECT_FALSE(custom_cursor.Deserialize(&iter));
54 54
55 // This custom cursor has enough data but is too big. 55 // This custom cursor has enough data but is too big.
56 Pickle large_custom_pickle; 56 base::Pickle large_custom_pickle;
57 // Type and hotspots. 57 // Type and hotspots.
58 large_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 58 large_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
59 large_custom_pickle.WriteInt(0); 59 large_custom_pickle.WriteInt(0);
60 large_custom_pickle.WriteInt(0); 60 large_custom_pickle.WriteInt(0);
61 // X & Y 61 // X & Y
62 static const int kTooBigSize = 4096 + 1; 62 static const int kTooBigSize = 4096 + 1;
63 large_custom_pickle.WriteInt(kTooBigSize); 63 large_custom_pickle.WriteInt(kTooBigSize);
64 large_custom_pickle.WriteInt(1); 64 large_custom_pickle.WriteInt(1);
65 // Scale 65 // Scale
66 large_custom_pickle.WriteFloat(1.0); 66 large_custom_pickle.WriteFloat(1.0);
67 // Data len including enough data for a 4097x1 image. 67 // Data len including enough data for a 4097x1 image.
68 large_custom_pickle.WriteInt(kTooBigSize * 4); 68 large_custom_pickle.WriteInt(kTooBigSize * 4);
69 for (int i = 0; i < kTooBigSize; ++i) 69 for (int i = 0; i < kTooBigSize; ++i)
70 large_custom_pickle.WriteUInt32(0); 70 large_custom_pickle.WriteUInt32(0);
71 iter = PickleIterator(large_custom_pickle); 71 iter = base::PickleIterator(large_custom_pickle);
72 EXPECT_FALSE(custom_cursor.Deserialize(&iter)); 72 EXPECT_FALSE(custom_cursor.Deserialize(&iter));
73 73
74 // This custom cursor uses negative lengths. 74 // This custom cursor uses negative lengths.
75 Pickle neg_custom_pickle; 75 base::Pickle neg_custom_pickle;
76 // Type and hotspots. 76 // Type and hotspots.
77 neg_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 77 neg_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
78 neg_custom_pickle.WriteInt(0); 78 neg_custom_pickle.WriteInt(0);
79 neg_custom_pickle.WriteInt(0); 79 neg_custom_pickle.WriteInt(0);
80 // X & Y 80 // X & Y
81 neg_custom_pickle.WriteInt(-1); 81 neg_custom_pickle.WriteInt(-1);
82 neg_custom_pickle.WriteInt(-1); 82 neg_custom_pickle.WriteInt(-1);
83 // Scale 83 // Scale
84 neg_custom_pickle.WriteFloat(1.0); 84 neg_custom_pickle.WriteFloat(1.0);
85 // Data len including enough data for a 1x1 image. 85 // Data len including enough data for a 1x1 image.
86 neg_custom_pickle.WriteInt(4); 86 neg_custom_pickle.WriteInt(4);
87 neg_custom_pickle.WriteUInt32(0); 87 neg_custom_pickle.WriteUInt32(0);
88 // Custom Windows message. 88 // Custom Windows message.
89 neg_custom_pickle.WriteUInt32(0); 89 neg_custom_pickle.WriteUInt32(0);
90 iter = PickleIterator(neg_custom_pickle); 90 iter = base::PickleIterator(neg_custom_pickle);
91 EXPECT_FALSE(custom_cursor.Deserialize(&iter)); 91 EXPECT_FALSE(custom_cursor.Deserialize(&iter));
92 92
93 // This custom cursor uses zero scale. 93 // This custom cursor uses zero scale.
94 Pickle scale_zero_custom_pickle; 94 base::Pickle scale_zero_custom_pickle;
95 // Type and hotspots. 95 // Type and hotspots.
96 scale_zero_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 96 scale_zero_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
97 scale_zero_custom_pickle.WriteInt(0); 97 scale_zero_custom_pickle.WriteInt(0);
98 scale_zero_custom_pickle.WriteInt(0); 98 scale_zero_custom_pickle.WriteInt(0);
99 // X & Y 99 // X & Y
100 scale_zero_custom_pickle.WriteInt(1); 100 scale_zero_custom_pickle.WriteInt(1);
101 scale_zero_custom_pickle.WriteInt(1); 101 scale_zero_custom_pickle.WriteInt(1);
102 // Scale 102 // Scale
103 scale_zero_custom_pickle.WriteFloat(0); 103 scale_zero_custom_pickle.WriteFloat(0);
104 // Data len including enough data for a 1x1 image. 104 // Data len including enough data for a 1x1 image.
105 scale_zero_custom_pickle.WriteInt(4); 105 scale_zero_custom_pickle.WriteInt(4);
106 scale_zero_custom_pickle.WriteUInt32(0); 106 scale_zero_custom_pickle.WriteUInt32(0);
107 // Custom Windows message. 107 // Custom Windows message.
108 scale_zero_custom_pickle.WriteUInt32(0); 108 scale_zero_custom_pickle.WriteUInt32(0);
109 iter = PickleIterator(scale_zero_custom_pickle); 109 iter = base::PickleIterator(scale_zero_custom_pickle);
110 EXPECT_FALSE(custom_cursor.Deserialize(&iter)); 110 EXPECT_FALSE(custom_cursor.Deserialize(&iter));
111 111
112 // This custom cursor uses tiny scale. 112 // This custom cursor uses tiny scale.
113 Pickle scale_tiny_custom_pickle; 113 base::Pickle scale_tiny_custom_pickle;
114 // Type and hotspots. 114 // Type and hotspots.
115 scale_tiny_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 115 scale_tiny_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
116 scale_tiny_custom_pickle.WriteInt(0); 116 scale_tiny_custom_pickle.WriteInt(0);
117 scale_tiny_custom_pickle.WriteInt(0); 117 scale_tiny_custom_pickle.WriteInt(0);
118 // X & Y 118 // X & Y
119 scale_tiny_custom_pickle.WriteInt(1); 119 scale_tiny_custom_pickle.WriteInt(1);
120 scale_tiny_custom_pickle.WriteInt(1); 120 scale_tiny_custom_pickle.WriteInt(1);
121 // Scale 121 // Scale
122 scale_tiny_custom_pickle.WriteFloat(0.001f); 122 scale_tiny_custom_pickle.WriteFloat(0.001f);
123 // Data len including enough data for a 1x1 image. 123 // Data len including enough data for a 1x1 image.
124 scale_tiny_custom_pickle.WriteInt(4); 124 scale_tiny_custom_pickle.WriteInt(4);
125 scale_tiny_custom_pickle.WriteUInt32(0); 125 scale_tiny_custom_pickle.WriteUInt32(0);
126 // Custom Windows message. 126 // Custom Windows message.
127 scale_tiny_custom_pickle.WriteUInt32(0); 127 scale_tiny_custom_pickle.WriteUInt32(0);
128 iter = PickleIterator(scale_tiny_custom_pickle); 128 iter = base::PickleIterator(scale_tiny_custom_pickle);
129 EXPECT_FALSE(custom_cursor.Deserialize(&iter)); 129 EXPECT_FALSE(custom_cursor.Deserialize(&iter));
130 } 130 }
131 131
132 TEST(WebCursorTest, ClampHotspot) { 132 TEST(WebCursorTest, ClampHotspot) {
133 WebCursor custom_cursor; 133 WebCursor custom_cursor;
134 // This is a valid custom cursor. 134 // This is a valid custom cursor.
135 Pickle ok_custom_pickle; 135 base::Pickle ok_custom_pickle;
136 // Type and hotspots. 136 // Type and hotspots.
137 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 137 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
138 // Hotspot is invalid --- outside the bounds of the image. 138 // Hotspot is invalid --- outside the bounds of the image.
139 ok_custom_pickle.WriteInt(5); 139 ok_custom_pickle.WriteInt(5);
140 ok_custom_pickle.WriteInt(5); 140 ok_custom_pickle.WriteInt(5);
141 // X & Y 141 // X & Y
142 ok_custom_pickle.WriteInt(2); 142 ok_custom_pickle.WriteInt(2);
143 ok_custom_pickle.WriteInt(2); 143 ok_custom_pickle.WriteInt(2);
144 // Scale 144 // Scale
145 ok_custom_pickle.WriteFloat(1.0); 145 ok_custom_pickle.WriteFloat(1.0);
146 // Data len including enough data for a 2x2 image. 146 // Data len including enough data for a 2x2 image.
147 ok_custom_pickle.WriteInt(4 * 4); 147 ok_custom_pickle.WriteInt(4 * 4);
148 for (size_t i = 0; i < 4; i++) 148 for (size_t i = 0; i < 4; i++)
149 ok_custom_pickle.WriteUInt32(0); 149 ok_custom_pickle.WriteUInt32(0);
150 // Custom Windows message. 150 // Custom Windows message.
151 ok_custom_pickle.WriteUInt32(0); 151 ok_custom_pickle.WriteUInt32(0);
152 PickleIterator iter(ok_custom_pickle); 152 base::PickleIterator iter(ok_custom_pickle);
153 ASSERT_TRUE(custom_cursor.Deserialize(&iter)); 153 ASSERT_TRUE(custom_cursor.Deserialize(&iter));
154 154
155 // Convert to WebCursorInfo, make sure the hotspot got clamped. 155 // Convert to WebCursorInfo, make sure the hotspot got clamped.
156 WebCursor::CursorInfo info; 156 WebCursor::CursorInfo info;
157 custom_cursor.GetCursorInfo(&info); 157 custom_cursor.GetCursorInfo(&info);
158 EXPECT_EQ(gfx::Point(1, 1), info.hotspot); 158 EXPECT_EQ(gfx::Point(1, 1), info.hotspot);
159 159
160 // Set hotspot to an invalid point again, pipe back through WebCursor, 160 // Set hotspot to an invalid point again, pipe back through WebCursor,
161 // and make sure the hotspot got clamped again. 161 // and make sure the hotspot got clamped again.
162 info.hotspot = gfx::Point(-1, -1); 162 info.hotspot = gfx::Point(-1, -1);
163 custom_cursor.InitFromCursorInfo(info); 163 custom_cursor.InitFromCursorInfo(info);
164 custom_cursor.GetCursorInfo(&info); 164 custom_cursor.GetCursorInfo(&info);
165 EXPECT_EQ(gfx::Point(0, 0), info.hotspot); 165 EXPECT_EQ(gfx::Point(0, 0), info.hotspot);
166 } 166 }
167 167
168 TEST(WebCursorTest, EmptyImage) { 168 TEST(WebCursorTest, EmptyImage) {
169 WebCursor custom_cursor; 169 WebCursor custom_cursor;
170 Pickle broken_cursor_pickle; 170 base::Pickle broken_cursor_pickle;
171 broken_cursor_pickle.WriteInt(WebCursorInfo::TypeCustom); 171 broken_cursor_pickle.WriteInt(WebCursorInfo::TypeCustom);
172 // Hotspot is at origin 172 // Hotspot is at origin
173 broken_cursor_pickle.WriteInt(0); 173 broken_cursor_pickle.WriteInt(0);
174 broken_cursor_pickle.WriteInt(0); 174 broken_cursor_pickle.WriteInt(0);
175 // X & Y are empty 175 // X & Y are empty
176 broken_cursor_pickle.WriteInt(0); 176 broken_cursor_pickle.WriteInt(0);
177 broken_cursor_pickle.WriteInt(0); 177 broken_cursor_pickle.WriteInt(0);
178 // Scale 178 // Scale
179 broken_cursor_pickle.WriteFloat(1.0); 179 broken_cursor_pickle.WriteFloat(1.0);
180 // No data for the image since the size is 0. 180 // No data for the image since the size is 0.
181 broken_cursor_pickle.WriteInt(0); 181 broken_cursor_pickle.WriteInt(0);
182 // Custom Windows message. 182 // Custom Windows message.
183 broken_cursor_pickle.WriteInt(0); 183 broken_cursor_pickle.WriteInt(0);
184 184
185 // Make sure we can read this on all platforms; it is technicaally a valid 185 // Make sure we can read this on all platforms; it is technicaally a valid
186 // cursor. 186 // cursor.
187 PickleIterator iter(broken_cursor_pickle); 187 base::PickleIterator iter(broken_cursor_pickle);
188 ASSERT_TRUE(custom_cursor.Deserialize(&iter)); 188 ASSERT_TRUE(custom_cursor.Deserialize(&iter));
189 } 189 }
190 190
191 TEST(WebCursorTest, Scale2) { 191 TEST(WebCursorTest, Scale2) {
192 WebCursor custom_cursor; 192 WebCursor custom_cursor;
193 // This is a valid custom cursor. 193 // This is a valid custom cursor.
194 Pickle ok_custom_pickle; 194 base::Pickle ok_custom_pickle;
195 // Type and hotspots. 195 // Type and hotspots.
196 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 196 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
197 ok_custom_pickle.WriteInt(0); 197 ok_custom_pickle.WriteInt(0);
198 ok_custom_pickle.WriteInt(0); 198 ok_custom_pickle.WriteInt(0);
199 // X & Y 199 // X & Y
200 ok_custom_pickle.WriteInt(1); 200 ok_custom_pickle.WriteInt(1);
201 ok_custom_pickle.WriteInt(1); 201 ok_custom_pickle.WriteInt(1);
202 // Scale - 2 image pixels per UI pixel. 202 // Scale - 2 image pixels per UI pixel.
203 ok_custom_pickle.WriteFloat(2.0); 203 ok_custom_pickle.WriteFloat(2.0);
204 // Data len including enough data for a 1x1 image. 204 // Data len including enough data for a 1x1 image.
205 ok_custom_pickle.WriteInt(4); 205 ok_custom_pickle.WriteInt(4);
206 ok_custom_pickle.WriteUInt32(0); 206 ok_custom_pickle.WriteUInt32(0);
207 // Custom Windows message. 207 // Custom Windows message.
208 ok_custom_pickle.WriteUInt32(0); 208 ok_custom_pickle.WriteUInt32(0);
209 PickleIterator iter(ok_custom_pickle); 209 base::PickleIterator iter(ok_custom_pickle);
210 EXPECT_TRUE(custom_cursor.Deserialize(&iter)); 210 EXPECT_TRUE(custom_cursor.Deserialize(&iter));
211 } 211 }
212 212
213 } // namespace content 213 } // namespace content
OLDNEW
« no previous file with comments | « content/common/cursors/webcursor_ozone.cc ('k') | content/common/gamepad_param_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698