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 "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; |
(...skipping 13 matching lines...) Expand all Loading... |
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 PickleIterator iter(ok_custom_pickle); |
33 EXPECT_TRUE(custom_cursor.Deserialize(&iter)); | 33 EXPECT_TRUE(custom_cursor.Deserialize(&iter)); |
34 | |
35 #if defined(TOOLKIT_GTK) | |
36 // On GTK+ using platforms, we should get a real native GdkCursor object back | |
37 // (and the memory used should automatically be freed by the WebCursor object | |
38 // for valgrind tests). | |
39 EXPECT_TRUE(custom_cursor.GetCustomCursor()); | |
40 #endif | |
41 } | 34 } |
42 | 35 |
43 TEST(WebCursorTest, BrokenCursorSerialization) { | 36 TEST(WebCursorTest, BrokenCursorSerialization) { |
44 WebCursor custom_cursor; | 37 WebCursor custom_cursor; |
45 // This custom cursor has not been send with enough data. | 38 // This custom cursor has not been send with enough data. |
46 Pickle short_custom_pickle; | 39 Pickle short_custom_pickle; |
47 // Type and hotspots. | 40 // Type and hotspots. |
48 short_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); | 41 short_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); |
49 short_custom_pickle.WriteInt(0); | 42 short_custom_pickle.WriteInt(0); |
50 short_custom_pickle.WriteInt(0); | 43 short_custom_pickle.WriteInt(0); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 broken_cursor_pickle.WriteFloat(1.0); | 179 broken_cursor_pickle.WriteFloat(1.0); |
187 // No data for the image since the size is 0. | 180 // No data for the image since the size is 0. |
188 broken_cursor_pickle.WriteInt(0); | 181 broken_cursor_pickle.WriteInt(0); |
189 // Custom Windows message. | 182 // Custom Windows message. |
190 broken_cursor_pickle.WriteInt(0); | 183 broken_cursor_pickle.WriteInt(0); |
191 | 184 |
192 // 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 |
193 // cursor. | 186 // cursor. |
194 PickleIterator iter(broken_cursor_pickle); | 187 PickleIterator iter(broken_cursor_pickle); |
195 ASSERT_TRUE(custom_cursor.Deserialize(&iter)); | 188 ASSERT_TRUE(custom_cursor.Deserialize(&iter)); |
196 | |
197 #if defined(TOOLKIT_GTK) | |
198 // On GTK+ using platforms, we make sure that we get NULL back from this | |
199 // method; the relevant GDK methods take NULL as a request to use the default | |
200 // cursor. | |
201 EXPECT_EQ(NULL, custom_cursor.GetCustomCursor()); | |
202 #endif | |
203 } | 189 } |
204 | 190 |
205 TEST(WebCursorTest, Scale2) { | 191 TEST(WebCursorTest, Scale2) { |
206 WebCursor custom_cursor; | 192 WebCursor custom_cursor; |
207 // This is a valid custom cursor. | 193 // This is a valid custom cursor. |
208 Pickle ok_custom_pickle; | 194 Pickle ok_custom_pickle; |
209 // Type and hotspots. | 195 // Type and hotspots. |
210 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); | 196 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); |
211 ok_custom_pickle.WriteInt(0); | 197 ok_custom_pickle.WriteInt(0); |
212 ok_custom_pickle.WriteInt(0); | 198 ok_custom_pickle.WriteInt(0); |
213 // X & Y | 199 // X & Y |
214 ok_custom_pickle.WriteInt(1); | 200 ok_custom_pickle.WriteInt(1); |
215 ok_custom_pickle.WriteInt(1); | 201 ok_custom_pickle.WriteInt(1); |
216 // Scale - 2 image pixels per UI pixel. | 202 // Scale - 2 image pixels per UI pixel. |
217 ok_custom_pickle.WriteFloat(2.0); | 203 ok_custom_pickle.WriteFloat(2.0); |
218 // Data len including enough data for a 1x1 image. | 204 // Data len including enough data for a 1x1 image. |
219 ok_custom_pickle.WriteInt(4); | 205 ok_custom_pickle.WriteInt(4); |
220 ok_custom_pickle.WriteUInt32(0); | 206 ok_custom_pickle.WriteUInt32(0); |
221 // Custom Windows message. | 207 // Custom Windows message. |
222 ok_custom_pickle.WriteUInt32(0); | 208 ok_custom_pickle.WriteUInt32(0); |
223 PickleIterator iter(ok_custom_pickle); | 209 PickleIterator iter(ok_custom_pickle); |
224 EXPECT_TRUE(custom_cursor.Deserialize(&iter)); | 210 EXPECT_TRUE(custom_cursor.Deserialize(&iter)); |
225 | |
226 #if defined(TOOLKIT_GTK) | |
227 // On GTK+ using platforms, we should get a real native GdkCursor object back | |
228 // (and the memory used should automatically be freed by the WebCursor object | |
229 // for valgrind tests). | |
230 EXPECT_TRUE(custom_cursor.GetCustomCursor()); | |
231 #endif | |
232 } | 211 } |
233 | 212 |
234 } // namespace content | 213 } // namespace content |
OLD | NEW |