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
diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp
index 8445032..69718a6 100644
--- a/libs/input/tests/Android.bp
+++ b/libs/input/tests/Android.bp
@@ -43,12 +43,15 @@
     },
     shared_libs: [
         "libandroid_runtime",
+        "libbase",
+        "libinput",
         "libinputservice",
         "libhwui",
         "libgui",
         "libutils",
     ],
     static_libs: [
+        "libflagtest",
         "libgmock",
         "libgtest",
     ],
diff --git a/libs/input/tests/PointerController_test.cpp b/libs/input/tests/PointerController_test.cpp
index d9efd3c..adfa91e 100644
--- a/libs/input/tests/PointerController_test.cpp
+++ b/libs/input/tests/PointerController_test.cpp
@@ -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 @@
     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 @@
     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);