Add Tests for work profile toggle

+ Fix minor style issues

Bug: 140099753
Bug: 112899690
Test: Manual
Change-Id: I1257560be79748abe54a75a74d93caa4390943b5
This commit is contained in:
Samuel Fufa
2020-02-04 12:08:11 -08:00
parent a7c931dd49
commit ea4dcf468e
7 changed files with 79 additions and 12 deletions

View File

@@ -23,14 +23,14 @@
<ImageView
android:id="@+id/icon"
android:contentDescription="@string/work_apps_paused_title"
android:layout_width="48dp"
android:layout_height="48dp"
android:tint="?attr/folderTextColor"
android:layout_width="32dp"
android:layout_height="32dp"
android:tint="?attr/workProfileOverlayTextColor"
android:src="@drawable/ic_corp_off" />
<TextView
style="@style/TextHeadline"
android:textColor="?attr/folderTextColor"
android:textColor="?attr/workProfileOverlayTextColor"
android:id="@+id/work_apps_paused_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -43,7 +43,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/folderTextColor"
android:textColor="?attr/workProfileOverlayTextColor"
android:text="@string/work_apps_paused_body"
android:textAlignment="center"
android:textSize="16sp" />

View File

@@ -32,6 +32,8 @@
android:layout_weight="1"
android:drawableStart="@drawable/ic_corp"
android:drawablePadding="3dp"
android:drawableTint="?attr/workProfileOverlayTextColor"
android:textColor="?attr/workProfileOverlayTextColor"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"

View File

@@ -41,6 +41,7 @@
<attr name="folderIconBorderColor" format="color" />
<attr name="folderTextColor" format="color" />
<attr name="folderHintColor" format="color" />
<attr name="workProfileOverlayTextColor" format="color" />
<!-- BubbleTextView specific attributes. -->
<declare-styleable name="BubbleTextView">

View File

@@ -50,6 +50,7 @@
<item name="folderTextColor">#FF212121</item>
<item name="folderHintColor">#FF616161</item>
<item name="loadingIconColor">#CCFFFFFF</item>
<item name="workProfileOverlayTextColor">#FF212121</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
@@ -77,6 +78,7 @@
<item name="folderFillColor">#CDFFFFFF</item>
<item name="folderIconBorderColor">#FF80868B</item>
<item name="folderTextColor">?attr/workspaceTextColor</item>
</style>
<style name="LauncherTheme.Dark" parent="@style/LauncherTheme">
@@ -100,6 +102,7 @@
<item name="folderHintColor">#FFCCCCCC</item>
<item name="isMainColorDark">true</item>
<item name="loadingIconColor">#99FFFFFF</item>
<item name="workProfileOverlayTextColor">@android:color/white</item>
</style>
<style name="LauncherTheme.Dark.DarkMainColor" parent="@style/LauncherTheme.Dark">

View File

@@ -153,6 +153,11 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
return mMultiValueAlpha.getProperty(index);
}
public WorkFooterContainer getWorkFooterContainer() {
return mWorkFooterContainer;
}
@Override
protected void setDampedScrollShift(float shift) {
// Bound the shift amount to avoid content from drawing on top (Y-val) of the QSB.

View File

@@ -119,6 +119,13 @@ public class WorkFooterContainer extends LinearLayout implements Insettable {
mWorkModeSwitch.refresh();
}
/**
* Returns work mode switch
*/
public WorkModeSwitch getWorkModeSwitch() {
return mWorkModeSwitch;
}
private boolean shouldShowWorkFooter() {
Launcher launcher = Launcher.getLauncher(getContext());
return Utilities.ATLEAST_P && (hasShortcutsPermission(launcher)

View File

@@ -16,17 +16,32 @@
package com.android.launcher3.ui;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.util.rule.TestStabilityRule.LOCAL;
import static com.android.launcher3.util.rule.TestStabilityRule.UNBUNDLED_POSTSUBMIT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsPagedView;
import com.android.launcher3.util.rule.TestStabilityRule;
import com.android.launcher3.views.WorkFooterContainer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.List;
import java.util.Objects;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class WorkTabTest extends AbstractLauncherUiTest {
@@ -52,16 +67,50 @@ public class WorkTabTest extends AbstractLauncherUiTest {
}
@Test
// b/143285809 Remove @Stability on 02/21/20 if the test doesn't flake.
@TestStabilityRule.Stability(flavors = LOCAL | UNBUNDLED_POSTSUBMIT)
public void workTabExists() {
mDevice.pressHome();
waitForLauncherCondition("Launcher didn't start", launcher -> launcher != null);
waitForLauncherCondition("Launcher didn't start", Objects::nonNull);
executeOnLauncher(launcher -> launcher.getStateManager().goToState(ALL_APPS));
/*
assertTrue("Personal tab is missing", waitForLauncherCondition(
launcher -> launcher.getAppsView().isPersonalTabVisible()));
assertTrue("Work tab is missing", waitForLauncherCondition(
launcher -> launcher.getAppsView().isWorkTabVisible()));
*/
waitForLauncherCondition("Personal tab is missing",
launcher -> launcher.getAppsView().isPersonalTabVisible());
waitForLauncherCondition("Work tab is missing",
launcher -> launcher.getAppsView().isWorkTabVisible());
}
@Test
// b/143285809 Remove @Stability on 02/21/20 if the test doesn't flake.
@TestStabilityRule.Stability(flavors = LOCAL | UNBUNDLED_POSTSUBMIT)
public void toggleWorks() {
mDevice.pressHome();
waitForLauncherCondition("Launcher didn't start", Objects::nonNull);
executeOnLauncher(launcher -> launcher.getStateManager().goToState(ALL_APPS));
waitForState("Launcher internal state didn't switch to All Apps", () -> ALL_APPS);
getOnceNotNull("Apps view did not bind",
launcher -> launcher.getAppsView().getWorkFooterContainer());
UserManager userManager = getFromLauncher(l -> l.getSystemService(UserManager.class));
assertEquals(2, userManager.getUserProfiles().size());
UserHandle workProfile = getFromLauncher(l -> {
UserHandle myHandle = Process.myUserHandle();
List<UserHandle> userProfiles = userManager.getUserProfiles();
return userProfiles.get(0) == myHandle ? userProfiles.get(1) : userProfiles.get(0);
});
waitForLauncherCondition("work profile can't be turned off",
l -> userManager.requestQuietModeEnabled(true, workProfile));
assertTrue(userManager.isQuietModeEnabled(workProfile));
executeOnLauncher(launcher -> {
WorkFooterContainer wf = launcher.getAppsView().getWorkFooterContainer();
((AllAppsPagedView) launcher.getAppsView().getContentView()).snapToPageImmediately(
AllAppsContainerView.AdapterHolder.WORK);
wf.getWorkModeSwitch().toggle();
});
waitForLauncherCondition("Work toggle did not work",
l -> l.getSystemService(UserManager.class).isQuietModeEnabled(workProfile));
}
}