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
Node render test suite on Android #12041
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
51 changes: 51 additions & 0 deletions
51
.../android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/LocalRequestTask.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,51 @@ | ||
package com.mapbox.mapboxsdk.http; | ||
|
||
import android.content.res.AssetManager; | ||
import android.os.AsyncTask; | ||
import com.mapbox.mapboxsdk.Mapbox; | ||
import timber.log.Timber; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
class LocalRequestTask extends AsyncTask<String, Void, byte[]> { | ||
|
||
private OnLocalRequestResponse requestResponse; | ||
|
||
LocalRequestTask(OnLocalRequestResponse requestResponse) { | ||
this.requestResponse = requestResponse; | ||
} | ||
|
||
@Override | ||
protected byte[] doInBackground(String... strings) { | ||
return loadFile(Mapbox.getApplicationContext().getAssets(), | ||
"integration/" + strings[0] | ||
.substring(8) | ||
.replaceAll("%20", " ") | ||
.replaceAll("%2c", ",")); | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(byte[] bytes) { | ||
super.onPostExecute(bytes); | ||
if (bytes != null && requestResponse != null) { | ||
requestResponse.onResponse(bytes); | ||
} | ||
} | ||
|
||
private static byte[] loadFile(AssetManager assets, String path) { | ||
byte[] buffer = null; | ||
try (InputStream input = assets.open(path)) { | ||
int size = input.available(); | ||
buffer = new byte[size]; | ||
input.read(buffer); | ||
} catch (IOException exception) { | ||
Timber.e(exception); | ||
} | ||
return buffer; | ||
} | ||
|
||
public interface OnLocalRequestResponse { | ||
void onResponse(byte[] bytes); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...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,70 @@ | ||
package com.mapbox.mapboxsdk.testapp.render; | ||
|
||
import android.Manifest; | ||
import android.support.test.espresso.IdlingPolicies; | ||
import android.support.test.espresso.IdlingRegistry; | ||
import android.support.test.espresso.IdlingResourceTimeoutException; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.rule.GrantPermissionRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import com.mapbox.mapboxsdk.testapp.activity.render.RenderTestActivity; | ||
import com.mapbox.mapboxsdk.testapp.utils.SnapshotterIdlingResource; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import timber.log.Timber; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
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 static final int RENDER_TEST_TIMEOUT = 30; | ||
private SnapshotterIdlingResource idlingResource; | ||
|
||
@Rule | ||
public ActivityTestRule<RenderTestActivity> activityRule = new ActivityTestRule<>(RenderTestActivity.class); | ||
|
||
@Rule | ||
public GrantPermissionRule writeRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE); | ||
|
||
@Rule | ||
public GrantPermissionRule readRule = GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE); | ||
|
||
@Before | ||
public void beforeTest() { | ||
IdlingPolicies.setMasterPolicyTimeout(RENDER_TEST_TIMEOUT, TimeUnit.MINUTES); | ||
setupIdlingResource(); | ||
} | ||
|
||
private void setupIdlingResource() { | ||
try { | ||
Timber.e("@Before test: register idle resource"); | ||
IdlingPolicies.setIdlingResourceTimeout(RENDER_TEST_TIMEOUT, TimeUnit.MINUTES); | ||
IdlingRegistry.getInstance().register(idlingResource = new SnapshotterIdlingResource(activityRule.getActivity())); | ||
} catch (IdlingResourceTimeoutException idlingResourceTimeoutException) { | ||
throw new RuntimeException("Idling out!"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRender() { | ||
onView(withId(android.R.id.content)).check(matches(isDisplayed())); | ||
} | ||
|
||
@After | ||
public void afterTest() { | ||
Timber.e("@After test: unregister idle resource"); | ||
IdlingRegistry.getInstance().unregister(idlingResource); | ||
} | ||
} |
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
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, RenderTestActivity.OnRenderTestCompletionListener { | ||
|
||
private IdlingResource.ResourceCallback resourceCallback; | ||
private boolean isSnapshotReady; | ||
|
||
public SnapshotterIdlingResource(RenderTestActivity activity) { | ||
activity.setOnRenderTestCompletionListener(this); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "SnapshotterIdlingResource"; | ||
} | ||
|
||
@Override | ||
public boolean isIdleNow() { | ||
return isSnapshotReady; | ||
} | ||
|
||
@Override | ||
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { | ||
this.resourceCallback = resourceCallback; | ||
} | ||
|
||
@Override | ||
public void onFinish() { | ||
isSnapshotReady = true; | ||
if (resourceCallback != null) { | ||
resourceCallback.onTransitionToIdle(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was only the debug setup. Can we remove it?