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
3 // found in the LICENSE file.
5 #include "ppapi/tests/test_mouse_cursor.h"
7 #include "ppapi/cpp/image_data.h"
8 #include "ppapi/tests/test_case.h"
9 #include "ppapi/tests/testing_instance.h"
11 REGISTER_TEST_CASE(MouseCursor
);
13 TestMouseCursor::TestMouseCursor(TestingInstance
* instance
)
14 : TestCase(instance
) {
17 bool TestMouseCursor::Init() {
18 mouse_cursor_interface_
= static_cast<const PPB_MouseCursor
*>(
19 pp::Module::Get()->GetBrowserInterface(PPB_MOUSECURSOR_INTERFACE
));
20 return !!mouse_cursor_interface_
;
23 void TestMouseCursor::RunTests(const std::string
& filter
) {
24 RUN_TEST(Type
, filter
);
25 RUN_TEST(Custom
, filter
);
26 RUN_TEST(Point
, filter
);
29 std::string
TestMouseCursor::TestType() {
30 ASSERT_TRUE(PP_ToBool(mouse_cursor_interface_
->SetCursor(
31 instance_
->pp_instance(), PP_MOUSECURSOR_TYPE_POINTER
, 0, NULL
)));
32 ASSERT_FALSE(PP_ToBool(mouse_cursor_interface_
->SetCursor(
33 instance_
->pp_instance(), static_cast<PP_MouseCursor_Type
>(-2),
38 std::string
TestMouseCursor::TestCustom() {
39 // First test a valid image.
40 pp::ImageData
valid_image(instance_
,
41 pp::ImageData::GetNativeImageDataFormat(),
42 pp::Size(16, 16), true);
43 PP_Point point
= { 0, 0 };
44 ASSERT_TRUE(PP_ToBool(mouse_cursor_interface_
->SetCursor(
45 instance_
->pp_instance(), PP_MOUSECURSOR_TYPE_CUSTOM
,
46 valid_image
.pp_resource(), &point
)));
48 // 0 image resource ID.
49 ASSERT_FALSE(PP_ToBool(mouse_cursor_interface_
->SetCursor(
50 instance_
->pp_instance(), PP_MOUSECURSOR_TYPE_CUSTOM
, 0, NULL
)));
52 // Image specified for predefined type.
53 ASSERT_FALSE(PP_ToBool(mouse_cursor_interface_
->SetCursor(
54 instance_
->pp_instance(), PP_MOUSECURSOR_TYPE_POINTER
,
55 valid_image
.pp_resource(), &point
)));
58 pp::ImageData
big_image(instance_
, pp::ImageData::GetNativeImageDataFormat(),
59 pp::Size(65, 12), true);
60 ASSERT_FALSE(PP_ToBool(mouse_cursor_interface_
->SetCursor(
61 instance_
->pp_instance(), PP_MOUSECURSOR_TYPE_CUSTOM
,
62 big_image
.pp_resource(), &point
)));
67 std::string
TestMouseCursor::TestPoint() {
68 pp::ImageData
valid_image(instance_
,
69 pp::ImageData::GetNativeImageDataFormat(),
70 pp::Size(16, 16), true);
71 PP_Point point
= { -1, 0 };
72 ASSERT_FALSE(PP_ToBool(mouse_cursor_interface_
->SetCursor(
73 instance_
->pp_instance(), PP_MOUSECURSOR_TYPE_CUSTOM
,
74 valid_image
.pp_resource(), &point
)));
78 ASSERT_FALSE(PP_ToBool(mouse_cursor_interface_
->SetCursor(
79 instance_
->pp_instance(), PP_MOUSECURSOR_TYPE_CUSTOM
,
80 valid_image
.pp_resource(), &point
)));