diff options
author | Luca Stefani <luca.stefani.ge1@gmail.com> | 2020-03-07 13:43:59 +0100 |
---|---|---|
committer | Luca Stefani <luca.stefani.ge1@gmail.com> | 2020-03-07 13:43:59 +0100 |
commit | 0007a046cf4f4bfed563aa52ffab9ec5e94ee6f0 (patch) | |
tree | 2bc4acf2f54df560a34dcc7b7844d9d18cc58131 /tests/src | |
parent | 744d192669a148bde24d36bef02deb05c2f7a1fa (diff) | |
parent | 02826bbe04d9dc1e6111f5d6ffd8706ac1f8f908 (diff) | |
download | packages_apps_Trebuchet-0007a046cf4f4bfed563aa52ffab9ec5e94ee6f0.tar.gz packages_apps_Trebuchet-0007a046cf4f4bfed563aa52ffab9ec5e94ee6f0.tar.bz2 packages_apps_Trebuchet-0007a046cf4f4bfed563aa52ffab9ec5e94ee6f0.zip |
Merge tag 'android-10.0.0_r31' into HEAD
Android 10.0.0 release 31
* tag 'android-10.0.0_r31': (218 commits)
Increase drag distance threshold when drag starts from deep press
Fix shortcut componentname in workspace layout logging
Fix shortcut componentname in workspace layout logging
perform accessbility focus when the recyclerview doesn't gain focus after fragment replacement in SettingsActivity
Persist predicted items when dragged to workspace
Import translations. DO NOT MERGE
Import translations. DO NOT MERGE
Align badging logic with platform IconDrawableFactory.
Fix bug where icon remains invisible after returning home.
Fix quick switch from home biased towards returning home
Fix recents scale sometimes lagging behind window scale
Fix folder open/close animation when grid size is small.
fix custom shortcut test
Improve quick switch from home by tracking both x and y motion
Move shelf peeking anim code to ShelfPeekAnim class
Fix folder available height calculation
Tapl: AllApps: ensuring a minimal vertical size of an icon
Enable a11y scrolling with item drag
disable custom shortcut test in oop
include predicted_rank in app launch logging
...
Change-Id: Id824c350cd133c4c8fa91de0f8793faed9003393
Diffstat (limited to 'tests/src')
13 files changed, 277 insertions, 61 deletions
diff --git a/tests/src/com/android/launcher3/model/LoaderCursorTest.java b/tests/src/com/android/launcher3/model/LoaderCursorTest.java index 7d60ad65b..64df8e0e9 100644 --- a/tests/src/com/android/launcher3/model/LoaderCursorTest.java +++ b/tests/src/com/android/launcher3/model/LoaderCursorTest.java @@ -15,9 +15,9 @@ import com.android.launcher3.icons.IconCache; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppState; -import com.android.launcher3.Utilities; import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.icons.BitmapInfo; +import com.android.launcher3.util.PackageManagerHelper; import org.junit.Before; import org.junit.Test; @@ -115,7 +115,7 @@ public class LoaderCursorTest { WorkspaceItemInfo info = mLoaderCursor.getAppShortcutInfo( new Intent().setComponent(cn), false /* allowMissingTarget */, true); assertNotNull(info); - assertTrue(Utilities.isLauncherAppTarget(info.intent)); + assertTrue(PackageManagerHelper.isLauncherAppTarget(info.intent)); } @Test @@ -127,7 +127,7 @@ public class LoaderCursorTest { WorkspaceItemInfo info = mLoaderCursor.getAppShortcutInfo( new Intent().setComponent(cn), true /* allowMissingTarget */, true); assertNotNull(info); - assertTrue(Utilities.isLauncherAppTarget(info.intent)); + assertTrue(PackageManagerHelper.isLauncherAppTarget(info.intent)); } @Test diff --git a/tests/src/com/android/launcher3/testcomponent/CustomShortcutConfigActivity.java b/tests/src/com/android/launcher3/testcomponent/CustomShortcutConfigActivity.java new file mode 100644 index 000000000..b673faa6f --- /dev/null +++ b/tests/src/com/android/launcher3/testcomponent/CustomShortcutConfigActivity.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2019 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.launcher3.testcomponent; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ShortcutInfo; +import android.content.pm.ShortcutManager; +import android.graphics.drawable.Icon; +import android.os.Bundle; + +import com.android.launcher3.R; + +import java.util.UUID; + +/** + * A custom shortcut is a 1x1 widget that launches a specific intent when user tap on it. + * Custom shortcuts are replaced by deep shortcuts after api 25. + */ +public class CustomShortcutConfigActivity extends BaseTestingActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Intent launchIntent = new Intent(this, BaseTestingActivity.class) + .setAction("com.android.launcher3.intent.action.test_shortcut"); + Intent shortcutIntent = createShortcutResultIntent( + this, UUID.randomUUID().toString(), "Shortcut", + R.drawable.ic_widget, launchIntent); + setResult(RESULT_OK, shortcutIntent); + finish(); + } + + private static Intent createShortcutResultIntent( + Context context, String uniqueId, String name, int iconId, Intent launchIntent) { + ShortcutInfo shortcutInfo = + createShortcutInfo(context, uniqueId, name, iconId, launchIntent); + ShortcutManager sm = context.getSystemService(ShortcutManager.class); + return sm.createShortcutResultIntent(shortcutInfo); + } + + private static ShortcutInfo createShortcutInfo( + Context context, String uniqueId, String name, int iconId, Intent launchIntent) { + return new ShortcutInfo.Builder(context, uniqueId) + .setShortLabel(name) + .setLongLabel(name) + .setIcon(Icon.createWithResource(context, iconId)) + .setIntent(launchIntent) + .build(); + } +} diff --git a/tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java b/tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java index 6a6916eec..42460961b 100644 --- a/tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java +++ b/tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java @@ -104,7 +104,8 @@ public class TestCommandReceiver extends ContentProvider { case GET_SYSTEM_HEALTH_MESSAGE: { final Bundle response = new Bundle(); - response.putString("result", TestHelpers.getSystemHealthMessage(getContext())); + response.putString("result", + TestHelpers.getSystemHealthMessage(getContext(), Long.parseLong(arg))); return response; } } diff --git a/tests/src/com/android/launcher3/touch/SwipeDetectorTest.java b/tests/src/com/android/launcher3/touch/SingleAxisSwipeDetectorTest.java index e04235708..5174e4dab 100644 --- a/tests/src/com/android/launcher3/touch/SwipeDetectorTest.java +++ b/tests/src/com/android/launcher3/touch/SingleAxisSwipeDetectorTest.java @@ -15,6 +15,12 @@ */ package com.android.launcher3.touch; +import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_BOTH; +import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_NEGATIVE; +import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_POSITIVE; +import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL; +import static com.android.launcher3.touch.SingleAxisSwipeDetector.VERTICAL; + import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyFloat; import static org.mockito.Matchers.anyObject; @@ -25,6 +31,10 @@ import static org.mockito.Mockito.verify; import android.util.Log; import android.view.ViewConfiguration; +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + import com.android.launcher3.testcomponent.TouchEventGenerator; import org.junit.Before; @@ -33,25 +43,21 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import androidx.test.InstrumentationRegistry; -import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; - @SmallTest @RunWith(AndroidJUnit4.class) -public class SwipeDetectorTest { +public class SingleAxisSwipeDetectorTest { - private static final String TAG = SwipeDetectorTest.class.getSimpleName(); + private static final String TAG = SingleAxisSwipeDetectorTest.class.getSimpleName(); public static void L(String s, Object... parts) { Log.d(TAG, (parts.length == 0) ? s : String.format(s, parts)); } private TouchEventGenerator mGenerator; - private SwipeDetector mDetector; + private SingleAxisSwipeDetector mDetector; private int mTouchSlop; @Mock - private SwipeDetector.Listener mMockListener; + private SingleAxisSwipeDetector.Listener mMockListener; @Mock private ViewConfiguration mMockConfig; @@ -65,8 +71,8 @@ public class SwipeDetectorTest { doReturn(orgConfig.getScaledMaximumFlingVelocity()).when(mMockConfig) .getScaledMaximumFlingVelocity(); - mDetector = new SwipeDetector(mMockConfig, mMockListener, SwipeDetector.VERTICAL, false); - mDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_BOTH, false); + mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, VERTICAL, false); + mDetector.setDetectableScrollConditions(DIRECTION_BOTH, false); mTouchSlop = orgConfig.getScaledTouchSlop(); doReturn(mTouchSlop).when(mMockConfig).getScaledTouchSlop(); @@ -75,8 +81,8 @@ public class SwipeDetectorTest { @Test public void testDragStart_verticalPositive() { - mDetector = new SwipeDetector(mMockConfig, mMockListener, SwipeDetector.VERTICAL, false); - mDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_POSITIVE, false); + mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, VERTICAL, false); + mDetector.setDetectableScrollConditions(DIRECTION_POSITIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100, 100 - mTouchSlop); // TODO: actually calculate the following parameters and do exact value checks. @@ -85,8 +91,8 @@ public class SwipeDetectorTest { @Test public void testDragStart_verticalNegative() { - mDetector = new SwipeDetector(mMockConfig, mMockListener, SwipeDetector.VERTICAL, false); - mDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_NEGATIVE, false); + mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, VERTICAL, false); + mDetector.setDetectableScrollConditions(DIRECTION_NEGATIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100, 100 + mTouchSlop); // TODO: actually calculate the following parameters and do exact value checks. @@ -103,8 +109,8 @@ public class SwipeDetectorTest { @Test public void testDragStart_horizontalPositive() { - mDetector = new SwipeDetector(mMockConfig, mMockListener, SwipeDetector.HORIZONTAL, false); - mDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_POSITIVE, false); + mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, false); + mDetector.setDetectableScrollConditions(DIRECTION_POSITIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100 + mTouchSlop, 100); @@ -114,8 +120,8 @@ public class SwipeDetectorTest { @Test public void testDragStart_horizontalNegative() { - mDetector = new SwipeDetector(mMockConfig, mMockListener, SwipeDetector.HORIZONTAL, false); - mDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_NEGATIVE, false); + mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, false); + mDetector.setDetectableScrollConditions(DIRECTION_NEGATIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100 - mTouchSlop, 100); @@ -125,8 +131,8 @@ public class SwipeDetectorTest { @Test public void testDragStart_horizontalRtlPositive() { - mDetector = new SwipeDetector(mMockConfig, mMockListener, SwipeDetector.HORIZONTAL, true); - mDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_POSITIVE, false); + mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, true); + mDetector.setDetectableScrollConditions(DIRECTION_POSITIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100 - mTouchSlop, 100); @@ -136,8 +142,8 @@ public class SwipeDetectorTest { @Test public void testDragStart_horizontalRtlNegative() { - mDetector = new SwipeDetector(mMockConfig, mMockListener, SwipeDetector.HORIZONTAL, true); - mDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_NEGATIVE, false); + mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, true); + mDetector.setDetectableScrollConditions(DIRECTION_NEGATIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100 + mTouchSlop, 100); @@ -160,6 +166,6 @@ public class SwipeDetectorTest { mGenerator.move(0, 100, 100 + mTouchSlop * 2); mGenerator.lift(0); // TODO: actually calculate the following parameters and do exact value checks. - verify(mMockListener).onDragEnd(anyFloat(), anyBoolean()); + verify(mMockListener).onDragEnd(anyFloat()); } } diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index dc890bb00..9a894b1ee 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -15,15 +15,16 @@ */ package com.android.launcher3.ui; -import static androidx.test.InstrumentationRegistry.getInstrumentation; - import static com.android.launcher3.tapl.LauncherInstrumentation.ContainerType; import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName; +import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static org.junit.Assert.assertTrue; import static java.lang.System.exit; +import static androidx.test.InstrumentationRegistry.getInstrumentation; + import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -47,7 +48,6 @@ import com.android.launcher3.LauncherModel; import com.android.launcher3.LauncherSettings; import com.android.launcher3.LauncherState; import com.android.launcher3.LauncherStateManager; -import com.android.launcher3.MainThreadExecutor; import com.android.launcher3.Utilities; import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.model.AppLaunchTracker; @@ -55,11 +55,13 @@ import com.android.launcher3.tapl.LauncherInstrumentation; import com.android.launcher3.tapl.TestHelpers; import com.android.launcher3.testcomponent.TestCommandReceiver; import com.android.launcher3.testing.TestProtocol; +import com.android.launcher3.util.LooperExecutor; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.Wait; import com.android.launcher3.util.rule.FailureWatcher; import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; +import com.android.launcher3.util.rule.TestStabilityRule; import org.junit.After; import org.junit.Before; @@ -89,10 +91,9 @@ public abstract class AbstractLauncherUiTest { public static final long DEFAULT_UI_TIMEOUT = 60000; // b/136278866 private static final String TAG = "AbstractLauncherUiTest"; - protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor(); + protected LooperExecutor mMainThreadExecutor = MAIN_EXECUTOR; protected final UiDevice mDevice = UiDevice.getInstance(getInstrumentation()); - protected final LauncherInstrumentation mLauncher = - new LauncherInstrumentation(getInstrumentation()); + protected final LauncherInstrumentation mLauncher = new LauncherInstrumentation(); protected Context mTargetContext; protected String mTargetPackage; @@ -104,8 +105,9 @@ public abstract class AbstractLauncherUiTest { } if (TestHelpers.isInLauncherProcess()) { Utilities.enableRunningInTestHarnessForTests(); - mLauncher.setSystemHealthSupplier(() -> TestCommandReceiver.callCommand( - TestCommandReceiver.GET_SYSTEM_HEALTH_MESSAGE).getString("result")); + mLauncher.setSystemHealthSupplier(startTime -> TestCommandReceiver.callCommand( + TestCommandReceiver.GET_SYSTEM_HEALTH_MESSAGE, startTime.toString()). + getString("result")); mLauncher.setOnSettledStateAction( containerType -> executeOnLauncher( launcher -> @@ -155,7 +157,8 @@ public abstract class AbstractLauncherUiTest { @Rule public TestRule mOrderSensitiveRules = RuleChain. - outerRule(mActivityMonitor). + outerRule(new TestStabilityRule()). + around(mActivityMonitor). around(getRulesInsideActivityMonitor()); public UiDevice getDevice() { @@ -169,8 +172,6 @@ public abstract class AbstractLauncherUiTest { mTargetContext = InstrumentationRegistry.getTargetContext(); mTargetPackage = mTargetContext.getPackageName(); - // Unlock the phone - mDevice.executeShellCommand("input keyevent 82"); } @After @@ -347,7 +348,8 @@ public abstract class AbstractLauncherUiTest { startIntent( getInstrumentation().getContext().getPackageManager().getLaunchIntentForPackage( packageName), - By.pkg(packageName).depth(0)); + By.pkg(packageName).depth(0), + true /* newTask */); } protected void startTestActivity(int activityNumber) { @@ -356,12 +358,17 @@ public abstract class AbstractLauncherUiTest { getLaunchIntentForPackage(packageName); intent.setComponent(new ComponentName(packageName, "com.android.launcher3.tests.Activity" + activityNumber)); - startIntent(intent, By.pkg(packageName).text("TestActivity" + activityNumber)); + startIntent(intent, By.pkg(packageName).text("TestActivity" + activityNumber), + false /* newTask */); } - private void startIntent(Intent intent, BySelector selector) { + private void startIntent(Intent intent, BySelector selector, boolean newTask) { intent.addCategory(Intent.CATEGORY_LAUNCHER); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + if (newTask) { + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + } else { + intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT); + } getInstrumentation().getTargetContext().startActivity(intent); assertTrue("App didn't start: " + selector, mDevice.wait(Until.hasObject(selector), DEFAULT_UI_TIMEOUT)); diff --git a/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java b/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java index a76b4a488..ff21880d0 100644 --- a/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java +++ b/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java @@ -73,7 +73,6 @@ public class DefaultLayoutProviderTest extends AbstractLauncherUiTest { // Launch the home activity mDevice.pressHome(); - waitForModelLoaded(); mLauncher.getWorkspace().getHotseatAppIcon(getSettingsApp().getLabel().toString()); } @@ -89,7 +88,6 @@ public class DefaultLayoutProviderTest extends AbstractLauncherUiTest { // Launch the home activity mDevice.pressHome(); - waitForModelLoaded(); // Verify widget present assertTrue("Widget is not present", @@ -106,7 +104,6 @@ public class DefaultLayoutProviderTest extends AbstractLauncherUiTest { // Launch the home activity mDevice.pressHome(); - waitForModelLoaded(); mLauncher.getWorkspace().getHotseatFolder("Folder: Copy"); } diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index c2a3c1c52..2cf6c2ba7 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -24,6 +24,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import android.util.Log; + import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; @@ -34,9 +36,9 @@ import com.android.launcher3.tapl.AllApps; import com.android.launcher3.tapl.AppIcon; import com.android.launcher3.tapl.AppIconMenu; import com.android.launcher3.tapl.AppIconMenuItem; -import com.android.launcher3.tapl.TestHelpers; import com.android.launcher3.tapl.Widgets; import com.android.launcher3.tapl.Workspace; +import com.android.launcher3.util.rule.TestStabilityRule.Stability; import com.android.launcher3.views.OptionsPopupView; import com.android.launcher3.widget.WidgetsFullSheet; import com.android.launcher3.widget.WidgetsRecyclerView; @@ -343,4 +345,10 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { public static String getAppPackageName() { return getInstrumentation().getContext().getPackageName(); } + + @Test + @Stability + public void testTestStabilityAttribute() { + Log.d("TestStabilityRule", "Hello world!"); + } } diff --git a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java index 3f35a3a73..e1b3edeb5 100644 --- a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java @@ -41,7 +41,6 @@ import com.android.launcher3.util.Wait; import com.android.launcher3.util.rule.ShellCommandRule; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,7 +52,8 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class AddConfigWidgetTest extends AbstractLauncherUiTest { - @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); + @Rule + public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); private LauncherAppWidgetProviderInfo mWidgetInfo; private AppWidgetManager mAppWidgetManager; @@ -70,14 +70,12 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest { @Test @PortraitLandscape - @org.junit.Ignore public void testWidgetConfig() throws Throwable { runTest(true); } @Test @PortraitLandscape - @org.junit.Ignore public void testConfigCancelled() throws Throwable { runTest(false); } diff --git a/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java index 1edce22ec..f9d1d93b3 100644 --- a/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java @@ -30,7 +30,6 @@ import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.ui.TestViewHelpers; import com.android.launcher3.util.rule.ShellCommandRule; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,11 +41,11 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class AddWidgetTest extends AbstractLauncherUiTest { - @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); + @Rule + public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); @Test @PortraitLandscape - @org.junit.Ignore public void testDragIcon() throws Throwable { clearHomescreen(); mDevice.pressHome(); @@ -70,4 +69,22 @@ public class AddWidgetTest extends AbstractLauncherUiTest { assertNotNull("Widget not found on the workspace", widget); widget.launch(getAppPackageName()); } + + /** + * Test dragging a custom shortcut to the workspace and launch it. + * + * A custom shortcut is a 1x1 widget that launches a specific intent when user tap on it. + * Custom shortcuts are replaced by deep shortcuts after api 25. + */ + @Test + @PortraitLandscape + public void testDragCustomShortcut() throws Throwable { + clearHomescreen(); + mDevice.pressHome(); + mLauncher.getWorkspace().openAllWidgets() + .getWidget("com.android.launcher3.testcomponent.CustomShortcutConfigActivity") + .dragToWorkspace(); + mLauncher.getWorkspace().getWorkspaceAppIcon("Shortcut") + .launch(getAppPackageName()); + } } diff --git a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java index e6348d9c0..f42bf1f3c 100644 --- a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java @@ -271,7 +271,6 @@ public class BindWidgetTest extends AbstractLauncherUiTest { // Launch the home activity mDevice.pressHome(); - waitForModelLoaded(); } private void verifyWidgetPresent(LauncherAppWidgetProviderInfo info) { diff --git a/tests/src/com/android/launcher3/util/Condition.java b/tests/src/com/android/launcher3/util/Condition.java index b564a1a87..d85dd3a2d 100644 --- a/tests/src/com/android/launcher3/util/Condition.java +++ b/tests/src/com/android/launcher3/util/Condition.java @@ -1,8 +1,8 @@ package com.android.launcher3.util; -import androidx.test.uiautomator.UiObject2; +import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; -import com.android.launcher3.MainThreadExecutor; +import androidx.test.uiautomator.UiObject2; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -16,7 +16,7 @@ public interface Condition { * Converts the condition to be run on UI thread. */ static Condition runOnUiThread(final Condition condition) { - final MainThreadExecutor executor = new MainThreadExecutor(); + final LooperExecutor executor = MAIN_EXECUTOR; return () -> { final AtomicBoolean value = new AtomicBoolean(false); final Throwable[] exceptions = new Throwable[1]; diff --git a/tests/src/com/android/launcher3/util/RaceConditionReproducer.java b/tests/src/com/android/launcher3/util/RaceConditionReproducer.java index 0235f95d0..8f8917320 100644 --- a/tests/src/com/android/launcher3/util/RaceConditionReproducer.java +++ b/tests/src/com/android/launcher3/util/RaceConditionReproducer.java @@ -16,6 +16,7 @@ package com.android.launcher3.util; +import static com.android.launcher3.util.Executors.createAndStartNewLooper; import static com.android.launcher3.util.RaceConditionTracker.ENTER_POSTFIX; import static com.android.launcher3.util.RaceConditionTracker.EXIT_POSTFIX; @@ -23,7 +24,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.os.Handler; -import android.os.HandlerThread; import android.util.Log; import java.util.ArrayList; @@ -72,9 +72,7 @@ public class RaceConditionReproducer implements RaceConditionTracker.EventProces private static final Handler POSTPONED_EVENT_RESUME_HANDLER = createEventResumeHandler(); private static Handler createEventResumeHandler() { - final HandlerThread thread = new HandlerThread("RaceConditionEventResumer"); - thread.start(); - return new Handler(thread.getLooper()); + return new Handler(createAndStartNewLooper("RaceConditionEventResumer")); } /** diff --git a/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java b/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java new file mode 100644 index 000000000..d7f41bf04 --- /dev/null +++ b/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2019 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.launcher3.util.rule; + +import static androidx.test.InstrumentationRegistry.getInstrumentation; + +import android.os.Build; +import android.util.Log; + +import androidx.test.uiautomator.UiDevice; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class TestStabilityRule implements TestRule { + private static final String TAG = "TestStabilityRule"; + private static final Pattern LAUNCHER_BUILD = + Pattern.compile("^(" + + "(?<local>(BuildFromAndroidStudio|" + + "([0-9]+|[A-Z])-eng\\.[a-z]+\\.[0-9]+\\.[0-9]+))|" + + "(?<presubmit>([0-9]+|[A-Z])-P[0-9]+)|" + + "(?<postsubmit>([0-9]+|[A-Z])-[0-9]+)|" + + "(?<platform>[0-9]+|[A-Z])" + + ")$"); + private static final Pattern PLATFORM_BUILD = + Pattern.compile("^(" + + "(?<commandLine>eng\\.[a-z]+\\.[0-9]+\\.[0-9]+)|" + + "(?<presubmit>P[0-9]+)|" + + "(?<postsubmit>[0-9]+)" + + ")$"); + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface Stability { + } + + @Override + public Statement apply(Statement base, Description description) { + if (description.getAnnotation(Stability.class) != null) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + getRunFlavor(); + + base.evaluate(); + } + }; + } else { + return base; + } + } + + private static void getRunFlavor() throws Exception { + final String launcherVersion = getInstrumentation(). + getContext(). + getPackageManager(). + getPackageInfo( + UiDevice.getInstance(getInstrumentation()). + getLauncherPackageName(), + 0). + versionName; + + final Matcher launcherBuildMatcher = LAUNCHER_BUILD.matcher(launcherVersion); + + if (!launcherBuildMatcher.find()) { + Log.e(TAG, "Match not found"); + } + + final String platformVersion = Build.VERSION.INCREMENTAL; + final Matcher platformBuildMatcher = PLATFORM_BUILD.matcher(platformVersion); + + if (!platformBuildMatcher.find()) { + Log.e(TAG, "Match not found"); + } + + Log.d(TAG, "Launcher: " + launcherVersion + ", platform: " + platformVersion); + + if (launcherBuildMatcher.group("local") != null && ( + platformBuildMatcher.group("commandLine") != null || + platformBuildMatcher.group("postsubmit") != null)) { + Log.d(TAG, "LOCAL RUN"); + } else if (launcherBuildMatcher.group("presubmit") != null + && platformBuildMatcher.group("postsubmit") != null) { + Log.d(TAG, "UNBUNDLED PRESUBMIT"); + } else if (launcherBuildMatcher.group("postsubmit") != null + && platformBuildMatcher.group("postsubmit") != null) { + Log.d(TAG, "UNBUNDLED POSTSUBMIT"); + } else if (launcherBuildMatcher.group("platform") != null + && platformBuildMatcher.group("presubmit") != null) { + Log.d(TAG, "PLATFORM PRESUBMIT"); + } else if (launcherBuildMatcher.group("platform") != null + && platformBuildMatcher.group("postsubmit") != null) { + Log.d(TAG, "PLATFORM POSTSUBMIT"); + } else { + Log.e(TAG, "ERROR3"); + } + } +} |