Loading core/tests/coretests/src/android/util/OrientationUtil.java 0 → 100644 +67 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 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 android.util; import android.app.Activity; import android.app.Instrumentation; import android.content.pm.ActivityInfo; import android.test.ActivityInstrumentationTestCase2; import com.android.internal.util.Preconditions; /** * Utilities for manipulating screen orientation. */ public final class OrientationUtil { private final Activity mActivity; private final Instrumentation mInstrumentation; private final Runnable mSetToPortrait = new Runnable() { @Override public void run() { mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } }; private final Runnable mSetToLandscape = new Runnable() { @Override public void run() { mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } }; public static OrientationUtil initializeAndStartActivityIfNotStarted( ActivityInstrumentationTestCase2 testCase) { Preconditions.checkNotNull(testCase); return new OrientationUtil(testCase.getActivity(), testCase.getInstrumentation()); } private OrientationUtil(Activity activity, Instrumentation instrumentation) { mActivity = activity; mInstrumentation = instrumentation; } public void setPortraitOrientation() { mInstrumentation.runOnMainSync(mSetToPortrait); } public void setLandscapeOrientation() { mInstrumentation.runOnMainSync(mSetToLandscape); } } core/tests/coretests/src/android/widget/TextViewActivityTest.java +9 −18 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.frameworks.coretests.R; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.SmallTest; import android.util.OrientationUtil; import android.view.KeyEvent; /** Loading @@ -43,14 +44,20 @@ import android.view.KeyEvent; */ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextViewActivity>{ private OrientationUtil mOrientationUtil; public TextViewActivityTest() { super(TextViewActivity.class); } @Override public void setUp() { mOrientationUtil = OrientationUtil.initializeAndStartActivityIfNotStarted(this); mOrientationUtil.setPortraitOrientation(); } @SmallTest public void testTypedTextIsOnScreen() throws Exception { getActivity(); final String helloWorld = "Hello world!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -60,8 +67,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testPositionCursorAtTextAtIndex() throws Exception { getActivity(); final String helloWorld = "Hello world!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -74,8 +79,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testLongPressToSelect() throws Exception { getActivity(); final String helloWorld = "Hello Kirk!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -87,8 +90,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testLongPressEmptySpace() throws Exception { getActivity(); final String helloWorld = "Hello big round sun!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -102,8 +103,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testLongPressAndDragToSelect() throws Exception { getActivity(); final String helloWorld = "Hello little handsome boy!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -115,8 +114,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testDoubleTapToSelect() throws Exception { getActivity(); final String helloWorld = "Hello SuetYi!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -128,8 +125,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testDoubleTapAndDragToSelect() throws Exception { getActivity(); final String helloWorld = "Hello young beautiful girl!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -141,8 +136,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testSelectBackwordsByTouch() throws Exception { getActivity(); final String helloWorld = "Hello king of the Jungle!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -154,8 +147,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testToolbarAppearsAfterSelection() throws Exception { getActivity(); // It'll be nice to check that the toolbar is not visible (or does not exist) here // I can't currently find a way to do this. I'll get to it later. Loading Loading
core/tests/coretests/src/android/util/OrientationUtil.java 0 → 100644 +67 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 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 android.util; import android.app.Activity; import android.app.Instrumentation; import android.content.pm.ActivityInfo; import android.test.ActivityInstrumentationTestCase2; import com.android.internal.util.Preconditions; /** * Utilities for manipulating screen orientation. */ public final class OrientationUtil { private final Activity mActivity; private final Instrumentation mInstrumentation; private final Runnable mSetToPortrait = new Runnable() { @Override public void run() { mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } }; private final Runnable mSetToLandscape = new Runnable() { @Override public void run() { mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } }; public static OrientationUtil initializeAndStartActivityIfNotStarted( ActivityInstrumentationTestCase2 testCase) { Preconditions.checkNotNull(testCase); return new OrientationUtil(testCase.getActivity(), testCase.getInstrumentation()); } private OrientationUtil(Activity activity, Instrumentation instrumentation) { mActivity = activity; mInstrumentation = instrumentation; } public void setPortraitOrientation() { mInstrumentation.runOnMainSync(mSetToPortrait); } public void setLandscapeOrientation() { mInstrumentation.runOnMainSync(mSetToLandscape); } }
core/tests/coretests/src/android/widget/TextViewActivityTest.java +9 −18 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.frameworks.coretests.R; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.SmallTest; import android.util.OrientationUtil; import android.view.KeyEvent; /** Loading @@ -43,14 +44,20 @@ import android.view.KeyEvent; */ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextViewActivity>{ private OrientationUtil mOrientationUtil; public TextViewActivityTest() { super(TextViewActivity.class); } @Override public void setUp() { mOrientationUtil = OrientationUtil.initializeAndStartActivityIfNotStarted(this); mOrientationUtil.setPortraitOrientation(); } @SmallTest public void testTypedTextIsOnScreen() throws Exception { getActivity(); final String helloWorld = "Hello world!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -60,8 +67,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testPositionCursorAtTextAtIndex() throws Exception { getActivity(); final String helloWorld = "Hello world!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -74,8 +79,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testLongPressToSelect() throws Exception { getActivity(); final String helloWorld = "Hello Kirk!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -87,8 +90,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testLongPressEmptySpace() throws Exception { getActivity(); final String helloWorld = "Hello big round sun!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -102,8 +103,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testLongPressAndDragToSelect() throws Exception { getActivity(); final String helloWorld = "Hello little handsome boy!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -115,8 +114,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testDoubleTapToSelect() throws Exception { getActivity(); final String helloWorld = "Hello SuetYi!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -128,8 +125,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testDoubleTapAndDragToSelect() throws Exception { getActivity(); final String helloWorld = "Hello young beautiful girl!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -141,8 +136,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testSelectBackwordsByTouch() throws Exception { getActivity(); final String helloWorld = "Hello king of the Jungle!"; onView(withId(R.id.textview)).perform(click()); onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); Loading @@ -154,8 +147,6 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV @SmallTest public void testToolbarAppearsAfterSelection() throws Exception { getActivity(); // It'll be nice to check that the toolbar is not visible (or does not exist) here // I can't currently find a way to do this. I'll get to it later. Loading