Commit 47af1c51 authored by Ben Joyce's avatar Ben Joyce Committed by Commit Bot

Update robolectric to 4.3

Needed to add some local modifications as seen in the README.
Namely added META-INF files and need to remove Jellybean from
SDKprovider. Also needed to use our customshadowasync.

Two test sets (platofrmsensor and NFC) needed to have sdk=21 set,
otherwise it uses sdk=19 and it complains the methods that we're
trying to mock don't exist.

GtestComputer needed to be changed as the test seems to no longer
exist after running, so can't query it for the description as was
done before.

Update androidx.test libraries to:
androidx.test:core:1.2.0
androidx.test:monitor:1.2.0
androidx.test:rules:1.2.0
androidx.test:runner:1.2.0
androidx.test.ext:junit:1.1.1

Bug: 965286
Change-Id: Ia0fe69a788d2662b85c4ce95a0ccb8b987a98510
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1966580
Commit-Queue: benjamin joyce <bjoyce@google.com>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740865}
parent 79d8c0af
......@@ -1356,7 +1356,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/robolectric',
'version': '1KXoOiNP1a_uZNdM2ybWKwAQNow1dHTXTig-ZK4Xgq8C',
'version': 'iC6RDM5EH3GEAzR-1shW_Mg0FeeNE5shq1okkFfuuNQC',
},
],
'condition': 'checkout_android',
......@@ -1364,7 +1364,7 @@ deps = {
},
'src/third_party/robolectric/robolectric': {
'url': Var('chromium_git') + '/external/robolectric.git' + '@' + '3d6dcabf5521e028c8efc2778ab6bd8c7b6d923c',
'url': Var('chromium_git') + '/external/robolectric.git' + '@' + 'f2df0efb033bb402399ebfb9bf58aefee5cced05',
'condition': 'checkout_android',
},
......@@ -2068,7 +2068,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/android_deps/libs/androidx_test_core',
'version': 'version:1.0.0-cr0',
'version': 'version:1.2.0-cr0',
},
],
'condition': 'checkout_android',
......@@ -2079,7 +2079,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/android_deps/libs/androidx_test_ext_junit',
'version': 'version:1.0.0-cr0',
'version': 'version:1.1.1-cr0',
},
],
'condition': 'checkout_android',
......@@ -2090,7 +2090,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/android_deps/libs/androidx_test_monitor',
'version': 'version:1.1.0-cr0',
'version': 'version:1.2.0-cr0',
},
],
'condition': 'checkout_android',
......@@ -2101,7 +2101,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/android_deps/libs/androidx_test_rules',
'version': 'version:1.1.0-cr0',
'version': 'version:1.2.0-cr0',
},
],
'condition': 'checkout_android',
......@@ -2112,7 +2112,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/android_deps/libs/androidx_test_runner',
'version': 'version:1.1.0-cr0',
'version': 'version:1.2.0-cr0',
},
],
'condition': 'checkout_android',
......
......@@ -94,11 +94,7 @@ public class WebappDataStorageTest {
@Override
public void onDataRetrieved(Bitmap actual) {
mCallbackCalled = true;
// TODO(lalitm) - once the Robolectric bug is fixed change to
// assertTrue(expected.sameAs(actual)).
// See bitmapEquals(Bitmap, Bitmap) for more information.
assertTrue(bitmapEquals(expected, actual));
assertTrue(expected.sameAs(actual));
}
});
BackgroundShadowAsyncTask.runBackgroundTasks();
......@@ -348,23 +344,6 @@ public class WebappDataStorageTest {
return storage;
}
// TODO(lalitm) - There seems to be a bug in Robolectric where a Bitmap
// produced from a byte stream is hardcoded to be a 100x100 bitmap with
// ARGB_8888 pixel format. Because of this, we need to work around the
// equality check of bitmaps. Remove this once the bug is fixed.
private static boolean bitmapEquals(Bitmap expected, Bitmap actual) {
if (actual.getWidth() != 100) return false;
if (actual.getHeight() != 100) return false;
if (!actual.getConfig().equals(Bitmap.Config.ARGB_8888)) return false;
for (int i = 0; i < actual.getWidth(); i++) {
for (int j = 0; j < actual.getHeight(); j++) {
if (actual.getPixel(i, j) != 0) return false;
}
}
return true;
}
private static Bitmap createBitmap() {
return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
}
......
......@@ -6,7 +6,7 @@ package org.chromium.webapk.shell_apk;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowAsyncTask;
import org.robolectric.shadows.ShadowLegacyAsyncTask;
import java.util.concurrent.Executor;
......@@ -21,7 +21,7 @@ import java.util.concurrent.Executor;
@SuppressWarnings("NoAndroidAsyncTaskCheck")
@Implements(android.os.AsyncTask.class)
public class CustomAndroidOsShadowAsyncTask<Params, Progress, Result>
extends ShadowAsyncTask<Params, Progress, Result> {
extends ShadowLegacyAsyncTask<Params, Progress, Result> {
@Override
@Implementation
public final android.os.AsyncTask<Params, Progress, Result> executeOnExecutor(
......
......@@ -50,7 +50,7 @@ import java.util.List;
* Unit tests for PlatformSensor and PlatformSensorProvider.
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@Config(sdk = 21, manifest = Config.NONE)
public class PlatformSensorAndProviderTest {
@Mock
private Context mContext;
......
......@@ -68,7 +68,7 @@ import java.util.Arrays;
* Unit tests for NfcImpl and NdefMessageUtils classes.
*/
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@Config(sdk = 21, manifest = Config.NONE)
public class NFCTest {
private TestNfcDelegate mDelegate;
private int mNextWatchId;
......
......@@ -43,12 +43,13 @@ public class GtestComputer extends Computer {
@Override
public void run(RunNotifier notifier) {
long startTimeMillis = System.currentTimeMillis();
mLogger.testCaseStarted(mRunner.getDescription(),
mRunner.getDescription().testCount());
// Robolectric 4.3 clears testExecutionContext after running so
// need to store data before running.
Description desc = mRunner.getDescription();
int testcount = mRunner.getDescription().testCount();
mLogger.testCaseStarted(desc, testcount);
mRunner.run(notifier);
mLogger.testCaseFinished(mRunner.getDescription(),
mRunner.getDescription().testCount(),
System.currentTimeMillis() - startTimeMillis);
mLogger.testCaseFinished(desc, testcount, System.currentTimeMillis() - startTimeMillis);
}
@Override
......
......@@ -432,7 +432,7 @@ android_aar_prebuilt("androidx_swiperefreshlayout_swiperefreshlayout_java") {
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
android_aar_prebuilt("androidx_test_core_java") {
aar_path = "libs/androidx_test_core/core-1.0.0.aar"
aar_path = "libs/androidx_test_core/core-1.2.0.aar"
info_path = "libs/androidx_test_core/androidx_test_core.info"
testonly = true
deps = [
......@@ -445,16 +445,22 @@ android_aar_prebuilt("androidx_test_core_java") {
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
android_aar_prebuilt("androidx_test_ext_junit_java") {
aar_path = "libs/androidx_test_ext_junit/junit-1.0.0.aar"
aar_path = "libs/androidx_test_ext_junit/junit-1.1.1.aar"
info_path = "libs/androidx_test_ext_junit/androidx_test_ext_junit.info"
testonly = true
deps = [ "//third_party/junit:junit" ]
skip_jetify = true
deps = [
":androidx_annotation_annotation_java",
":androidx_test_core_java",
":androidx_test_monitor_java",
"//third_party/junit:junit",
]
}
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
android_aar_prebuilt("androidx_test_monitor_java") {
aar_path = "libs/androidx_test_monitor/monitor-1.1.0.aar"
aar_path = "libs/androidx_test_monitor/monitor-1.2.0.aar"
info_path = "libs/androidx_test_monitor/androidx_test_monitor.info"
testonly = true
deps = [ ":androidx_annotation_annotation_java" ]
......@@ -463,7 +469,7 @@ android_aar_prebuilt("androidx_test_monitor_java") {
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
android_aar_prebuilt("androidx_test_rules_java") {
aar_path = "libs/androidx_test_rules/rules-1.1.0.aar"
aar_path = "libs/androidx_test_rules/rules-1.2.0.aar"
info_path = "libs/androidx_test_rules/androidx_test_rules.info"
testonly = true
deps = [ ":androidx_test_runner_java" ]
......@@ -477,7 +483,7 @@ android_aar_prebuilt("androidx_test_rules_java") {
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
android_aar_prebuilt("androidx_test_runner_java") {
aar_path = "libs/androidx_test_runner/runner-1.1.0.aar"
aar_path = "libs/androidx_test_runner/runner-1.2.0.aar"
info_path = "libs/androidx_test_runner/androidx_test_runner.info"
testonly = true
deps = [
......
......@@ -146,11 +146,11 @@ dependencies {
buildCompile "commons-cli:commons-cli:1.3.1"
// testCompile targets have test_only = true.
testCompile "androidx.test:core:1.0.0"
testCompile "androidx.test:monitor:1.1.0"
testCompile "androidx.test:rules:1.1.0"
testCompile "androidx.test:runner:1.1.0"
testCompile "androidx.test.ext:junit:1.0.0"
testCompile "androidx.test:core:1.2.0"
testCompile "androidx.test:monitor:1.2.0"
testCompile "androidx.test:rules:1.2.0"
testCompile "androidx.test:runner:1.2.0"
testCompile "androidx.test.ext:junit:1.1.1"
testCompile "androidx.test.uiautomator:uiautomator:2.2.0"
testCompile "com.googlecode.java-diff-utils:diffutils:1.3.0"
}
......
Name: AndroidX Test Library
Short Name: core
URL: https://developer.android.com/testing
Version: 1.0.0
Version: 1.2.0
License: Apache Version 2.0
License File: NOT_SHIPPED
Security Critical: no
......
......@@ -6,8 +6,8 @@ assets = [ ]
has_classes_jar = true
has_native_libraries = false
has_proguard_flags = false
has_r_text_file = true
has_r_text_file = false
is_manifest_empty = false
resources = [ "res/values/values.xml" ]
resources = [ ]
subjar_tuples = [ ]
subjars = [ ]
......@@ -3,8 +3,8 @@
# found in the LICENSE file.
# To create CIPD package run the following command.
# cipd create --pkg-def cipd.yaml -tag version:1.0.0-cr0
# cipd create --pkg-def cipd.yaml -tag version:1.2.0-cr0
package: chromium/third_party/android_deps/libs/androidx_test_core
description: "AndroidX Test Library"
data:
- file: core-1.0.0.aar
- file: core-1.2.0.aar
Name: AndroidX Test Library
Short Name: junit
URL: https://developer.android.com/testing
Version: 1.0.0
Version: 1.1.1
License: Apache Version 2.0
License File: NOT_SHIPPED
Security Critical: no
......
......@@ -3,8 +3,8 @@
# found in the LICENSE file.
# To create CIPD package run the following command.
# cipd create --pkg-def cipd.yaml -tag version:1.0.0-cr0
# cipd create --pkg-def cipd.yaml -tag version:1.1.1-cr0
package: chromium/third_party/android_deps/libs/androidx_test_ext_junit
description: "AndroidX Test Library"
data:
- file: junit-1.0.0.aar
- file: junit-1.1.1.aar
Name: AndroidX Test Library
Short Name: monitor
URL: https://developer.android.com/testing
Version: 1.1.0
Version: 1.2.0
License: Apache Version 2.0
License File: NOT_SHIPPED
Security Critical: no
......
......@@ -3,8 +3,8 @@
# found in the LICENSE file.
# To create CIPD package run the following command.
# cipd create --pkg-def cipd.yaml -tag version:1.1.0-cr0
# cipd create --pkg-def cipd.yaml -tag version:1.2.0-cr0
package: chromium/third_party/android_deps/libs/androidx_test_monitor
description: "AndroidX Test Library"
data:
- file: monitor-1.1.0.aar
- file: monitor-1.2.0.aar
Name: AndroidX Test Library
Short Name: rules
URL: https://developer.android.com/testing
Version: 1.1.0
Version: 1.2.0
License: Apache Version 2.0
License File: NOT_SHIPPED
Security Critical: no
......
......@@ -3,8 +3,8 @@
# found in the LICENSE file.
# To create CIPD package run the following command.
# cipd create --pkg-def cipd.yaml -tag version:1.1.0-cr0
# cipd create --pkg-def cipd.yaml -tag version:1.2.0-cr0
package: chromium/third_party/android_deps/libs/androidx_test_rules
description: "AndroidX Test Library"
data:
- file: rules-1.1.0.aar
- file: rules-1.2.0.aar
Name: AndroidX Test Library
Short Name: runner
URL: https://developer.android.com/testing
Version: 1.1.0
Version: 1.2.0
License: Apache Version 2.0
License File: NOT_SHIPPED
Security Critical: no
......
......@@ -3,8 +3,8 @@
# found in the LICENSE file.
# To create CIPD package run the following command.
# cipd create --pkg-def cipd.yaml -tag version:1.1.0-cr0
# cipd create --pkg-def cipd.yaml -tag version:1.2.0-cr0
package: chromium/third_party/android_deps/libs/androidx_test_runner
description: "AndroidX Test Library"
data:
- file: runner-1.1.0.aar
- file: runner-1.2.0.aar
This diff is collapsed.
agrieve@chromium.org
bjoyce@chromium.org
jbudorick@chromium.org
yolandyan@chromium.org
# COMPONENT: Test>Android
Name: Robolectric
URL: http://robolectric.org
Version: 4.0.1
Version: 4.3.1
License: Apache 2.0
License File: NOT_SHIPPED
Security Critical: no
......@@ -15,13 +15,17 @@ Local Modifications:
needing maven third_party libraries.
- Added custom_asynctask folder to have workable copies of shadows required
for our own implementation of AsyncTask
- Added DefaultSdkProvider as a local file with Jellybean references removed.
How To Update:
- Visit the migration guide to see which APIs changed and need updating.
http://robolectric.org/migrating/
- Have git admins create a branch for the version in
https://chromium.googlesource.com/external/robolectric and set DEPS to the
revision.
- Read through the build.gradle files and make sure all of the depenencies
in our BUILD.gn file are correct.
- Update file names in our BUILD.gn file.
- Update DEPS to new Robolectric revision.
- Update the source files and add their names in our BUILD.gn file.
- Update local/robolectric/src/main/resources/robolectric-version.properties
to the new Robolectric version.
- Update CIPD package to include new Robolectric Android libraries.
- Update CIPD package to include the new Robolectric Android libraries file
and replace the references to the previous ones with the new one.
......@@ -13,3 +13,5 @@ data:
- file: lib/android-all-8.0.0_r4-robolectric-r1.jar
- file: lib/android-all-8.1.0-robolectric-4611349.jar
- file: lib/android-all-9-robolectric-4913185-2.jar
- file: lib/android-all-10-robolectric-5803371.jar
package org.robolectric.plugins;
import static android.os.Build.VERSION_CODES.KITKAT;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1;
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.N;
import static android.os.Build.VERSION_CODES.N_MR1;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.O_MR1;
import static android.os.Build.VERSION_CODES.P;
import static android.os.Build.VERSION_CODES.Q;
import com.google.auto.service.AutoService;
import com.google.common.base.Preconditions;
import org.robolectric.internal.dependency.DependencyJar;
import org.robolectric.internal.dependency.DependencyResolver;
import org.robolectric.pluginapi.Sdk;
import org.robolectric.pluginapi.SdkProvider;
import org.robolectric.util.Util;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import java.util.SortedMap;
import java.util.TreeMap;
import javax.annotation.Priority;
import javax.inject.Inject;
/**
* Robolectric's default {@link SdkProvider}.
*
* The list of SDKs is hard-coded. SDKs are obtained from the provided {@link DependencyResolver}.
*/
@SuppressWarnings("NewApi")
@AutoService(SdkProvider.class)
@Priority(Integer.MIN_VALUE)
public class DefaultSdkProvider implements SdkProvider {
private static final int RUNNING_JAVA_VERSION = Util.getJavaVersion();
private final DependencyResolver dependencyResolver;
private final SortedMap<Integer, Sdk> knownSdks;
@Inject
public DefaultSdkProvider(DependencyResolver dependencyResolver) {
this.dependencyResolver = Preconditions.checkNotNull(dependencyResolver);
TreeMap<Integer, Sdk> tmpKnownSdks = new TreeMap<>();
populateSdks(tmpKnownSdks);
this.knownSdks = Collections.unmodifiableSortedMap(tmpKnownSdks);
}
protected void populateSdks(TreeMap<Integer, Sdk> knownSdks) {
// Chrome's robolectric only goes back to 4.4, so remove these.
// knownSdks.put(JELLY_BEAN, new DefaultSdk(JELLY_BEAN, "4.1.2_r1", "r1", "REL", 8));
// knownSdks.put(JELLY_BEAN_MR1, new DefaultSdk(JELLY_BEAN_MR1, "4.2.2_r1.2", "r1", "REL",
// 8)); knownSdks.put(JELLY_BEAN_MR2, new DefaultSdk(JELLY_BEAN_MR2, "4.3_r2", "r1", "REL",
// 8));
knownSdks.put(KITKAT, new DefaultSdk(KITKAT, "4.4_r1", "r2", "REL", 8));
knownSdks.put(LOLLIPOP, new DefaultSdk(LOLLIPOP, "5.0.2_r3", "r0", "REL", 8));
knownSdks.put(LOLLIPOP_MR1, new DefaultSdk(LOLLIPOP_MR1, "5.1.1_r9", "r2", "REL", 8));
knownSdks.put(M, new DefaultSdk(M, "6.0.1_r3", "r1", "REL", 8));
knownSdks.put(N, new DefaultSdk(N, "7.0.0_r1", "r1", "REL", 8));
knownSdks.put(N_MR1, new DefaultSdk(N_MR1, "7.1.0_r7", "r1", "REL", 8));
knownSdks.put(O, new DefaultSdk(O, "8.0.0_r4", "r1", "REL", 8));
knownSdks.put(O_MR1, new DefaultSdk(O_MR1, "8.1.0", "4611349", "REL", 8));
knownSdks.put(P, new DefaultSdk(P, "9", "4913185-2", "REL", 8));
knownSdks.put(Q, new DefaultSdk(Q, "10", "5803371", "REL", 9));
}
@Override
public Collection<Sdk> getSdks() {
return Collections.unmodifiableCollection(knownSdks.values());
}
/** Represents an Android SDK stored at Maven Central. */
public class DefaultSdk extends Sdk {
private final String androidVersion;
private final String robolectricVersion;
private final String codeName;
private final int requiredJavaVersion;
private Path jarPath;
public DefaultSdk(int apiLevel, String androidVersion, String robolectricVersion,
String codeName, int requiredJavaVersion) {
super(apiLevel);
this.androidVersion = androidVersion;
this.robolectricVersion = robolectricVersion;
this.codeName = codeName;
this.requiredJavaVersion = requiredJavaVersion;
Preconditions.checkNotNull(dependencyResolver);
}
@Override
public String getAndroidVersion() {
return androidVersion;
}
@Override
public String getAndroidCodeName() {
return codeName;
}
private DependencyJar getAndroidSdkDependency() {
if (!isSupported()) {
throw new UnsupportedClassVersionError(getUnsupportedMessage());
}
return new DependencyJar("org.robolectric", "android-all",
getAndroidVersion() + "-robolectric-" + robolectricVersion, null);
}
@Override
public synchronized Path getJarPath() {
if (jarPath == null) {
URL url = dependencyResolver.getLocalArtifactUrl(getAndroidSdkDependency());
jarPath = Util.pathFrom(url);
if (!Files.exists(jarPath)) {
throw new RuntimeException(
"SDK " + getApiLevel() + " jar not present at " + jarPath);
}
}
return jarPath;
}
@Override
public boolean isSupported() {
return requiredJavaVersion <= RUNNING_JAVA_VERSION;
}
@Override
public String getUnsupportedMessage() {
return String.format(Locale.getDefault(),
"Android SDK %d requires Java %d (have Java %d)", getApiLevel(),
requiredJavaVersion, RUNNING_JAVA_VERSION);
}
}
}
org.robolectric.plugins.ConfigConfigurer
org.robolectric.plugins.LooperModeConfigurer
org.robolectric.plugins.TextLayoutModeConfigurer
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment