OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "webkit/glue/webcursor.h" | 7 #include "webkit/glue/webcursor.h" |
8 #include "webkit/tools/test_shell/test_shell_test.h" | 8 #include "webkit/tools/test_shell/test_shell_test.h" |
9 | 9 |
10 TEST(WebCursorTest, CursorSerialization) { | 10 TEST(WebCursorTest, CursorSerialization) { |
11 WebCursor custom_cursor; | 11 WebCursor custom_cursor; |
12 // This is a valid custom cursor. | 12 // This is a valid custom cursor. |
13 Pickle ok_custom_pickle; | 13 Pickle ok_custom_pickle; |
14 // Type and hotspots. | 14 // Type and hotspots. |
15 ok_custom_pickle.WriteInt(0); | 15 ok_custom_pickle.WriteInt(0); |
16 ok_custom_pickle.WriteInt(0); | 16 ok_custom_pickle.WriteInt(0); |
17 ok_custom_pickle.WriteInt(0); | 17 ok_custom_pickle.WriteInt(0); |
18 // X & Y | 18 // X & Y |
19 ok_custom_pickle.WriteInt(1); | 19 ok_custom_pickle.WriteInt(1); |
20 ok_custom_pickle.WriteInt(1); | 20 ok_custom_pickle.WriteInt(1); |
21 // Data len including enough data for a 1x1 image. | 21 // Data len including enough data for a 1x1 image. |
22 ok_custom_pickle.WriteInt(4); | 22 ok_custom_pickle.WriteInt(4); |
23 ok_custom_pickle.WriteUInt32(0); | 23 ok_custom_pickle.WriteUInt32(0); |
24 // Custom Windows message. | 24 // Custom Windows message. |
25 ok_custom_pickle.WriteIntPtr(0); | 25 ok_custom_pickle.WriteIntPtr(NULL); |
26 void* iter = NULL; | 26 void* iter = NULL; |
27 EXPECT_TRUE(custom_cursor.Deserialize(&ok_custom_pickle, &iter)); | 27 EXPECT_TRUE(custom_cursor.Deserialize(&ok_custom_pickle, &iter)); |
28 | 28 |
29 // This custom cursor has not been send with enough data. | 29 // This custom cursor has not been send with enough data. |
30 Pickle short_custom_pickle; | 30 Pickle short_custom_pickle; |
31 // Type and hotspots. | 31 // Type and hotspots. |
32 short_custom_pickle.WriteInt(0); | 32 short_custom_pickle.WriteInt(0); |
33 short_custom_pickle.WriteInt(0); | 33 short_custom_pickle.WriteInt(0); |
34 short_custom_pickle.WriteInt(0); | 34 short_custom_pickle.WriteInt(0); |
35 // X & Y | 35 // X & Y |
36 short_custom_pickle.WriteInt(1); | 36 short_custom_pickle.WriteInt(1); |
37 short_custom_pickle.WriteInt(1); | 37 short_custom_pickle.WriteInt(1); |
38 // Data len not including enough data for a 1x1 image. | 38 // Data len not including enough data for a 1x1 image. |
39 short_custom_pickle.WriteInt(3); | 39 short_custom_pickle.WriteInt(3); |
40 short_custom_pickle.WriteUInt32(0); | 40 short_custom_pickle.WriteUInt32(0); |
41 // Custom Windows message. | 41 // Custom Windows message. |
42 ok_custom_pickle.WriteIntPtr(0); | 42 ok_custom_pickle.WriteIntPtr(NULL); |
43 iter = NULL; | 43 iter = NULL; |
44 EXPECT_FALSE(custom_cursor.Deserialize(&short_custom_pickle, &iter)); | 44 EXPECT_FALSE(custom_cursor.Deserialize(&short_custom_pickle, &iter)); |
45 | 45 |
46 // This custom cursor has enough data but is too big. | 46 // This custom cursor has enough data but is too big. |
47 Pickle large_custom_pickle; | 47 Pickle large_custom_pickle; |
48 // Type and hotspots. | 48 // Type and hotspots. |
49 large_custom_pickle.WriteInt(0); | 49 large_custom_pickle.WriteInt(0); |
50 large_custom_pickle.WriteInt(0); | 50 large_custom_pickle.WriteInt(0); |
51 large_custom_pickle.WriteInt(0); | 51 large_custom_pickle.WriteInt(0); |
52 // X & Y | 52 // X & Y |
53 static const int kTooBigSize = 4096 + 1; | 53 static const int kTooBigSize = 4096 + 1; |
54 large_custom_pickle.WriteInt(kTooBigSize); | 54 large_custom_pickle.WriteInt(kTooBigSize); |
55 large_custom_pickle.WriteInt(1); | 55 large_custom_pickle.WriteInt(1); |
56 // Data len including enough data for a 4097x1 image. | 56 // Data len including enough data for a 4097x1 image. |
57 large_custom_pickle.WriteInt(kTooBigSize * 4); | 57 large_custom_pickle.WriteInt(kTooBigSize * 4); |
58 for (int i = 0; i < kTooBigSize; ++i) | 58 for (int i = 0; i < kTooBigSize; ++i) |
59 large_custom_pickle.WriteUInt32(0); | 59 large_custom_pickle.WriteUInt32(0); |
60 // Custom Windows message. | 60 // Custom Windows message. |
61 ok_custom_pickle.WriteIntPtr(0); | 61 ok_custom_pickle.WriteIntPtr(NULL); |
62 iter = NULL; | 62 iter = NULL; |
63 EXPECT_FALSE(custom_cursor.Deserialize(&large_custom_pickle, &iter)); | 63 EXPECT_FALSE(custom_cursor.Deserialize(&large_custom_pickle, &iter)); |
64 | 64 |
65 // This custom cursor uses negative lengths. | 65 // This custom cursor uses negative lengths. |
66 Pickle neg_custom_pickle; | 66 Pickle neg_custom_pickle; |
67 // Type and hotspots. | 67 // Type and hotspots. |
68 neg_custom_pickle.WriteInt(0); | 68 neg_custom_pickle.WriteInt(0); |
69 neg_custom_pickle.WriteInt(0); | 69 neg_custom_pickle.WriteInt(0); |
70 neg_custom_pickle.WriteInt(0); | 70 neg_custom_pickle.WriteInt(0); |
71 // X & Y | 71 // X & Y |
72 neg_custom_pickle.WriteInt(-1); | 72 neg_custom_pickle.WriteInt(-1); |
73 neg_custom_pickle.WriteInt(-1); | 73 neg_custom_pickle.WriteInt(-1); |
74 // Data len including enough data for a 1x1 image. | 74 // Data len including enough data for a 1x1 image. |
75 neg_custom_pickle.WriteInt(4); | 75 neg_custom_pickle.WriteInt(4); |
76 neg_custom_pickle.WriteUInt32(0); | 76 neg_custom_pickle.WriteUInt32(0); |
77 // Custom Windows message. | 77 // Custom Windows message. |
78 neg_custom_pickle.WriteIntPtr(0); | 78 neg_custom_pickle.WriteIntPtr(NULL); |
79 iter = NULL; | 79 iter = NULL; |
80 EXPECT_FALSE(custom_cursor.Deserialize(&neg_custom_pickle, &iter)); | 80 EXPECT_FALSE(custom_cursor.Deserialize(&neg_custom_pickle, &iter)); |
81 } | 81 } |
82 | 82 |
OLD | NEW |