From e641866f272fe10870d088d7775b6d248f5ffc20 Mon Sep 17 00:00:00 2001 From: James Willcox Date: Thu, 23 Aug 2018 13:12:20 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- build.gradle | 3 ++ mobile/android/geckoview/build.gradle | 6 +-- .../geckoview/test/GeckoResultTest.java | 3 -- .../test/rule/GeckoSessionTestRule.java | 48 +++++++++++-------- mobile/android/geckoview_example/build.gradle | 9 ---- .../geckoview_example/ApplicationTest.java | 13 ----- .../GeckoViewActivityTest.java | 32 ------------- .../geckoview_example/ExampleUnitTest.java | 15 ------ 8 files changed, 34 insertions(+), 95 deletions(-) delete mode 100644 mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/ApplicationTest.java delete mode 100644 mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/GeckoViewActivityTest.java delete mode 100644 mobile/android/geckoview_example/src/test/java/org/mozilla/geckoview_example/ExampleUnitTest.java diff --git a/build.gradle b/build.gradle index 9aa1d50da22e..825bdb4c3944 100644 --- a/build.gradle +++ b/build.gradle @@ -111,6 +111,9 @@ afterEvaluate { "-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"] diff --git a/mobile/android/geckoview/build.gradle b/mobile/android/geckoview/build.gradle index 95eceb2647e6..08965e054299 100644 --- a/mobile/android/geckoview/build.gradle +++ b/mobile/android/geckoview/build.gradle @@ -200,9 +200,9 @@ dependencies { 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" } diff --git 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 index 954730c0e8e1..74a90b74ae71 100644 --- 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 @@ -29,9 +29,6 @@ public class GeckoResultTest { private static class MockException extends RuntimeException { } - @Rule - public UiThreadTestRule mUiThreadTestRule = new UiThreadTestRule(); - private boolean mDone; private void waitUntilDone() { diff --git 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 index 54019b3eef2c..1b4bf0de6292 100644 --- 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 @@ -7,7 +7,6 @@ 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; @@ -32,6 +31,7 @@ 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; @@ -42,17 +42,12 @@ 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; @@ -77,6 +72,7 @@ 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; @@ -88,7 +84,7 @@ import kotlin.reflect.KClass; * 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; @@ -1478,23 +1474,35 @@ public class GeckoSessionTestRule extends UiThreadTestRule { @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 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; + }; } /** diff --git a/mobile/android/geckoview_example/build.gradle b/mobile/android/geckoview_example/build.gradle index d3a0ad8e127c..57942efbc419 100644 --- a/mobile/android/geckoview_example/build.gradle +++ b/mobile/android/geckoview_example/build.gradle @@ -15,7 +15,6 @@ android { applicationId "org.mozilla.geckoview_example" versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -30,16 +29,8 @@ android { } 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') } diff --git a/mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/ApplicationTest.java b/mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/ApplicationTest.java deleted file mode 100644 index 88630b1974d2..000000000000 --- 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; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/GeckoViewActivityTest.java b/mobile/android/geckoview_example/src/androidTest/java/org/mozilla/geckoview_example/GeckoViewActivityTest.java deleted file mode 100644 index 85ba6d068ced..000000000000 --- 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 mActivityRule = new ActivityTestRule<>(GeckoViewActivity.class); - - @Test - public void testA() throws InterruptedException { - onView(withId(R.id.gecko_view)) - .check(matches(isDisplayed())); - } -} diff --git a/mobile/android/geckoview_example/src/test/java/org/mozilla/geckoview_example/ExampleUnitTest.java b/mobile/android/geckoview_example/src/test/java/org/mozilla/geckoview_example/ExampleUnitTest.java deleted file mode 100644 index 14f82340be3c..000000000000 --- 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