Skip to content

Commit 626adac

Browse files
HeniganHenigan
authored andcommitted
Add LockScreen UI tests
1 parent 715cb54 commit 626adac

4 files changed

Lines changed: 268 additions & 4 deletions

File tree

android/sdl_android/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ dependencies {
4343
api fileTree(dir: 'libs', include: ['*.jar'])
4444
api 'com.smartdevicelink:bson_java_port:RC1_1.2.2'
4545
api 'com.livio.taskmaster:taskmaster:0.3.0'
46-
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
47-
exclude group: 'com.android.support', module: 'support-annotations'
48-
})
46+
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
4947
testImplementation 'junit:junit:4.12'
5048
testImplementation 'org.mockito:mockito-core:3.0.0'
5149
androidTestImplementation 'org.mockito:mockito-core:3.0.0'
@@ -54,6 +52,9 @@ dependencies {
5452
api 'androidx.annotation:annotation:1.1.0'
5553
api 'androidx.lifecycle:lifecycle-extensions:2.2.0'
5654
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.2.0'
55+
debugImplementation("androidx.test:core:1.3.0")
56+
debugImplementation("androidx.test:rules:1.3.0")
57+
debugImplementation("androidx.test:runner:1.3.0")
5758
}
5859

5960
buildscript {

android/sdl_android/src/androidTest/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<application android:debuggable="true">
1818
<uses-library android:name="android.test.runner" />
19+
<activity android:name=".managers.lockscreen.SDLLockScreenActivity"/>
1920
</application>
2021

2122
</manifest>
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
package com.smartdevicelink.managers.lockscreen;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.content.IntentFilter;
7+
8+
import androidx.test.espresso.action.ViewActions;
9+
import androidx.test.espresso.intent.rule.IntentsTestRule;
10+
import androidx.test.espresso.matcher.ViewMatchers;
11+
import androidx.test.ext.junit.rules.ActivityScenarioRule;
12+
import androidx.test.ext.junit.runners.AndroidJUnit4;
13+
import androidx.test.filters.LargeTest;
14+
15+
import com.smartdevicelink.R;
16+
import com.smartdevicelink.managers.CompletionListener;
17+
import com.smartdevicelink.managers.ISdl;
18+
import com.smartdevicelink.protocol.enums.FunctionID;
19+
import com.smartdevicelink.proxy.rpc.OnDriverDistraction;
20+
import com.smartdevicelink.proxy.rpc.OnHMIStatus;
21+
import com.smartdevicelink.proxy.rpc.enums.DriverDistractionState;
22+
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
23+
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
24+
25+
import org.junit.Ignore;
26+
import org.junit.Rule;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
import org.mockito.invocation.InvocationOnMock;
30+
import org.mockito.stubbing.Answer;
31+
32+
import static androidx.test.espresso.Espresso.onView;
33+
import static androidx.test.espresso.assertion.ViewAssertions.matches;
34+
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
35+
import static androidx.test.espresso.matcher.ViewMatchers.withText;
36+
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
37+
import static org.junit.Assert.assertEquals;
38+
import static org.junit.Assert.fail;
39+
import static org.mockito.ArgumentMatchers.any;
40+
import static org.mockito.ArgumentMatchers.eq;
41+
import static org.mockito.Mockito.doAnswer;
42+
import static org.mockito.Mockito.mock;
43+
44+
45+
//These tests are used to ensure the lockScreen UI Behavior
46+
//They are ignored for CICD purposes and should be run manually during release testing
47+
@RunWith(AndroidJUnit4.class)
48+
@LargeTest
49+
@Ignore
50+
public class SDLLockScreenActivityEspressoTest {
51+
52+
private OnRPCNotificationListener onDDListener;
53+
private OnRPCNotificationListener onHMIListener;
54+
private OnRPCNotificationListener onSystemRequestListener;
55+
56+
@Rule
57+
public ActivityScenarioRule<SDLLockScreenActivity> activityRule =
58+
new ActivityScenarioRule<>(SDLLockScreenActivity.class);
59+
60+
@Rule
61+
public IntentsTestRule<SDLLockScreenActivity> intentsTestRule =
62+
new IntentsTestRule<>(SDLLockScreenActivity.class);
63+
64+
@Test
65+
public void test1() {
66+
testLockScreenBehavior(DriverDistractionState.DD_OFF, null, true, null, false);
67+
}
68+
69+
@Test
70+
public void test2() {
71+
testLockScreenBehavior(DriverDistractionState.DD_OFF, false, true, null, false);
72+
}
73+
74+
@Test
75+
public void test3() {
76+
testLockScreenBehavior(DriverDistractionState.DD_OFF, true, true, null, true);
77+
}
78+
79+
@Test
80+
public void test4() {
81+
testLockScreenBehavior(DriverDistractionState.DD_OFF, null, false, false, false);
82+
}
83+
84+
@Test
85+
public void test5() {
86+
testLockScreenBehavior(DriverDistractionState.DD_OFF, null, false, true, true);
87+
}
88+
89+
@Test
90+
public void test6() {
91+
testLockScreenBehavior(DriverDistractionState.DD_OFF, false, false, false, false);
92+
}
93+
94+
@Test
95+
public void test7() {
96+
testLockScreenBehavior(DriverDistractionState.DD_OFF, false, false, true, false);
97+
}
98+
99+
@Test
100+
public void test8() {
101+
testLockScreenBehavior(DriverDistractionState.DD_OFF, true, false, true, true);
102+
}
103+
104+
@Test
105+
public void test9() {
106+
testLockScreenBehavior(DriverDistractionState.DD_ON, true, false, false, true);
107+
}
108+
109+
@Test
110+
public void test10() {
111+
testLockScreenBehavior(DriverDistractionState.DD_ON, null, true, null, false);
112+
}
113+
114+
@Test
115+
public void test11() {
116+
testLockScreenBehavior(DriverDistractionState.DD_ON, false, true, null, false);
117+
}
118+
119+
@Test
120+
public void test12() {
121+
testLockScreenBehavior(DriverDistractionState.DD_ON, true, true, null, true);
122+
}
123+
124+
@Test
125+
public void test13() {
126+
testLockScreenBehavior(DriverDistractionState.DD_ON, null, false, false, false);
127+
}
128+
129+
@Test
130+
public void test14() {
131+
testLockScreenBehavior(DriverDistractionState.DD_ON, null, false, true, true);
132+
}
133+
134+
@Test
135+
public void test15() {
136+
testLockScreenBehavior(DriverDistractionState.DD_ON, false, false, false, false);
137+
}
138+
139+
@Test
140+
public void test16() {
141+
testLockScreenBehavior(DriverDistractionState.DD_ON, false, false, true, false);
142+
}
143+
144+
@Test
145+
public void test17() {
146+
testLockScreenBehavior(DriverDistractionState.DD_ON, true, false, true, true);
147+
}
148+
149+
@Test
150+
public void test18() {
151+
testLockScreenBehavior(DriverDistractionState.DD_ON, true, false, false, true);
152+
}
153+
154+
public void testLockScreenBehavior(final DriverDistractionState dd, final Boolean lockScreenDismissibility, final boolean firstDD, final Boolean previousLockScreenDismissibility, final boolean dismissEnabled){
155+
LockScreenConfig lockScreenConfig = new LockScreenConfig();
156+
lockScreenConfig.setDisplayMode(LockScreenConfig.DISPLAY_MODE_ALWAYS);
157+
lockScreenConfig.enableDismissGesture(true);
158+
lockScreenConfig.setCustomView(0);
159+
lockScreenConfig.setAppIcon(0);
160+
161+
LockScreenManager lockScreenManager = setupLockScreenManager(lockScreenConfig);
162+
163+
lockScreenManager.start(new CompletionListener() {
164+
@Override
165+
public void onComplete(boolean success) {
166+
OnHMIStatus onHMIStatus = new OnHMIStatus();
167+
onHMIStatus.setHmiLevel(HMILevel.HMI_FULL);
168+
onHMIListener.onNotified(onHMIStatus);
169+
170+
if (!firstDD) {
171+
OnDriverDistraction firstOnDriverDistraction = new OnDriverDistraction();
172+
if (dd == DriverDistractionState.DD_OFF) {
173+
firstOnDriverDistraction.setState(DriverDistractionState.DD_ON);
174+
} else {
175+
firstOnDriverDistraction.setState(DriverDistractionState.DD_OFF);
176+
}
177+
178+
if (previousLockScreenDismissibility != null) {
179+
firstOnDriverDistraction.setLockscreenDismissibility(previousLockScreenDismissibility);
180+
}
181+
182+
onDDListener.onNotified(firstOnDriverDistraction);
183+
}
184+
185+
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
186+
if (lockScreenDismissibility != null) {
187+
onDriverDistraction.setLockscreenDismissibility(lockScreenDismissibility);
188+
}
189+
onDriverDistraction.setState(dd);
190+
onDDListener.onNotified(onDriverDistraction);
191+
192+
193+
if (dismissEnabled) {
194+
onView(withText("Swipe down to dismiss, acknowledging that you are not the driver.")).check(matches(isDisplayed()));
195+
} else {
196+
onView(withText("Locked for your safety")).check(matches(isDisplayed()));
197+
}
198+
199+
BroadcastReceiver receiver = new BroadcastReceiver() {
200+
@Override
201+
public void onReceive(Context context, Intent intent) {
202+
if (dismissEnabled) {
203+
assertEquals(intent.getAction(), SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED);
204+
} else {
205+
//Activity should not be dismissible test failed due to lock screen being dismissed
206+
fail();
207+
}
208+
}
209+
};
210+
211+
intentsTestRule.getActivity().registerReceiver(receiver, new IntentFilter(SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED));
212+
213+
onView(ViewMatchers.withId(R.id.lockscreen_linear_layout)).perform(ViewActions.swipeDown());
214+
}
215+
});
216+
}
217+
218+
private LockScreenManager setupLockScreenManager(LockScreenConfig lockScreenConfig) {
219+
ISdl internalInterface = mock(ISdl.class);
220+
221+
Answer<Void> onDDStatusAnswer = new Answer<Void>() {
222+
@Override
223+
public Void answer(InvocationOnMock invocation) {
224+
Object[] args = invocation.getArguments();
225+
onDDListener = (OnRPCNotificationListener) args[1];
226+
return null;
227+
}
228+
};
229+
230+
Answer<Void> onHMIStatusAnswer = new Answer<Void>() {
231+
@Override
232+
public Void answer(InvocationOnMock invocation) {
233+
Object[] args = invocation.getArguments();
234+
onHMIListener = (OnRPCNotificationListener) args[1];
235+
return null;
236+
}
237+
};
238+
239+
Answer<Void> onSystemRequestAnswer = new Answer<Void>() {
240+
@Override
241+
public Void answer(InvocationOnMock invocation) {
242+
Object[] args = invocation.getArguments();
243+
onSystemRequestListener = (OnRPCNotificationListener) args[1];
244+
return null;
245+
}
246+
};
247+
248+
doAnswer(onDDStatusAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_DRIVER_DISTRACTION), any(OnRPCNotificationListener.class));
249+
doAnswer(onHMIStatusAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_HMI_STATUS), any(OnRPCNotificationListener.class));
250+
doAnswer(onSystemRequestAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_SYSTEM_REQUEST), any(OnRPCNotificationListener.class));
251+
252+
Context context = getInstrumentation().getContext();
253+
254+
return new LockScreenManager(lockScreenConfig, context, internalInterface);
255+
}
256+
}

android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/LockScreenManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ public void onNotified(RPCNotification notification) {
200200
DebugTool.logInfo(TAG, "Lock screen dismissible: " + isDismissible);
201201
if (isDismissible != null) {
202202
// both of these conditions must be met to be able to dismiss lockscreen
203-
if (isDismissible && enableDismissGesture) {
203+
if (!isDismissible) {
204+
mIsLockscreenDismissible = false;
205+
}
206+
else if (isDismissible && enableDismissGesture) {
204207
mIsLockscreenDismissible = true;
205208

206209
// if DisplayMode is set to ALWAYS, it will be shown before the first DD notification.
@@ -217,6 +220,9 @@ public void onNotified(RPCNotification notification) {
217220
// launch lock screen
218221
driverDistStatus = true;
219222
launchLockScreenActivity();
223+
} else if (ddState.getState() == DriverDistractionState.DD_OFF && displayMode == LockScreenConfig.DISPLAY_MODE_ALWAYS) {
224+
driverDistStatus = false;
225+
launchLockScreenActivity();
220226
} else {
221227
// close lock screen
222228
driverDistStatus = false;

0 commit comments

Comments
 (0)