This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
#include "base/pickle.h"
#include "content/common/cursors/webcursor.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebCursorInfo.h"
using blink::WebCursorInfo;
namespace content {
TEST(WebCursorTest, OKCursorSerialization) {
WebCursor custom_cursor;
Pickle ok_custom_pickle;
ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
ok_custom_pickle.WriteInt(0);
ok_custom_pickle.WriteInt(0);
ok_custom_pickle.WriteInt(1);
ok_custom_pickle.WriteInt(1);
ok_custom_pickle.WriteFloat(1.0);
ok_custom_pickle.WriteInt(4);
ok_custom_pickle.WriteUInt32(0);
ok_custom_pickle.WriteUInt32(0);
PickleIterator iter(ok_custom_pickle);
EXPECT_TRUE(custom_cursor.Deserialize(&iter));
#if defined(TOOLKIT_GTK)
EXPECT_TRUE(custom_cursor.GetCustomCursor());
#endif
}
TEST(WebCursorTest, BrokenCursorSerialization) {
WebCursor custom_cursor;
Pickle short_custom_pickle;
short_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
short_custom_pickle.WriteInt(0);
short_custom_pickle.WriteInt(0);
short_custom_pickle.WriteInt(1);
short_custom_pickle.WriteInt(1);
short_custom_pickle.WriteFloat(1.0);
short_custom_pickle.WriteInt(3);
short_custom_pickle.WriteUInt32(0);
PickleIterator iter(short_custom_pickle);
EXPECT_FALSE(custom_cursor.Deserialize(&iter));
Pickle large_custom_pickle;
large_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
large_custom_pickle.WriteInt(0);
large_custom_pickle.WriteInt(0);
static const int kTooBigSize = 4096 + 1;
large_custom_pickle.WriteInt(kTooBigSize);
large_custom_pickle.WriteInt(1);
large_custom_pickle.WriteFloat(1.0);
large_custom_pickle.WriteInt(kTooBigSize * 4);
for (int i = 0; i < kTooBigSize; ++i)
large_custom_pickle.WriteUInt32(0);
iter = PickleIterator(large_custom_pickle);
EXPECT_FALSE(custom_cursor.Deserialize(&iter));
Pickle neg_custom_pickle;
neg_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
neg_custom_pickle.WriteInt(0);
neg_custom_pickle.WriteInt(0);
neg_custom_pickle.WriteInt(-1);
neg_custom_pickle.WriteInt(-1);
neg_custom_pickle.WriteFloat(1.0);
neg_custom_pickle.WriteInt(4);
neg_custom_pickle.WriteUInt32(0);
neg_custom_pickle.WriteUInt32(0);
iter = PickleIterator(neg_custom_pickle);
EXPECT_FALSE(custom_cursor.Deserialize(&iter));
Pickle scale_zero_custom_pickle;
scale_zero_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
scale_zero_custom_pickle.WriteInt(0);
scale_zero_custom_pickle.WriteInt(0);
scale_zero_custom_pickle.WriteInt(1);
scale_zero_custom_pickle.WriteInt(1);
scale_zero_custom_pickle.WriteFloat(0);
scale_zero_custom_pickle.WriteInt(4);
scale_zero_custom_pickle.WriteUInt32(0);
scale_zero_custom_pickle.WriteUInt32(0);
iter = PickleIterator(scale_zero_custom_pickle);
EXPECT_FALSE(custom_cursor.Deserialize(&iter));
Pickle scale_tiny_custom_pickle;
scale_tiny_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
scale_tiny_custom_pickle.WriteInt(0);
scale_tiny_custom_pickle.WriteInt(0);
scale_tiny_custom_pickle.WriteInt(1);
scale_tiny_custom_pickle.WriteInt(1);
scale_tiny_custom_pickle.WriteFloat(0.001f);
scale_tiny_custom_pickle.WriteInt(4);
scale_tiny_custom_pickle.WriteUInt32(0);
scale_tiny_custom_pickle.WriteUInt32(0);
iter = PickleIterator(scale_tiny_custom_pickle);
EXPECT_FALSE(custom_cursor.Deserialize(&iter));
}
TEST(WebCursorTest, ClampHotspot) {
WebCursor custom_cursor;
Pickle ok_custom_pickle;
ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
ok_custom_pickle.WriteInt(5);
ok_custom_pickle.WriteInt(5);
ok_custom_pickle.WriteInt(2);
ok_custom_pickle.WriteInt(2);
ok_custom_pickle.WriteFloat(1.0);
ok_custom_pickle.WriteInt(4 * 4);
for (size_t i = 0; i < 4; i++)
ok_custom_pickle.WriteUInt32(0);
ok_custom_pickle.WriteUInt32(0);
PickleIterator iter(ok_custom_pickle);
ASSERT_TRUE(custom_cursor.Deserialize(&iter));
WebCursor::CursorInfo info;
custom_cursor.GetCursorInfo(&info);
EXPECT_EQ(gfx::Point(1, 1), info.hotspot);
info.hotspot = gfx::Point(-1, -1);
custom_cursor.InitFromCursorInfo(info);
custom_cursor.GetCursorInfo(&info);
EXPECT_EQ(gfx::Point(0, 0), info.hotspot);
}
TEST(WebCursorTest, EmptyImage) {
WebCursor custom_cursor;
Pickle broken_cursor_pickle;
broken_cursor_pickle.WriteInt(WebCursorInfo::TypeCustom);
broken_cursor_pickle.WriteInt(0);
broken_cursor_pickle.WriteInt(0);
broken_cursor_pickle.WriteInt(0);
broken_cursor_pickle.WriteInt(0);
broken_cursor_pickle.WriteFloat(1.0);
broken_cursor_pickle.WriteInt(0);
broken_cursor_pickle.WriteInt(0);
PickleIterator iter(broken_cursor_pickle);
ASSERT_TRUE(custom_cursor.Deserialize(&iter));
#if defined(TOOLKIT_GTK)
EXPECT_EQ(NULL, custom_cursor.GetCustomCursor());
#endif
}
TEST(WebCursorTest, Scale2) {
WebCursor custom_cursor;
Pickle ok_custom_pickle;
ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
ok_custom_pickle.WriteInt(0);
ok_custom_pickle.WriteInt(0);
ok_custom_pickle.WriteInt(1);
ok_custom_pickle.WriteInt(1);
ok_custom_pickle.WriteFloat(2.0);
ok_custom_pickle.WriteInt(4);
ok_custom_pickle.WriteUInt32(0);
ok_custom_pickle.WriteUInt32(0);
PickleIterator iter(ok_custom_pickle);
EXPECT_TRUE(custom_cursor.Deserialize(&iter));
#if defined(TOOLKIT_GTK)
EXPECT_TRUE(custom_cursor.GetCustomCursor());
#endif
}
}