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] - Render tests with PixelMatch
- Loading branch information
Showing
20 changed files
with
491 additions
and
0 deletions.
There are no files selected for viewing
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
64 changes: 64 additions & 0 deletions
64
...ndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/render/RenderTest.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,64 @@ | ||
package com.mapbox.mapboxsdk.testapp.render; | ||
|
||
import android.support.test.espresso.Espresso; | ||
|
||
import android.support.test.espresso.IdlingPolicies; | ||
import android.support.test.espresso.IdlingResourceTimeoutException; | ||
|
||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.mapbox.mapboxsdk.testapp.activity.render.RenderTestActivity; | ||
import com.mapbox.mapboxsdk.testapp.utils.SnapshotterIdlingResource; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import timber.log.Timber; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
|
||
/** | ||
* Instrumentation render tests | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class RenderTest { | ||
|
||
private SnapshotterIdlingResource idlingResource; | ||
|
||
@Rule | ||
public ActivityTestRule<RenderTestActivity> rule = new ActivityTestRule<>(RenderTestActivity.class); | ||
|
||
@Before | ||
public void beforeTest() { | ||
try { | ||
Timber.e("@Before test: register idle resource"); | ||
IdlingPolicies.setIdlingResourceTimeout(2, TimeUnit.MINUTES); | ||
Espresso.registerIdlingResources(idlingResource = new SnapshotterIdlingResource(rule.getActivity())); | ||
} catch (IdlingResourceTimeoutException idlingResourceTimeoutException) { | ||
throw new RuntimeException("Idling out!"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRender() { | ||
onView(withId(android.R.id.content)).check(matches(isDisplayed())); | ||
Assert.assertTrue(rule.getActivity().isFinishedRendering()); | ||
} | ||
|
||
@After | ||
public void afterTest() { | ||
Timber.e("@After test: unregister idle resource"); | ||
Espresso.unregisterIdlingResources(idlingResource); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...pp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/SnapshotterIdlingResource.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,38 @@ | ||
package com.mapbox.mapboxsdk.testapp.utils; | ||
|
||
import android.support.test.espresso.IdlingResource; | ||
|
||
import com.mapbox.mapboxsdk.testapp.activity.render.RenderTestActivity; | ||
|
||
public class SnapshotterIdlingResource implements IdlingResource { | ||
|
||
private final RenderTestActivity activity; | ||
private IdlingResource.ResourceCallback resourceCallback; | ||
|
||
public SnapshotterIdlingResource(RenderTestActivity activity) { | ||
this.activity = activity; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return getClass().getSimpleName(); | ||
} | ||
|
||
@Override | ||
public boolean isIdleNow() { | ||
boolean idle = isSnapshotReady(); | ||
if (idle && resourceCallback != null) { | ||
resourceCallback.onTransitionToIdle(); | ||
} | ||
return idle; | ||
} | ||
|
||
@Override | ||
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { | ||
this.resourceCallback = resourceCallback; | ||
} | ||
|
||
private boolean isSnapshotReady() { | ||
return activity != null && activity.isFinishedRendering(); | ||
} | ||
} |
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
145 changes: 145 additions & 0 deletions
145
platform/android/MapboxGLAndroidSDKTestApp/src/main/assets/render-test.json
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,145 @@ | ||
[ | ||
{ | ||
"name": "World", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
0, | ||
0 | ||
], | ||
"zoom": 0, | ||
"tilt": 0, | ||
"bearing": 0, | ||
"styleUrl": "mapbox://styles/mapbox/streets-v10" | ||
}, | ||
{ | ||
"name": "Brussels", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
50.846728, | ||
4.352429 | ||
], | ||
"zoom": 12, | ||
"tilt": 0, | ||
"bearing": 0, | ||
"styleUrl": "mapbox://styles/mapbox/streets-v10" | ||
}, | ||
{ | ||
"name": "San Francisco", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
37.772544, | ||
-122.426622 | ||
], | ||
"zoom": 9, | ||
"tilt": 60, | ||
"bearing": 0, | ||
"styleUrl": "mapbox://styles/mapbox/streets-v10" | ||
}, | ||
{ | ||
"name": "Washington DC", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
38.897717, | ||
-77.036035 | ||
], | ||
"zoom": 18, | ||
"tilt": 20, | ||
"bearing": 180, | ||
"styleUrl": "mapbox://styles/mapbox/streets-v10" | ||
}, | ||
{ | ||
"name": "Ayacucho", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
-13.164131, | ||
-74.220973 | ||
], | ||
"zoom": 12, | ||
"tilt": 30, | ||
"bearing": 270, | ||
"styleUrl": "mapbox://styles/mapbox/streets-v10" | ||
}, | ||
{ | ||
"name": "Bangalore", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
12.970020, | ||
77.590421 | ||
], | ||
"zoom": 14, | ||
"tilt": 0, | ||
"bearing": 0, | ||
"styleUrl": "mapbox://styles/mapbox/streets-v10" | ||
}, | ||
{ | ||
"name": "Berlin", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
52.519716, | ||
13.402068 | ||
], | ||
"zoom": 12, | ||
"tilt": 0, | ||
"bearing": 0, | ||
"styleUrl": "mapbox://styles/mapbox/streets-v10" | ||
}, | ||
{ | ||
"name": "Lisbon", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
38.722062, | ||
-9.138746 | ||
], | ||
"zoom": 15, | ||
"tilt": 45, | ||
"bearing": 90, | ||
"styleUrl": "mapbox://styles/mapbox/outdoors-v10" | ||
}, | ||
{ | ||
"name": "Helsinki", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
60.171283, | ||
24.933533 | ||
], | ||
"zoom": 12, | ||
"tilt": 0, | ||
"bearing": 0, | ||
"styleUrl": "mapbox://styles/mapbox/streets-v10" | ||
}, | ||
{ | ||
"name": "Madrid", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
40.417025, | ||
-3.705287 | ||
], | ||
"zoom": 16, | ||
"tilt": 35, | ||
"bearing": 0, | ||
"styleUrl": "mapbox://styles/mapbox/light-v9" | ||
}, | ||
{ | ||
"name": "London", | ||
"width": 512, | ||
"height": 512, | ||
"center": [ | ||
51.508049, | ||
-0.129756 | ||
], | ||
"zoom": 12, | ||
"tilt": 0, | ||
"bearing": 0, | ||
"styleUrl": "mapbox://styles/mapbox/dark-v9" | ||
} | ||
] |
Oops, something went wrong.