summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilal Alsharifi <599206+bilal-alsharifi@users.noreply.github.com>2020-10-14 14:13:05 -0400
committerGitHub <noreply@github.com>2020-10-14 14:13:05 -0400
commit6d783cdb97f6ab4f458725b7d89ab8d56b966e17 (patch)
tree7af5c18141cab10c466bc4ae579a90ecccf32e72
parentd7e54de7e2127bc994d847de156ad74e6a9f574b (diff)
parent46283864ecf72d0f0b7622966133a94cca50170b (diff)
downloadsdl_android-6d783cdb97f6ab4f458725b7d89ab8d56b966e17.tar.gz
Merge pull request #1527 from smartdevicelink/feature/lockscreen_ui_testing
Feature/lockscreen ui testing
-rw-r--r--android/sdl_android/build.gradle12
-rw-r--r--android/sdl_android/src/androidTest/AndroidManifest.xml1
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivityEspressoTest.java255
3 files changed, 262 insertions, 6 deletions
diff --git a/android/sdl_android/build.gradle b/android/sdl_android/build.gradle
index 7844d4145..c9f5ba246 100644
--- a/android/sdl_android/build.gradle
+++ b/android/sdl_android/build.gradle
@@ -43,17 +43,17 @@ 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'
- })
+ api 'androidx.lifecycle:lifecycle-extensions:2.2.0'
+ api 'androidx.annotation:annotation:1.1.0'
+ annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.2.0'
+
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:3.0.0'
androidTestImplementation 'org.mockito:mockito-core:3.0.0'
androidTestImplementation 'org.mockito:mockito-android:3.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
- api 'androidx.annotation:annotation:1.1.0'
- api 'androidx.lifecycle:lifecycle-extensions:2.2.0'
- annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.2.0'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
+ androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.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..264c4c741
--- /dev/null
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/lockscreen/SDLLockScreenActivityEspressoTest.java
@@ -0,0 +1,255 @@
+package com.smartdevicelink.managers.lockscreen;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Handler;
+import android.os.Looper;
+
+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 //Remove this annotation before running these tests
+public class SDLLockScreenActivityEspressoTest {
+
+ private OnRPCNotificationListener onDDListener;
+ private OnRPCNotificationListener onHMIListener;
+
+ @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);
+
+ if (Looper.myLooper() == null) {
+ Looper.prepare();
+ }
+ 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);
+
+
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ if (dismissEnabled) {
+ onView(withText(R.string.default_lockscreen_warning_message)).check(matches(isDisplayed()));
+ } else {
+ onView(withText(R.string.lockscreen_text)).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());
+ }
+ }, 1000);
+ }
+ });
+ }
+
+ 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;
+ }
+ };
+
+ 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));
+
+ Context context = getInstrumentation().getContext();
+
+ return new LockScreenManager(lockScreenConfig, context, internalInterface);
+ }
+}