Commit 32131e10 authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Allow screenshots to be taken in non-incognito Grid Tab Switcher

Bug: None
Change-Id: I32d97be235c917b49a3bcb7866cf5083f4b0175f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2005975Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734991}
parent ea83b160
...@@ -12,7 +12,7 @@ import androidx.annotation.VisibleForTesting; ...@@ -12,7 +12,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver; import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver;
import org.chromium.chrome.browser.compositor.layouts.LayoutManagerChrome; import org.chromium.chrome.browser.compositor.layouts.LayoutManagerChrome;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.FeatureUtilities;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
...@@ -22,7 +22,6 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector; ...@@ -22,7 +22,6 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector;
public class IncognitoTabSnapshotController extends EmptyTabModelSelectorObserver { public class IncognitoTabSnapshotController extends EmptyTabModelSelectorObserver {
private final Window mWindow; private final Window mWindow;
private final TabModelSelector mTabModelSelector; private final TabModelSelector mTabModelSelector;
private final OverviewModeObserver mOverviewModeObserver;
private boolean mInOverviewMode; private boolean mInOverviewMode;
/** /**
...@@ -44,7 +43,7 @@ public class IncognitoTabSnapshotController extends EmptyTabModelSelectorObserve ...@@ -44,7 +43,7 @@ public class IncognitoTabSnapshotController extends EmptyTabModelSelectorObserve
mWindow = window; mWindow = window;
mTabModelSelector = tabModelSelector; mTabModelSelector = tabModelSelector;
mOverviewModeObserver = new EmptyOverviewModeObserver() { OverviewModeObserver mOverviewModeObserver = new EmptyOverviewModeObserver() {
@Override @Override
public void onOverviewModeStartedShowing(boolean showToolbar) { public void onOverviewModeStartedShowing(boolean showToolbar) {
mInOverviewMode = true; mInOverviewMode = true;
...@@ -92,19 +91,23 @@ public class IncognitoTabSnapshotController extends EmptyTabModelSelectorObserve ...@@ -92,19 +91,23 @@ public class IncognitoTabSnapshotController extends EmptyTabModelSelectorObserve
boolean isInIncognitoModel = mTabModelSelector.getCurrentModel().isIncognito(); boolean isInIncognitoModel = mTabModelSelector.getCurrentModel().isIncognito();
// If we're using the overlapping tab switcher, we show the edge of the open incognito tabs // If we're using the overlapping tab switcher, we show the edge of the open incognito tabs
// even if the tab switcher is showing the normal stack. But if the horizontal tab switcher // even if the tab switcher is showing the normal stack. But if the grid tab switcher
// is enabled, incognito tabs are not visible while we're showing the normal tabs. // is enabled, incognito tabs are not visible while we're showing the normal tabs.
return isInIncognitoModel return isInIncognitoModel
|| (!ChromeFeatureList.isEnabled(ChromeFeatureList.HORIZONTAL_TAB_SWITCHER_ANDROID) || (!isGridTabSwitcherEnabled() && mInOverviewMode && getIncognitoTabCount() > 0);
&& mInOverviewMode && getIncognitoTabCount() > 0);
} }
// Set in overview mode for testing. // Set in overview mode for testing.
@VisibleForTesting @VisibleForTesting
public void setInOverViewMode(boolean overviewMode) { void setInOverViewMode(boolean overviewMode) {
mInOverviewMode = overviewMode; mInOverviewMode = overviewMode;
} }
@VisibleForTesting
public boolean isGridTabSwitcherEnabled() {
return FeatureUtilities.isGridTabSwitcherEnabled();
}
/** /**
* @return The number of incognito tabs. * @return The number of incognito tabs.
*/ */
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.incognito; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.incognito;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import android.view.Window; import android.view.Window;
...@@ -23,12 +24,9 @@ import org.robolectric.annotation.Config; ...@@ -23,12 +24,9 @@ import org.robolectric.annotation.Config;
import org.chromium.base.test.BaseRobolectricTestRunner; import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.browser.compositor.layouts.LayoutManagerChrome; import org.chromium.chrome.browser.compositor.layouts.LayoutManagerChrome;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import java.util.HashMap;
/** /**
* Unit tests for IncognitoTabSnapshotController.java. * Unit tests for IncognitoTabSnapshotController.java.
*/ */
...@@ -58,51 +56,53 @@ public class IncognitoTabSnapshotControllerTest { ...@@ -58,51 +56,53 @@ public class IncognitoTabSnapshotControllerTest {
} }
@Test @Test
public void testUpdateIncognitoStateIncognitoAndEarlyReturn() { public void testUpdateIncognitoState_IncognitoAndEarlyReturn() {
mParams.flags = WindowManager.LayoutParams.FLAG_SECURE; mParams.flags = WindowManager.LayoutParams.FLAG_SECURE;
doReturn(mParams).when(mWindow).getAttributes(); doReturn(mParams).when(mWindow).getAttributes();
mController = new TestIncognitoTabSnapshotController(true); mController = spy(new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector));
doReturn(true).when(mController).isShowingIncognito();
mController.updateIncognitoState(); mController.updateIncognitoState();
verify(mWindow, never()).addFlags(WindowManager.LayoutParams.FLAG_SECURE); verify(mWindow, never()).addFlags(WindowManager.LayoutParams.FLAG_SECURE);
verify(mWindow, never()).clearFlags(WindowManager.LayoutParams.FLAG_SECURE); verify(mWindow, never()).clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
Assert.assertEquals(
"Flag should be secure", WindowManager.LayoutParams.FLAG_SECURE, mParams.flags);
} }
@Test @Test
public void testUpdateIncognitoStateNotIncognitoAndEarlyReturn() { public void testUpdateIncognitoState_NotIncognitoAndEarlyReturn() {
mParams.flags = 0; mParams.flags = 0;
doReturn(mParams).when(mWindow).getAttributes(); doReturn(mParams).when(mWindow).getAttributes();
mController = new TestIncognitoTabSnapshotController(false); mController = spy(new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector));
doReturn(false).when(mController).isShowingIncognito();
mController.updateIncognitoState(); mController.updateIncognitoState();
verify(mWindow, never()).addFlags(WindowManager.LayoutParams.FLAG_SECURE); verify(mWindow, never()).addFlags(WindowManager.LayoutParams.FLAG_SECURE);
Assert.assertEquals("Flag should be zero", 0, mParams.flags); verify(mWindow, never()).clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
} }
@Test @Test
public void testUpdateIncognitoStateSwitchingToIncognito() { public void testUpdateIncognitoState_SwitchingToIncognito() {
mParams.flags = 0; mParams.flags = 0;
doReturn(mParams).when(mWindow).getAttributes(); doReturn(mParams).when(mWindow).getAttributes();
mController = new TestIncognitoTabSnapshotController(true); mController = spy(new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector));
doReturn(true).when(mController).isShowingIncognito();
mController.updateIncognitoState(); mController.updateIncognitoState();
verify(mWindow, atLeastOnce()).addFlags(WindowManager.LayoutParams.FLAG_SECURE); verify(mWindow, atLeastOnce()).addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} }
@Test @Test
public void testUpdateIncognitoStateSwitchingToNonIncognito() { public void testUpdateIncognitoState_SwitchingToNonIncognito() {
mParams.flags = WindowManager.LayoutParams.FLAG_SECURE; mParams.flags = WindowManager.LayoutParams.FLAG_SECURE;
doReturn(mParams).when(mWindow).getAttributes(); doReturn(mParams).when(mWindow).getAttributes();
mController = new TestIncognitoTabSnapshotController(false); mController = spy(new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector));
doReturn(false).when(mController).isShowingIncognito();
mController.updateIncognitoState(); mController.updateIncognitoState();
verify(mWindow, atLeastOnce()).clearFlags(WindowManager.LayoutParams.FLAG_SECURE); verify(mWindow, atLeastOnce()).clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
} }
@Test @Test
public void testIsShowingIncognitoNotInOverviewMode() { public void testIsShowingIncognito_IncognitoModel_NotInOverviewMode() {
mController = new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector); mController = new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector);
mController.setInOverViewMode(false); mController.setInOverViewMode(false);
doReturn(mTabModel).when(mSelector).getCurrentModel(); doReturn(mTabModel).when(mSelector).getCurrentModel();
...@@ -113,9 +113,9 @@ public class IncognitoTabSnapshotControllerTest { ...@@ -113,9 +113,9 @@ public class IncognitoTabSnapshotControllerTest {
} }
@Test @Test
public void testIsShowingIncognitoInOverviewMode() { public void testIsShowingIncognito_IncognitoModel_InOverviewMode() {
mController = new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector); mController = new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector);
mController.setInOverViewMode(false); mController.setInOverViewMode(true);
doReturn(mTabModel).when(mSelector).getCurrentModel(); doReturn(mTabModel).when(mSelector).getCurrentModel();
doReturn(true).when(mTabModel).isIncognito(); doReturn(true).when(mTabModel).isIncognito();
Assert.assertTrue("isShowingIncognito should be true", mController.isShowingIncognito()); Assert.assertTrue("isShowingIncognito should be true", mController.isShowingIncognito());
...@@ -124,52 +124,41 @@ public class IncognitoTabSnapshotControllerTest { ...@@ -124,52 +124,41 @@ public class IncognitoTabSnapshotControllerTest {
} }
@Test @Test
public void testInOverviewModeWithIncognitoTab() { public void testIsShowingIncognito_NormalModel_WithIncognitoTab_GridTabSwitcher() {
HashMap<String, Boolean> features = new HashMap<String, Boolean>(); mController = spy(new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector));
features.put(ChromeFeatureList.HORIZONTAL_TAB_SWITCHER_ANDROID, false); mController.setInOverViewMode(true);
ChromeFeatureList.setTestFeatures(features);
mController = new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector); doReturn(mTabModel).when(mSelector).getCurrentModel();
doReturn(false).when(mTabModel).isIncognito();
doReturn(true).when(mController).isGridTabSwitcherEnabled();
doReturn(mTabModel).when(mSelector).getModel(true);
doReturn(1).when(mTabModel).getCount();
Assert.assertFalse("isShowingIncognito should be false", mController.isShowingIncognito());
}
@Test
public void testIsShowingIncognito_NormalModel_WithIncognitoTab() {
mController = spy(new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector));
mController.setInOverViewMode(true); mController.setInOverViewMode(true);
doReturn(mTabModel).when(mSelector).getCurrentModel(); doReturn(mTabModel).when(mSelector).getCurrentModel();
doReturn(false).when(mTabModel).isIncognito(); doReturn(false).when(mTabModel).isIncognito();
doReturn(false).when(mController).isGridTabSwitcherEnabled();
doReturn(mTabModel).when(mSelector).getModel(true); doReturn(mTabModel).when(mSelector).getModel(true);
doReturn(1).when(mTabModel).getCount(); doReturn(1).when(mTabModel).getCount();
Assert.assertTrue("isShowingIncognito should be true", mController.isShowingIncognito()); Assert.assertTrue("isShowingIncognito should be true", mController.isShowingIncognito());
verify(mTabModel, atLeastOnce()).getCount();
} }
@Test @Test
public void testInOverviewModeWithNoIncognitoTab() { public void testIsShowingIncognito_NormalModel_NoIncognitoTab() {
HashMap<String, Boolean> features = new HashMap<String, Boolean>(); mController = spy(new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector));
features.put(ChromeFeatureList.HORIZONTAL_TAB_SWITCHER_ANDROID, false);
ChromeFeatureList.setTestFeatures(features);
mController = new IncognitoTabSnapshotController(mWindow, mLayoutManager, mSelector);
mController.setInOverViewMode(true); mController.setInOverViewMode(true);
doReturn(mTabModel).when(mSelector).getCurrentModel(); doReturn(mTabModel).when(mSelector).getCurrentModel();
doReturn(false).when(mTabModel).isIncognito(); doReturn(false).when(mTabModel).isIncognito();
doReturn(false).when(mController).isGridTabSwitcherEnabled();
doReturn(mTabModel).when(mSelector).getModel(true); doReturn(mTabModel).when(mSelector).getModel(true);
doReturn(0).when(mTabModel).getCount(); doReturn(0).when(mTabModel).getCount();
Assert.assertFalse("isShowingIncognito should be false", mController.isShowingIncognito()); Assert.assertFalse("isShowingIncognito should be false", mController.isShowingIncognito());
verify(mTabModel, atLeastOnce()).getCount();
}
class TestIncognitoTabSnapshotController extends IncognitoTabSnapshotController {
private boolean mIsShowingIncognito;
public TestIncognitoTabSnapshotController(boolean isShowingIncognito) {
super(mWindow, mLayoutManager, mSelector);
mIsShowingIncognito = isShowingIncognito;
}
@Override
boolean isShowingIncognito() {
return mIsShowingIncognito;
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment