Skip to content

Commit

Permalink
Clear InputMethodManager.sInstance for SDK > P
Browse files Browse the repository at this point in the history
This fixes a minor case of test pollution when a test interacts with a
TextView.

InputMethodManager.sInstance still gets populated in SDK > P, and it may
contain a reference to a ViewRootImpl (mCurRootView), which causes an Activity
to leak across tests.

PiperOrigin-RevId: 411153919
  • Loading branch information
hoisie authored and copybara-robolectric committed Nov 22, 2021
1 parent bda68fd commit f0d451b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Manifest for ATSL integration tests
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.robolectric.integration.axt">
<uses-sdk android:targetSdkVersion="28"/>

<uses-permission android:name="android.permission.READ_CONTACTS"/>

<application>
<activity android:name="org.robolectric.integrationtests.axt.EspressoActivity"
android:label="Activity Label"
android:exported="true" />
<activity android:name="org.robolectric.integrationtests.axt.ActivityWithPlatformMenu"
android:exported="true">
</activity>
<activity android:name="org.robolectric.integrationtests.axt.ActivityWithAppCompatMenu"
android:exported="true"
android:theme="@style/Theme.AppCompat" />
<activity android:name="org.robolectric.integrationtests.axt.AppCompatActivityWithToolbarMenu"
android:exported="true"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity android:name="org.robolectric.integrationtests.axt.ActivityWithSwitchCompat"
android:exported="true"
android:theme="@style/Theme.AppCompat" />
<activity android:name="org.robolectric.integrationtests.axt.StubBrowserActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.robolectric.integrationtests.axt">

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="27"/>

<application>
<activity android:name=".EspressoActivity" android:exported="true"/>
</application>

<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="org.robolectric.integration.axt"/>

</manifest>
Expand Up @@ -267,9 +267,10 @@ public static void reset() {
_InputMethodManager_ _reflector = reflector(_InputMethodManager_.class);
if (apiLevel <= JELLY_BEAN_MR1) {
_reflector.setMInstance(null);
} else if (apiLevel <= P) {
_reflector.setInstance(null);
} else {
_reflector.setInstance(null);
}
if (apiLevel > P) {
_reflector.getInstanceMap().clear();
}
}
Expand Down

0 comments on commit f0d451b

Please sign in to comment.