Loading packages/SystemUI/multivalentTests/src/com/android/systemui/SysuiTestCaseSelfTest.kt 0 → 100644 +35 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.systemui import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.google.common.truth.Truth import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class SysuiTestCaseSelfTest : SysuiTestCase() { private val contextBeforeSetup = context // cf b/311612168 @Test fun captureCorrectContextBeforeSetupRuns() { Truth.assertThat(contextBeforeSetup).isEqualTo(context) } } packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCase.java +15 −6 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.testing.TestWithLooperRule; import android.testing.TestableLooper; import android.util.Log; import androidx.annotation.NonNull; import androidx.core.animation.AndroidXAnimatorIsolationRule; import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.UiDevice; Loading Loading @@ -68,8 +69,20 @@ public abstract class SysuiTestCase { public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(DEVICE_DEFAULT); @Rule public SysuiTestableContext mContext = new SysuiTestableContext( public SysuiTestableContext mContext = createTestableContext(); @NonNull private SysuiTestableContext createTestableContext() { SysuiTestableContext context = new SysuiTestableContext( InstrumentationRegistry.getContext(), getLeakCheck()); if (isRobolectricTest()) { // Manually associate a Display to context for Robolectric test. Similar to b/214297409 return context.createDefaultDisplayContext(); } else { return context; } } @Rule public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule = new DexmakerShareClassLoaderRule(); Loading @@ -84,10 +97,6 @@ public abstract class SysuiTestCase { @Before public void SysuiSetup() throws Exception { // Manually associate a Display to context for Robolectric test. Similar to b/214297409 if (isRobolectricTest()) { mContext = mContext.createDefaultDisplayContext(); } mSysuiDependency = new SysuiTestDependency(mContext, shouldFailOnLeakedReceiver()); mDependency = mSysuiDependency.install(); mRealInstrumentation = InstrumentationRegistry.getInstrumentation(); Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/SysuiTestCaseSelfTest.kt 0 → 100644 +35 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.systemui import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.google.common.truth.Truth import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class SysuiTestCaseSelfTest : SysuiTestCase() { private val contextBeforeSetup = context // cf b/311612168 @Test fun captureCorrectContextBeforeSetupRuns() { Truth.assertThat(contextBeforeSetup).isEqualTo(context) } }
packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCase.java +15 −6 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.testing.TestWithLooperRule; import android.testing.TestableLooper; import android.util.Log; import androidx.annotation.NonNull; import androidx.core.animation.AndroidXAnimatorIsolationRule; import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.UiDevice; Loading Loading @@ -68,8 +69,20 @@ public abstract class SysuiTestCase { public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(DEVICE_DEFAULT); @Rule public SysuiTestableContext mContext = new SysuiTestableContext( public SysuiTestableContext mContext = createTestableContext(); @NonNull private SysuiTestableContext createTestableContext() { SysuiTestableContext context = new SysuiTestableContext( InstrumentationRegistry.getContext(), getLeakCheck()); if (isRobolectricTest()) { // Manually associate a Display to context for Robolectric test. Similar to b/214297409 return context.createDefaultDisplayContext(); } else { return context; } } @Rule public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule = new DexmakerShareClassLoaderRule(); Loading @@ -84,10 +97,6 @@ public abstract class SysuiTestCase { @Before public void SysuiSetup() throws Exception { // Manually associate a Display to context for Robolectric test. Similar to b/214297409 if (isRobolectricTest()) { mContext = mContext.createDefaultDisplayContext(); } mSysuiDependency = new SysuiTestDependency(mContext, shouldFailOnLeakedReceiver()); mDependency = mSysuiDependency.install(); mRealInstrumentation = InstrumentationRegistry.getInstrumentation(); Loading