This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - add orientation change regression test
- Loading branch information
Showing
3 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...oxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/OrientationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.mapbox.mapboxsdk.maps; | ||
|
||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; | ||
import com.mapbox.mapboxsdk.testapp.activity.camera.CameraAnimationTypeActivity; | ||
import org.junit.Test; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isRoot; | ||
import static com.mapbox.mapboxsdk.testapp.action.OrientationChangeAction.orientationLandscape; | ||
import static com.mapbox.mapboxsdk.testapp.action.OrientationChangeAction.orientationLandscapeReverse; | ||
import static com.mapbox.mapboxsdk.testapp.action.OrientationChangeAction.orientationPortrait; | ||
import static com.mapbox.mapboxsdk.testapp.action.OrientationChangeAction.orientationPortraitReverse; | ||
|
||
public class OrientationTest extends BaseActivityTest { | ||
|
||
@Test | ||
public void testChangeDeviceOrientation() { | ||
onView(isRoot()).perform(orientationLandscape()); | ||
waitLoop(2200); | ||
onView(isRoot()).perform(orientationPortrait()); | ||
waitLoop(2500); | ||
onView(isRoot()).perform(orientationLandscapeReverse()); | ||
waitLoop(500); | ||
onView(isRoot()).perform(orientationPortraitReverse()); | ||
waitLoop(1250); | ||
onView(isRoot()).perform(orientationLandscape()); | ||
waitLoop(750); | ||
onView(isRoot()).perform(orientationPortrait()); | ||
waitLoop(950); | ||
onView(isRoot()).perform(orientationLandscapeReverse()); | ||
onView(isRoot()).perform(orientationPortraitReverse()); | ||
onView(isRoot()).perform(orientationLandscape()); | ||
onView(isRoot()).perform(orientationPortrait()); | ||
} | ||
|
||
@Override | ||
protected Class getActivityClass() { | ||
return CameraAnimationTypeActivity.class; | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...App/src/androidTest/java/com/mapbox/mapboxsdk/testapp/action/OrientationChangeAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.mapbox.mapboxsdk.testapp.action; | ||
|
||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.ContextWrapper; | ||
import android.content.pm.ActivityInfo; | ||
import android.support.test.espresso.UiController; | ||
import android.support.test.espresso.ViewAction; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import org.hamcrest.Matcher; | ||
|
||
import static android.support.test.espresso.matcher.ViewMatchers.isRoot; | ||
|
||
public class OrientationChangeAction implements ViewAction { | ||
|
||
private final int orientation; | ||
|
||
private OrientationChangeAction(int orientation) { | ||
this.orientation = orientation; | ||
} | ||
|
||
public static ViewAction orientationLandscape() { | ||
return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | ||
} | ||
|
||
public static ViewAction orientationPortrait() { | ||
return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | ||
} | ||
|
||
public static ViewAction orientationLandscapeReverse() { | ||
return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); | ||
} | ||
|
||
public static ViewAction orientationPortraitReverse() { | ||
return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); | ||
} | ||
|
||
@Override | ||
public Matcher<View> getConstraints() { | ||
return isRoot(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "change orientation to " + orientation; | ||
} | ||
|
||
@Override | ||
public void perform(UiController uiController, View view) { | ||
uiController.loopMainThreadUntilIdle(); | ||
Activity activity = getActivity(view.getContext()); | ||
if (activity == null && view instanceof ViewGroup) { | ||
ViewGroup v = (ViewGroup) view; | ||
int c = v.getChildCount(); | ||
for (int i = 0; i < c && activity == null; ++i) { | ||
activity = getActivity(v.getChildAt(i).getContext()); | ||
} | ||
} | ||
activity.setRequestedOrientation(orientation); | ||
} | ||
|
||
private Activity getActivity(Context context) { | ||
while (context instanceof ContextWrapper) { | ||
if (context instanceof Activity) { | ||
return (Activity) context; | ||
} | ||
context = ((ContextWrapper) context).getBaseContext(); | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters