Commit 744fd440 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Revert "Consolidate app banner testing."

This reverts commit 58ab87ff.

Reason for revert: suspected for lsan browser_tests and mus_browser_tests failures since
https://ci.chromium.org/buildbot/chromium.memory/Linux%20Chromium%20OS%20ASan%20LSan%20Tests%20%281%29/25937
 - AppBannerManagerBrowserTest.CheckOnLoadWithSufficientEngagementCancelBannerAfterPromptInHandler
 - AppBannerManagerBrowserTest.ExperimentalFlowWebAppBannerReprompt
 - AppBannerManagerBrowserTest.ExperimentalFlowWebAppBannerPromptNeedsGesture

(and others in later runs)> Possibly timeout related.

Original change's description:
> Consolidate app banner testing.
> 
> This CL removes several different app banner testing files, and replaces
> them by calling the necessary JavaScript setup code in one test file.
> For instance, all tests will no longer have the "appinstalled" title
> overwriting, as that will only be active when the appropriate setup
> JavaScript is run.
> 
> This allows future tests to be more easily added, and reduces collisions
> when manipulating the page title.
> 
> BUG=806923
> 
> Change-Id: Ia28837b8675a2e1fe329cb1df1be4798ddb03d02
> Reviewed-on: https://chromium-review.googlesource.com/892182
> Commit-Queue: Dominick Ng <dominickn@chromium.org>
> Reviewed-by: Matt Giuca <mgiuca@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#532978}

TBR=mgiuca@chromium.org,dominickn@chromium.org

