Bug 1480920 - Bump versions for Android test runner packages r=jchen
authorJames Willcox <snorp@snorp.net>
Thu, 23 Aug 2018 13:12:20 +0000
changeset 433142 f5732e0812ff1cac72c698dd6c0a52a7a8bd445a
parent 433141 b168deee0bcf1a33737941eb78acc065a1c9c053
child 433143 488b580cad59b79fc92053fb18dd01ef2c0da15c
push id106985
push usercsabou@mozilla.com
push dateThu, 23 Aug 2018 21:47:08 +0000
treeherdermozilla-inbound@3ca4d76bcc88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1480920
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1480920 - Bump versions for Android test runner packages r=jchen This also removes the trivial tests for geckoview_example that were causing problems. Differential Revision: https://phabricator.services.mozilla.com/D3991
build.gradle
mobile/android/geckoview/build.gradle
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoResultTest.java
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
mobile/android/geckoview_example/build.gradle
mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/ApplicationTest.java
mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/GeckoViewActivityTest.java
mobile/android/geckoview_example/src/test/java/org/mozilla/geckoview_example/ExampleUnitTest.java
--- a/build.gradle
+++ b/build.gradle
@@ -106,16 +106,19 @@ afterEvaluate {
                 // Add compiler args for all code except third-party code.
                 options.compilerArgs += [
                     // Turn on all warnings, except...
                     "-Xlint:all",
                     // Deprecation, because we do use deprecated API for compatibility.
                     "-Xlint:-deprecation",
                     // Serial, because we don't use Java serialization.
                     "-Xlint:-serial",
+                    // Classfile, because javac has a bug with MethodParameters attributes
+                    // with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
+                    "-Xlint:-classfile",
                     // Turn all remaining warnings into errors,
                     // unless marked by @SuppressWarnings.
                     "-Werror"]
             }
             if (project.name == 'app') {
                 tasks.withType(JavaCompile) {
                     // Turn off classfile warnings because upon updating to play services 15.0.0
                     // a warning is being thrown from play-services-base which fails the build
--- a/mobile/android/geckoview/build.gradle
+++ b/mobile/android/geckoview/build.gradle
@@ -195,19 +195,19 @@ dependencies {
     implementation "com.android.support:palette-v7:$support_library_version"
 
     testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
     testImplementation 'junit:junit:4.12'
     testImplementation 'org.robolectric:robolectric:3.8'
     testImplementation 'org.mockito:mockito-core:1.10.19'
 
     androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
-    androidTestImplementation 'com.android.support.test:runner:0.5'
-    androidTestImplementation 'com.android.support.test:rules:0.5'
-    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
+    androidTestImplementation 'com.android.support.test:runner:1.0.2'
+    androidTestImplementation 'com.android.support.test:rules:1.0.2'
+    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
     androidTestImplementation "com.android.support:support-annotations:$support_library_version"
 }
 
 apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"
 
 android.libraryVariants.all { variant ->
     // See the notes in mobile/android/app/build.gradle for details on including
     // Gecko binaries and the Omnijar.
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoResultTest.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoResultTest.java
@@ -24,19 +24,16 @@ import static org.junit.Assert.assertTha
 @RunWith(AndroidJUnit4.class)
 @MediumTest
 public class GeckoResultTest {
     private static final long DEFAULT_TIMEOUT = 5000;
 
     private static class MockException extends RuntimeException {
     }
 
-    @Rule
-    public UiThreadTestRule mUiThreadTestRule = new UiThreadTestRule();
-
     private boolean mDone;
 
     private void waitUntilDone() {
         assertThat("We should not be done", mDone, equalTo(false));
 
         while (!mDone) {
             UiThreadUtils.loopUntilIdle(DEFAULT_TIMEOUT);
         }
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
@@ -2,17 +2,16 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.geckoview.test.rule;
 
 import org.mozilla.gecko.gfx.GeckoDisplay;
 import org.mozilla.geckoview.BuildConfig;
-import org.mozilla.geckoview.GeckoResponse;
 import org.mozilla.geckoview.GeckoResult;
 import org.mozilla.geckoview.GeckoResult.OnExceptionListener;
 import org.mozilla.geckoview.GeckoResult.OnValueListener;
 import org.mozilla.geckoview.GeckoRuntime;
 import org.mozilla.geckoview.GeckoRuntimeSettings;
 import org.mozilla.geckoview.GeckoSession;
 import org.mozilla.geckoview.GeckoSessionSettings;
 import org.mozilla.geckoview.SessionTextInput;
@@ -27,37 +26,33 @@ import static org.hamcrest.Matchers.*;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
 import org.hamcrest.Matcher;
 
 import org.json.JSONObject;
 
 import org.junit.rules.ErrorCollector;
+import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
 import android.app.Instrumentation;
 import android.graphics.Point;
 import android.graphics.SurfaceTexture;
 import android.net.LocalSocketAddress;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Debug;
-import android.os.Handler;
 import android.os.Looper;
-import android.os.Message;
-import android.os.MessageQueue;
 import android.os.Process;
 import android.os.SystemClock;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.test.InstrumentationRegistry;
-import android.support.test.rule.UiThreadTestRule;
-import android.util.Log;
 import android.util.Pair;
 import android.view.MotionEvent;
 import android.view.Surface;
 
 import java.io.File;
 import java.lang.annotation.Annotation;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
@@ -72,28 +67,29 @@ import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.regex.Pattern;
 
 import kotlin.jvm.JvmClassMappingKt;
 import kotlin.reflect.KClass;
 
 /**
  * TestRule that, for each test, sets up a GeckoSession, runs the test on the UI thread,
  * and tears down the GeckoSession at the end of the test. The rule also provides methods
  * for waiting on particular callbacks to be called, and methods for asserting that
  * callbacks are called in the proper order.
  */
-public class GeckoSessionTestRule extends UiThreadTestRule {
+public class GeckoSessionTestRule implements TestRule {
     private static final String LOGTAG = "GeckoSessionTestRule";
 
     private static final long DEFAULT_TIMEOUT_MILLIS = 10000;
     private static final long DEFAULT_ARM_DEVICE_TIMEOUT_MILLIS = 30000;
     private static final long DEFAULT_ARM_EMULATOR_TIMEOUT_MILLIS = 120000;
     private static final long DEFAULT_X86_DEVICE_TIMEOUT_MILLIS = 30000;
     private static final long DEFAULT_X86_EMULATOR_TIMEOUT_MILLIS = 5000;
     private static final long DEFAULT_IDE_DEBUG_TIMEOUT_MILLIS = 86400000;
@@ -1473,33 +1469,45 @@ public class GeckoSessionTestRule extend
         mLastWaitEnd = 0;
         mTimeoutMillis = 0;
         mRDPTabs = null;
         mRDPChromeProcess = null;
     }
 
     @Override
     public Statement apply(final Statement base, final Description description) {
-        return super.apply(new Statement() {
+        return new Statement() {
             @Override
             public void evaluate() throws Throwable {
-                try {
-                    prepareStatement(description);
-                    base.evaluate();
-                    performTestEndCheck();
-                } finally {
-                    cleanupStatement();
+                final AtomicReference<Throwable> exceptionRef = new AtomicReference<>();
+                mInstrumentation.runOnMainSync(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            prepareStatement(description);
+                            base.evaluate();
+                            performTestEndCheck();
+                        } catch (Throwable t) {
+                            exceptionRef.set(t);
+                        } finally {
+                            try {
+                                cleanupStatement();
+                            } catch (Throwable t) {
+                                exceptionRef.set(t);
+                            }
+                        }
+                    }
+                });
+
+                Throwable throwable = exceptionRef.get();
+                if (throwable != null) {
+                    throw throwable;
                 }
             }
-        }, description);
-    }
-
-    @Override
-    protected boolean shouldRunOnUiThread(final Description description) {
-        return true;
+        };
     }
 
     /**
      * Wait until a page load has finished on any session. A session must have started a
      * page load since the last wait, or this method will wait indefinitely.
      */
     public void waitForPageStop() {
         waitForPageStop(/* session */ null);
--- a/mobile/android/geckoview_example/build.gradle
+++ b/mobile/android/geckoview_example/build.gradle
@@ -10,36 +10,27 @@ android {
     defaultConfig {
         targetSdkVersion project.ext.targetSdkVersion
         minSdkVersion project.ext.minSdkVersion
         manifestPlaceholders = project.ext.manifestPlaceholders
 
         applicationId "org.mozilla.geckoview_example"
         versionCode 1
         versionName "1.0"
-        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
     }
 
     buildTypes {
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
     }
 
     project.configureProductFlavors.delegate = it
     project.configureProductFlavors()
 }
 
 dependencies {
-    testImplementation 'junit:junit:4.12'
-
     implementation "com.android.support:support-annotations:$support_library_version"
     implementation "com.android.support:appcompat-v7:$support_library_version"
 
-    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
-    androidTestImplementation 'com.android.support.test:runner:0.5'
-    // Not defining this library again results in test-app assuming 23.1.1, and the following errors:
-    // "Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (23.1.1) differ."
-    androidTestImplementation "com.android.support:support-annotations:$support_library_version"
-
     implementation project(path: ':geckoview')
 }
deleted file mode 100644
--- a/mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.mozilla.geckoview_example;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
- */
-public class ApplicationTest extends ApplicationTestCase<Application> {
-    public ApplicationTest() {
-        super(Application.class);
-    }
-}
\ No newline at end of file
deleted file mode 100644
--- a/mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/GeckoViewActivityTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.geckoview_example;
-
-import android.support.test.rule.ActivityTestRule;
-import android.support.test.runner.AndroidJUnit4;
-
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-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;
-
-@RunWith(AndroidJUnit4.class)
-public class GeckoViewActivityTest {
-
-    @Rule
-    public ActivityTestRule<GeckoViewActivity> mActivityRule = new ActivityTestRule<>(GeckoViewActivity.class);
-
-    @Test
-    public void testA() throws InterruptedException {
-        onView(withId(R.id.gecko_view))
-                .check(matches(isDisplayed()));
-    }
-}
deleted file mode 100644
--- a/mobile/android/geckoview_example/src/test/java/org/mozilla/geckoview_example/ExampleUnitTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.mozilla.geckoview_example;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * To work on unit tests, switch the Test Artifact in the Build Variants view.
- */
-public class ExampleUnitTest {
-    @Test
-    public void addition_isCorrect() throws Exception {
-        assertEquals(4, 2 + 2);
-    }
-}
\ No newline at end of file