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

Commit 3551f68e authored by Joshua Mokut's avatar Joshua Mokut Committed by Josh
Browse files

Fixed Failing tests for pinInputFieldStyledFocusState Flag advance

When attempting to turn on pinInputFieldStyledFocusState Flag
ag/26151700 Test failures occured due to
1. the usage of JavaAdapter.collectFlow
   which under the hood calls view.repeatWhenAttached which should only be called
   from main thread but our tests were not calling this from mainthread.
2. Attempting to write a value to a null object gotten from acessing a
   mocked object's field(passwordTextView.layoutParams)

Fixes: 316106516
Test: NA
Flag: NA
Change-Id: I078020dd7753e0f5c275c4a7572e5f5109847ad7
parent d0d2eb59
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.keyguard

import android.testing.TestableLooper
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.ImageView
@@ -51,10 +52,14 @@ import org.mockito.MockitoAnnotations

@SmallTest
@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper
// collectFlow in KeyguardPinBasedInputViewController.onViewAttached calls JavaAdapter.CollectFlow,
// which calls View.onRepeatWhenAttached, which requires being run on main thread.
@TestableLooper.RunWithLooper(setAsMainLooper = true)
class KeyguardPasswordViewControllerTest : SysuiTestCase() {
    @Mock private lateinit var keyguardPasswordView: KeyguardPasswordView
    @Mock private lateinit var passwordEntry: EditText
    private var passwordEntryLayoutParams =
        ViewGroup.LayoutParams(/* width = */ 0, /* height = */ 0)
    @Mock lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
    @Mock lateinit var securityMode: KeyguardSecurityModel.SecurityMode
    @Mock lateinit var lockPatternUtils: LockPatternUtils
@@ -92,7 +97,7 @@ class KeyguardPasswordViewControllerTest : SysuiTestCase() {
        whenever(keyguardPasswordView.findViewById<ImageView>(R.id.switch_ime_button))
            .thenReturn(mock(ImageView::class.java))
        `when`(keyguardPasswordView.resources).thenReturn(context.resources)

        whenever(passwordEntry.layoutParams).thenReturn(passwordEntryLayoutParams)
        val keyguardKeyboardInteractor = KeyguardKeyboardInteractor(FakeKeyboardRepository())
        val fakeFeatureFlags = FakeFeatureFlags()
        fakeFeatureFlags.set(Flags.LOCKSCREEN_ENABLE_LANDSCAPE, false)
+7 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.when;

import android.testing.TestableLooper.RunWithLooper;
import android.view.View;
import android.view.ViewGroup;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
@@ -48,13 +49,17 @@ import org.mockito.MockitoAnnotations;

@SmallTest
@RunWith(AndroidJUnit4.class)
@RunWithLooper
// collectFlow in KeyguardPinBasedInputViewController.onViewAttached calls JavaAdapter.CollectFlow,
// which calls View.onRepeatWhenAttached, which requires being run on main thread.
@RunWithLooper(setAsMainLooper = true)
public class KeyguardPinBasedInputViewControllerTest extends SysuiTestCase {

    @Mock
    private KeyguardPinBasedInputView mPinBasedInputView;
    @Mock
    private PasswordTextView mPasswordEntry;
    private final ViewGroup.LayoutParams mPasswordEntryLayoutParams =
            new ViewGroup.LayoutParams(/* width= */ 0, /* height= */ 0);
    @Mock
    private BouncerKeyguardMessageArea mKeyguardMessageArea;
    @Mock
@@ -103,6 +108,7 @@ public class KeyguardPinBasedInputViewControllerTest extends SysuiTestCase {
                .thenReturn(mOkButton);

        when(mPinBasedInputView.getResources()).thenReturn(getContext().getResources());
        when(mPasswordEntry.getLayoutParams()).thenReturn(mPasswordEntryLayoutParams);
        KeyguardKeyboardInteractor keyguardKeyboardInteractor =
                new KeyguardKeyboardInteractor(new FakeKeyboardRepository());
        FakeFeatureFlags featureFlags = new FakeFeatureFlags();
+9 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.keyguard

import android.testing.TestableLooper
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -59,7 +60,9 @@ import org.mockito.MockitoAnnotations

@SmallTest
@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper
// collectFlow in KeyguardPinBasedInputViewController.onViewAttached calls JavaAdapter.CollectFlow,
// which calls View.onRepeatWhenAttached, which requires being run on main thread.
@TestableLooper.RunWithLooper(setAsMainLooper = true)
class KeyguardPinViewControllerTest : SysuiTestCase() {

    private lateinit var objectKeyguardPINView: KeyguardPINView
@@ -90,6 +93,8 @@ class KeyguardPinViewControllerTest : SysuiTestCase() {
    @Mock private val mEmergencyButtonController: EmergencyButtonController? = null
    private val falsingCollector: FalsingCollector = FalsingCollectorFake()
    private val keyguardKeyboardInteractor = KeyguardKeyboardInteractor(FakeKeyboardRepository())
    private val passwordTextViewLayoutParams =
        ViewGroup.LayoutParams(/* width= */ 0, /* height= */ 0)
    @Mock lateinit var postureController: DevicePostureController
    @Mock lateinit var mSelectedUserInteractor: SelectedUserInteractor

@@ -104,11 +109,9 @@ class KeyguardPinViewControllerTest : SysuiTestCase() {
    @Before
    fun setup() {
        MockitoAnnotations.initMocks(this)
        Mockito.`when`(mockKeyguardPinView.requireViewById<View>(R.id.bouncer_message_area))
        `when`(mockKeyguardPinView.requireViewById<View>(R.id.bouncer_message_area))
            .thenReturn(keyguardMessageArea)
        Mockito.`when`(
                keyguardMessageAreaControllerFactory.create(any(KeyguardMessageArea::class.java))
            )
        `when`(keyguardMessageAreaControllerFactory.create(any(KeyguardMessageArea::class.java)))
            .thenReturn(keyguardMessageAreaController)
        `when`(mockKeyguardPinView.passwordTextViewId).thenReturn(R.id.pinEntry)
        `when`(mockKeyguardPinView.findViewById<PasswordTextView>(R.id.pinEntry))
@@ -121,6 +124,7 @@ class KeyguardPinViewControllerTest : SysuiTestCase() {
        `when`(mockKeyguardPinView.buttons).thenReturn(arrayOf())
        `when`(lockPatternUtils.getPinLength(anyInt())).thenReturn(6)
        `when`(featureFlags.isEnabled(Flags.LOCKSCREEN_ENABLE_LANDSCAPE)).thenReturn(false)
        `when`(passwordTextView.layoutParams).thenReturn(passwordTextViewLayoutParams)

        objectKeyguardPINView =
            View.inflate(mContext, R.layout.keyguard_pin_view, null)
+3 −1
Original line number Diff line number Diff line
@@ -49,7 +49,9 @@ import org.mockito.MockitoAnnotations

@SmallTest
@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper
// collectFlow in KeyguardPinBasedInputViewController.onViewAttached calls JavaAdapter.CollectFlow,
// which calls View.onRepeatWhenAttached, which requires being run on main thread.
@TestableLooper.RunWithLooper(setAsMainLooper = true)
class KeyguardSimPinViewControllerTest : SysuiTestCase() {
    private lateinit var simPinView: KeyguardSimPinView
    private lateinit var underTest: KeyguardSimPinViewController
+3 −1
Original line number Diff line number Diff line
@@ -43,7 +43,9 @@ import org.mockito.MockitoAnnotations

@SmallTest
@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper
// collectFlow in KeyguardPinBasedInputViewController.onViewAttached calls JavaAdapter.CollectFlow,
// which calls View.onRepeatWhenAttached, which requires being run on main thread.
@TestableLooper.RunWithLooper(setAsMainLooper = true)
class KeyguardSimPukViewControllerTest : SysuiTestCase() {
    private lateinit var simPukView: KeyguardSimPukView
    private lateinit var underTest: KeyguardSimPukViewController