Commit cc42e982 authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Add more UI integration tests

Add UI integration tests for:
 - testScrollPageToTrigger
 - testShadowVisibleOnScroll
 - testInProductHelp
 - testMultiInstanceMode

And updated testEnterAndExitTabSwitcher.

BUG=835450

Change-Id: Ife58a7ba6dde69687d652f81fd2657cecdf5cb61
Reviewed-on: https://chromium-review.googlesource.com/1036795Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555232}
parent 36d29057
...@@ -39,7 +39,7 @@ class ContextualSuggestionsDependencyFactory { ...@@ -39,7 +39,7 @@ class ContextualSuggestionsDependencyFactory {
* @return A {@link ContextualSuggestionsSource} for getting contextual suggestions for * @return A {@link ContextualSuggestionsSource} for getting contextual suggestions for
* the current user. * the current user.
*/ */
ContextualSuggestionsSource createContextualSuggestionSource(Profile profile) { ContextualSuggestionsSource createContextualSuggestionsSource(Profile profile) {
return new ContextualSuggestionsSource(profile); return new ContextualSuggestionsSource(profile);
} }
......
...@@ -143,7 +143,7 @@ class ContextualSuggestionsMediator ...@@ -143,7 +143,7 @@ class ContextualSuggestionsMediator
public void onEnabledStateChanged(boolean enabled) { public void onEnabledStateChanged(boolean enabled) {
if (enabled) { if (enabled) {
mSuggestionsSource = ContextualSuggestionsDependencyFactory.getInstance() mSuggestionsSource = ContextualSuggestionsDependencyFactory.getInstance()
.createContextualSuggestionSource(mProfile); .createContextualSuggestionsSource(mProfile);
mFetchHelper = ContextualSuggestionsDependencyFactory.getInstance().createFetchHelper( mFetchHelper = ContextualSuggestionsDependencyFactory.getInstance().createFetchHelper(
this, mTabModelSelector); this, mTabModelSelector);
} else { } else {
...@@ -371,4 +371,9 @@ class ContextualSuggestionsMediator ...@@ -371,4 +371,9 @@ class ContextualSuggestionsMediator
void showContentInSheetForTesting() { void showContentInSheetForTesting() {
showContentInSheet(); showContentInSheet();
} }
@VisibleForTesting
TextBubble getHelpBubbleForTesting() {
return mHelpBubble;
}
} }
...@@ -1590,6 +1590,7 @@ chrome_test_java_sources = [ ...@@ -1590,6 +1590,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/contextual_suggestions/ContextualSuggestionsTest.java", "javatests/src/org/chromium/chrome/browser/contextual_suggestions/ContextualSuggestionsTest.java",
"javatests/src/org/chromium/chrome/browser/contextual_suggestions/FakeContextualSuggestionsSource.java", "javatests/src/org/chromium/chrome/browser/contextual_suggestions/FakeContextualSuggestionsSource.java",
"javatests/src/org/chromium/chrome/browser/contextual_suggestions/FakeEnabledStateMonitor.java", "javatests/src/org/chromium/chrome/browser/contextual_suggestions/FakeEnabledStateMonitor.java",
"javatests/src/org/chromium/chrome/browser/contextual_suggestions/FakeTracker.java",
"javatests/src/org/chromium/chrome/browser/crash/LogcatExtractionRunnableTest.java", "javatests/src/org/chromium/chrome/browser/crash/LogcatExtractionRunnableTest.java",
"javatests/src/org/chromium/chrome/browser/crash/MinidumpUploadServiceTest.java", "javatests/src/org/chromium/chrome/browser/crash/MinidumpUploadServiceTest.java",
"javatests/src/org/chromium/chrome/browser/crash/PureJavaExceptionReporterTest.java", "javatests/src/org/chromium/chrome/browser/crash/PureJavaExceptionReporterTest.java",
...@@ -1635,6 +1636,7 @@ chrome_test_java_sources = [ ...@@ -1635,6 +1636,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/firstrun/FirstRunActivityTestObserver.java", "javatests/src/org/chromium/chrome/browser/firstrun/FirstRunActivityTestObserver.java",
"javatests/src/org/chromium/chrome/browser/firstrun/FirstRunIntegrationTest.java", "javatests/src/org/chromium/chrome/browser/firstrun/FirstRunIntegrationTest.java",
"javatests/src/org/chromium/chrome/browser/fullscreen/FullscreenManagerTest.java", "javatests/src/org/chromium/chrome/browser/fullscreen/FullscreenManagerTest.java",
"javatests/src/org/chromium/chrome/browser/fullscreen/FullscreenManagerTestUtils.java",
"javatests/src/org/chromium/chrome/browser/gcore/MockConnectedTask.java", "javatests/src/org/chromium/chrome/browser/gcore/MockConnectedTask.java",
"javatests/src/org/chromium/chrome/browser/gcore/MockConnectedTaskTest.java", "javatests/src/org/chromium/chrome/browser/gcore/MockConnectedTaskTest.java",
"javatests/src/org/chromium/chrome/browser/gsa/GSAAccountChangeListenerTest.java", "javatests/src/org/chromium/chrome/browser/gsa/GSAAccountChangeListenerTest.java",
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.contextual_suggestions; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.contextual_suggestions;
import org.junit.rules.TestWatcher; import org.junit.rules.TestWatcher;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
...@@ -52,10 +53,14 @@ public class ContextualSuggestionsDependenciesRule extends TestWatcher { ...@@ -52,10 +53,14 @@ public class ContextualSuggestionsDependenciesRule extends TestWatcher {
public EnabledStateMonitor enabledStateMonitor; public EnabledStateMonitor enabledStateMonitor;
public FetchHelper fetchHelper; public FetchHelper fetchHelper;
public CallbackHelper createSuggestionsSourceCallback = new CallbackHelper();
@Override @Override
ContextualSuggestionsSource createContextualSuggestionSource(Profile profile) { ContextualSuggestionsSource createContextualSuggestionsSource(Profile profile) {
createSuggestionsSourceCallback.notifyCalled();
if (suggestionsSource != null) return suggestionsSource; if (suggestionsSource != null) return suggestionsSource;
return super.createContextualSuggestionSource(profile); return super.createContextualSuggestionsSource(profile);
} }
@Override @Override
......
...@@ -11,11 +11,13 @@ import static org.junit.Assert.assertNull; ...@@ -11,11 +11,13 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -23,17 +25,28 @@ import org.junit.rules.TestRule; ...@@ -23,17 +25,28 @@ import org.junit.rules.TestRule;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.contextual_suggestions.ContextualSuggestionsModel.PropertyKey;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.fullscreen.FullscreenManagerTestUtils;
import org.chromium.chrome.browser.modelutil.ListObservable;
import org.chromium.chrome.browser.modelutil.ListObservable.ListObserver;
import org.chromium.chrome.browser.multiwindow.MultiWindowTestHelper;
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
import org.chromium.chrome.browser.ntp.ContextMenuManager; import org.chromium.chrome.browser.ntp.ContextMenuManager;
import org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder; import org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder;
import org.chromium.chrome.browser.test.ScreenShooter; import org.chromium.chrome.browser.test.ScreenShooter;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.chrome.test.BottomSheetTestRule; import org.chromium.chrome.test.BottomSheetTestRule;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule; import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
...@@ -46,6 +59,7 @@ import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; ...@@ -46,6 +59,7 @@ import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils;
import org.chromium.chrome.test.util.browser.compositor.layouts.DisableChromeAnimations; import org.chromium.chrome.test.util.browser.compositor.layouts.DisableChromeAnimations;
import org.chromium.components.feature_engagement.FeatureConstants; import org.chromium.components.feature_engagement.FeatureConstants;
import org.chromium.content.browser.test.util.TestWebContentsObserver; import org.chromium.content.browser.test.util.TestWebContentsObserver;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.ui.test.util.UiRestriction; import org.chromium.ui.test.util.UiRestriction;
...@@ -84,6 +98,14 @@ public class ContextualSuggestionsTest { ...@@ -84,6 +98,14 @@ public class ContextualSuggestionsTest {
private ContextualSuggestionsModel mModel; private ContextualSuggestionsModel mModel;
private BottomSheet mBottomSheet; private BottomSheet mBottomSheet;
// Used in multi-instance test.
private ContextualSuggestionsCoordinator mCoordinator2;
private ContextualSuggestionsMediator mMediator2;
private ContextualSuggestionsModel mModel2;
private BottomSheet mBottomSheet2;
private CallbackHelper mToolbarShadowVisibleCallback = new CallbackHelper();
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mFakeSource = new FakeContextualSuggestionsSource(); mFakeSource = new FakeContextualSuggestionsSource();
...@@ -102,6 +124,13 @@ public class ContextualSuggestionsTest { ...@@ -102,6 +124,13 @@ public class ContextualSuggestionsTest {
mMediator = mCoordinator.getMediatorForTesting(); mMediator = mCoordinator.getMediatorForTesting();
mModel = mCoordinator.getModelForTesting(); mModel = mCoordinator.getModelForTesting();
stateMonitor.setObserver(mMediator); stateMonitor.setObserver(mMediator);
mModel.addObserver((source, propertyKey) -> {
if (propertyKey == PropertyKey.TOOLBAR_SHADOW_VISIBILITY
&& mModel.getToolbarShadowVisibility()) {
mToolbarShadowVisibleCallback.notifyCalled();
}
});
}); });
mBottomSheet = mActivityTestRule.getActivity().getBottomSheet(); mBottomSheet = mActivityTestRule.getActivity().getBottomSheet();
...@@ -150,6 +179,35 @@ public class ContextualSuggestionsTest { ...@@ -150,6 +179,35 @@ public class ContextualSuggestionsTest {
recyclerView.getAdapter().getItemCount()); recyclerView.getAdapter().getItemCount());
} }
@Test
@MediumTest
@Feature({"ContextualSuggestions"})
public void testScrollPageToTrigger() throws InterruptedException, TimeoutException {
assertEquals("Sheet should be hidden.", BottomSheet.SHEET_STATE_HIDDEN,
mBottomSheet.getSheetState());
CallbackHelper fullyPeekedCallback = new CallbackHelper();
mBottomSheet.addObserver(new EmptyBottomSheetObserver() {
@Override
public void onSheetFullyPeeked() {
fullyPeekedCallback.notifyCalled();
}
});
// Scroll the base page, hiding then reshowing the browser controls.
FullscreenManagerTestUtils.disableBrowserOverrides();
FullscreenManagerTestUtils.waitForBrowserControlsToBeMoveable(
mActivityTestRule, mActivityTestRule.getActivity().getActivityTab());
// Assert that the sheet is now visible.
fullyPeekedCallback.waitForCallback(0);
assertEquals("Sheet should be peeked.", BottomSheet.SHEET_STATE_PEEK,
mBottomSheet.getSheetState());
assertTrue("Bottom sheet should contain suggestions content.",
mBottomSheet.getCurrentSheetContent()
instanceof ContextualSuggestionsBottomSheetContent);
}
@Test @Test
@MediumTest @MediumTest
@Feature({"ContextualSuggestions"}) @Feature({"ContextualSuggestions"})
...@@ -246,29 +304,6 @@ public class ContextualSuggestionsTest { ...@@ -246,29 +304,6 @@ public class ContextualSuggestionsTest {
assertFalse("Sheet should be closed.", mBottomSheet.isSheetOpen()); assertFalse("Sheet should be closed.", mBottomSheet.isSheetOpen());
} }
@Test
@MediumTest
@Feature({"ContextualSuggestions"})
public void testEnterTabSwitcher() throws Exception {
forceShowSuggestions();
ThreadUtils.runOnUiThreadBlocking(() -> {
mActivityTestRule.getActivity().getLayoutManager().showOverview(false);
mBottomSheet.endAnimations();
});
assertEquals("Sheet should be hidden.", BottomSheet.SHEET_STATE_HIDDEN,
mBottomSheet.getSheetState());
ThreadUtils.runOnUiThreadBlocking(() -> {
mActivityTestRule.getActivity().getLayoutManager().hideOverview(false);
mBottomSheet.endAnimations();
});
assertEquals("Sheet should be peeking.", BottomSheet.SHEET_STATE_PEEK,
mBottomSheet.getSheetState());
}
@Test @Test
@MediumTest @MediumTest
@Feature({"ContextualSuggestions"}) @Feature({"ContextualSuggestions"})
...@@ -294,6 +329,130 @@ public class ContextualSuggestionsTest { ...@@ -294,6 +329,130 @@ public class ContextualSuggestionsTest {
assertEquals(titleWidth, title.getWidth() + menuButton.getWidth()); assertEquals(titleWidth, title.getWidth() + menuButton.getWidth());
} }
@Test
@MediumTest
@Feature({"ContextualSuggestions"})
public void testShadowVisibleOnScroll() throws InterruptedException, TimeoutException {
forceShowSuggestions();
openSheet();
assertFalse("Shadow shouldn't be visible.", mModel.getToolbarShadowVisibility());
int currentCallCount = mToolbarShadowVisibleCallback.getCallCount();
ThreadUtils.runOnUiThreadBlocking(() -> {
RecyclerView view =
(RecyclerView) mBottomSheet.getCurrentSheetContent().getContentView();
view.scrollToPosition(5);
});
mToolbarShadowVisibleCallback.waitForCallback(currentCallCount);
assertTrue("Shadow should be visible.", mModel.getToolbarShadowVisibility());
}
@Test
@MediumTest
@Feature({"ContextualSuggestions"})
public void testInProductHelp() throws InterruptedException, TimeoutException {
FakeTracker tracker = new FakeTracker(FeatureConstants.CONTEXTUAL_SUGGESTIONS_FEATURE);
TrackerFactory.setTrackerForTests(tracker);
forceShowSuggestions();
assertTrue(
"Help bubble should be showing.", mMediator.getHelpBubbleForTesting().isShowing());
ThreadUtils.runOnUiThreadBlocking(() -> mMediator.getHelpBubbleForTesting().dismiss());
Assert.assertEquals("Help bubble should be dimissed.", 1,
tracker.mDimissedCallbackHelper.getCallCount());
}
@Test
@LargeTest
@Feature({"ContextualSuggestions"})
public void testMultiInstanceMode() throws Exception {
ChromeTabbedActivity activity1 = mActivityTestRule.getActivity();
forceShowSuggestions();
openSheet();
MultiWindowUtils.getInstance().setIsInMultiWindowModeForTesting(true);
ChromeTabbedActivity activity2 = MultiWindowTestHelper.createSecondChromeTabbedActivity(
activity1, new LoadUrlParams(mTestServer.getURL(TEST_PAGE)));
ChromeActivityTestRule.waitForActivityNativeInitializationComplete(activity2);
CallbackHelper itemRangeInsertedCallback = new CallbackHelper();
ThreadUtils.runOnUiThreadBlocking(() -> {
mCoordinator2 = activity2.getContextualSuggestionsCoordinatorForTesting();
mMediator2 = mCoordinator2.getMediatorForTesting();
mModel2 = mCoordinator2.getModelForTesting();
mBottomSheet2 = activity2.getBottomSheet();
mModel2.mClusterListObservable.addObserver(new ListObserver() {
@Override
public void onItemRangeInserted(ListObservable source, int index, int count) {
itemRangeInsertedCallback.notifyCalled();
}
@Override
public void onItemRangeRemoved(ListObservable source, int index, int count) {}
@Override
public void onItemRangeChanged(
ListObservable source, int index, int count, Object payload) {}
});
mMediator2.onEnabledStateChanged(true);
});
assertNotEquals("There should be two coordinators.", mCoordinator, mCoordinator2);
assertNotEquals("There should be two mediators.", mMediator, mMediator2);
assertNotEquals("There should be two models.", mModel, mModel2);
assertEquals("There should have been two requests to create a ContextualSuggestionsSource",
2,
mContextualSuggestionsDeps.getFactory()
.createSuggestionsSourceCallback.getCallCount());
itemRangeInsertedCallback.waitForCallback(0);
assertEquals("Second model has incorrect number of items.",
(int) FakeContextualSuggestionsSource.TOTAL_ITEM_COUNT,
mModel2.getClusterList().getItemCount());
ThreadUtils.runOnUiThreadBlocking(() -> {
mMediator2.showContentInSheetForTesting();
mBottomSheet2.endAnimations();
ContextualSuggestionsBottomSheetContent content1 =
(ContextualSuggestionsBottomSheetContent) mBottomSheet.getCurrentSheetContent();
ContextualSuggestionsBottomSheetContent content2 =
(ContextualSuggestionsBottomSheetContent)
mBottomSheet2.getCurrentSheetContent();
assertNotEquals("There should be two bottom sheet contents", content1, content2);
});
assertEquals("Sheet in the second activity should be peeked.", BottomSheet.SHEET_STATE_PEEK,
mBottomSheet2.getSheetState());
assertEquals("Sheet in the first activity should be open.", BottomSheet.SHEET_STATE_FULL,
mBottomSheet.getSheetState());
ThreadUtils.runOnUiThreadBlocking(
() -> mBottomSheet2.setSheetState(BottomSheet.SHEET_STATE_FULL, false));
SnippetArticleViewHolder holder = getFirstSuggestionViewHolder(mBottomSheet2);
String expectedUrl = holder.getUrl();
ChromeTabUtils.invokeContextMenuAndOpenInOtherWindow(activity2, activity1, holder.itemView,
ContextMenuManager.ID_OPEN_IN_NEW_WINDOW, false, expectedUrl);
ThreadUtils.runOnUiThreadBlocking(() -> {
mBottomSheet.endAnimations();
mBottomSheet2.endAnimations();
});
assertTrue("Sheet in second activity should be opened.", mBottomSheet2.isSheetOpen());
assertFalse("Sheet in first activity should be closed.", mBottomSheet.isSheetOpen());
}
@Test @Test
@MediumTest @MediumTest
@Feature({"ContextualSuggestions", "UiCatalogue"}) @Feature({"ContextualSuggestions", "UiCatalogue"})
...@@ -338,7 +497,7 @@ public class ContextualSuggestionsTest { ...@@ -338,7 +497,7 @@ public class ContextualSuggestionsTest {
assertEquals("Sheet should be peeked.", BottomSheet.SHEET_STATE_PEEK, assertEquals("Sheet should be peeked.", BottomSheet.SHEET_STATE_PEEK,
mBottomSheet.getSheetState()); mBottomSheet.getSheetState());
assertTrue("Bottom sheet should contain suggestions content", assertTrue("Bottom sheet should contain suggestions content.",
mBottomSheet.getCurrentSheetContent() mBottomSheet.getCurrentSheetContent()
instanceof ContextualSuggestionsBottomSheetContent); instanceof ContextualSuggestionsBottomSheetContent);
}); });
...@@ -364,8 +523,12 @@ public class ContextualSuggestionsTest { ...@@ -364,8 +523,12 @@ public class ContextualSuggestionsTest {
} }
private SnippetArticleViewHolder getFirstSuggestionViewHolder() { private SnippetArticleViewHolder getFirstSuggestionViewHolder() {
return getFirstSuggestionViewHolder(mBottomSheet);
}
private SnippetArticleViewHolder getFirstSuggestionViewHolder(BottomSheet bottomSheet) {
ContextualSuggestionsBottomSheetContent content = ContextualSuggestionsBottomSheetContent content =
(ContextualSuggestionsBottomSheetContent) mBottomSheet.getCurrentSheetContent(); (ContextualSuggestionsBottomSheetContent) bottomSheet.getCurrentSheetContent();
RecyclerView recyclerView = (RecyclerView) content.getContentView(); RecyclerView recyclerView = (RecyclerView) content.getContentView();
RecyclerViewTestUtils.waitForStableRecyclerView(recyclerView); RecyclerViewTestUtils.waitForStableRecyclerView(recyclerView);
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.contextual_suggestions;
import android.text.TextUtils;
import org.junit.Assert;
import org.chromium.base.Callback;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.components.feature_engagement.Tracker;
/**
* A feature engagement {@link Tracker} for testing.
*/
class FakeTracker implements Tracker {
public CallbackHelper mDimissedCallbackHelper = new CallbackHelper();
private String mEnabledFeature;
public FakeTracker(String enabledFeature) {
mEnabledFeature = enabledFeature;
}
@Override
public void notifyEvent(String event) {}
@Override
public boolean shouldTriggerHelpUI(String feature) {
return TextUtils.equals(mEnabledFeature, feature);
}
@Override
public int getTriggerState(String feature) {
return 0;
}
@Override
public void dismissed(String feature) {
Assert.assertEquals("Wrong feature dismissed.", mEnabledFeature, feature);
mDimissedCallbackHelper.notifyCalled();
}
@Override
public boolean isInitialized() {
return true;
}
@Override
public void addOnInitializedCallback(Callback<Boolean> callback) {}
@Override
public boolean wouldTriggerHelpUI(String feature) {
return shouldTriggerHelpUI(feature);
}
@Override
public DisplayLockHandle acquireDisplayLock() {
return null;
}
}
...@@ -25,7 +25,6 @@ import org.junit.Test; ...@@ -25,7 +25,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
...@@ -34,7 +33,6 @@ import org.chromium.base.test.util.UrlUtils; ...@@ -34,7 +33,6 @@ import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.FullscreenListener;
import org.chromium.chrome.browser.omnibox.UrlBar; import org.chromium.chrome.browser.omnibox.UrlBar;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabStateBrowserControlsVisibilityDelegate; import org.chromium.chrome.browser.tab.TabStateBrowserControlsVisibilityDelegate;
...@@ -50,12 +48,9 @@ import org.chromium.content.browser.test.util.JavaScriptUtils; ...@@ -50,12 +48,9 @@ import org.chromium.content.browser.test.util.JavaScriptUtils;
import org.chromium.content.browser.test.util.TestTouchUtils; import org.chromium.content.browser.test.util.TestTouchUtils;
import org.chromium.content.browser.test.util.TouchCommon; import org.chromium.content.browser.test.util.TouchCommon;
import org.chromium.content.browser.test.util.UiUtils; import org.chromium.content.browser.test.util.UiUtils;
import org.chromium.content_public.browser.RenderCoordinates;
import org.chromium.content_public.browser.SelectionPopupController; import org.chromium.content_public.browser.SelectionPopupController;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
...@@ -173,7 +168,7 @@ public class FullscreenManagerTest { ...@@ -173,7 +168,7 @@ public class FullscreenManagerTest {
@LargeTest @LargeTest
@Feature({"Fullscreen"}) @Feature({"Fullscreen"})
public void testExitPersistentFullscreenAllowsManualFullscreen() throws InterruptedException { public void testExitPersistentFullscreenAllowsManualFullscreen() throws InterruptedException {
disableBrowserOverrides(); FullscreenManagerTestUtils.disableBrowserOverrides();
mActivityTestRule.startMainActivityWithURL(LONG_FULLSCREEN_API_HTML_TEST_PAGE); mActivityTestRule.startMainActivityWithURL(LONG_FULLSCREEN_API_HTML_TEST_PAGE);
ChromeFullscreenManager fullscreenManager = ChromeFullscreenManager fullscreenManager =
...@@ -188,22 +183,23 @@ public class FullscreenManagerTest { ...@@ -188,22 +183,23 @@ public class FullscreenManagerTest {
TouchCommon.singleClickView(view); TouchCommon.singleClickView(view);
FullscreenTestUtils.waitForPersistentFullscreen(delegate, true); FullscreenTestUtils.waitForPersistentFullscreen(delegate, true);
waitForBrowserControlsPosition(-browserControlsHeight); FullscreenManagerTestUtils.waitForBrowserControlsPosition(
mActivityTestRule, -browserControlsHeight);
TestTouchUtils.sleepForDoubleTapTimeout(InstrumentationRegistry.getInstrumentation()); TestTouchUtils.sleepForDoubleTapTimeout(InstrumentationRegistry.getInstrumentation());
TouchCommon.singleClickView(view); TouchCommon.singleClickView(view);
FullscreenTestUtils.waitForPersistentFullscreen(delegate, false); FullscreenTestUtils.waitForPersistentFullscreen(delegate, false);
waitForBrowserControlsPosition(0); FullscreenManagerTestUtils.waitForBrowserControlsPosition(mActivityTestRule, 0);
scrollBrowserControls(false); FullscreenManagerTestUtils.scrollBrowserControls(mActivityTestRule, false);
scrollBrowserControls(true); FullscreenManagerTestUtils.scrollBrowserControls(mActivityTestRule, true);
} }
@Test @Test
@LargeTest @LargeTest
@Feature({"Fullscreen"}) @Feature({"Fullscreen"})
public void testManualHidingShowingBrowserControls() throws InterruptedException { public void testManualHidingShowingBrowserControls() throws InterruptedException {
disableBrowserOverrides(); FullscreenManagerTestUtils.disableBrowserOverrides();
mActivityTestRule.startMainActivityWithURL(LONG_HTML_TEST_PAGE); mActivityTestRule.startMainActivityWithURL(LONG_HTML_TEST_PAGE);
final ChromeFullscreenManager fullscreenManager = final ChromeFullscreenManager fullscreenManager =
...@@ -211,7 +207,8 @@ public class FullscreenManagerTest { ...@@ -211,7 +207,8 @@ public class FullscreenManagerTest {
Assert.assertEquals(fullscreenManager.getTopControlOffset(), 0f, 0); Assert.assertEquals(fullscreenManager.getTopControlOffset(), 0f, 0);
waitForBrowserControlsToBeMoveable(mActivityTestRule.getActivity().getActivityTab()); FullscreenManagerTestUtils.waitForBrowserControlsToBeMoveable(
mActivityTestRule, mActivityTestRule.getActivity().getActivityTab());
// Check that the URL bar has not grabbed focus (http://crbug/236365) // Check that the URL bar has not grabbed focus (http://crbug/236365)
UrlBar urlBar = (UrlBar) mActivityTestRule.getActivity().findViewById(R.id.url_bar); UrlBar urlBar = (UrlBar) mActivityTestRule.getActivity().findViewById(R.id.url_bar);
...@@ -223,7 +220,7 @@ public class FullscreenManagerTest { ...@@ -223,7 +220,7 @@ public class FullscreenManagerTest {
@Feature({"Fullscreen"}) @Feature({"Fullscreen"})
public void testHidingBrowserControlsRemovesSurfaceFlingerOverlay() public void testHidingBrowserControlsRemovesSurfaceFlingerOverlay()
throws InterruptedException { throws InterruptedException {
disableBrowserOverrides(); FullscreenManagerTestUtils.disableBrowserOverrides();
mActivityTestRule.startMainActivityWithURL(LONG_HTML_TEST_PAGE); mActivityTestRule.startMainActivityWithURL(LONG_HTML_TEST_PAGE);
final ChromeFullscreenManager fullscreenManager = final ChromeFullscreenManager fullscreenManager =
...@@ -246,7 +243,7 @@ public class FullscreenManagerTest { ...@@ -246,7 +243,7 @@ public class FullscreenManagerTest {
// When the top-controls are removed, we need a layout to trigger the // When the top-controls are removed, we need a layout to trigger the
// transparent region for the app to be updated. // transparent region for the app to be updated.
scrollBrowserControls(false); FullscreenManagerTestUtils.scrollBrowserControls(mActivityTestRule, false);
CriteriaHelper.pollUiThread( CriteriaHelper.pollUiThread(
new Criteria() { new Criteria() {
@Override @Override
...@@ -279,7 +276,7 @@ public class FullscreenManagerTest { ...@@ -279,7 +276,7 @@ public class FullscreenManagerTest {
@LargeTest @LargeTest
@Feature({"Fullscreen"}) @Feature({"Fullscreen"})
public void testManualFullscreenDisabledForChromePages() throws InterruptedException { public void testManualFullscreenDisabledForChromePages() throws InterruptedException {
disableBrowserOverrides(); FullscreenManagerTestUtils.disableBrowserOverrides();
// The credits page was chosen as it is a chrome:// page that is long and would support // The credits page was chosen as it is a chrome:// page that is long and would support
// manual fullscreen if it were supported. // manual fullscreen if it were supported.
mActivityTestRule.startMainActivityWithURL("chrome://credits"); mActivityTestRule.startMainActivityWithURL("chrome://credits");
...@@ -298,23 +295,23 @@ public class FullscreenManagerTest { ...@@ -298,23 +295,23 @@ public class FullscreenManagerTest {
TouchCommon.dragStart(mActivityTestRule.getActivity(), dragX, dragStartY, downTime); TouchCommon.dragStart(mActivityTestRule.getActivity(), dragX, dragStartY, downTime);
TouchCommon.dragTo(mActivityTestRule.getActivity(), dragX, dragX, dragStartY, dragFullY, TouchCommon.dragTo(mActivityTestRule.getActivity(), dragX, dragX, dragStartY, dragFullY,
100, downTime); 100, downTime);
waitForBrowserControlsPosition(0f); FullscreenManagerTestUtils.waitForBrowserControlsPosition(mActivityTestRule, 0f);
TouchCommon.dragEnd(mActivityTestRule.getActivity(), dragX, dragFullY, downTime); TouchCommon.dragEnd(mActivityTestRule.getActivity(), dragX, dragFullY, downTime);
waitForBrowserControlsPosition(0f); FullscreenManagerTestUtils.waitForBrowserControlsPosition(mActivityTestRule, 0f);
} }
@Test @Test
@LargeTest @LargeTest
@Feature({"Fullscreen"}) @Feature({"Fullscreen"})
public void testControlsShownOnUnresponsiveRenderer() throws InterruptedException { public void testControlsShownOnUnresponsiveRenderer() throws InterruptedException {
disableBrowserOverrides(); FullscreenManagerTestUtils.disableBrowserOverrides();
mActivityTestRule.startMainActivityWithURL(LONG_HTML_TEST_PAGE); mActivityTestRule.startMainActivityWithURL(LONG_HTML_TEST_PAGE);
ChromeFullscreenManager fullscreenManager = ChromeFullscreenManager fullscreenManager =
mActivityTestRule.getActivity().getFullscreenManager(); mActivityTestRule.getActivity().getFullscreenManager();
Assert.assertEquals(fullscreenManager.getTopControlOffset(), 0f, 0); Assert.assertEquals(fullscreenManager.getTopControlOffset(), 0f, 0);
scrollBrowserControls(false); FullscreenManagerTestUtils.scrollBrowserControls(mActivityTestRule, false);
Tab tab = mActivityTestRule.getActivity().getActivityTab(); Tab tab = mActivityTestRule.getActivity().getActivityTab();
final TabWebContentsDelegateAndroid delegate = final TabWebContentsDelegateAndroid delegate =
...@@ -325,7 +322,7 @@ public class FullscreenManagerTest { ...@@ -325,7 +322,7 @@ public class FullscreenManagerTest {
delegate.rendererUnresponsive(); delegate.rendererUnresponsive();
} }
}); });
waitForBrowserControlsPosition(0f); FullscreenManagerTestUtils.waitForBrowserControlsPosition(mActivityTestRule, 0f);
ThreadUtils.runOnUiThread(new Runnable() { ThreadUtils.runOnUiThread(new Runnable() {
@Override @Override
...@@ -346,7 +343,7 @@ public class FullscreenManagerTest { ...@@ -346,7 +343,7 @@ public class FullscreenManagerTest {
@Test @Test
@DisabledTest(message = "crbug.com/642336") @DisabledTest(message = "crbug.com/642336")
public void testPrerenderedPageSupportsManualHiding() throws InterruptedException { public void testPrerenderedPageSupportsManualHiding() throws InterruptedException {
disableBrowserOverrides(); FullscreenManagerTestUtils.disableBrowserOverrides();
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
EmbeddedTestServer testServer = EmbeddedTestServer testServer =
...@@ -364,7 +361,7 @@ public class FullscreenManagerTest { ...@@ -364,7 +361,7 @@ public class FullscreenManagerTest {
OmniboxTestUtils.toggleUrlBarFocus(urlBar, false); OmniboxTestUtils.toggleUrlBarFocus(urlBar, false);
OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, false); OmniboxTestUtils.waitForFocusAndKeyboardActive(urlBar, false);
waitForBrowserControlsToBeMoveable(tab); FullscreenManagerTestUtils.waitForBrowserControlsToBeMoveable(mActivityTestRule, tab);
} finally { } finally {
testServer.stopAndDestroyServer(); testServer.stopAndDestroyServer();
} }
...@@ -377,7 +374,7 @@ public class FullscreenManagerTest { ...@@ -377,7 +374,7 @@ public class FullscreenManagerTest {
@DisabledTest(message = "crbug.com/698413") @DisabledTest(message = "crbug.com/698413")
public void testBrowserControlsShownWhenInputIsFocused() public void testBrowserControlsShownWhenInputIsFocused()
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
disableBrowserOverrides(); FullscreenManagerTestUtils.disableBrowserOverrides();
mActivityTestRule.startMainActivityWithURL(LONG_HTML_WITH_AUTO_FOCUS_INPUT_TEST_PAGE); mActivityTestRule.startMainActivityWithURL(LONG_HTML_WITH_AUTO_FOCUS_INPUT_TEST_PAGE);
ChromeFullscreenManager fullscreenManager = ChromeFullscreenManager fullscreenManager =
...@@ -401,121 +398,8 @@ public class FullscreenManagerTest { ...@@ -401,121 +398,8 @@ public class FullscreenManagerTest {
"document.getElementById('input_text').blur();"); "document.getElementById('input_text').blur();");
waitForEditableNodeToLoseFocus(tab); waitForEditableNodeToLoseFocus(tab);
waitForBrowserControlsToBeMoveable(mActivityTestRule.getActivity().getActivityTab()); FullscreenManagerTestUtils.waitForBrowserControlsToBeMoveable(
} mActivityTestRule, mActivityTestRule.getActivity().getActivityTab());
private void scrollBrowserControls(boolean show) {
ChromeFullscreenManager fullscreenManager =
mActivityTestRule.getActivity().getFullscreenManager();
int browserControlsHeight = fullscreenManager.getTopControlsHeight();
waitForPageToBeScrollable(mActivityTestRule.getActivity().getActivityTab());
float dragX = 50f;
// Use a larger scroll range than the height of the browser controls to ensure we overcome
// the delay in a scroll start being sent.
float dragStartY = browserControlsHeight * 3;
float dragEndY = dragStartY - browserControlsHeight * 2;
float expectedPosition = -browserControlsHeight;
if (show) {
expectedPosition = 0f;
float tempDragStartY = dragStartY;
dragStartY = dragEndY;
dragEndY = tempDragStartY;
}
long downTime = SystemClock.uptimeMillis();
TouchCommon.dragStart(mActivityTestRule.getActivity(), dragX, dragStartY, downTime);
TouchCommon.dragTo(
mActivityTestRule.getActivity(), dragX, dragX, dragStartY, dragEndY, 100, downTime);
TouchCommon.dragEnd(mActivityTestRule.getActivity(), dragX, dragEndY, downTime);
waitForBrowserControlsPosition(expectedPosition);
}
private void waitForBrowserControlsPosition(float position) {
final ChromeFullscreenManager fullscreenManager =
mActivityTestRule.getActivity().getFullscreenManager();
CriteriaHelper.pollUiThread(Criteria.equals(position, new Callable<Float>() {
@Override
public Float call() {
return fullscreenManager.getTopControlOffset();
}
}));
}
private void waitForPageToBeScrollable(final Tab tab) {
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
return RenderCoordinates.fromWebContents(tab.getWebContents())
.getContentHeightPixInt()
> tab.getContentView().getHeight();
}
});
}
/**
* Waits for the browser controls to be moveable by user gesture.
* <p>
* This function requires the browser controls to start fully visible. It till then ensure that
* at some point the controls can be moved by user gesture. It will then fully cycle the top
* controls to entirely hidden and back to fully shown.
*/
private void waitForBrowserControlsToBeMoveable(final Tab tab) throws InterruptedException {
waitForBrowserControlsPosition(0f);
final CallbackHelper contentMovedCallback = new CallbackHelper();
final ChromeFullscreenManager fullscreenManager =
mActivityTestRule.getActivity().getFullscreenManager();
final float initialVisibleContentOffset = fullscreenManager.getTopVisibleContentOffset();
fullscreenManager.addListener(new FullscreenListener() {
@Override
public void onControlsOffsetChanged(float topOffset, float bottomOffset,
boolean needsAnimate) {
if (fullscreenManager.getTopVisibleContentOffset() != initialVisibleContentOffset) {
contentMovedCallback.notifyCalled();
fullscreenManager.removeListener(this);
}
}
@Override
public void onToggleOverlayVideoMode(boolean enabled) {
}
@Override
public void onContentOffsetChanged(float offset) {
}
@Override
public void onBottomControlsHeightChanged(int bottomControlsHeight) {
}
});
float dragX = 50f;
float dragStartY = tab.getView().getHeight() - 50f;
for (int i = 0; i < 10; i++) {
float dragEndY = dragStartY - fullscreenManager.getTopControlsHeight();
long downTime = SystemClock.uptimeMillis();
TouchCommon.dragStart(mActivityTestRule.getActivity(), dragX, dragStartY, downTime);
TouchCommon.dragTo(mActivityTestRule.getActivity(), dragX, dragX, dragStartY, dragEndY,
100, downTime);
TouchCommon.dragEnd(mActivityTestRule.getActivity(), dragX, dragEndY, downTime);
try {
contentMovedCallback.waitForCallback(0, 1, 500, TimeUnit.MILLISECONDS);
scrollBrowserControls(false);
scrollBrowserControls(true);
return;
} catch (TimeoutException e) {
// Ignore and retry
}
}
Assert.fail("Visible content never moved as expected.");
} }
private void waitForEditableNodeToLoseFocus(final Tab tab) { private void waitForEditableNodeToLoseFocus(final Tab tab) {
...@@ -528,13 +412,4 @@ public class FullscreenManagerTest { ...@@ -528,13 +412,4 @@ public class FullscreenManagerTest {
} }
}); });
} }
private void disableBrowserOverrides() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
BrowserStateBrowserControlsVisibilityDelegate.disableForTesting();
}
});
}
} }
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.fullscreen;
import android.os.SystemClock;
import org.junit.Assert;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.FullscreenListener;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.TouchCommon;
import org.chromium.content_public.browser.RenderCoordinates;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* Utility methods for testing the {@link ChromeFullscreenManager}.
*/
public class FullscreenManagerTestUtils {
/**
* Scrolls the underlying web page to show or hide the browser controls.
* @param testRule The test rule for the currently running test.
* @param show Whether the browser controls should be shown.
*/
public static void scrollBrowserControls(ChromeTabbedActivityTestRule testRule, boolean show) {
ChromeFullscreenManager fullscreenManager = testRule.getActivity().getFullscreenManager();
int browserControlsHeight = fullscreenManager.getTopControlsHeight();
waitForPageToBeScrollable(testRule.getActivity().getActivityTab());
float dragX = 50f;
// Use a larger scroll range than the height of the browser controls to ensure we overcome
// the delay in a scroll start being sent.
float dragStartY = browserControlsHeight * 3;
float dragEndY = dragStartY - browserControlsHeight * 2;
float expectedPosition = -browserControlsHeight;
if (show) {
expectedPosition = 0f;
float tempDragStartY = dragStartY;
dragStartY = dragEndY;
dragEndY = tempDragStartY;
}
long downTime = SystemClock.uptimeMillis();
TouchCommon.dragStart(testRule.getActivity(), dragX, dragStartY, downTime);
TouchCommon.dragTo(
testRule.getActivity(), dragX, dragX, dragStartY, dragEndY, 100, downTime);
TouchCommon.dragEnd(testRule.getActivity(), dragX, dragEndY, downTime);
waitForBrowserControlsPosition(testRule, expectedPosition);
}
/**
* Waits for the browser controls to reach the specified position.
* @param testRule The test rule for the currently running test.
* @param position The desired top controls offset.
*/
public static void waitForBrowserControlsPosition(
ChromeTabbedActivityTestRule testRule, float position) {
final ChromeFullscreenManager fullscreenManager =
testRule.getActivity().getFullscreenManager();
CriteriaHelper.pollUiThread(Criteria.equals(position, new Callable<Float>() {
@Override
public Float call() {
return fullscreenManager.getTopControlOffset();
}
}));
}
/**
* Waits for the base page to be scrollable.
* @param tab The current activity tab.
*/
public static void waitForPageToBeScrollable(final Tab tab) {
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
return RenderCoordinates.fromWebContents(tab.getWebContents())
.getContentHeightPixInt()
> tab.getContentView().getHeight();
}
});
}
/**
* Waits for the browser controls to be moveable by user gesture.
*
* This function requires the browser controls to start fully visible. Then it ensures that
* at some point the controls can be moved by user gesture. It will then fully cycle the top
* controls to entirely hidden and back to fully shown.
*
* @param testRule The test rule for the currently running test.
* @param tab The current activity tab.
*/
public static void waitForBrowserControlsToBeMoveable(
ChromeTabbedActivityTestRule testRule, final Tab tab) throws InterruptedException {
waitForBrowserControlsPosition(testRule, 0f);
final CallbackHelper contentMovedCallback = new CallbackHelper();
final ChromeFullscreenManager fullscreenManager =
testRule.getActivity().getFullscreenManager();
final float initialVisibleContentOffset = fullscreenManager.getTopVisibleContentOffset();
fullscreenManager.addListener(new FullscreenListener() {
@Override
public void onControlsOffsetChanged(
float topOffset, float bottomOffset, boolean needsAnimate) {
if (fullscreenManager.getTopVisibleContentOffset() != initialVisibleContentOffset) {
contentMovedCallback.notifyCalled();
fullscreenManager.removeListener(this);
}
}
@Override
public void onToggleOverlayVideoMode(boolean enabled) {}
@Override
public void onContentOffsetChanged(float offset) {}
@Override
public void onBottomControlsHeightChanged(int bottomControlsHeight) {}
});
float dragX = 50f;
float dragStartY = tab.getView().getHeight() - 50f;
for (int i = 0; i < 10; i++) {
float dragEndY = dragStartY - fullscreenManager.getTopControlsHeight();
long downTime = SystemClock.uptimeMillis();
TouchCommon.dragStart(testRule.getActivity(), dragX, dragStartY, downTime);
TouchCommon.dragTo(
testRule.getActivity(), dragX, dragX, dragStartY, dragEndY, 100, downTime);
TouchCommon.dragEnd(testRule.getActivity(), dragX, dragEndY, downTime);
try {
contentMovedCallback.waitForCallback(0, 1, 500, TimeUnit.MILLISECONDS);
scrollBrowserControls(testRule, false);
scrollBrowserControls(testRule, true);
return;
} catch (TimeoutException e) {
// Ignore and retry
}
}
Assert.fail("Visible content never moved as expected.");
}
/**
* Disable any browser visibility overrides for testing.
*/
public static void disableBrowserOverrides() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
BrowserStateBrowserControlsVisibilityDelegate.disableForTesting();
}
});
}
}
...@@ -27,6 +27,7 @@ import org.chromium.chrome.browser.ChromeTabbedActivity; ...@@ -27,6 +27,7 @@ import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType;
import org.chromium.chrome.browser.widget.FadingBackgroundView; import org.chromium.chrome.browser.widget.FadingBackgroundView;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetContent; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.ContentPriority; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.ContentPriority;
...@@ -125,6 +126,36 @@ public class BottomSheetControllerTest { ...@@ -125,6 +126,36 @@ public class BottomSheetControllerTest {
mBottomSheet.getCurrentSheetContent()); mBottomSheet.getCurrentSheetContent());
} }
@Test
@MediumTest
@Feature({"BottomSheetController"})
public void testSheetHiddenAfterTabSwitcher() throws InterruptedException, TimeoutException {
// Open a second tab and then reselect the original activity tab.
Tab tab1 = mActivityTestRule.getActivity().getActivityTab();
ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
Tab tab2 = mActivityTestRule.getActivity().getActivityTab();
requestContentInSheet(mLowPriorityContent, true);
// Enter the tab switcher and select a different tab.
ThreadUtils.runOnUiThreadBlocking(() -> {
mActivityTestRule.getActivity().getLayoutManager().showOverview(false);
mBottomSheet.endAnimations();
assertEquals("The bottom sheet should be hidden.", BottomSheet.SHEET_STATE_HIDDEN,
mBottomSheet.getSheetState());
mActivityTestRule.getActivity().getTabModelSelector().getCurrentModel().setIndex(
0, TabSelectionType.FROM_USER);
mActivityTestRule.getActivity().getLayoutManager().hideOverview(false);
mBottomSheet.endAnimations();
});
assertEquals("The bottom sheet still should be hidden.", BottomSheet.SHEET_STATE_HIDDEN,
mBottomSheet.getSheetState());
assertEquals("The bottom sheet is showing incorrect content.", null,
mBottomSheet.getCurrentSheetContent());
}
@Test @Test
@MediumTest @MediumTest
@Feature({"BottomSheetController"}) @Feature({"BottomSheetController"})
......
...@@ -159,6 +159,29 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe ...@@ -159,6 +159,29 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe
return 0; return 0;
} }
/**
* Waits for the activity to fully finish its native initialization.
* @param The {@link ChromeActivity} to wait for.
*/
public static void waitForActivityNativeInitializationComplete(ChromeActivity activity) {
CriteriaHelper.pollUiThread(()
-> ChromeBrowserInitializer.getInstance(activity)
.hasNativeInitializationCompleted(),
"Native initialization never finished",
20 * CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
CriteriaHelper.pollUiThread(() -> activity.didFinishNativeInitialization(),
"Native initialization (of Activity) never finished");
}
/**
* Waits for the activity to fully finish its native initialization.
*/
public void waitForActivityNativeInitializationComplete() {
waitForActivityNativeInitializationComplete(getActivity());
}
/** /**
* Invokes {@link Instrumentation#startActivitySync(Intent)} and sets the * Invokes {@link Instrumentation#startActivitySync(Intent)} and sets the
* test case's activity to the result. See the documentation for * test case's activity to the result. See the documentation for
...@@ -407,21 +430,6 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe ...@@ -407,21 +430,6 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe
InstrumentationRegistry.getInstrumentation().waitForIdleSync(); InstrumentationRegistry.getInstrumentation().waitForIdleSync();
} }
/**
* Waits for the activity to fully finish it's native initialization.
*/
public void waitForActivityNativeInitializationComplete() {
CriteriaHelper.pollUiThread(()
-> ChromeBrowserInitializer.getInstance(getActivity())
.hasNativeInitializationCompleted(),
"Native initialization never finished",
20 * CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
CriteriaHelper.pollUiThread(() -> getActivity().didFinishNativeInitialization(),
"Native initialization (of Activity) never finished");
}
/** /**
* Prepares a URL intent to start the activity. * Prepares a URL intent to start the activity.
* @param intent the intent to be modified * @param intent the intent to be modified
......
...@@ -638,7 +638,9 @@ public class ChromeTabUtils { ...@@ -638,7 +638,9 @@ public class ChromeTabUtils {
* asserts that a new tab is opened and is incognito if expectIncognito is true. * asserts that a new tab is opened and is incognito if expectIncognito is true.
* For use in testing long-press context menu options that open new tabs. * For use in testing long-press context menu options that open new tabs.
* *
* @param view The View to long press. * @param testRule The {@link ChromeTabbedActivityTestRule} used to retrieve the currently
* running activity.
* @param view The {@link View} to long press.
* @param contextMenuItemId The context menu item to select on the view. * @param contextMenuItemId The context menu item to select on the view.
* @param expectIncognito Whether the opened tab is expected to be incognito. * @param expectIncognito Whether the opened tab is expected to be incognito.
* @param expectedUrl The expected url for the new tab. * @param expectedUrl The expected url for the new tab.
...@@ -676,4 +678,53 @@ public class ChromeTabUtils { ...@@ -676,4 +678,53 @@ public class ChromeTabUtils {
Assert.assertFalse(testRule.getActivity().getTabModelSelector().isIncognitoSelected()); Assert.assertFalse(testRule.getActivity().getTabModelSelector().isIncognitoSelected());
} }
} }
/**
* Long presses the view, selects an item from the context menu, and
* asserts that a new tab is opened and is incognito if expectIncognito is true.
* For use in testing long-press context menu options that open new tabs in a different
* ChromeTabbedActivity instance.
*
* @param foregroundActivity The {@link ChromeTabbedActivity} currently in the foreground.
* @param backgroundActivity The {@link ChromeTabbedActivity} currently in the background. The
* new tab is expected to open in this activity.
* @param view The {@link View} in the {@code foregroundActivity} to long press.
* @param contextMenuItemId The context menu item to select on the view.
* @param expectIncognito Whether the opened tab is expected to be incognito.
* @param expectedUrl The expected url for the new tab.
*/
public static void invokeContextMenuAndOpenInOtherWindow(
ChromeTabbedActivity foregroundActivity, ChromeTabbedActivity backgroundActivity,
View view, int contextMenuItemId, boolean expectIncognito, final String expectedUrl)
throws InterruptedException, ExecutionException {
final CallbackHelper createdCallback = new CallbackHelper();
final TabModel tabModel =
backgroundActivity.getTabModelSelector().getModel(expectIncognito);
tabModel.addObserver(new EmptyTabModelObserver() {
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
if (TextUtils.equals(expectedUrl, tab.getUrl())) {
createdCallback.notifyCalled();
tabModel.removeObserver(this);
}
}
});
TestTouchUtils.performLongClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), view);
Assert.assertTrue(InstrumentationRegistry.getInstrumentation().invokeContextMenuAction(
foregroundActivity, contextMenuItemId, 0));
try {
createdCallback.waitForCallback(0);
} catch (TimeoutException e) {
Assert.fail("Never received tab creation event");
}
if (expectIncognito) {
Assert.assertTrue(backgroundActivity.getTabModelSelector().isIncognitoSelected());
} else {
Assert.assertFalse(backgroundActivity.getTabModelSelector().isIncognitoSelected());
}
}
} }
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