Change-Id: Ie030290324c689b3df616de9aa35b6e52e7584c5
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 806923
Reviewed-on: https://chromium-review.googlesource.com/895024Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533178}
parent e0a80bb7
......@@ -45,6 +45,7 @@ import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.infobar.InfoBarContainer.InfoBarAnimationListener;
import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.webapps.WebappDataStorage;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -96,6 +97,9 @@ public class AppBannerManagerTest {
private static final String WEB_APP_PATH = "/chrome/test/data/banners/manifest_test_page.html";
private static final String WEB_APP_BEFORE_INSTALL_PROMPT_PATH =
"/chrome/test/data/banners/prompt_test_page.html";
private static final String WEB_APP_SHORT_TITLE_MANIFEST =
"/chrome/test/data/banners/manifest_short_name_only.json";
......@@ -189,6 +193,7 @@ public class AppBannerManagerTest {
private TestPackageManager mPackageManager;
private EmbeddedTestServer mTestServer;
private String mWebAppUrl;
private String mWebAppApiUrl;
@Before
public void setUp() throws Exception {
......@@ -212,6 +217,7 @@ public class AppBannerManagerTest {
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
mNativeAppUrl = mTestServer.getURL(NATIVE_APP_PATH);
mWebAppUrl = mTestServer.getURL(WEB_APP_PATH);
mWebAppApiUrl = mTestServer.getURL(WEB_APP_BEFORE_INSTALL_PROMPT_PATH);
}
@After
......@@ -318,8 +324,7 @@ public class AppBannerManagerTest {
}
public void triggerWebAppBanner(ChromeActivityTestRule<? extends ChromeActivity> rule,
String url, String setupScript, String expectedTitle, boolean installApp)
throws Exception {
String url, String expectedTitle, boolean installApp) throws Exception {
// Visit the site in a new tab.
resetEngagementForUrl(url, 0);
rule.loadUrlInNewTab("about:blank");
......@@ -345,10 +350,6 @@ public class AppBannerManagerTest {
resetEngagementForUrl(url, 10);
new TabLoadObserver(rule.getActivity().getActivityTab())
.fullyLoadUrl(url, PageTransition.TYPED);
if (setupScript != null) {
rule.runJavaScriptCodeInCurrentTab(setupScript);
}
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
......@@ -439,7 +440,7 @@ public class AppBannerManagerTest {
@Feature({"AppBanners"})
public void testBannerAppearsThenDoesNotAppearAgainForCustomTime() throws Exception {
AppBannerManager.setDaysAfterDismissAndIgnoreForTesting(7, 7);
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl, null, WEB_APP_TITLE, false);
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl, WEB_APP_TITLE, false);
// Revisit the page to make the banner go away, but don't explicitly dismiss it.
// This hides the banner for two weeks.
......@@ -567,7 +568,7 @@ public class AppBannerManagerTest {
@SmallTest
@Feature({"AppBanners"})
public void testWebAppBannerAppears() throws Exception {
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl, null, WEB_APP_TITLE, false);
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl, WEB_APP_TITLE, false);
// Verify metrics calling in the successful case.
ThreadUtils.runOnUiThread(() -> {
......@@ -589,7 +590,7 @@ public class AppBannerManagerTest {
@SmallTest
@Feature({"AppBanners"})
public void testWebAppBannerDoesNotAppearAfterInstall() throws Exception {
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl, null, WEB_APP_TITLE, true);
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl, WEB_APP_TITLE, true);
// The banner should not reshow after the site has been installed.
AppBannerManager.setTimeDeltaForTesting(100);
......@@ -605,7 +606,7 @@ public class AppBannerManagerTest {
triggerWebAppBanner(mTabbedActivityTestRule,
WebappTestPage.urlOfPageWithServiceWorkerAndManifest(
mTestServer, WEB_APP_SHORT_TITLE_MANIFEST),
null, WEB_APP_SHORT_TITLE, false);
WEB_APP_SHORT_TITLE, false);
}
@Test
......@@ -615,41 +616,19 @@ public class AppBannerManagerTest {
triggerWebAppBanner(mTabbedActivityTestRule,
WebappTestPage.urlOfPageWithServiceWorkerAndManifest(
mTestServer, WEB_APP_EMPTY_NAME_MANIFEST),
null, WEB_APP_SHORT_TITLE, false);
}
@Test
@MediumTest
@Feature({"AppBanners"})
public void testAppInstalledEventAutomaticPrompt() throws Exception {
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl, "verifyEvents('appinstalled')",
WEB_APP_TITLE, true);
// The appinstalled event should fire (and cause the title to change).
new TabTitleObserver(mTabbedActivityTestRule.getActivity().getActivityTab(),
"Got appinstalled: listener, attr")
.waitForTitleUpdate(3);
}
@Test
@MediumTest
@Feature({"AppBanners"})
public void testAppInstalledEventApi() throws Exception {
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl,
"addPromptListener(PromptAction.CALL_PROMPT_DELAYED);verifyEvents('appinstalled');",
WEB_APP_TITLE, true);
// The appinstalled event should fire (and cause the title to change).
new TabTitleObserver(mTabbedActivityTestRule.getActivity().getActivityTab(),
"Got appinstalled: listener, attr")
.waitForTitleUpdate(3);
WEB_APP_SHORT_TITLE, false);
}
private void runWebAppBannerAndCheckInstallEvent(
ChromeActivityTestRule<? extends ChromeActivity> rule, String webAppUrl,
String setupScript, int expectedBucket) throws Exception {
triggerWebAppBanner(rule, webAppUrl, setupScript, WEB_APP_TITLE, true);
int expectedBucket) throws Exception {
triggerWebAppBanner(rule, webAppUrl, WEB_APP_TITLE, true);
// The appinstalled event should fire (and cause the title to change).
Tab tab = rule.getActivity().getActivityTab();
new TabTitleObserver(tab, "Got appinstalled").waitForTitleUpdate(3);
// We should have recorded the AUTOMATIC_BROWSER_TAB install source.
ThreadUtils.runOnUiThread(() -> {
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
......@@ -661,7 +640,7 @@ public class AppBannerManagerTest {
@SmallTest
@Feature({"AppBanners"})
public void testPostInstallationAutomaticPromptBrowserTab() throws Exception {
runWebAppBannerAndCheckInstallEvent(mTabbedActivityTestRule, mWebAppUrl, null, 2);
runWebAppBannerAndCheckInstallEvent(mTabbedActivityTestRule, mWebAppUrl, 2);
}
@Test
......@@ -671,15 +650,14 @@ public class AppBannerManagerTest {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank"));
runWebAppBannerAndCheckInstallEvent(mCustomTabActivityTestRule, mWebAppUrl, null, 3);
runWebAppBannerAndCheckInstallEvent(mCustomTabActivityTestRule, mWebAppUrl, 3);
}
@Test
@SmallTest
@Feature({"AppBanners"})
public void testPostInstallationApiBrowserTab() throws Exception {
runWebAppBannerAndCheckInstallEvent(mTabbedActivityTestRule, mWebAppUrl,
"addPromptListener(PromptAction.CALL_PROMPT_DELAYED)", 4);
runWebAppBannerAndCheckInstallEvent(mTabbedActivityTestRule, mWebAppApiUrl, 4);
}
@Test
......@@ -689,8 +667,7 @@ public class AppBannerManagerTest {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank"));
runWebAppBannerAndCheckInstallEvent(mCustomTabActivityTestRule, mWebAppUrl,
"addPromptListener(PromptAction.CALL_PROMPT_DELAYED)", 5);
runWebAppBannerAndCheckInstallEvent(mCustomTabActivityTestRule, mWebAppApiUrl, 5);
}
@Test
......@@ -747,7 +724,7 @@ public class AppBannerManagerTest {
final TestDataStorageFactory dataStorageFactory = new TestDataStorageFactory();
WebappDataStorage.setFactoryForTests(dataStorageFactory);
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl, null, WEB_APP_TITLE, true);
triggerWebAppBanner(mTabbedActivityTestRule, mWebAppUrl, WEB_APP_TITLE, true);
// Make sure that the splash screen icon was downloaded.
CriteriaHelper.pollUiThread(new Criteria() {
......
......@@ -88,6 +88,10 @@ public class AddToHomescreenManagerTest {
private static final String MANIFEST_PATH = "/chrome/test/data/banners/manifest_test_page.html";
private static final String MANIFEST_TITLE = "Web app banner test page";
private static final String EVENT_WEBAPP_PATH =
"/chrome/test/data/banners/appinstalled_test_page.html";
private static final String EVENT_WEBAPP_TITLE = "appinstalled event test page";
private static class TestShortcutHelperDelegate extends ShortcutHelper.Delegate {
public String mRequestedShortcutTitle;
public Intent mRequestedShortcutIntent;
......@@ -298,8 +302,7 @@ public class AddToHomescreenManagerTest {
@SmallTest
@Feature("{Webapp}")
public void testAddWebappShortcutAppInstalledEvent() throws Exception {
loadUrl(mTestServerRule.getServer().getURL(MANIFEST_PATH), MANIFEST_TITLE);
mActivityTestRule.runJavaScriptCodeInCurrentTab("verifyEvents('appinstalled')");
loadUrl(mTestServerRule.getServer().getURL(EVENT_WEBAPP_PATH), EVENT_WEBAPP_TITLE);
addShortcutToTab(mTab, "", true);
// Wait for the tab title to change. This will happen (due to the JavaScript that runs
......
<!DOCTYPE html>
<html>
<head>
<title>appinstalled event test page</title>
<script>
// These blanks will get filled in when each event comes through.
var gotEventsFrom = ['________', '____'];
function setTitle() {
window.document.title = 'Got appinstalled: ' +
gotEventsFrom.join(', ');
}
window.addEventListener('load', () => {
// Test both the addEventListener and onX attribute versions.
// When an app is installed, each should fire once.
window.addEventListener('appinstalled', () => {
gotEventsFrom[0] = 'listener';
setTitle();
});
window.onappinstalled = () => {
gotEventsFrom[1] = 'attr';
setTitle();
};
});
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>beforeinstallprompt event test page</title>
<link rel="manifest" href="manifest.json" />
<script src="main.js"></script>
<script>
// These blanks will get filled in when each event comes through.
var gotEventsFrom = ['________', '____'];
function setTitle() {
window.document.title = 'Got beforeinstallprompt: ' +
gotEventsFrom.join(', ');
}
window.addEventListener('load', () => {
// Test both the addEventListener and onX attribute versions.
// When a prompt is shown, each should fire once.
window.addEventListener('beforeinstallprompt', () => {
gotEventsFrom[0] = 'listener';
setTitle();
});
window.onbeforeinstallprompt = () => {
gotEventsFrom[1] = 'attr';
setTitle();
};
});
</script>
</head>
<body onload="initialize()"></body>
</html>
<html>
<head>
<title>Web app banner test page</title>
<script src="main.js"></script>
<script>
// If a "manifest=/path/to/manifest.json" query argument is provided to
// the URL accessing this page, that path is injected as the manifest tag.
// Otherwise, "manifest.json" is used as the manifest tag.
addManifestLinkTag();
window.addEventListener('beforeinstallprompt', function(e) {
console.log('Preventing banner from appearing');
e.preventDefault();
// Navigate the window to trigger the banner cancellation.
window.location.href = "/";
});
</script>
</head>
<body onload="initialize()">Cancels the banner.</body>
</html>
......@@ -2,71 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const PromptAction = {
CALL_PROMPT_DELAYED: 0,
CALL_PROMPT_IN_HANDLER: 1,
CANCEL_PROMPT: 2,
STASH_EVENT: 3,
};
const LISTENER = "listener";
const ATTR = "attr";
// These blanks will get filled in when each event comes through.
let gotEventsFrom = ['_'.repeat(LISTENER.length), '_'.repeat(ATTR.length)];
let stashedEvent = null;
function initialize() {
navigator.serviceWorker.register('service_worker.js');
}
function verifyEvents(eventName) {
function setTitle() {
window.document.title = 'Got ' + eventName + ': ' +
gotEventsFrom.join(', ');
}
window.addEventListener(eventName, () => {
gotEventsFrom[0] = LISTENER;
setTitle();
});
window['on' + eventName] = () => {
gotEventsFrom[1] = ATTR;
setTitle();
};
}
function callPrompt(event) {
event.prompt();
}
function callStashedPrompt() {
if (stashedEvent === null) {
throw new Error('No event was previously stashed');
}
stashedEvent.prompt();
}
function addPromptListener(promptAction) {
window.addEventListener('beforeinstallprompt', function(e) {
e.preventDefault();
switch (promptAction) {
case PromptAction.CALL_PROMPT_DELAYED:
setTimeout(callPrompt, 0, e);
break;
case PromptAction.CALL_PROMPT_IN_HANDLER:
callPrompt(e);
break;
case PromptAction.CANCEL_PROMPT:
// Navigate the window to trigger the banner cancellation.
window.location.href = "/";
break;
case PromptAction.STASH_EVENT:
stashedEvent = e;
break;
}
window.addEventListener('appinstalled', () => {
window.document.title = 'Got appinstalled';
});
}
......
......@@ -4,6 +4,6 @@
<script src="main.js"></script>
</head>
<body onload="initialize()">
Do-nothing page with a service worker, but no manifest.
Do-nothing page with a service worker, but no manifest.
</body>
</html>
</html>
\ No newline at end of file
<html>
<head>
<title>Web app banner test page</title>
<link rel="manifest" href="manifest.json" />
<script>
navigator.serviceWorker.register('service_worker_no_fetch_handler.js');
</script>
</head>
<body>
Do-nothing page with a service worker missing a fetch handler.
Page with a service worker missing a fetch handler.
</body>
</html>
......@@ -4,6 +4,6 @@
<link rel="manifest" href="play_app_manifest.json" />
</head>
<body>
Do-nothing page with a manifest specifying a native Play app.
Do-nothing page with a manifest requesting a native app banner.
</body>
</html>
......@@ -3,7 +3,7 @@
<title>Native app banner test page</title>
<link rel="manifest" href="play_app_url_manifest.json" />
</head>
<body>
Do-nothing page with a manifest specifying a native Play app by URL.
<body onload="initialize()">
Do-nothing page with a service worker.
</body>
</html>
<html>
<head>
<title>Web app banner test page</title>
<link rel="manifest" href="manifest.json" />
<script src="main.js"></script>
<script>
window.addEventListener('beforeinstallprompt', function(e) {
e.preventDefault();
e.prompt();
});
</script>
</head>
<body onload="initialize()">Cancels the banner, then prompts for it to be shown in the handler.</body>
</html>
<html>
<head>
<title>Web app banner test page</title>
<link rel="manifest" href="manifest.json" />
<script src="main.js"></script>
<script>
var e = 1;
function callPrompt() {
e.prompt();
}
window.addEventListener('beforeinstallprompt', function(event) {
e = event;
});
</script>
</head>
<body onload="initialize()"></body>
</html>
<html>
<head>
<title>Web app banner test page</title>
<link rel="manifest" href="manifest.json" />
<script src="main.js"></script>
<script>
function callPrompt(event) {
event.prompt();
}
window.addEventListener('beforeinstallprompt', function(e) {
e.preventDefault();
setTimeout(callPrompt, 0, e);
});
</script>
</head>
<body onload="initialize()">Cancels the banner, then prompts for it to be shown later.</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