Get basic tests working with ActivityScenario and manifest
Test: atest MemtagPreferenceControllerTest Bug: 302146641 Change-Id: I06d94ae151cadd8498b009886ba7d4bd888911cc
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
package="com.android.settings">
|
package="com.android.settings">
|
||||||
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
|
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
|
||||||
|
|
||||||
<application/>
|
<application>
|
||||||
|
<activity android:name="com.android.settings.security.TestActivity" android:exported="true" />
|
||||||
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@@ -24,11 +24,9 @@ import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.fragment.app.FragmentContainerView;
|
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||||
import androidx.test.rule.ActivityTestRule;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||||
@@ -37,11 +35,11 @@ import com.android.settingslib.RestrictedSwitchPreference;
|
|||||||
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
|
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowSystemProperties;
|
import org.robolectric.shadows.ShadowSystemProperties;
|
||||||
|
|
||||||
@@ -57,8 +55,8 @@ public class MemtagPreferenceControllerTest {
|
|||||||
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_supported";
|
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_supported";
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ActivityTestRule<TestActivity> mActivityTestRule =
|
public ActivityScenarioRule<TestActivity> mActivityScenario =
|
||||||
new ActivityTestRule<>(TestActivity.class);
|
new ActivityScenarioRule<>(TestActivity.class);
|
||||||
|
|
||||||
private MemtagPage mMemtagPage;
|
private MemtagPage mMemtagPage;
|
||||||
private MemtagPreferenceController mController;
|
private MemtagPreferenceController mController;
|
||||||
@@ -70,17 +68,18 @@ public class MemtagPreferenceControllerTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
|
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
|
||||||
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mMemtagPage = new MemtagPage();
|
mMemtagPage = new MemtagPage();
|
||||||
mActivity = mActivityTestRule.getActivity();
|
System.out.println("Activity: " + mActivity);
|
||||||
mActivity
|
mActivityScenario.getScenario().onActivity(a -> {
|
||||||
.getSupportFragmentManager()
|
a.getSupportFragmentManager()
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.add(TestActivity.CONTAINER_VIEW_ID, mMemtagPage)
|
.add(TestActivity.CONTAINER_VIEW_ID, mMemtagPage)
|
||||||
.commit();
|
.commitNow();
|
||||||
mController = new MemtagPreferenceController(mContext, FRAGMENT_TAG);
|
mController = new MemtagPreferenceController(a, FRAGMENT_TAG);
|
||||||
mController.setFragment(mMemtagPage);
|
mController.setFragment(mMemtagPage);
|
||||||
|
});
|
||||||
|
System.out.println("Committed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -135,6 +134,7 @@ public class MemtagPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void setChecked_isChecked_doesNotShowDialog() {
|
public void setChecked_isChecked_doesNotShowDialog() {
|
||||||
ZygoteShadow.setSupportsMemoryTagging(false);
|
ZygoteShadow.setSupportsMemoryTagging(false);
|
||||||
mController.setChecked(false);
|
mController.setChecked(false);
|
||||||
@@ -142,6 +142,7 @@ public class MemtagPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void setChecked_isUnchecked_doesNotShowDialog() {
|
public void setChecked_isUnchecked_doesNotShowDialog() {
|
||||||
ZygoteShadow.setSupportsMemoryTagging(true);
|
ZygoteShadow.setSupportsMemoryTagging(true);
|
||||||
mController.setChecked(true);
|
mController.setChecked(true);
|
||||||
@@ -155,18 +156,4 @@ public class MemtagPreferenceControllerTest {
|
|||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
assertThat(preference.isDisabledByAdmin()).isTrue();
|
assertThat(preference.isDisabledByAdmin()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TestActivity extends FragmentActivity {
|
|
||||||
|
|
||||||
private static final int CONTAINER_VIEW_ID = 1234;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle bundle) {
|
|
||||||
super.onCreate(bundle);
|
|
||||||
|
|
||||||
FragmentContainerView contentView = new FragmentContainerView(this);
|
|
||||||
contentView.setId(CONTAINER_VIEW_ID);
|
|
||||||
setContentView(contentView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.security;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.fragment.app.FragmentContainerView;
|
||||||
|
|
||||||
|
public final class TestActivity extends FragmentActivity {
|
||||||
|
|
||||||
|
static final int CONTAINER_VIEW_ID = 1234;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle bundle) {
|
||||||
|
super.onCreate(bundle);
|
||||||
|
|
||||||
|
FragmentContainerView contentView = new FragmentContainerView(this);
|
||||||
|
contentView.setId(CONTAINER_VIEW_ID);
|
||||||
|
setContentView(contentView);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user