Home | History | Annotate | Download | only in tests
      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.
      4 
      5 #include "ppapi/tests/test_mouse_cursor.h"
      6 
      7 #include "ppapi/cpp/image_data.h"
      8 #include "ppapi/tests/test_case.h"
      9 #include "ppapi/tests/testing_instance.h"
     10 
     11 REGISTER_TEST_CASE(MouseCursor);
     12 
     13 TestMouseCursor::TestMouseCursor(TestingInstance* instance)
     14     : TestCase(instance) {
     15 }
     16 
     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_;
     21 }
     22 
     23 void TestMouseCursor::RunTests(const std::string& filter) {
     24   RUN_TEST(Type, filter);
     25   RUN_TEST(Custom, filter);
     26   RUN_TEST(Point, filter);
     27 }
     28 
     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),
     34       0, NULL)));
     35   PASS();
     36 }
     37 
     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)));
     47 
     48   // 0 image resource ID.
     49   ASSERT_FALSE(PP_ToBool(mouse_cursor_interface_->SetCursor(
     50       instance_->pp_instance(), PP_MOUSECURSOR_TYPE_CUSTOM, 0, NULL)));
     51 
     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)));
     56 
     57   // A too-big image.
     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)));
     63 
     64   PASS();
     65 }
     66 
     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)));
     75 
     76   point.x = 67;
     77   point.y = 5;
     78   ASSERT_FALSE(PP_ToBool(mouse_cursor_interface_->SetCursor(
     79       instance_->pp_instance(), PP_MOUSECURSOR_TYPE_CUSTOM,
     80       valid_image.pp_resource(), &point)));
     81   PASS();
     82 }
     83