Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87827b5d authored by Tony Mak's avatar Tony Mak
Browse files

Add sanity test for work tab

Create work profile and assert the tab is there.
Also, fixed openAllApps in the test.

FIX: 74390632

Change-Id: I526b4da0609643057a3d2306fa0034d57167840e
parent f2523dc8
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -15,9 +15,6 @@
 */
package com.android.launcher3.ui;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import android.app.Instrumentation;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -37,22 +34,27 @@ import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
import android.view.MotionEvent;

import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.testcomponent.AppWidgetNoConfig;
import com.android.launcher3.testcomponent.AppWidgetWithConfig;

import org.junit.Before;

import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Before;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

/**
 * Base class for all instrumentation tests providing various utility methods.
@@ -63,6 +65,7 @@ public abstract class AbstractLauncherUiTest {
    public static final long DEFAULT_BROADCAST_TIMEOUT_SECS = 5;

    public static final long DEFAULT_UI_TIMEOUT = 3000;
    public static final long LARGE_UI_TIMEOUT = 10000;
    public static final long DEFAULT_WORKER_TIMEOUT_SECS = 5;

    protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
@@ -95,8 +98,13 @@ public abstract class AbstractLauncherUiTest {
    protected UiObject2 openAllApps() {
        mDevice.waitForIdle();
        if (FeatureFlags.NO_ALL_APPS_ICON) {
            // clicking on the page indicator brings up all apps tray on non tablets.
            findViewById(R.id.page_indicator).click();
            UiObject2 hotseat = mDevice.wait(
                    Until.findObject(getSelectorForId(R.id.hotseat)), 2500);
            Point start = hotseat.getVisibleCenter();
            int endY = (int) (mDevice.getDisplayHeight() * 0.1f);
            // 100 px/step
            mDevice.swipe(start.x, start.y, start.x, endY, (start.y - endY) / 100);

        } else {
            mDevice.wait(Until.findObject(
                    By.desc(mTargetContext.getString(R.string.all_apps_button_label))),
+79 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018, 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.ui;

import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;

import com.android.launcher3.R;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertTrue;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class WorkTabTest extends AbstractLauncherUiTest {
    @Rule
    public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
    @Rule
    public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher();

    private int mProfileUserId;

    @Before
    public void createWorkProfile() throws Exception {
        String output =
                mDevice.executeShellCommand(
                        "pm create-user --profileOf 0 --managed TestProfile");
        assertTrue("Failed to create work profile", output.startsWith("Success"));

        String[] tokens = output.split("\\s+");
        mProfileUserId = Integer.parseInt(tokens[tokens.length - 1]);

        mDevice.executeShellCommand("am start-user " + mProfileUserId);
    }

    @After
    public void removeWorkProfile() throws Exception {
        mDevice.executeShellCommand("pm remove-user " + mProfileUserId);
    }

    @Test
    public void workTabExists() {
        mActivityMonitor.startLauncher();

        // Open all apps and wait for load complete
        final UiObject2 appsContainer = openAllApps();
        assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT));

        assertTrue("Personal tab is missing",
                mDevice.wait(Until.hasObject(getSelectorForId(R.id.tab_personal)),
                        LARGE_UI_TIMEOUT));
        assertTrue("Work tab is missing",
                mDevice.wait(Until.hasObject(getSelectorForId(R.id.tab_work)), LARGE_UI_TIMEOUT));
    }
}
 No newline at end of file