Loading src/com/android/launcher3/testing/HotseatCellCenterRequest.java 0 → 100644 +99 −0 Original line number Diff line number Diff line /* * 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.launcher3.testing; import android.os.Parcel; import android.os.Parcelable; /** * Request object for querying a hotseat cell region in Rect. */ public class HotseatCellCenterRequest implements TestInformationRequest { public final int cellInd; @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(cellInd); } @Override public String getRequestName() { return TestProtocol.REQUEST_HOTSEAT_CELL_CENTER; } public static final Parcelable.Creator<HotseatCellCenterRequest> CREATOR = new Parcelable.Creator<HotseatCellCenterRequest>() { @Override public HotseatCellCenterRequest createFromParcel(Parcel source) { return new HotseatCellCenterRequest(source); } @Override public HotseatCellCenterRequest[] newArray(int size) { return new HotseatCellCenterRequest[size]; } }; private HotseatCellCenterRequest(int cellInd) { this.cellInd = cellInd; } private HotseatCellCenterRequest(Parcel in) { this(in.readInt()); } /** * Create a builder for HotseatCellCenterRequest. * * @return HotseatCellCenterRequest builder. */ public static HotseatCellCenterRequest.Builder builder() { return new HotseatCellCenterRequest.Builder(); } /** * HotseatCellCenterRequest Builder. */ public static final class Builder { private int mCellInd; private Builder() { mCellInd = 0; } /** * Set the index of hotseat cells. */ public HotseatCellCenterRequest.Builder setCellInd(int i) { this.mCellInd = i; return this; } /** * build the HotseatCellCenterRequest. */ public HotseatCellCenterRequest build() { return new HotseatCellCenterRequest(mCellInd); } } } src/com/android/launcher3/testing/TestInformationHandler.java +17 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import androidx.annotation.Nullable; import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Hotseat; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; Loading Loading @@ -185,7 +186,7 @@ public class TestInformationHandler implements ResourceBasedOverride { return new int[]{cellLayout.getCountX(), cellLayout.getCountY()}; }); case TestProtocol.REQUEST_WORKSPACE_CELL_CENTER: case TestProtocol.REQUEST_WORKSPACE_CELL_CENTER: { final WorkspaceCellCenterRequest request = extra.getParcelable( TestProtocol.TEST_INFO_REQUEST_FIELD); return getLauncherUIProperty(Bundle::putParcelable, launcher -> { Loading @@ -197,6 +198,21 @@ public class TestInformationHandler implements ResourceBasedOverride { cellLayout, request.cellX, request.cellY, request.spanX, request.spanY); return new Point(cellRect.centerX(), cellRect.centerY()); }); } case TestProtocol.REQUEST_HOTSEAT_CELL_CENTER: { final HotseatCellCenterRequest request = extra.getParcelable( TestProtocol.TEST_INFO_REQUEST_FIELD); return getLauncherUIProperty(Bundle::putParcelable, launcher -> { final Hotseat hotseat = launcher.getHotseat(); final Rect cellRect = getDescendantRectRelativeToDragLayerForCell(launcher, hotseat, request.cellInd, /* cellY= */ 0, /* spanX= */ 1, /* spanY= */ 1); // TODO(b/234322284): return the real center point. return new Point(cellRect.left + (cellRect.right - cellRect.left) / 3, cellRect.centerY()); }); } case TestProtocol.REQUEST_HAS_TIS: { response.putBoolean( Loading src/com/android/launcher3/testing/TestProtocol.java +2 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,8 @@ public final class TestProtocol { public static final String REQUEST_WORKSPACE_CELL_LAYOUT_SIZE = "workspace-cell-layout-size"; public static final String REQUEST_WORKSPACE_CELL_CENTER = "workspace-cell-center"; public static final String REQUEST_HOTSEAT_CELL_CENTER = "hotseat-cell-center"; public static final String REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET = "get-focused-task-height-for-tablet"; public static final String REQUEST_GET_GRID_TASK_SIZE_RECT_FOR_TABLET = Loading tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +12 −0 Original line number Diff line number Diff line Loading @@ -554,6 +554,18 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { } } @Test @PortraitLandscape public void testAddDeleteShortcutOnHotseat() { mLauncher.getWorkspace() .deleteAppIcon(mLauncher.getWorkspace().getHotseatAppIcon(0)) .switchToAllApps() .getAppIcon(APP_NAME) .dragToHotseat(0); mLauncher.getWorkspace().deleteAppIcon( mLauncher.getWorkspace().getHotseatAppIcon(APP_NAME)); } /** * @return List of workspace grid coordinates. Those are not pixels. See {@link * Workspace#getIconGridDimensions()} Loading tests/tapl/com/android/launcher3/tapl/HomeAppIcon.java +39 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ import android.graphics.Rect; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; import java.util.function.Supplier; /** * App icon on the workspace or all apps. */ Loading Loading @@ -100,9 +102,46 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W } } /** * Drag an object to the given cell in hotseat. The target cell should be expected to be empty. * * @param cellInd zero based index number of the hotseat cells. * @return the workspace app icon. */ @NonNull public WorkspaceAppIcon dragToHotseat(int cellInd) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer( String.format("want to drag the icon to hotseat cell %d", cellInd)) ) { final Supplier<Point> dest = () -> Workspace.getHotseatCellCenter(mLauncher, cellInd); Workspace.dragIconToHotseat( mLauncher, this, dest, () -> addExpectedEventsForLongClick(), /*expectDropEvents= */ null); try (LauncherInstrumentation.Closable ignore = mLauncher.addContextLayer("dragged")) { WorkspaceAppIcon appIcon = (WorkspaceAppIcon) mLauncher.getWorkspace().getHotseatAppIcon(mAppName); mLauncher.assertTrue( String.format("The %s icon should be in the hotseat cell %d.", mAppName, cellInd), appIcon.isInHotseatCell(cellInd)); return appIcon; } } } /** This method requires public access, however should not be called in tests. */ @Override public Launchable getLaunchable() { return this; } boolean isInHotseatCell(int cellInd) { final Point center = Workspace.getHotseatCellCenter(mLauncher, cellInd); return mObject.getVisibleBounds().contains(center.x, center.y); } } Loading
src/com/android/launcher3/testing/HotseatCellCenterRequest.java 0 → 100644 +99 −0 Original line number Diff line number Diff line /* * 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.launcher3.testing; import android.os.Parcel; import android.os.Parcelable; /** * Request object for querying a hotseat cell region in Rect. */ public class HotseatCellCenterRequest implements TestInformationRequest { public final int cellInd; @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(cellInd); } @Override public String getRequestName() { return TestProtocol.REQUEST_HOTSEAT_CELL_CENTER; } public static final Parcelable.Creator<HotseatCellCenterRequest> CREATOR = new Parcelable.Creator<HotseatCellCenterRequest>() { @Override public HotseatCellCenterRequest createFromParcel(Parcel source) { return new HotseatCellCenterRequest(source); } @Override public HotseatCellCenterRequest[] newArray(int size) { return new HotseatCellCenterRequest[size]; } }; private HotseatCellCenterRequest(int cellInd) { this.cellInd = cellInd; } private HotseatCellCenterRequest(Parcel in) { this(in.readInt()); } /** * Create a builder for HotseatCellCenterRequest. * * @return HotseatCellCenterRequest builder. */ public static HotseatCellCenterRequest.Builder builder() { return new HotseatCellCenterRequest.Builder(); } /** * HotseatCellCenterRequest Builder. */ public static final class Builder { private int mCellInd; private Builder() { mCellInd = 0; } /** * Set the index of hotseat cells. */ public HotseatCellCenterRequest.Builder setCellInd(int i) { this.mCellInd = i; return this; } /** * build the HotseatCellCenterRequest. */ public HotseatCellCenterRequest build() { return new HotseatCellCenterRequest(mCellInd); } } }
src/com/android/launcher3/testing/TestInformationHandler.java +17 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import androidx.annotation.Nullable; import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Hotseat; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; Loading Loading @@ -185,7 +186,7 @@ public class TestInformationHandler implements ResourceBasedOverride { return new int[]{cellLayout.getCountX(), cellLayout.getCountY()}; }); case TestProtocol.REQUEST_WORKSPACE_CELL_CENTER: case TestProtocol.REQUEST_WORKSPACE_CELL_CENTER: { final WorkspaceCellCenterRequest request = extra.getParcelable( TestProtocol.TEST_INFO_REQUEST_FIELD); return getLauncherUIProperty(Bundle::putParcelable, launcher -> { Loading @@ -197,6 +198,21 @@ public class TestInformationHandler implements ResourceBasedOverride { cellLayout, request.cellX, request.cellY, request.spanX, request.spanY); return new Point(cellRect.centerX(), cellRect.centerY()); }); } case TestProtocol.REQUEST_HOTSEAT_CELL_CENTER: { final HotseatCellCenterRequest request = extra.getParcelable( TestProtocol.TEST_INFO_REQUEST_FIELD); return getLauncherUIProperty(Bundle::putParcelable, launcher -> { final Hotseat hotseat = launcher.getHotseat(); final Rect cellRect = getDescendantRectRelativeToDragLayerForCell(launcher, hotseat, request.cellInd, /* cellY= */ 0, /* spanX= */ 1, /* spanY= */ 1); // TODO(b/234322284): return the real center point. return new Point(cellRect.left + (cellRect.right - cellRect.left) / 3, cellRect.centerY()); }); } case TestProtocol.REQUEST_HAS_TIS: { response.putBoolean( Loading
src/com/android/launcher3/testing/TestProtocol.java +2 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,8 @@ public final class TestProtocol { public static final String REQUEST_WORKSPACE_CELL_LAYOUT_SIZE = "workspace-cell-layout-size"; public static final String REQUEST_WORKSPACE_CELL_CENTER = "workspace-cell-center"; public static final String REQUEST_HOTSEAT_CELL_CENTER = "hotseat-cell-center"; public static final String REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET = "get-focused-task-height-for-tablet"; public static final String REQUEST_GET_GRID_TASK_SIZE_RECT_FOR_TABLET = Loading
tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +12 −0 Original line number Diff line number Diff line Loading @@ -554,6 +554,18 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { } } @Test @PortraitLandscape public void testAddDeleteShortcutOnHotseat() { mLauncher.getWorkspace() .deleteAppIcon(mLauncher.getWorkspace().getHotseatAppIcon(0)) .switchToAllApps() .getAppIcon(APP_NAME) .dragToHotseat(0); mLauncher.getWorkspace().deleteAppIcon( mLauncher.getWorkspace().getHotseatAppIcon(APP_NAME)); } /** * @return List of workspace grid coordinates. Those are not pixels. See {@link * Workspace#getIconGridDimensions()} Loading
tests/tapl/com/android/launcher3/tapl/HomeAppIcon.java +39 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ import android.graphics.Rect; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; import java.util.function.Supplier; /** * App icon on the workspace or all apps. */ Loading Loading @@ -100,9 +102,46 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W } } /** * Drag an object to the given cell in hotseat. The target cell should be expected to be empty. * * @param cellInd zero based index number of the hotseat cells. * @return the workspace app icon. */ @NonNull public WorkspaceAppIcon dragToHotseat(int cellInd) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer( String.format("want to drag the icon to hotseat cell %d", cellInd)) ) { final Supplier<Point> dest = () -> Workspace.getHotseatCellCenter(mLauncher, cellInd); Workspace.dragIconToHotseat( mLauncher, this, dest, () -> addExpectedEventsForLongClick(), /*expectDropEvents= */ null); try (LauncherInstrumentation.Closable ignore = mLauncher.addContextLayer("dragged")) { WorkspaceAppIcon appIcon = (WorkspaceAppIcon) mLauncher.getWorkspace().getHotseatAppIcon(mAppName); mLauncher.assertTrue( String.format("The %s icon should be in the hotseat cell %d.", mAppName, cellInd), appIcon.isInHotseatCell(cellInd)); return appIcon; } } } /** This method requires public access, however should not be called in tests. */ @Override public Launchable getLaunchable() { return this; } boolean isInHotseatCell(int cellInd) { final Point center = Workspace.getHotseatCellCenter(mLauncher, cellInd); return mObject.getVisibleBounds().contains(center.x, center.y); } }