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

Side by Side Diff: webkit/glue/webcursor_unittest.cc

Issue 9447084: Refactor Pickle Read methods to use higher performance PickleIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile (racing with incoming CLs) Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webcursor_mac.mm ('k') | webkit/glue/webcursor_win.cc » ('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) 2011 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 "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 7 #include "third_party/WebKit/Source/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, OKCursorSerialization) { 13 TEST(WebCursorTest, OKCursorSerialization) {
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(WebCursorInfo::TypeCustom); 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 PickleIterator iter(ok_custom_pickle);
30 EXPECT_TRUE(custom_cursor.Deserialize(&ok_custom_pickle, &iter)); 30 EXPECT_TRUE(custom_cursor.Deserialize(&iter));
31 31
32 #if defined(TOOLKIT_USES_GTK) 32 #if defined(TOOLKIT_USES_GTK)
33 // On GTK+ using platforms, we should get a real native GdkCursor object back 33 // On GTK+ using platforms, we should get a real native GdkCursor object back
34 // (and the memory used should automatically be freed by the WebCursor object 34 // (and the memory used should automatically be freed by the WebCursor object
35 // for valgrind tests). 35 // for valgrind tests).
36 EXPECT_TRUE(custom_cursor.GetCustomCursor()); 36 EXPECT_TRUE(custom_cursor.GetCustomCursor());
37 #endif 37 #endif
38 } 38 }
39 39
40 TEST(WebCursorTest, BrokenCursorSerialization) { 40 TEST(WebCursorTest, BrokenCursorSerialization) {
41 WebCursor custom_cursor; 41 WebCursor custom_cursor;
42 // This custom cursor has not been send with enough data. 42 // This custom cursor has not been send with enough data.
43 Pickle short_custom_pickle; 43 Pickle short_custom_pickle;
44 // Type and hotspots. 44 // Type and hotspots.
45 short_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 45 short_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
46 short_custom_pickle.WriteInt(0); 46 short_custom_pickle.WriteInt(0);
47 short_custom_pickle.WriteInt(0); 47 short_custom_pickle.WriteInt(0);
48 // X & Y 48 // X & Y
49 short_custom_pickle.WriteInt(1); 49 short_custom_pickle.WriteInt(1);
50 short_custom_pickle.WriteInt(1); 50 short_custom_pickle.WriteInt(1);
51 // Data len not including enough data for a 1x1 image. 51 // Data len not including enough data for a 1x1 image.
52 short_custom_pickle.WriteInt(3); 52 short_custom_pickle.WriteInt(3);
53 short_custom_pickle.WriteUInt32(0); 53 short_custom_pickle.WriteUInt32(0);
54 void* iter = NULL; 54 PickleIterator iter(short_custom_pickle);
55 EXPECT_FALSE(custom_cursor.Deserialize(&short_custom_pickle, &iter)); 55 EXPECT_FALSE(custom_cursor.Deserialize(&iter));
56 56
57 // This custom cursor has enough data but is too big. 57 // This custom cursor has enough data but is too big.
58 Pickle large_custom_pickle; 58 Pickle large_custom_pickle;
59 // Type and hotspots. 59 // Type and hotspots.
60 large_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 60 large_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
61 large_custom_pickle.WriteInt(0); 61 large_custom_pickle.WriteInt(0);
62 large_custom_pickle.WriteInt(0); 62 large_custom_pickle.WriteInt(0);
63 // X & Y 63 // X & Y
64 static const int kTooBigSize = 4096 + 1; 64 static const int kTooBigSize = 4096 + 1;
65 large_custom_pickle.WriteInt(kTooBigSize); 65 large_custom_pickle.WriteInt(kTooBigSize);
66 large_custom_pickle.WriteInt(1); 66 large_custom_pickle.WriteInt(1);
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 = NULL; 71 iter = PickleIterator(large_custom_pickle);
72 EXPECT_FALSE(custom_cursor.Deserialize(&large_custom_pickle, &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 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 // Data len including enough data for a 1x1 image. 83 // Data len including enough data for a 1x1 image.
84 neg_custom_pickle.WriteInt(4); 84 neg_custom_pickle.WriteInt(4);
85 neg_custom_pickle.WriteUInt32(0); 85 neg_custom_pickle.WriteUInt32(0);
86 // Custom Windows message. 86 // Custom Windows message.
87 neg_custom_pickle.WriteUInt32(0); 87 neg_custom_pickle.WriteUInt32(0);
88 iter = NULL; 88 iter = PickleIterator(neg_custom_pickle);
89 EXPECT_FALSE(custom_cursor.Deserialize(&neg_custom_pickle, &iter)); 89 EXPECT_FALSE(custom_cursor.Deserialize(&iter));
90 } 90 }
91 91
92 #if defined(OS_WIN) 92 #if defined(OS_WIN)
93 TEST(WebCursorTest, WindowsCursorConversion) { 93 TEST(WebCursorTest, WindowsCursorConversion) {
94 WebCursor custom_cursor; 94 WebCursor custom_cursor;
95 Pickle win32_custom_pickle; 95 Pickle win32_custom_pickle;
96 WebCursor win32_custom_cursor; 96 WebCursor win32_custom_cursor;
97 win32_custom_cursor.InitFromExternalCursor( 97 win32_custom_cursor.InitFromExternalCursor(
98 reinterpret_cast<HCURSOR>(1000)); 98 reinterpret_cast<HCURSOR>(1000));
99 EXPECT_TRUE(win32_custom_cursor.Serialize(&win32_custom_pickle)); 99 EXPECT_TRUE(win32_custom_cursor.Serialize(&win32_custom_pickle));
100 void* iter = NULL; 100 PickleIterator iter(win32_custom_pickle);
101 EXPECT_TRUE(custom_cursor.Deserialize(&win32_custom_pickle, &iter)); 101 EXPECT_TRUE(custom_cursor.Deserialize(&iter));
102 EXPECT_EQ(reinterpret_cast<HCURSOR>(1000), custom_cursor.GetCursor(NULL)); 102 EXPECT_EQ(reinterpret_cast<HCURSOR>(1000), custom_cursor.GetCursor(NULL));
103 } 103 }
104 #endif // OS_WIN 104 #endif // OS_WIN
105 105
106 TEST(WebCursorTest, ClampHotspot) { 106 TEST(WebCursorTest, ClampHotspot) {
107 WebCursor custom_cursor; 107 WebCursor custom_cursor;
108 // This is a valid custom cursor. 108 // This is a valid custom cursor.
109 Pickle ok_custom_pickle; 109 Pickle ok_custom_pickle;
110 // Type and hotspots. 110 // Type and hotspots.
111 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 111 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
112 // Hotspot is invalid --- outside the bounds of the image. 112 // Hotspot is invalid --- outside the bounds of the image.
113 ok_custom_pickle.WriteInt(5); 113 ok_custom_pickle.WriteInt(5);
114 ok_custom_pickle.WriteInt(5); 114 ok_custom_pickle.WriteInt(5);
115 // X & Y 115 // X & Y
116 ok_custom_pickle.WriteInt(2); 116 ok_custom_pickle.WriteInt(2);
117 ok_custom_pickle.WriteInt(2); 117 ok_custom_pickle.WriteInt(2);
118 // Data len including enough data for a 2x2 image. 118 // Data len including enough data for a 2x2 image.
119 ok_custom_pickle.WriteInt(4 * 4); 119 ok_custom_pickle.WriteInt(4 * 4);
120 for (size_t i = 0; i < 4; i++) 120 for (size_t i = 0; i < 4; i++)
121 ok_custom_pickle.WriteUInt32(0); 121 ok_custom_pickle.WriteUInt32(0);
122 // Custom Windows message. 122 // Custom Windows message.
123 ok_custom_pickle.WriteUInt32(0); 123 ok_custom_pickle.WriteUInt32(0);
124 void* iter = NULL; 124 PickleIterator iter(ok_custom_pickle);
125 ASSERT_TRUE(custom_cursor.Deserialize(&ok_custom_pickle, &iter)); 125 ASSERT_TRUE(custom_cursor.Deserialize(&iter));
126 126
127 // Convert to WebCursorInfo, make sure the hotspot got clamped. 127 // Convert to WebCursorInfo, make sure the hotspot got clamped.
128 WebCursorInfo info; 128 WebCursorInfo info;
129 custom_cursor.GetCursorInfo(&info); 129 custom_cursor.GetCursorInfo(&info);
130 EXPECT_EQ(gfx::Point(1, 1), gfx::Point(info.hotSpot)); 130 EXPECT_EQ(gfx::Point(1, 1), gfx::Point(info.hotSpot));
131 131
132 // Set hotspot to an invalid point again, pipe back through WebCursor, 132 // Set hotspot to an invalid point again, pipe back through WebCursor,
133 // and make sure the hotspot got clamped again. 133 // and make sure the hotspot got clamped again.
134 info.hotSpot = gfx::Point(-1, -1); 134 info.hotSpot = gfx::Point(-1, -1);
135 custom_cursor.InitFromCursorInfo(info); 135 custom_cursor.InitFromCursorInfo(info);
(...skipping 11 matching lines...) Expand all
147 // X & Y are empty 147 // X & Y are empty
148 broken_cursor_pickle.WriteInt(0); 148 broken_cursor_pickle.WriteInt(0);
149 broken_cursor_pickle.WriteInt(0); 149 broken_cursor_pickle.WriteInt(0);
150 // No data for the image since the size is 0. 150 // No data for the image since the size is 0.
151 broken_cursor_pickle.WriteInt(0); 151 broken_cursor_pickle.WriteInt(0);
152 // Custom Windows message. 152 // Custom Windows message.
153 broken_cursor_pickle.WriteInt(0); 153 broken_cursor_pickle.WriteInt(0);
154 154
155 // Make sure we can read this on all platforms; it is technicaally a valid 155 // Make sure we can read this on all platforms; it is technicaally a valid
156 // cursor. 156 // cursor.
157 void* iter = NULL; 157 PickleIterator iter(broken_cursor_pickle);
158 ASSERT_TRUE(custom_cursor.Deserialize(&broken_cursor_pickle, &iter)); 158 ASSERT_TRUE(custom_cursor.Deserialize(&iter));
159 159
160 #if defined(TOOLKIT_USES_GTK) 160 #if defined(TOOLKIT_USES_GTK)
161 // On GTK+ using platforms, we make sure that we get NULL back from this 161 // On GTK+ using platforms, we make sure that we get NULL back from this
162 // method; the relevant GDK methods take NULL as a request to use the default 162 // method; the relevant GDK methods take NULL as a request to use the default
163 // cursor. 163 // cursor.
164 EXPECT_EQ(NULL, custom_cursor.GetCustomCursor()); 164 EXPECT_EQ(NULL, custom_cursor.GetCustomCursor());
165 #endif 165 #endif
166 } 166 }
OLDNEW
« no previous file with comments | « webkit/glue/webcursor_mac.mm ('k') | webkit/glue/webcursor_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698