Loading packages/SystemUI/tests/src/com/android/systemui/SysuiBaseFragmentTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -14,13 +14,18 @@ package com.android.systemui; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.app.Fragment; import android.app.Instrumentation; import android.support.test.InstrumentationRegistry; import android.testing.BaseFragmentTest; import com.android.systemui.utils.leaks.LeakCheckedTest; import com.android.systemui.utils.leaks.LeakCheckedTest.SysuiLeakCheck; import org.junit.After; import org.junit.Before; import org.junit.Rule; Loading @@ -33,6 +38,7 @@ public abstract class SysuiBaseFragmentTest extends BaseFragmentTest { protected final TestableDependency mDependency = new TestableDependency(mContext); protected SysuiTestableContext mSysuiContext; private Instrumentation mRealInstrumentation; public SysuiBaseFragmentTest(Class<? extends Fragment> cls) { super(cls); Loading @@ -44,6 +50,20 @@ public abstract class SysuiBaseFragmentTest extends BaseFragmentTest { SystemUIFactory.createFromConfig(mContext); // TODO: Figure out another way to give reference to a SysuiTestableContext. mSysuiContext = (SysuiTestableContext) mContext; mRealInstrumentation = InstrumentationRegistry.getInstrumentation(); Instrumentation inst = spy(mRealInstrumentation); when(inst.getContext()).thenThrow(new RuntimeException( "SysUI Tests should use SysuiTestCase#getContext or SysuiTestCase#mContext")); when(inst.getTargetContext()).thenThrow(new RuntimeException( "SysUI Tests should use SysuiTestCase#getContext or SysuiTestCase#mContext")); InstrumentationRegistry.registerInstance(inst, InstrumentationRegistry.getArguments()); } @After public void SysuiTeardown() { InstrumentationRegistry.registerInstance(mRealInstrumentation, InstrumentationRegistry.getArguments()); } @Override Loading packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java +20 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,10 @@ */ package com.android.systemui; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.app.Instrumentation; import android.content.Context; import android.os.Handler; import android.os.Looper; Loading @@ -24,6 +28,7 @@ import android.support.test.filters.SmallTest; import android.testing.LeakCheck; import android.util.Log; import org.junit.After; import org.junit.Before; import org.junit.Rule; Loading @@ -42,11 +47,26 @@ public abstract class SysuiTestCase { public SysuiTestableContext mContext = new SysuiTestableContext( InstrumentationRegistry.getContext(), getLeakCheck()); public TestableDependency mDependency = new TestableDependency(mContext); private Instrumentation mRealInstrumentation; @Before public void SysuiSetup() throws Exception { System.setProperty("dexmaker.share_classloader", "true"); SystemUIFactory.createFromConfig(mContext); mRealInstrumentation = InstrumentationRegistry.getInstrumentation(); Instrumentation inst = spy(mRealInstrumentation); when(inst.getContext()).thenThrow(new RuntimeException( "SysUI Tests should use SysuiTestCase#getContext or SysuiTestCase#mContext")); when(inst.getTargetContext()).thenThrow(new RuntimeException( "SysUI Tests should use SysuiTestCase#getContext or SysuiTestCase#mContext")); InstrumentationRegistry.registerInstance(inst, InstrumentationRegistry.getArguments()); } @After public void SysuiTeardown() { InstrumentationRegistry.registerInstance(mRealInstrumentation, InstrumentationRegistry.getArguments()); } protected LeakCheck getLeakCheck() { Loading packages/SystemUI/tests/src/com/android/systemui/util/wakelock/WakeLockTest.java +1 −3 Original line number Diff line number Diff line Loading @@ -41,9 +41,7 @@ public class WakeLockTest extends SysuiTestCase { @Before public void setUp() { Context context = InstrumentationRegistry.getContext(); mInner = WakeLock.createPartialInner(context, WakeLockTest.class.getName()); mInner = WakeLock.createPartialInner(mContext, WakeLockTest.class.getName()); mWakeLock = WakeLock.wrap(mInner); } Loading tests/testables/src/android/testing/ViewUtils.java +2 −4 Original line number Diff line number Diff line Loading @@ -39,8 +39,7 @@ public class ViewUtils { LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, LayoutParams.TYPE_APPLICATION_OVERLAY, 0, PixelFormat.TRANSLUCENT); InstrumentationRegistry.getContext() .getSystemService(WindowManager.class).addView(view, lp); view.getContext().getSystemService(WindowManager.class).addView(view, lp); } /** Loading @@ -49,7 +48,6 @@ public class ViewUtils { * This is currently done by removing the view from a window. */ public static void detachView(View view) { InstrumentationRegistry.getContext() .getSystemService(WindowManager.class).removeViewImmediate(view); view.getContext().getSystemService(WindowManager.class).removeViewImmediate(view); } } Loading
packages/SystemUI/tests/src/com/android/systemui/SysuiBaseFragmentTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -14,13 +14,18 @@ package com.android.systemui; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.app.Fragment; import android.app.Instrumentation; import android.support.test.InstrumentationRegistry; import android.testing.BaseFragmentTest; import com.android.systemui.utils.leaks.LeakCheckedTest; import com.android.systemui.utils.leaks.LeakCheckedTest.SysuiLeakCheck; import org.junit.After; import org.junit.Before; import org.junit.Rule; Loading @@ -33,6 +38,7 @@ public abstract class SysuiBaseFragmentTest extends BaseFragmentTest { protected final TestableDependency mDependency = new TestableDependency(mContext); protected SysuiTestableContext mSysuiContext; private Instrumentation mRealInstrumentation; public SysuiBaseFragmentTest(Class<? extends Fragment> cls) { super(cls); Loading @@ -44,6 +50,20 @@ public abstract class SysuiBaseFragmentTest extends BaseFragmentTest { SystemUIFactory.createFromConfig(mContext); // TODO: Figure out another way to give reference to a SysuiTestableContext. mSysuiContext = (SysuiTestableContext) mContext; mRealInstrumentation = InstrumentationRegistry.getInstrumentation(); Instrumentation inst = spy(mRealInstrumentation); when(inst.getContext()).thenThrow(new RuntimeException( "SysUI Tests should use SysuiTestCase#getContext or SysuiTestCase#mContext")); when(inst.getTargetContext()).thenThrow(new RuntimeException( "SysUI Tests should use SysuiTestCase#getContext or SysuiTestCase#mContext")); InstrumentationRegistry.registerInstance(inst, InstrumentationRegistry.getArguments()); } @After public void SysuiTeardown() { InstrumentationRegistry.registerInstance(mRealInstrumentation, InstrumentationRegistry.getArguments()); } @Override Loading
packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java +20 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,10 @@ */ package com.android.systemui; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.app.Instrumentation; import android.content.Context; import android.os.Handler; import android.os.Looper; Loading @@ -24,6 +28,7 @@ import android.support.test.filters.SmallTest; import android.testing.LeakCheck; import android.util.Log; import org.junit.After; import org.junit.Before; import org.junit.Rule; Loading @@ -42,11 +47,26 @@ public abstract class SysuiTestCase { public SysuiTestableContext mContext = new SysuiTestableContext( InstrumentationRegistry.getContext(), getLeakCheck()); public TestableDependency mDependency = new TestableDependency(mContext); private Instrumentation mRealInstrumentation; @Before public void SysuiSetup() throws Exception { System.setProperty("dexmaker.share_classloader", "true"); SystemUIFactory.createFromConfig(mContext); mRealInstrumentation = InstrumentationRegistry.getInstrumentation(); Instrumentation inst = spy(mRealInstrumentation); when(inst.getContext()).thenThrow(new RuntimeException( "SysUI Tests should use SysuiTestCase#getContext or SysuiTestCase#mContext")); when(inst.getTargetContext()).thenThrow(new RuntimeException( "SysUI Tests should use SysuiTestCase#getContext or SysuiTestCase#mContext")); InstrumentationRegistry.registerInstance(inst, InstrumentationRegistry.getArguments()); } @After public void SysuiTeardown() { InstrumentationRegistry.registerInstance(mRealInstrumentation, InstrumentationRegistry.getArguments()); } protected LeakCheck getLeakCheck() { Loading
packages/SystemUI/tests/src/com/android/systemui/util/wakelock/WakeLockTest.java +1 −3 Original line number Diff line number Diff line Loading @@ -41,9 +41,7 @@ public class WakeLockTest extends SysuiTestCase { @Before public void setUp() { Context context = InstrumentationRegistry.getContext(); mInner = WakeLock.createPartialInner(context, WakeLockTest.class.getName()); mInner = WakeLock.createPartialInner(mContext, WakeLockTest.class.getName()); mWakeLock = WakeLock.wrap(mInner); } Loading
tests/testables/src/android/testing/ViewUtils.java +2 −4 Original line number Diff line number Diff line Loading @@ -39,8 +39,7 @@ public class ViewUtils { LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, LayoutParams.TYPE_APPLICATION_OVERLAY, 0, PixelFormat.TRANSLUCENT); InstrumentationRegistry.getContext() .getSystemService(WindowManager.class).addView(view, lp); view.getContext().getSystemService(WindowManager.class).addView(view, lp); } /** Loading @@ -49,7 +48,6 @@ public class ViewUtils { * This is currently done by removing the view from a window. */ public static void detachView(View view) { InstrumentationRegistry.getContext() .getSystemService(WindowManager.class).removeViewImmediate(view); view.getContext().getSystemService(WindowManager.class).removeViewImmediate(view); } }