From f295d7aeabcd39c4b0b7a7a3ed7222f31ad9e3d0 Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Sat, 13 Nov 2021 02:22:34 +0000 Subject: [PATCH] [RemoteInputView] Fix the RemoteInputViewTest Bug: 193539698 Test: atest RemoteInputViewTest Change-Id: I264a9f18c0071e34b876a8e807350b71ad82e675 --- .../statusbar/policy/RemoteInputViewTest.java | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java index 27ddb362f030d..ba7bbfe11bdca 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java @@ -46,6 +46,7 @@ import android.view.inputmethod.InputConnection; import android.widget.EditText; import android.widget.ImageButton; +import androidx.annotation.NonNull; import androidx.test.filters.SmallTest; import com.android.internal.logging.UiEventLogger; @@ -55,6 +56,7 @@ import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.statusbar.NotificationRemoteInputManager; import com.android.systemui.statusbar.RemoteInputController; +import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.notification.row.NotificationTestHelper; import com.android.systemui.statusbar.phone.LightBarController; @@ -85,7 +87,6 @@ public class RemoteInputViewTest extends SysuiTestCase { @Mock private LightBarController mLightBarController; private BlockingQueueIntentReceiver mReceiver; private final UiEventLoggerFake mUiEventLoggerFake = new UiEventLoggerFake(); - private RemoteInputView mView; @Before public void setUp() throws Exception { @@ -112,13 +113,17 @@ public class RemoteInputViewTest extends SysuiTestCase { mContext.unregisterReceiver(mReceiver); } - private void setTestPendingIntent(RemoteInputView view) { + private void setTestPendingIntent(RemoteInputView view, RemoteInputViewController controller) { PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(TEST_ACTION), PendingIntent.FLAG_MUTABLE); RemoteInput input = new RemoteInput.Builder(TEST_RESULT_KEY).build(); + RemoteInput[] inputs = {input}; view.setPendingIntent(pendingIntent); - view.setRemoteInput(new RemoteInput[]{input}, input, null /* editedSuggestionInfo */); + controller.setPendingIntent(pendingIntent); + view.setRemoteInput(inputs, input, null /* editedSuggestionInfo */); + controller.setRemoteInput(input); + controller.setRemoteInputs(inputs); } @Test @@ -129,8 +134,9 @@ public class RemoteInputViewTest extends SysuiTestCase { TestableLooper.get(this)); ExpandableNotificationRow row = helper.createRow(); RemoteInputView view = RemoteInputView.inflate(mContext, null, row.getEntry(), mController); + RemoteInputViewController controller = bindController(view, row.getEntry()); - setTestPendingIntent(view); + setTestPendingIntent(view, controller); view.focus(); @@ -140,6 +146,7 @@ public class RemoteInputViewTest extends SysuiTestCase { sendButton.performClick(); Intent resultIntent = mReceiver.waitForIntent(); + assertNotNull(resultIntent); assertEquals(TEST_REPLY, RemoteInput.getResultsFromIntent(resultIntent).get(TEST_RESULT_KEY)); assertEquals(RemoteInput.SOURCE_FREE_FORM_INPUT, @@ -167,8 +174,9 @@ public class RemoteInputViewTest extends SysuiTestCase { UserHandle.getUid(fromUser.getIdentifier(), DUMMY_MESSAGE_APP_ID), toUser); RemoteInputView view = RemoteInputView.inflate(mContext, null, row.getEntry(), mController); + RemoteInputViewController controller = bindController(view, row.getEntry()); - setTestPendingIntent(view); + setTestPendingIntent(view, controller); view.focus(); @@ -224,8 +232,9 @@ public class RemoteInputViewTest extends SysuiTestCase { TestableLooper.get(this)); ExpandableNotificationRow row = helper.createRow(); RemoteInputView view = RemoteInputView.inflate(mContext, null, row.getEntry(), mController); + RemoteInputViewController controller = bindController(view, row.getEntry()); - setTestPendingIntent(view); + setTestPendingIntent(view, controller); // Open view, send a reply view.focus(); @@ -253,8 +262,9 @@ public class RemoteInputViewTest extends SysuiTestCase { TestableLooper.get(this)); ExpandableNotificationRow row = helper.createRow(); RemoteInputView view = RemoteInputView.inflate(mContext, null, row.getEntry(), mController); + RemoteInputViewController controller = bindController(view, row.getEntry()); - setTestPendingIntent(view); + setTestPendingIntent(view, controller); // Open view, attach an image view.focus(); @@ -279,4 +289,21 @@ public class RemoteInputViewTest extends SysuiTestCase { .NOTIFICATION_REMOTE_INPUT_ATTACH_IMAGE.getId(), mUiEventLoggerFake.eventId(1)); } + + // NOTE: because we're refactoring the RemoteInputView and moving logic into the + // RemoteInputViewController, it's easiest to just test the system of the two classes together. + @NonNull + private RemoteInputViewController bindController( + RemoteInputView view, + NotificationEntry entry) { + RemoteInputViewControllerImpl viewController = new RemoteInputViewControllerImpl( + view, + entry, + mRemoteInputQuickSettingsDisabler, + mController, + mShortcutManager, + mUiEventLoggerFake); + viewController.bind(); + return viewController; + } }