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

Commit 61a4cd44 authored by Joshua Mokut's avatar Joshua Mokut Committed by Android (Google) Code Review
Browse files

Merge "Remove shortcut helper rewrite flags from Tests" into main

parents ce0cf889 74dcc16a
Loading
Loading
Loading
Loading
+0 −179
Original line number Diff line number Diff line
/*
 * Copyright (c) 2023 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.systemui.statusbar;

import static com.android.systemui.Flags.FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE;

import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.content.Intent;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.dx.mockito.inline.extended.StaticMockitoSession;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.flags.FakeFeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.shared.recents.utilities.Utilities;
import com.android.systemui.utils.windowmanager.WindowManagerProvider;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.quality.Strictness;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class KeyboardShortcutsReceiverTest extends SysuiTestCase {

    private static final Intent SHOW_INTENT = new Intent(Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS);
    private static final Intent DISMISS_INTENT =
            new Intent(Intent.ACTION_DISMISS_KEYBOARD_SHORTCUTS);

    private StaticMockitoSession mockitoSession;
    private KeyboardShortcutsReceiver mKeyboardShortcutsReceiver;
    private final FakeFeatureFlags mFeatureFlags = new FakeFeatureFlags();

    @Mock private KeyboardShortcuts mKeyboardShortcuts;
    @Mock private KeyboardShortcutListSearch mKeyboardShortcutListSearch;
    @Mock private WindowManagerProvider mWindowManagerProvider;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mSetFlagsRule.disableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE);
        mKeyboardShortcuts.mContext = mContext;
        mKeyboardShortcutListSearch.mContext = mContext;
        KeyboardShortcuts.sInstance = mKeyboardShortcuts;
        KeyboardShortcutListSearch.sInstance = mKeyboardShortcutListSearch;

        mKeyboardShortcutsReceiver = spy(new KeyboardShortcutsReceiver(mFeatureFlags,
                mWindowManagerProvider));
    }

    @Before
    public void startStaticMocking() {
        mockitoSession =
                ExtendedMockito.mockitoSession()
                        .spyStatic(Utilities.class)
                        .strictness(Strictness.LENIENT)
                        .startMocking();
    }

    @After
    public void endStaticMocking() {
        mockitoSession.finishMocking();
    }

    @Test
    public void onReceive_whenFlagOffDeviceIsTablet_showKeyboardShortcuts() {
        mFeatureFlags.set(Flags.SHORTCUT_LIST_SEARCH_LAYOUT, false);
        when(Utilities.isLargeScreen(mContext)).thenReturn(true);

        mKeyboardShortcutsReceiver.onReceive(mContext, SHOW_INTENT);

        verify(mKeyboardShortcuts).showKeyboardShortcuts(anyInt());
        verify(mKeyboardShortcutListSearch, never()).showKeyboardShortcuts(anyInt());
    }

    @Test
    public void onReceive_whenFlagOffDeviceIsNotTablet_showKeyboardShortcuts() {
        mFeatureFlags.set(Flags.SHORTCUT_LIST_SEARCH_LAYOUT, false);
        when(Utilities.isLargeScreen(mContext)).thenReturn(false);

        mKeyboardShortcutsReceiver.onReceive(mContext, SHOW_INTENT);

        verify(mKeyboardShortcuts).showKeyboardShortcuts(anyInt());
        verify(mKeyboardShortcutListSearch, never()).showKeyboardShortcuts(anyInt());
    }

    @Test
    public void onReceive_whenFlagOnDeviceIsTablet_showKeyboardShortcutListSearch() {
        mFeatureFlags.set(Flags.SHORTCUT_LIST_SEARCH_LAYOUT, true);
        when(Utilities.isLargeScreen(mContext)).thenReturn(true);

        mKeyboardShortcutsReceiver.onReceive(mContext, SHOW_INTENT);

        verify(mKeyboardShortcuts, never()).showKeyboardShortcuts(anyInt());
        verify(mKeyboardShortcutListSearch).showKeyboardShortcuts(anyInt());
    }

    @Test
    public void onReceive_whenFlagOnDeviceIsNotTablet_showKeyboardShortcuts() {
        mFeatureFlags.set(Flags.SHORTCUT_LIST_SEARCH_LAYOUT, true);
        when(Utilities.isLargeScreen(mContext)).thenReturn(false);

        mKeyboardShortcutsReceiver.onReceive(mContext, SHOW_INTENT);

        verify(mKeyboardShortcuts).showKeyboardShortcuts(anyInt());
        verify(mKeyboardShortcutListSearch, never()).showKeyboardShortcuts(anyInt());
    }

    @Test
    public void onShowIntent_rewriteFlagOn_oldFlagOn_isLargeScreen_doesNotLaunchOldVersions() {
        mFeatureFlags.set(Flags.SHORTCUT_LIST_SEARCH_LAYOUT, true);
        mSetFlagsRule.enableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE);
        when(Utilities.isLargeScreen(mContext)).thenReturn(true);

        mKeyboardShortcutsReceiver.onReceive(mContext, SHOW_INTENT);

        verifyNoMoreInteractions(mKeyboardShortcuts, mKeyboardShortcutListSearch);
    }

    @Test
    public void onShowIntent_rewriteFlagOn_oldFlagOn_isSmallScreen_doesNotLaunchOldVersions() {
        mFeatureFlags.set(Flags.SHORTCUT_LIST_SEARCH_LAYOUT, true);
        mSetFlagsRule.enableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE);
        when(Utilities.isLargeScreen(mContext)).thenReturn(false);

        mKeyboardShortcutsReceiver.onReceive(mContext, SHOW_INTENT);

        verifyNoMoreInteractions(mKeyboardShortcuts, mKeyboardShortcutListSearch);
    }

    @Test
    public void onDismissIntent_rewriteFlagOn_oldFlagOn_isLargeScreen_doesNotDismissOldVersions() {
        mFeatureFlags.set(Flags.SHORTCUT_LIST_SEARCH_LAYOUT, true);
        mSetFlagsRule.enableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE);
        when(Utilities.isLargeScreen(mContext)).thenReturn(true);

        mKeyboardShortcutsReceiver.onReceive(mContext, DISMISS_INTENT);

        verifyNoMoreInteractions(mKeyboardShortcuts, mKeyboardShortcutListSearch);
    }

    @Test
    public void onDismissIntent_rewriteFlagOn_oldFlagOn_isSmallScreen_doesNotDismissOldVersions() {
        mFeatureFlags.set(Flags.SHORTCUT_LIST_SEARCH_LAYOUT, true);
        mSetFlagsRule.enableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE);
        when(Utilities.isLargeScreen(mContext)).thenReturn(false);

        mKeyboardShortcutsReceiver.onReceive(mContext, DISMISS_INTENT);

        verifyNoMoreInteractions(mKeyboardShortcuts, mKeyboardShortcutListSearch);
    }
}
+0 −112
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import static android.hardware.devicestate.DeviceState.PROPERTY_POWER_CONFIGURAT
import static android.provider.Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED;
import static android.provider.Settings.Global.HEADS_UP_ON;

import static com.android.systemui.Flags.FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE;
import static com.android.systemui.flags.Flags.SHORTCUT_LIST_SEARCH_LAYOUT;
import static com.android.systemui.shared.Flags.FLAG_AMBIENT_AOD;
import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
@@ -1243,7 +1242,6 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @EnableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void dismissKeyboardShortcuts_largeScreen_bothFlagsEnabled_doesNotDismissAny() {
        switchToLargeScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, true);
@@ -1255,32 +1253,6 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void dismissKeyboardShortcuts_largeScreen_newFlagsDisabled_dismissesTabletVersion() {
        switchToLargeScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, true);
        createCentralSurfaces();

        dismissKeyboardShortcuts();

        verify(mKeyboardShortcutListSearch).dismissKeyboardShortcuts();
    }

    @Test
    @DisableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void dismissKeyboardShortcuts_largeScreen_bothFlagsDisabled_dismissesPhoneVersion() {
        switchToLargeScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, false);
        createCentralSurfaces();

        dismissKeyboardShortcuts();

        verify(mKeyboardShortcuts).dismissKeyboardShortcuts();
        verifyNoMoreInteractions(mKeyboardShortcutListSearch);
    }

    @Test
    @EnableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void dismissKeyboardShortcuts_smallScreen_bothFlagsEnabled_doesNotDismissAny() {
        switchToSmallScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, true);
@@ -1292,33 +1264,6 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void dismissKeyboardShortcuts_smallScreen_newFlagsDisabled_dismissesPhoneVersion() {
        switchToSmallScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, true);
        createCentralSurfaces();

        dismissKeyboardShortcuts();

        verify(mKeyboardShortcuts).dismissKeyboardShortcuts();
        verifyNoMoreInteractions(mKeyboardShortcutListSearch);
    }

    @Test
    @DisableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void dismissKeyboardShortcuts_smallScreen_bothFlagsDisabled_dismissesPhoneVersion() {
        switchToSmallScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, false);
        createCentralSurfaces();

        dismissKeyboardShortcuts();

        verify(mKeyboardShortcuts).dismissKeyboardShortcuts();
        verifyNoMoreInteractions(mKeyboardShortcutListSearch);
    }

    @Test
    @EnableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void toggleKeyboardShortcuts_largeScreen_bothFlagsEnabled_doesNotTogglesAny() {
        switchToLargeScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, true);
@@ -1331,35 +1276,6 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void toggleKeyboardShortcuts_largeScreen_newFlagsDisabled_togglesTabletVersion() {
        switchToLargeScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, true);
        createCentralSurfaces();

        int deviceId = 654;
        toggleKeyboardShortcuts(deviceId);

        verify(mKeyboardShortcutListSearch).showKeyboardShortcuts(deviceId);
        verifyNoMoreInteractions(mKeyboardShortcuts);
    }

    @Test
    @DisableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void toggleKeyboardShortcuts_largeScreen_bothFlagsDisabled_togglesPhoneVersion() {
        switchToLargeScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, false);
        createCentralSurfaces();

        int deviceId = 987;
        toggleKeyboardShortcuts(deviceId);

        verify(mKeyboardShortcuts).showKeyboardShortcuts(deviceId);
        verifyNoMoreInteractions(mKeyboardShortcutListSearch);
    }

    @Test
    @EnableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void toggleKeyboardShortcuts_smallScreen_bothFlagsEnabled_doesNotToggleAny() {
        switchToSmallScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, true);
@@ -1371,34 +1287,6 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
        verifyNoMoreInteractions(mKeyboardShortcuts, mKeyboardShortcutListSearch);
    }

    @Test
    @DisableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void toggleKeyboardShortcuts_smallScreen_newFlagsDisabled_togglesPhoneVersion() {
        switchToSmallScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, true);
        createCentralSurfaces();

        int deviceId = 456;
        toggleKeyboardShortcuts(deviceId);

        verify(mKeyboardShortcuts).showKeyboardShortcuts(deviceId);
        verifyNoMoreInteractions(mKeyboardShortcutListSearch);
    }

    @Test
    @DisableFlags(FLAG_KEYBOARD_SHORTCUT_HELPER_REWRITE)
    public void toggleKeyboardShortcuts_smallScreen_bothFlagsDisabled_togglesPhoneVersion() {
        switchToSmallScreen();
        mFeatureFlags.set(SHORTCUT_LIST_SEARCH_LAYOUT, false);
        createCentralSurfaces();

        int deviceId = 123;
        toggleKeyboardShortcuts(deviceId);

        verify(mKeyboardShortcuts).showKeyboardShortcuts(deviceId);
        verifyNoMoreInteractions(mKeyboardShortcutListSearch);
    }

    private void dismissKeyboardShortcuts() {
        mMessageRouter.sendMessage(MSG_DISMISS_KEYBOARD_SHORTCUTS_MENU);
        mMainExecutor.runAllReady();