Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c7aa6f2 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Pointer Icon Refactor: Update PointerController tests

When PointerChoreographer is enabled, the PointerControllers are used in
a different way, where the presentation mode is set once and never
changed. This should be reflected in the tests.

When the flag is enabled, ensure that the tests call the APIs in the
expected manner.

Bug: 293587049
Bug: 315538661
Test: atest libinputservice_test
Change-Id: I24205c4c02484c4a28946c152a2c507bfc371b8e
parent 7d1daa11
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -43,12 +43,15 @@ cc_test {
    },
    shared_libs: [
        "libandroid_runtime",
        "libbase",
        "libinput",
        "libinputservice",
        "libhwui",
        "libgui",
        "libutils",
    ],
    static_libs: [
        "libflagtest",
        "libgmock",
        "libgtest",
    ],
+36 −1
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 */

#include <com_android_input_flags.h>
#include <flag_macros.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <input/PointerController.h>
@@ -28,6 +30,8 @@

namespace android {

namespace input_flags = com::android::input::flags;

enum TestCursorType {
    CURSOR_TYPE_DEFAULT = 0,
    CURSOR_TYPE_HOVER,
@@ -261,7 +265,20 @@ TEST_F(PointerControllerTest, useStylusTypeForStylusHover) {
    mPointerController->reloadPointerResources();
}

TEST_F(PointerControllerTest, updatePointerIcon) {
TEST_F_WITH_FLAGS(PointerControllerTest, setPresentationBeforeDisplayViewportDoesNotLoadResources,
                  REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(input_flags, enable_pointer_choreographer))) {
    // Setting the presentation mode before a display viewport is set will not load any resources.
    mPointerController->setPresentation(PointerController::Presentation::POINTER);
    ASSERT_TRUE(mPolicy->noResourcesAreLoaded());

    // When the display is set, then the resources are loaded.
    ensureDisplayViewportIsSet();
    ASSERT_TRUE(mPolicy->allResourcesAreLoaded());
}

TEST_F_WITH_FLAGS(PointerControllerTest, updatePointerIcon,
                  REQUIRES_FLAGS_DISABLED(ACONFIG_FLAG(input_flags,
                                                       enable_pointer_choreographer))) {
    ensureDisplayViewportIsSet();
    mPointerController->setPresentation(PointerController::Presentation::POINTER);
    mPointerController->unfade(PointerController::Transition::IMMEDIATE);
@@ -277,6 +294,24 @@ TEST_F(PointerControllerTest, updatePointerIcon) {
    mPointerController->updatePointerIcon(static_cast<PointerIconStyle>(type));
}

TEST_F_WITH_FLAGS(PointerControllerTest, updatePointerIconWithChoreographer,
                  REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(input_flags, enable_pointer_choreographer))) {
    // When PointerChoreographer is enabled, the presentation mode is set before the viewport.
    mPointerController->setPresentation(PointerController::Presentation::POINTER);
    ensureDisplayViewportIsSet();
    mPointerController->unfade(PointerController::Transition::IMMEDIATE);

    int32_t type = CURSOR_TYPE_ADDITIONAL;
    std::pair<float, float> hotspot = getHotSpotCoordinatesForType(type);
    EXPECT_CALL(*mPointerSprite, setVisible(true));
    EXPECT_CALL(*mPointerSprite, setAlpha(1.0f));
    EXPECT_CALL(*mPointerSprite,
                setIcon(AllOf(Field(&SpriteIcon::style, static_cast<PointerIconStyle>(type)),
                              Field(&SpriteIcon::hotSpotX, hotspot.first),
                              Field(&SpriteIcon::hotSpotY, hotspot.second))));
    mPointerController->updatePointerIcon(static_cast<PointerIconStyle>(type));
}

TEST_F(PointerControllerTest, setCustomPointerIcon) {
    ensureDisplayViewportIsSet();
    mPointerController->unfade(PointerController::Transition::IMMEDIATE);