Commit 6edfeadd authored by Donn Denman's avatar Donn Denman Committed by Commit Bot

[Preview Tab] Add a test suite.

A new test suite for the Preview Tab.

Also adds a helper for FirstRunFlow.
Using the helper in existing tests will be done separately.

BUG=952319

Change-Id: I756483ce549f9664012a24db8b62e1cdc43b9361
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2136282
Commit-Queue: Donn Denman <donnd@chromium.org>
Commit-Queue: Theresa  <twellington@chromium.org>
Auto-Submit: Donn Denman <donnd@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758265}
parent a5301433
...@@ -184,6 +184,7 @@ chrome_test_java_sources = [ ...@@ -184,6 +184,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/feedback/ConnectivityCheckerTestRule.java", "javatests/src/org/chromium/chrome/browser/feedback/ConnectivityCheckerTestRule.java",
"javatests/src/org/chromium/chrome/browser/feedback/ConnectivityTaskTest.java", "javatests/src/org/chromium/chrome/browser/feedback/ConnectivityTaskTest.java",
"javatests/src/org/chromium/chrome/browser/findinpage/FindTest.java", "javatests/src/org/chromium/chrome/browser/findinpage/FindTest.java",
"javatests/src/org/chromium/chrome/browser/firstrun/DisableFirstRun.java",
"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/firstrun/FirstRunUtilsTest.java", "javatests/src/org/chromium/chrome/browser/firstrun/FirstRunUtilsTest.java",
...@@ -418,6 +419,7 @@ chrome_test_java_sources = [ ...@@ -418,6 +419,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/policy/CombinedPolicyProviderTest.java", "javatests/src/org/chromium/chrome/browser/policy/CombinedPolicyProviderTest.java",
"javatests/src/org/chromium/chrome/browser/portals/PortalsTest.java", "javatests/src/org/chromium/chrome/browser/portals/PortalsTest.java",
"javatests/src/org/chromium/chrome/browser/prerender/ExternalPrerenderHandlerTest.java", "javatests/src/org/chromium/chrome/browser/prerender/ExternalPrerenderHandlerTest.java",
"javatests/src/org/chromium/chrome/browser/previewtab/PreviewTabTest.java",
"javatests/src/org/chromium/chrome/browser/printing/PrintingControllerTest.java", "javatests/src/org/chromium/chrome/browser/printing/PrintingControllerTest.java",
"javatests/src/org/chromium/chrome/browser/privacy/settings/PrivacyPreferencesManagerNativeTest.java", "javatests/src/org/chromium/chrome/browser/privacy/settings/PrivacyPreferencesManagerNativeTest.java",
"javatests/src/org/chromium/chrome/browser/provider/ProviderBookmarkNodeUnitTest.java", "javatests/src/org/chromium/chrome/browser/provider/ProviderBookmarkNodeUnitTest.java",
......
...@@ -281,6 +281,11 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator implements Native ...@@ -281,6 +281,11 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator implements Native
sEnableStatusIndicatorForTests = disable; sEnableStatusIndicatorForTests = disable;
} }
@VisibleForTesting
public EphemeralTabCoordinator getEphemeralTabCoordinatorForTesting() {
return mEphemeralTabCoordinatorSupplier.get();
}
/** /**
* Triggers the display of an appropriate promo, if any, returning true if a promo is actually * Triggers the display of an appropriate promo, if any, returning true if a promo is actually
* displayed. * displayed.
......
// Copyright 2020 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.firstrun;
import org.junit.rules.ExternalResource;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
* JUnit 4 rule that disables the First-Run Flow for tests.
* This is needed to correctly populate the Context Menu.
* <p>
* The CommandLineFlags setting is redundant, but helps ensure that clients know that they don't
* need to add it themselves. This is also set in ChromeActivityTest, but having this here
* adds resilience to changes in that class.
*/
@CommandLineFlags.Add(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
public class DisableFirstRun extends ExternalResource {
@Override
protected void before() {
TestThreadUtils.runOnUiThreadBlocking(() -> FirstRunStatus.setFirstRunFlowComplete(true));
}
@Override
protected void after() {
TestThreadUtils.runOnUiThreadBlocking(() -> FirstRunStatus.setFirstRunFlowComplete(false));
}
}
donnd@chromium.org
jinsukkim@chromium.org
# TEAM: preview-tab@google.com
# COMPONENT: UI>Browser>Mobile>PreviewTab
// Copyright 2020 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.previewtab;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTabCoordinator;
import org.chromium.chrome.browser.firstrun.DisableFirstRun;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabbed_mode.TabbedRootUiCoordinator;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils;
import org.chromium.content_public.browser.test.util.DOMUtils;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServerRule;
/**
* Tests the Preview Tab, also known as the Ephemeral Tab. Based on the
* FocusedEditableTextFieldZoomTest and TabsTest.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@DisableFeatures({ChromeFeatureList.REVAMPED_CONTEXT_MENU})
public class PreviewTabTest {
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule
public EmbeddedTestServerRule mTestServer = new EmbeddedTestServerRule();
/** Needed to ensure the First Run Flow is disabled automatically during setUp, etc. */
@Rule
public DisableFirstRun mDisableFirstRunFlowRule = new DisableFirstRun();
private static final String BASE_PAGE = "/chrome/test/data/android/previewtab/base_page.html";
private static final String PREVIEW_TAB_DOM_ID = "previewTab";
private static final String NEAR_BOTTOM_DOM_ID = "nearBottom";
private EphemeralTabCoordinator mEphemeralTabCoordinator;
@Before
public void setUp() {
mActivityTestRule.startMainActivityWithURL(mTestServer.getServer().getURL(BASE_PAGE));
TestThreadUtils.runOnUiThreadBlocking(() -> {
TabbedRootUiCoordinator tabbedRootUiCoordinator =
((TabbedRootUiCoordinator) mActivityTestRule.getActivity()
.getRootUiCoordinatorForTesting());
mEphemeralTabCoordinator =
tabbedRootUiCoordinator.getEphemeralTabCoordinatorForTesting();
});
}
/**
* Test bringing up the PT, scrolling the base page but never expanding the PT, then closing it.
*/
@Test
@MediumTest
@Feature({"PreviewTab"})
public void testOpenAndClose() throws Throwable {
Assert.assertFalse(
"Test did not start without a Preview Tab", mEphemeralTabCoordinator.isOpened());
ChromeActivity activity = mActivityTestRule.getActivity();
Tab tab = activity.getActivityTab();
ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
activity, tab, PREVIEW_TAB_DOM_ID, R.id.contextmenu_open_in_ephemeral_tab);
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
Assert.assertTrue("The Preview Tab did not open", mEphemeralTabCoordinator.isOpened());
// Scroll the base page.
DOMUtils.scrollNodeIntoView(tab.getWebContents(), NEAR_BOTTOM_DOM_ID);
Assert.assertTrue("The Preview Tab did not stay open after a scroll action",
mEphemeralTabCoordinator.isOpened());
// Close the PT.
TestThreadUtils.runOnUiThreadBlocking(() -> mEphemeralTabCoordinator.close());
// TODO(donnd): check that it's actually closed once https://crbug.com/1068449 is fixed.
}
// TODO(donnd): add more tests.
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>Another Page</title>
</head>
<body>
<h1>Another Page</h1>
<p>This is just another page with content.</p>
<p>We use
<a href="https://en.wikipedia.org/wiki/Lorem_ipsum" id="lipsum">lipsum</a>
to fill the page.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>Preview Tab Base Page</title>
</head>
<body>
<h1>Base Page</h1>
<p>This is the page with content in Chrome that the user is reading when they want to bring up a Preview Tab. Here's a link to a page
<a href="preview_tab.html" id="previewTab">Preview Tab</a>
and this text continues, and then ends.</p>
<p>In this paragraph we have an image that is also a link. Here's the image/link:
<a href="preview_tab.html" id="previewImage">
<img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/
/ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcpp
V0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7"
width="16" height="14" alt="embedded folder icon" id="dataUrlIcon" /></a>
which goes to the same Preview Page, but can also bring up the image using Preview Image.</p>
<p>We use
<a href="https://en.wikipedia.org/wiki/Lorem_ipsum" id="lipsum">lipsum</a>
to fill the page.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
<p>This is a node <b><span id="nearBottom">near the bottom</span></b> of this page.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>Preview Tab Preview</title>
</head>
<body style="background-color:powderblue;">
<h1>Preview Tab</h1>
<p>This is a test Preview Tab. It has content the that user wants to look at quickly before returning to the Base Page that they started with, and is providing some context by still remaining partionally in view.</p>
<p>Here's a link to another page used to test trying to bring up a Preview Tab within a Preview Tab: another
<a href="another_page.html" id="anotherPage">page</a>.
Taking the link should be possible, using navigation within the Preview Tab.</p>
</body>
</html>
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