diff options
author | Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com> | 2020-10-12 15:22:21 -0400 |
---|---|---|
committer | Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com> | 2020-10-12 15:22:21 -0400 |
commit | 626adac79f134ec2a3d1da3b16b865d69483ef98 (patch) | |
tree | f19a6101d38dade9ced0bf687a06c19d63d052e6 | |
parent | 715cb541c0034c7660fc152e418243c95ca96bce (diff) | |
download | sdl_android-626adac79f134ec2a3d1da3b16b865d69483ef98.tar.gz |
Add LockScreen UI tests
4 files changed, 268 insertions, 4 deletions
diff --git a/android/sdl_android/build.gradle b/android/sdl_android/build.gradle index f4652d968..21dcf840e 100644 --- a/android/sdl_android/build.gradle +++ b/android/sdl_android/build.gradle @@ -43,9 +43,7 @@ dependencies { api fileTree(dir: 'libs', include: ['*.jar']) api 'com.smartdevicelink:bson_java_port:RC1_1.2.2' api 'com.livio.taskmaster:taskmaster:0.3.0' - androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { - exclude group: 'com.android.support', module: 'support-annotations' - }) + androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:3.0.0' androidTestImplementation 'org.mockito:mockito-core:3.0.0' @@ -54,6 +52,9 @@ dependencies { api 'androidx.annotation:annotation:1.1.0' api 'androidx.lifecycle:lifecycle-extensions:2.2.0' annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.2.0' + debugImplementation("androidx.test:core:1.3.0") + debugImplementation("androidx.test:rules:1.3.0") + debugImplementation("androidx.test:runner:1.3.0") } buildscript { diff --git a/android/sdl_android/src/androidTest/AndroidManifest.xml b/android/sdl_android/src/androidTest/AndroidManifest.xml index 203bf840b..559fccf22 100644 --- a/android/sdl_android/src/androidTest/AndroidManifest.xml +++ b/android/sdl_android/src/androidTest/AndroidManifest.xml @@ -16,6 +16,7 @@ <application android:debuggable="true"> <uses-library android:name="android.test.runner" /> + <activity android:name=".managers.lockscreen.SDLLockScreenActivity"/> </application> </manifest> diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivityEspressoTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivityEspressoTest.java new file mode 100644 index 000000000..fbc95e9b8 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivityEspressoTest.java @@ -0,0 +1,256 @@ +package com.smartdevicelink.managers.lockscreen; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; + +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.intent.rule.IntentsTestRule; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +import com.smartdevicelink.R; +import com.smartdevicelink.managers.CompletionListener; +import com.smartdevicelink.managers.ISdl; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.rpc.OnDriverDistraction; +import com.smartdevicelink.proxy.rpc.OnHMIStatus; +import com.smartdevicelink.proxy.rpc.enums.DriverDistractionState; +import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; + +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; + + +//These tests are used to ensure the lockScreen UI Behavior +//They are ignored for CICD purposes and should be run manually during release testing +@RunWith(AndroidJUnit4.class) +@LargeTest +@Ignore +public class SDLLockScreenActivityEspressoTest { + + private OnRPCNotificationListener onDDListener; + private OnRPCNotificationListener onHMIListener; + private OnRPCNotificationListener onSystemRequestListener; + + @Rule + public ActivityScenarioRule<SDLLockScreenActivity> activityRule = + new ActivityScenarioRule<>(SDLLockScreenActivity.class); + + @Rule + public IntentsTestRule<SDLLockScreenActivity> intentsTestRule = + new IntentsTestRule<>(SDLLockScreenActivity.class); + + @Test + public void test1() { + testLockScreenBehavior(DriverDistractionState.DD_OFF, null, true, null, false); + } + + @Test + public void test2() { + testLockScreenBehavior(DriverDistractionState.DD_OFF, false, true, null, false); + } + + @Test + public void test3() { + testLockScreenBehavior(DriverDistractionState.DD_OFF, true, true, null, true); + } + + @Test + public void test4() { + testLockScreenBehavior(DriverDistractionState.DD_OFF, null, false, false, false); + } + + @Test + public void test5() { + testLockScreenBehavior(DriverDistractionState.DD_OFF, null, false, true, true); + } + + @Test + public void test6() { + testLockScreenBehavior(DriverDistractionState.DD_OFF, false, false, false, false); + } + + @Test + public void test7() { + testLockScreenBehavior(DriverDistractionState.DD_OFF, false, false, true, false); + } + + @Test + public void test8() { + testLockScreenBehavior(DriverDistractionState.DD_OFF, true, false, true, true); + } + + @Test + public void test9() { + testLockScreenBehavior(DriverDistractionState.DD_ON, true, false, false, true); + } + + @Test + public void test10() { + testLockScreenBehavior(DriverDistractionState.DD_ON, null, true, null, false); + } + + @Test + public void test11() { + testLockScreenBehavior(DriverDistractionState.DD_ON, false, true, null, false); + } + + @Test + public void test12() { + testLockScreenBehavior(DriverDistractionState.DD_ON, true, true, null, true); + } + + @Test + public void test13() { + testLockScreenBehavior(DriverDistractionState.DD_ON, null, false, false, false); + } + + @Test + public void test14() { + testLockScreenBehavior(DriverDistractionState.DD_ON, null, false, true, true); + } + + @Test + public void test15() { + testLockScreenBehavior(DriverDistractionState.DD_ON, false, false, false, false); + } + + @Test + public void test16() { + testLockScreenBehavior(DriverDistractionState.DD_ON, false, false, true, false); + } + + @Test + public void test17() { + testLockScreenBehavior(DriverDistractionState.DD_ON, true, false, true, true); + } + + @Test + public void test18() { + testLockScreenBehavior(DriverDistractionState.DD_ON, true, false, false, true); + } + + public void testLockScreenBehavior(final DriverDistractionState dd, final Boolean lockScreenDismissibility, final boolean firstDD, final Boolean previousLockScreenDismissibility, final boolean dismissEnabled){ + LockScreenConfig lockScreenConfig = new LockScreenConfig(); + lockScreenConfig.setDisplayMode(LockScreenConfig.DISPLAY_MODE_ALWAYS); + lockScreenConfig.enableDismissGesture(true); + lockScreenConfig.setCustomView(0); + lockScreenConfig.setAppIcon(0); + + LockScreenManager lockScreenManager = setupLockScreenManager(lockScreenConfig); + + lockScreenManager.start(new CompletionListener() { + @Override + public void onComplete(boolean success) { + OnHMIStatus onHMIStatus = new OnHMIStatus(); + onHMIStatus.setHmiLevel(HMILevel.HMI_FULL); + onHMIListener.onNotified(onHMIStatus); + + if (!firstDD) { + OnDriverDistraction firstOnDriverDistraction = new OnDriverDistraction(); + if (dd == DriverDistractionState.DD_OFF) { + firstOnDriverDistraction.setState(DriverDistractionState.DD_ON); + } else { + firstOnDriverDistraction.setState(DriverDistractionState.DD_OFF); + } + + if (previousLockScreenDismissibility != null) { + firstOnDriverDistraction.setLockscreenDismissibility(previousLockScreenDismissibility); + } + + onDDListener.onNotified(firstOnDriverDistraction); + } + + OnDriverDistraction onDriverDistraction = new OnDriverDistraction(); + if (lockScreenDismissibility != null) { + onDriverDistraction.setLockscreenDismissibility(lockScreenDismissibility); + } + onDriverDistraction.setState(dd); + onDDListener.onNotified(onDriverDistraction); + + + if (dismissEnabled) { + onView(withText("Swipe down to dismiss, acknowledging that you are not the driver.")).check(matches(isDisplayed())); + } else { + onView(withText("Locked for your safety")).check(matches(isDisplayed())); + } + + BroadcastReceiver receiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (dismissEnabled) { + assertEquals(intent.getAction(), SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED); + } else { + //Activity should not be dismissible test failed due to lock screen being dismissed + fail(); + } + } + }; + + intentsTestRule.getActivity().registerReceiver(receiver, new IntentFilter(SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED)); + + onView(ViewMatchers.withId(R.id.lockscreen_linear_layout)).perform(ViewActions.swipeDown()); + } + }); + } + + private LockScreenManager setupLockScreenManager(LockScreenConfig lockScreenConfig) { + ISdl internalInterface = mock(ISdl.class); + + Answer<Void> onDDStatusAnswer = new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) { + Object[] args = invocation.getArguments(); + onDDListener = (OnRPCNotificationListener) args[1]; + return null; + } + }; + + Answer<Void> onHMIStatusAnswer = new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) { + Object[] args = invocation.getArguments(); + onHMIListener = (OnRPCNotificationListener) args[1]; + return null; + } + }; + + Answer<Void> onSystemRequestAnswer = new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) { + Object[] args = invocation.getArguments(); + onSystemRequestListener = (OnRPCNotificationListener) args[1]; + return null; + } + }; + + doAnswer(onDDStatusAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_DRIVER_DISTRACTION), any(OnRPCNotificationListener.class)); + doAnswer(onHMIStatusAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_HMI_STATUS), any(OnRPCNotificationListener.class)); + doAnswer(onSystemRequestAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_SYSTEM_REQUEST), any(OnRPCNotificationListener.class)); + + Context context = getInstrumentation().getContext(); + + return new LockScreenManager(lockScreenConfig, context, internalInterface); + } +} diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/LockScreenManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/LockScreenManager.java index 105396fa2..483d948e2 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/LockScreenManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/LockScreenManager.java @@ -200,7 +200,10 @@ public class LockScreenManager extends BaseSubManager { DebugTool.logInfo(TAG, "Lock screen dismissible: " + isDismissible); if (isDismissible != null) { // both of these conditions must be met to be able to dismiss lockscreen - if (isDismissible && enableDismissGesture) { + if (!isDismissible) { + mIsLockscreenDismissible = false; + } + else if (isDismissible && enableDismissGesture) { mIsLockscreenDismissible = true; // if DisplayMode is set to ALWAYS, it will be shown before the first DD notification. @@ -217,6 +220,9 @@ public class LockScreenManager extends BaseSubManager { // launch lock screen driverDistStatus = true; launchLockScreenActivity(); + } else if (ddState.getState() == DriverDistractionState.DD_OFF && displayMode == LockScreenConfig.DISPLAY_MODE_ALWAYS) { + driverDistStatus = false; + launchLockScreenActivity(); } else { // close lock screen driverDistStatus = false; |