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

Commit a3d673a8 authored by Eric Lin's avatar Eric Lin Committed by Android (Google) Code Review
Browse files

Merge "Move MockToken to shared test utils module." into main

parents 9e4a50f4 037f522d
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -18,11 +18,9 @@ package com.android.wm.shell.bubbles

import android.content.ComponentName
import android.content.Context
import android.os.IBinder
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import android.platform.test.flag.junit.SetFlagsRule
import android.window.IWindowContainerToken
import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import androidx.test.core.app.ApplicationProvider
@@ -32,11 +30,12 @@ import com.android.window.flags.Flags.FLAG_DISALLOW_BUBBLE_TO_ENTER_PIP
import com.android.window.flags.Flags.FLAG_EXCLUDE_TASK_FROM_RECENTS
import com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_ANYTHING
import com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_TASK_VIEW_LISTENER
import com.android.wm.shell.MockToken
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.bubbles.util.BubbleTestUtils.verifyEnterBubbleTransaction
import com.android.wm.shell.taskview.TaskView
import com.android.wm.shell.taskview.TaskViewController
import com.android.wm.shell.taskview.TaskViewTaskController
import com.android.wm.shell.bubbles.util.BubbleTestUtils.verifyEnterBubbleTransaction
import com.google.common.truth.Truth.assertThat
import com.google.common.util.concurrent.MoreExecutors.directExecutor
import org.junit.Before
@@ -68,9 +67,7 @@ class BubbleExpandedViewTest(flags: FlagsParameterization) {
    private val componentName = ComponentName(context, "TestClass")

    private val taskOrganizer = mock<ShellTaskOrganizer>()
    private val taskViewTaskToken = WindowContainerToken(mock<IWindowContainerToken> {
        on { asBinder() } doReturn mock<IBinder>()
    })
    private val taskViewTaskToken: WindowContainerToken = MockToken.token()
    private var taskViewController = mock<TaskViewController>()
    private val taskViewTaskController = mock<TaskViewTaskController> {
        on { taskOrganizer } doReturn taskOrganizer
+4 −7
Original line number Diff line number Diff line
@@ -20,10 +20,8 @@ import android.app.ActivityManager
import android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD
import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN
import android.os.Binder
import android.os.IBinder
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import android.window.IWindowContainerToken
import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -34,11 +32,13 @@ import com.android.window.flags.Flags.FLAG_EXCLUDE_TASK_FROM_RECENTS
import com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_ANYTHING
import com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_APP_COMPAT_FIXES
import com.android.wm.shell.Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE
import com.android.wm.shell.MockToken
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.bubbles.util.BubbleTestUtils.verifyExitBubbleTransaction
import com.android.wm.shell.splitscreen.SplitScreenController
import com.android.wm.shell.taskview.TaskView
import com.android.wm.shell.taskview.TaskViewTaskController
import com.android.wm.shell.splitscreen.SplitScreenController
import java.util.Optional
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -51,7 +51,6 @@ import org.mockito.kotlin.never
import org.mockito.kotlin.stub
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyNoInteractions
import java.util.Optional

/**
 * Unit tests for [BubbleTaskStackListener].
@@ -85,9 +84,7 @@ class BubbleTaskStackListenerTest {
        { Optional.of(splitScreenController) },
    )
    private val bubbleTaskId = 123
    private val bubbleTaskToken = WindowContainerToken(mock<IWindowContainerToken> {
        on { asBinder() } doReturn mock<IBinder>()
    })
    private val bubbleTaskToken: WindowContainerToken = MockToken.token()
    private val task = ActivityManager.RunningTaskInfo().apply {
        taskId = bubbleTaskId
        token = bubbleTaskToken
+2 −5
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.content.Context
import android.content.Intent
import android.content.pm.ShortcutInfo
import android.graphics.drawable.Icon
import android.os.IBinder
import android.os.UserHandle
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
@@ -33,7 +32,6 @@ import android.service.notification.NotificationListenerService.Ranking
import android.service.notification.StatusBarNotification
import android.view.View
import android.widget.FrameLayout
import android.window.IWindowContainerToken
import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import androidx.test.core.app.ApplicationProvider
@@ -45,6 +43,7 @@ import com.android.window.flags.Flags.FLAG_DISALLOW_BUBBLE_TO_ENTER_PIP
import com.android.window.flags.Flags.FLAG_EXCLUDE_TASK_FROM_RECENTS
import com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_ANYTHING
import com.android.wm.shell.Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE
import com.android.wm.shell.MockToken
import com.android.wm.shell.R
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.bubbles.Bubbles.BubbleMetadataFlagListener
@@ -87,9 +86,7 @@ class BubbleTaskViewListenerTest {
    private val context = ApplicationProvider.getApplicationContext<Context>()

    private val taskOrganizer = mock<ShellTaskOrganizer>()
    private val taskViewTaskToken = WindowContainerToken(mock<IWindowContainerToken> {
        on { asBinder() } doReturn mock<IBinder>()
    })
    private val taskViewTaskToken: WindowContainerToken = MockToken.token()
    private var taskViewController = mock<TaskViewController>()
    private val taskInfo = mock<ActivityManager.RunningTaskInfo>()
    private val taskViewTaskController = mock<TaskViewTaskController> {
+0 −40
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.wm.shell;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.os.IBinder;
import android.window.WindowContainerToken;

/**
 * {@link WindowContainerToken} wrapper that supports a mock binder
 */
public class MockToken {
    private final WindowContainerToken mToken;

    public MockToken() {
        mToken = mock(WindowContainerToken.class);
        IBinder binder = mock(IBinder.class);
        when(mToken.asBinder()).thenReturn(binder);
    }

    public WindowContainerToken token() {
        return mToken;
    }
}
+1 −13
Original line number Diff line number Diff line
@@ -20,9 +20,6 @@ import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.WindowConfiguration;
@@ -30,16 +27,14 @@ import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.IBinder;
import android.view.Display;
import android.window.IWindowContainerToken;
import android.window.WindowContainerToken;

public final class TestRunningTaskInfoBuilder {
    static int sNextTaskId = 500;
    private Rect mBounds = new Rect(0, 0, 100, 100);

    private WindowContainerToken mToken = createMockWCToken();
    private WindowContainerToken mToken = new MockToken().token();
    private int mParentTaskId = INVALID_TASK_ID;
    private int mUid = INVALID_TASK_ID;
    private int mTaskId = INVALID_TASK_ID;
@@ -59,13 +54,6 @@ public final class TestRunningTaskInfoBuilder {
    private int mNumActivities = 1;
    private long mLastActiveTime;

    public static WindowContainerToken createMockWCToken() {
        final IWindowContainerToken itoken = mock(IWindowContainerToken.class);
        final IBinder asBinder = mock(IBinder.class);
        doReturn(asBinder).when(itoken).asBinder();
        return new WindowContainerToken(itoken);
    }

    public TestRunningTaskInfoBuilder setToken(WindowContainerToken token) {
        mToken = token;
        return this;
Loading