diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-10-20 10:20:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-20 10:20:56 +0200 |
commit | 9a7139b65ccc7d75c256cb04c4ec1e6bd4e327b6 (patch) | |
tree | b33621c0939b228867c962e2c60d14b3513ddfb3 /platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils | |
parent | 76f91cc88d5e2c19bcac3e1421bd13b510e21979 (diff) | |
download | qtlocation-mapboxgl-9a7139b65ccc7d75c256cb04c4ec1e6bd4e327b6.tar.gz |
[android] - move instrumentation test code to correct package for Android Studio run configurations integration. (#6748)
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils')
5 files changed, 0 insertions, 252 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/DrawerUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/DrawerUtils.java deleted file mode 100644 index 8b39503d45..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/DrawerUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.mapbox.mapboxsdk.utils; - -import android.support.annotation.StringRes; -import android.support.test.espresso.Espresso; -import android.support.test.espresso.action.ViewActions; -import android.support.test.espresso.matcher.ViewMatchers; - -import com.mapbox.mapboxsdk.testapp.R; - -import org.hamcrest.Matchers; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription; - -public class DrawerUtils { - - private final static String HOME_BUTTON_STRING = "Navigate up"; - - public static void openDrawer(){ - onView(withContentDescription(HOME_BUTTON_STRING)).perform(click()); - } - - public static void clickItem(@StringRes int txtId){ - Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.design_menu_item_text), - ViewMatchers.hasSibling(ViewMatchers.withText(txtId)))).perform(ViewActions.click()); - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/GestureUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/GestureUtils.java deleted file mode 100644 index 38d76f5d83..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/GestureUtils.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.mapbox.mapboxsdk.utils; - -import android.support.annotation.IdRes; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.action.ViewActions.doubleClick; -import static android.support.test.espresso.matcher.ViewMatchers.withId; - -public class GestureUtils { - - public static void doubleClickGesture(@IdRes int id){ - onView(withId(id)).perform(doubleClick()); - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java deleted file mode 100644 index 43f3c07589..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.mapbox.mapboxsdk.utils; - -import android.app.Activity; -import android.support.test.espresso.IdlingResource; -import android.util.Log; - -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.maps.MapboxMap; - -import java.lang.reflect.Field; - -public class OnMapReadyIdlingResource implements IdlingResource { - - private final Activity activity; - private MapboxMap mapboxMap; - private IdlingResource.ResourceCallback resourceCallback; - - public OnMapReadyIdlingResource(Activity activity) { - this.activity = activity; - } - - @Override - public String getName() { - return getClass().getSimpleName(); - } - - @Override - public boolean isIdleNow() { - boolean idle = isMapboxMapReady(); - if (idle && resourceCallback != null) { - resourceCallback.onTransitionToIdle(); - } - return idle; - } - - @Override - public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { - this.resourceCallback = resourceCallback; - } - - private boolean isMapboxMapReady() { - try { - Field field = activity.getClass().getDeclaredField("mapboxMap"); - field.setAccessible(true); - mapboxMap = (MapboxMap) field.get(activity); - Log.e(MapboxConstants.TAG, "isMapboxReady called with value " + (mapboxMap != null)); - return mapboxMap != null; - } catch (Exception e) { - Log.e(MapboxConstants.TAG, "could not reflect", e); - return false; - } - } - - public MapboxMap getMapboxMap() { - return mapboxMap; - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/ScreenshotUtil.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/ScreenshotUtil.java deleted file mode 100644 index 87b2d181f9..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/ScreenshotUtil.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.mapbox.mapboxsdk.utils; - -import android.app.Activity; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.os.Environment; -import android.util.Log; -import android.view.TextureView; -import android.view.View; -import android.view.ViewGroup; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -/** - * The built-in Fuzz Suite on AWS Device Farm takes screenshots after every test. However, - * this doesn't happen with Espresso unless we manually do it. This class fixes it. - */ -public class ScreenshotUtil { - - private static final String LOG_TAG = ScreenshotUtil.class.getName(); - - // Where to store the files. This path is required by AWS Device Farm: - // http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-android-instrumentation.html#test-types-android-instrumentation-screenshots - private static final String SCREENSHOT_FOLDER = "test-screenshots"; - - // Image type and quality - private static final String DEFAULT_IMAGE_EXTENSION = ".png"; - private static final Bitmap.CompressFormat DEFAULT_IMAGE_FORMAT = Bitmap.CompressFormat.PNG; - private static final int DEFAULT_IMAGE_QUALITY = 100; - - public static void take(Activity activity, String testName) { - - // Check if storage is available - if (!isExternalStorageWritable()) { - Log.d(LOG_TAG, "External storage is not available."); - return; - } - - // Get a bitmap from the activity root view. When the drawing cache is enabled, -// // the next call to getDrawingCache() will draw the view in a bitmap. - View rootView = activity.getWindow().getDecorView().getRootView(); -// rootView.setDrawingCacheEnabled(true);r -// rootView.setDrawingCacheEnabled(false); - - Bitmap bitmap = null; - - // Add the SurfaceView bit (see getAllTextureViews() below) - List<TextureView> tilingViews = getAllTextureViews(rootView); - if (tilingViews.size() > 0) { - bitmap = Bitmap.createBitmap(tilingViews.get(0).getHeight(),tilingViews.get(0).getWidth(), Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - for (TextureView TextureView : tilingViews) { - Bitmap b = TextureView.getBitmap(TextureView.getWidth(), TextureView.getHeight()); - int[] location = new int[2]; - TextureView.getLocationInWindow(location); - int[] location2 = new int[2]; - TextureView.getLocationOnScreen(location2); - canvas.drawBitmap(b, 0,0, null); - } - } - - // Save the bitmap in external storage - String uniqueAbsolutePath = getUniqueAbsolutePath(testName); - File outputFile = new File(uniqueAbsolutePath); - OutputStream outputStream = null; - try { - outputStream = new FileOutputStream(outputFile); - bitmap.compress(DEFAULT_IMAGE_FORMAT, DEFAULT_IMAGE_QUALITY, outputStream); - outputStream.flush(); - } catch (Exception e) { - - e.printStackTrace(); - } finally { - if (outputStream != null) { - try { - outputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } - - /* - * The classic way of taking a screenshot (above) doesn't work with TextureView, this fixes it: - * http://stackoverflow.com/questions/19704060/screen-capture-textureview-is-black-using-drawingcache - */ - - public static List<TextureView> getAllTextureViews(View view) - { - List<TextureView> tilingViews = new ArrayList<TextureView>(); - if (view instanceof TextureView) { - tilingViews.add((TextureView)view); - } else if(view instanceof ViewGroup) { - ViewGroup viewGroup = (ViewGroup)view; - for (int i = 0; i < viewGroup.getChildCount(); i++) { - tilingViews.addAll(getAllTextureViews(viewGroup.getChildAt(i))); - } - } - - return tilingViews; - } - - /* - * Utils - */ - - public static boolean isExternalStorageWritable() { - // Checks if external storage is available for read and write - String state = Environment.getExternalStorageState(); - return Environment.MEDIA_MOUNTED.equals(state); - } - - private static String getUniqueAbsolutePath(String testName) { - // A screenshot after every test vs. manual tests - String filename = UUID.randomUUID().toString() + DEFAULT_IMAGE_EXTENSION; - if (testName != null && !testName.isEmpty()) { - filename = testName + DEFAULT_IMAGE_EXTENSION; - } - - String externalPath = Environment.getExternalStorageDirectory().toString(); - String path = externalPath + File.separator + SCREENSHOT_FOLDER; - File dir = new File(path); - dir.mkdirs(); - path += File.separator + filename; - Log.d(LOG_TAG, "Screenshot path: " + path); - return path; - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/ViewUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/ViewUtils.java deleted file mode 100644 index 739fce1cfb..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/ViewUtils.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.mapbox.mapboxsdk.utils; - -import android.support.annotation.IdRes; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.matcher.ViewMatchers.withId; - -public class ViewUtils { - - public static void clickView(@IdRes int viewRes) { - onView(withId(viewRes)) - .perform(click()); - } -} |