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; ...@@ -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.InfoBarContainer.InfoBarAnimationListener;
import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item; import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item;
import org.chromium.chrome.browser.profiles.Profile; 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.browser.webapps.WebappDataStorage;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
...@@ -96,6 +97,9 @@ public class AppBannerManagerTest { ...@@ -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_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 = private static final String WEB_APP_SHORT_TITLE_MANIFEST =
"/chrome/test/data/banners/manifest_short_name_only.json"; "/chrome/test/data/banners/manifest_short_name_only.json";
...@@ -189,6 +193,7 @@ public class AppBannerManagerTest { ...@@ -189,6 +193,7 @@ public class AppBannerManagerTest {
private TestPackageManager mPackageManager; private TestPackageManager mPackageManager;
private EmbeddedTestServer mTestServer; private EmbeddedTestServer mTestServer;
private String mWebAppUrl; private String mWebAppUrl;
private String mWebAppApiUrl;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
...@@ -212,6 +217,7 @@ public class AppBannerManagerTest { ...@@ -212,6 +217,7 @@ public class AppBannerManagerTest {
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext()); mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
mNativeAppUrl = mTestServer.getURL(NATIVE_APP_PATH); mNativeAppUrl = mTestServer.getURL(NATIVE_APP_PATH);
mWebAppUrl = mTestServer.getURL(WEB_APP_PATH); mWebAppUrl = mTestServer.getURL(WEB_APP_PATH);
mWebAppApiUrl = mTestServer.getURL(WEB_APP_BEFORE_INSTALL_PROMPT_PATH);
} }
@After @After
...@@ -318,8 +324,7 @@ public class AppBannerManagerTest { ...@@ -318,8 +324,7 @@ public class AppBannerManagerTest {
} }
public void triggerWebAppBanner(ChromeActivityTestRule<? extends ChromeActivity> rule, public void triggerWebAppBanner(ChromeActivityTestRule<? extends ChromeActivity> rule,
String url, String setupScript, String expectedTitle, boolean installApp) String url, String expectedTitle, boolean installApp) throws Exception {
throws Exception {
// Visit the site in a new tab. // Visit the site in a new tab.
resetEngagementForUrl(url, 0); resetEngagementForUrl(url, 0);
rule.loadUrlInNewTab("about:blank"); rule.loadUrlInNewTab("about:blank");
...@@ -345,10 +350,6 @@ public class AppBannerManagerTest { ...@@ -345,10 +350,6 @@ public class AppBannerManagerTest {
resetEngagementForUrl(url, 10); resetEngagementForUrl(url, 10);
new TabLoadObserver(rule.getActivity().getActivityTab()) new TabLoadObserver(rule.getActivity().getActivityTab())
.fullyLoadUrl(url, PageTransition.TYPED); .fullyLoadUrl(url, PageTransition.TYPED);
if (setupScript != null) {
rule.runJavaScriptCodeInCurrentTab(setupScript);
}
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
...@@ -439,7 +440,7 @@ public class AppBannerManagerTest { ...@@ -439,7 +440,7 @@ public class AppBannerManagerTest {
@Feature({"AppBanners"}) @Feature({"AppBanners"})
public void testBannerAppearsThenDoesNotAppearAgainForCustomTime() throws Exception { public void testBannerAppearsThenDoesNotAppearAgainForCustomTime() throws Exception {
AppBannerManager.setDaysAfterDismissAndIgnoreForTesting(7, 7); 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. // Revisit the page to make the banner go away, but don't explicitly dismiss it.
// This hides the banner for two weeks. // This hides the banner for two weeks.
...@@ -567,7 +568,7 @@ public class AppBannerManagerTest { ...@@ -567,7 +568,7 @@ public class AppBannerManagerTest {
@SmallTest @SmallTest
@Feature({"AppBanners"}) @Feature({"AppBanners"})
public void testWebAppBannerAppears() throws Exception { 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. // Verify metrics calling in the successful case.
ThreadUtils.runOnUiThread(() -> { ThreadUtils.runOnUiThread(() -> {
...@@ -589,7 +590,7 @@ public class AppBannerManagerTest { ...@@ -589,7 +590,7 @@ public class AppBannerManagerTest {
@SmallTest @SmallTest
@Feature({"AppBanners"}) @Feature({"AppBanners"})
public void testWebAppBannerDoesNotAppearAfterInstall() throws Exception { 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. // The banner should not reshow after the site has been installed.
AppBannerManager.setTimeDeltaForTesting(100); AppBannerManager.setTimeDeltaForTesting(100);
...@@ -605,7 +606,7 @@ public class AppBannerManagerTest { ...@@ -605,7 +606,7 @@ public class AppBannerManagerTest {
triggerWebAppBanner(mTabbedActivityTestRule, triggerWebAppBanner(mTabbedActivityTestRule,
WebappTestPage.urlOfPageWithServiceWorkerAndManifest( WebappTestPage.urlOfPageWithServiceWorkerAndManifest(
mTestServer, WEB_APP_SHORT_TITLE_MANIFEST), mTestServer, WEB_APP_SHORT_TITLE_MANIFEST),
null, WEB_APP_SHORT_TITLE, false); WEB_APP_SHORT_TITLE, false);
} }
@Test @Test
...@@ -615,41 +616,19 @@ public class AppBannerManagerTest { ...@@ -615,41 +616,19 @@ public class AppBannerManagerTest {
triggerWebAppBanner(mTabbedActivityTestRule, triggerWebAppBanner(mTabbedActivityTestRule,
WebappTestPage.urlOfPageWithServiceWorkerAndManifest( WebappTestPage.urlOfPageWithServiceWorkerAndManifest(
mTestServer, WEB_APP_EMPTY_NAME_MANIFEST), mTestServer, WEB_APP_EMPTY_NAME_MANIFEST),
null, WEB_APP_SHORT_TITLE, false); 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);
} }
private void runWebAppBannerAndCheckInstallEvent( private void runWebAppBannerAndCheckInstallEvent(
ChromeActivityTestRule<? extends ChromeActivity> rule, String webAppUrl, ChromeActivityTestRule<? extends ChromeActivity> rule, String webAppUrl,
String setupScript, int expectedBucket) throws Exception { int expectedBucket) throws Exception {
triggerWebAppBanner(rule, webAppUrl, setupScript, WEB_APP_TITLE, true); 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(() -> { ThreadUtils.runOnUiThread(() -> {
Assert.assertEquals(1, Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting( RecordHistogram.getHistogramValueCountForTesting(
...@@ -661,7 +640,7 @@ public class AppBannerManagerTest { ...@@ -661,7 +640,7 @@ public class AppBannerManagerTest {
@SmallTest @SmallTest
@Feature({"AppBanners"}) @Feature({"AppBanners"})
public void testPostInstallationAutomaticPromptBrowserTab() throws Exception { public void testPostInstallationAutomaticPromptBrowserTab() throws Exception {
runWebAppBannerAndCheckInstallEvent(mTabbedActivityTestRule, mWebAppUrl, null, 2); runWebAppBannerAndCheckInstallEvent(mTabbedActivityTestRule, mWebAppUrl, 2);
} }
@Test @Test
...@@ -671,15 +650,14 @@ public class AppBannerManagerTest { ...@@ -671,15 +650,14 @@ public class AppBannerManagerTest {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent( mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
CustomTabsTestUtils.createMinimalCustomTabIntent( CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank")); InstrumentationRegistry.getTargetContext(), "about:blank"));
runWebAppBannerAndCheckInstallEvent(mCustomTabActivityTestRule, mWebAppUrl, null, 3); runWebAppBannerAndCheckInstallEvent(mCustomTabActivityTestRule, mWebAppUrl, 3);
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AppBanners"}) @Feature({"AppBanners"})
public void testPostInstallationApiBrowserTab() throws Exception { public void testPostInstallationApiBrowserTab() throws Exception {
runWebAppBannerAndCheckInstallEvent(mTabbedActivityTestRule, mWebAppUrl, runWebAppBannerAndCheckInstallEvent(mTabbedActivityTestRule, mWebAppApiUrl, 4);
"addPromptListener(PromptAction.CALL_PROMPT_DELAYED)", 4);
} }
@Test @Test
...@@ -689,8 +667,7 @@ public class AppBannerManagerTest { ...@@ -689,8 +667,7 @@ public class AppBannerManagerTest {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent( mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
CustomTabsTestUtils.createMinimalCustomTabIntent( CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank")); InstrumentationRegistry.getTargetContext(), "about:blank"));
runWebAppBannerAndCheckInstallEvent(mCustomTabActivityTestRule, mWebAppUrl, runWebAppBannerAndCheckInstallEvent(mCustomTabActivityTestRule, mWebAppApiUrl, 5);
"addPromptListener(PromptAction.CALL_PROMPT_DELAYED)", 5);
} }
@Test @Test
...@@ -747,7 +724,7 @@ public class AppBannerManagerTest { ...@@ -747,7 +724,7 @@ public class AppBannerManagerTest {
final TestDataStorageFactory dataStorageFactory = new TestDataStorageFactory(); final TestDataStorageFactory dataStorageFactory = new TestDataStorageFactory();
WebappDataStorage.setFactoryForTests(dataStorageFactory); 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. // Make sure that the splash screen icon was downloaded.
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
......
...@@ -88,6 +88,10 @@ public class AddToHomescreenManagerTest { ...@@ -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_PATH = "/chrome/test/data/banners/manifest_test_page.html";
private static final String MANIFEST_TITLE = "Web app banner test page"; 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 { private static class TestShortcutHelperDelegate extends ShortcutHelper.Delegate {
public String mRequestedShortcutTitle; public String mRequestedShortcutTitle;
public Intent mRequestedShortcutIntent; public Intent mRequestedShortcutIntent;
...@@ -298,8 +302,7 @@ public class AddToHomescreenManagerTest { ...@@ -298,8 +302,7 @@ public class AddToHomescreenManagerTest {
@SmallTest @SmallTest
@Feature("{Webapp}") @Feature("{Webapp}")
public void testAddWebappShortcutAppInstalledEvent() throws Exception { public void testAddWebappShortcutAppInstalledEvent() throws Exception {
loadUrl(mTestServerRule.getServer().getURL(MANIFEST_PATH), MANIFEST_TITLE); loadUrl(mTestServerRule.getServer().getURL(EVENT_WEBAPP_PATH), EVENT_WEBAPP_TITLE);
mActivityTestRule.runJavaScriptCodeInCurrentTab("verifyEvents('appinstalled')");
addShortcutToTab(mTab, "", true); addShortcutToTab(mTab, "", true);
// Wait for the tab title to change. This will happen (due to the JavaScript that runs // Wait for the tab title to change. This will happen (due to the JavaScript that runs
......
...@@ -190,24 +190,26 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest { ...@@ -190,24 +190,26 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest {
AppBannerManagerTest* manager, AppBannerManagerTest* manager,
const std::string& url, const std::string& url,
const std::vector<double>& engagement_scores, const std::vector<double>& engagement_scores,
const std::string& setup_script,
WebappInstallSource expected_install_source, WebappInstallSource expected_install_source,
InstallableStatusCode expected_code_for_histogram, InstallableStatusCode expected_code_for_histogram,
bool expected_to_record_minutes_histogram) { bool expected_to_record_minutes_histogram,
RunBannerTest(browser, manager, url, engagement_scores, setup_script, bool expected_to_show) {
RunBannerTest(browser, manager, url, engagement_scores,
expected_install_source, expected_code_for_histogram, expected_install_source, expected_code_for_histogram,
expected_to_record_minutes_histogram, base::string16()); expected_to_record_minutes_histogram, expected_to_show,
base::string16(), ui::PAGE_TRANSITION_TYPED);
} }
void RunBannerTest(Browser* browser, void RunBannerTest(Browser* browser,
AppBannerManagerTest* manager, AppBannerManagerTest* manager,
const std::string& url, const std::string& url,
const std::vector<double>& engagement_scores, const std::vector<double>& engagement_scores,
const std::string& setup_script,
WebappInstallSource expected_install_source, WebappInstallSource expected_install_source,
InstallableStatusCode expected_code_for_histogram, InstallableStatusCode expected_code_for_histogram,
bool expected_to_record_minutes_histogram, bool expected_to_record_minutes_histogram,
const base::string16 expected_tab_title) { bool expected_to_show,
const base::string16 expected_tab_title,
ui::PageTransition transition) {
base::HistogramTester histograms; base::HistogramTester histograms;
GURL test_url = embedded_test_server()->GetURL(url); GURL test_url = embedded_test_server()->GetURL(url);
...@@ -234,21 +236,17 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest { ...@@ -234,21 +236,17 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest {
++iterations; ++iterations;
} }
// The final loop should have set sufficient engagement for the banner to // On the final loop, we expect the banner pipeline to trigger - the
// trigger. Spin the run loop and wait for the manager to finish. // navigation should generate the final engagement to show the banner. Spin
// the run loop and wait for the manager to finish.
base::RunLoop run_loop; base::RunLoop run_loop;
manager->clear_will_show(); manager->clear_will_show();
manager->PrepareDone(run_loop.QuitClosure()); manager->PrepareDone(run_loop.QuitClosure());
NavigateParams nav_params(browser, test_url, ui::PAGE_TRANSITION_LINK); NavigateParams nav_params(browser, test_url, transition);
ui_test_utils::NavigateToURL(&nav_params); ui_test_utils::NavigateToURL(&nav_params);
if (!setup_script.empty()) {
EXPECT_TRUE(content::ExecuteScript(
browser->tab_strip_model()->GetActiveWebContents(), setup_script));
}
run_loop.Run(); run_loop.Run();
EXPECT_EQ(expected_code_for_histogram == SHOWING_WEB_APP_BANNER, EXPECT_EQ(expected_to_show, manager->banner_shown());
manager->banner_shown());
EXPECT_EQ(expected_install_source, manager->install_source()); EXPECT_EQ(expected_install_source, manager->install_source());
// Generally the manager will be in the complete state, however some test // Generally the manager will be in the complete state, however some test
...@@ -282,7 +280,6 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest { ...@@ -282,7 +280,6 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest {
void TriggerBannerFlowWithNavigation(Browser* browser, void TriggerBannerFlowWithNavigation(Browser* browser,
AppBannerManagerTest* manager, AppBannerManagerTest* manager,
const GURL& url, const GURL& url,
const std::string& setup_script,
bool expected_will_show, bool expected_will_show,
State expected_state) { State expected_state) {
// Use NavigateToURLWithDisposition as it isn't overloaded, so can be used // Use NavigateToURLWithDisposition as it isn't overloaded, so can be used
...@@ -292,23 +289,18 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest { ...@@ -292,23 +289,18 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest {
base::BindOnce(&ui_test_utils::NavigateToURLWithDisposition, browser, base::BindOnce(&ui_test_utils::NavigateToURLWithDisposition, browser,
url, WindowOpenDisposition::CURRENT_TAB, url, WindowOpenDisposition::CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION), ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION),
setup_script, expected_will_show, expected_state); expected_will_show, expected_state);
} }
void TriggerBannerFlow(Browser* browser, void TriggerBannerFlow(Browser* browser,
AppBannerManagerTest* manager, AppBannerManagerTest* manager,
base::OnceClosure trigger_task, base::OnceClosure trigger_task,
const std::string& setup_script,
bool expected_will_show, bool expected_will_show,
State expected_state) { State expected_state) {
base::RunLoop run_loop; base::RunLoop run_loop;
manager->clear_will_show(); manager->clear_will_show();
manager->PrepareDone(run_loop.QuitClosure()); manager->PrepareDone(run_loop.QuitClosure());
std::move(trigger_task).Run(); std::move(trigger_task).Run();
if (!setup_script.empty()) {
EXPECT_TRUE(content::ExecuteScript(
browser->tab_strip_model()->GetActiveWebContents(), setup_script));
}
run_loop.Run(); run_loop.Run();
EXPECT_EQ(expected_will_show, manager->banner_shown()); EXPECT_EQ(expected_will_show, manager->banner_shown());
...@@ -321,9 +313,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreated) { ...@@ -321,9 +313,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreated) {
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{0, 10}; std::vector<double> engagement_scores{0, 10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
engagement_scores, std::string(), engagement_scores,
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, true); SHOWING_WEB_APP_BANNER, true, true);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -332,9 +324,10 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -332,9 +324,10 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{10}; std::vector<double> engagement_scores{10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
engagement_scores, std::string(), engagement_scores,
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, true); SHOWING_WEB_APP_BANNER, true, true, base::string16(),
ui::PAGE_TRANSITION_LINK);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -343,9 +336,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -343,9 +336,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{0, 1, 2, 3, 4, 5, 10}; std::vector<double> engagement_scores{0, 1, 2, 3, 4, 5, 10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
engagement_scores, std::string(), engagement_scores,
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, true); SHOWING_WEB_APP_BANNER, true, true);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -354,33 +347,33 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -354,33 +347,33 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{0, 10}; std::vector<double> engagement_scores{0, 10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
engagement_scores, std::string(), engagement_scores,
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, true); SHOWING_WEB_APP_BANNER, true, true);
AppBannerManager::SetTimeDeltaForTesting(1); AppBannerManager::SetTimeDeltaForTesting(1);
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
engagement_scores, std::string(), WebappInstallSource::COUNT, engagement_scores, WebappInstallSource::COUNT,
PREVIOUSLY_IGNORED, false); PREVIOUSLY_IGNORED, false, false);
AppBannerManager::SetTimeDeltaForTesting(13); AppBannerManager::SetTimeDeltaForTesting(13);
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
engagement_scores, std::string(), WebappInstallSource::COUNT, engagement_scores, WebappInstallSource::COUNT,
PREVIOUSLY_IGNORED, false); PREVIOUSLY_IGNORED, false, false);
AppBannerManager::SetTimeDeltaForTesting(14); AppBannerManager::SetTimeDeltaForTesting(14);
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
engagement_scores, std::string(), engagement_scores,
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, false); SHOWING_WEB_APP_BANNER, false, true);
AppBannerSettingsHelper::SetDaysAfterDismissAndIgnoreToTrigger(90, 2); AppBannerSettingsHelper::SetDaysAfterDismissAndIgnoreToTrigger(90, 2);
AppBannerManager::SetTimeDeltaForTesting(16); AppBannerManager::SetTimeDeltaForTesting(16);
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
engagement_scores, std::string(), engagement_scores,
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, false); SHOWING_WEB_APP_BANNER, false, true);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -391,9 +384,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -391,9 +384,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
RunBannerTest(browser(), manager.get(), RunBannerTest(browser(), manager.get(),
GetURLOfPageWithServiceWorkerAndManifest( GetURLOfPageWithServiceWorkerAndManifest(
"/banners/manifest_no_type.json"), "/banners/manifest_no_type.json"),
engagement_scores, std::string(), engagement_scores,
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, true); SHOWING_WEB_APP_BANNER, true, true);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -404,9 +397,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -404,9 +397,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
RunBannerTest(browser(), manager.get(), RunBannerTest(browser(), manager.get(),
GetURLOfPageWithServiceWorkerAndManifest( GetURLOfPageWithServiceWorkerAndManifest(
"/banners/manifest_no_type_caps.json"), "/banners/manifest_no_type_caps.json"),
engagement_scores, std::string(), engagement_scores,
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, true); SHOWING_WEB_APP_BANNER, true, true);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) { IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) {
...@@ -414,8 +407,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) { ...@@ -414,8 +407,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) {
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{10}; std::vector<double> engagement_scores{10};
RunBannerTest(browser(), manager.get(), "/banners/no_manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/no_manifest_test_page.html",
engagement_scores, std::string(), WebappInstallSource::COUNT, engagement_scores, WebappInstallSource::COUNT, NO_MANIFEST,
NO_MANIFEST, false); false, false);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) { IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) {
...@@ -425,8 +418,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) { ...@@ -425,8 +418,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) {
RunBannerTest(browser(), manager.get(), RunBannerTest(browser(), manager.get(),
GetURLOfPageWithServiceWorkerAndManifest( GetURLOfPageWithServiceWorkerAndManifest(
"/banners/manifest_missing.json"), "/banners/manifest_missing.json"),
engagement_scores, std::string(), WebappInstallSource::COUNT, engagement_scores, WebappInstallSource::COUNT, MANIFEST_EMPTY,
MANIFEST_EMPTY, false); false, false);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -440,42 +433,40 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -440,42 +433,40 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
// onbeforeinstallprompt attribute. // onbeforeinstallprompt attribute.
// Note that this test does not call beforeinstallpromptevent.prompt(); it // Note that this test does not call beforeinstallpromptevent.prompt(); it
// merely ensures that the event was sent and received by the page. // merely ensures that the event was sent and received by the page.
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(
engagement_scores, "verifyEvents('beforeinstallprompt')", browser(), manager.get(), "/banners/beforeinstallprompt_test_page.html",
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, engagement_scores, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, true, SHOWING_WEB_APP_BANNER, true, true,
base::ASCIIToUTF16("Got beforeinstallprompt: listener, attr")); base::ASCIIToUTF16("Got beforeinstallprompt: listener, attr"),
ui::PAGE_TRANSITION_TYPED);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) { IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) {
std::unique_ptr<AppBannerManagerTest> manager( std::unique_ptr<AppBannerManagerTest> manager(
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{10}; std::vector<double> engagement_scores{10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/cancel_test_page.html",
engagement_scores, engagement_scores, WebappInstallSource::COUNT,
"addPromptListener(PromptAction.CANCEL_PROMPT)", RENDERER_CANCELLED, false, false);
WebappInstallSource::COUNT, RENDERER_CANCELLED, false);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBanner) { IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBanner) {
std::unique_ptr<AppBannerManagerTest> manager( std::unique_ptr<AppBannerManagerTest> manager(
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{0, 5, 10}; std::vector<double> engagement_scores{0, 5, 10};
RunBannerTest( RunBannerTest(browser(), manager.get(), "/banners/prompt_test_page.html",
browser(), manager.get(), "/banners/manifest_test_page.html", engagement_scores, WebappInstallSource::API_BROWSER_TAB,
engagement_scores, "addPromptListener(PromptAction.CALL_PROMPT_DELAYED)", SHOWING_WEB_APP_BANNER, true, true);
WebappInstallSource::API_BROWSER_TAB, SHOWING_WEB_APP_BANNER, true);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBannerInHandler) { IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBannerInHandler) {
std::unique_ptr<AppBannerManagerTest> manager( std::unique_ptr<AppBannerManagerTest> manager(
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{0, 2, 5, 10}; std::vector<double> engagement_scores{0, 2, 5, 10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(),
engagement_scores, "/banners/prompt_in_handler_test_page.html", engagement_scores,
"addPromptListener(PromptAction.CALL_PROMPT_IN_HANDLER)",
WebappInstallSource::API_BROWSER_TAB, SHOWING_WEB_APP_BANNER, WebappInstallSource::API_BROWSER_TAB, SHOWING_WEB_APP_BANNER,
true); true, true);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -483,18 +474,16 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -483,18 +474,16 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
std::unique_ptr<AppBannerManagerTest> manager( std::unique_ptr<AppBannerManagerTest> manager(
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{10}; std::vector<double> engagement_scores{10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(),
engagement_scores, "/banners/prompt_in_handler_test_page.html", engagement_scores,
"addPromptListener(PromptAction.CALL_PROMPT_IN_HANDLER)",
WebappInstallSource::API_BROWSER_TAB, SHOWING_WEB_APP_BANNER, WebappInstallSource::API_BROWSER_TAB, SHOWING_WEB_APP_BANNER,
true); true, true);
std::string cancel_test_page_url = std::string cancel_test_page_url =
GetURLOfPageWithManifest("/banners/manifest_test_page.html?manifest=", GetURLOfPageWithManifest("/banners/cancel_test_page.html?manifest=",
"/banners/manifest_different_start_url.json"); "/banners/manifest_different_start_url.json");
RunBannerTest(browser(), manager.get(), cancel_test_page_url, RunBannerTest(browser(), manager.get(), cancel_test_page_url,
engagement_scores, engagement_scores, WebappInstallSource::COUNT,
"addPromptListener(PromptAction.CANCEL_PROMPT)", RENDERER_CANCELLED, false, false);
WebappInstallSource::COUNT, RENDERER_CANCELLED, false);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) { IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) {
...@@ -502,8 +491,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) { ...@@ -502,8 +491,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) {
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{10}; std::vector<double> engagement_scores{10};
RunBannerTest(browser(), manager.get(), "/banners/iframe_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/iframe_test_page.html",
engagement_scores, std::string(), WebappInstallSource::COUNT, engagement_scores, WebappInstallSource::COUNT, NO_MANIFEST,
NO_MANIFEST, false); false, false);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, DoesNotShowInIncognito) { IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, DoesNotShowInIncognito) {
...@@ -514,7 +503,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, DoesNotShowInIncognito) { ...@@ -514,7 +503,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, DoesNotShowInIncognito) {
std::vector<double> engagement_scores{10}; std::vector<double> engagement_scores{10};
RunBannerTest(incognito_browser, manager.get(), RunBannerTest(incognito_browser, manager.get(),
"/banners/manifest_test_page.html", engagement_scores, "/banners/manifest_test_page.html", engagement_scores,
std::string(), WebappInstallSource::COUNT, IN_INCOGNITO, false); WebappInstallSource::COUNT, IN_INCOGNITO, false, false);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -526,9 +515,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -526,9 +515,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{10}; std::vector<double> engagement_scores{10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
engagement_scores, std::string(), engagement_scores,
WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB, WebappInstallSource::AUTOMATIC_PROMPT_BROWSER_TAB,
SHOWING_WEB_APP_BANNER, true); SHOWING_WEB_APP_BANNER, true, true);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -539,10 +528,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -539,10 +528,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
std::unique_ptr<AppBannerManagerTest> manager( std::unique_ptr<AppBannerManagerTest> manager(
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{10}; std::vector<double> engagement_scores{10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(), "/banners/cancel_test_page.html",
engagement_scores, engagement_scores, WebappInstallSource::COUNT,
"addPromptListener(PromptAction.CANCEL_PROMPT)", RENDERER_CANCELLED, false, false);
WebappInstallSource::COUNT, RENDERER_CANCELLED, false);
} }
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(
...@@ -554,18 +542,16 @@ IN_PROC_BROWSER_TEST_F( ...@@ -554,18 +542,16 @@ IN_PROC_BROWSER_TEST_F(
std::unique_ptr<AppBannerManagerTest> manager( std::unique_ptr<AppBannerManagerTest> manager(
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
std::vector<double> engagement_scores{10}; std::vector<double> engagement_scores{10};
RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", RunBannerTest(browser(), manager.get(),
engagement_scores, "/banners/prompt_in_handler_test_page.html", engagement_scores,
"addPromptListener(PromptAction.CALL_PROMPT_IN_HANDLER)",
WebappInstallSource::API_BROWSER_TAB, SHOWING_WEB_APP_BANNER, WebappInstallSource::API_BROWSER_TAB, SHOWING_WEB_APP_BANNER,
true); true, true);
std::string cancel_test_page_url = std::string cancel_test_page_url =
GetURLOfPageWithManifest("/banners/manifest_test_page.html?manifest=", GetURLOfPageWithManifest("/banners/cancel_test_page.html?manifest=",
"/banners/manifest_different_start_url.json"); "/banners/manifest_different_start_url.json");
RunBannerTest(browser(), manager.get(), cancel_test_page_url, RunBannerTest(browser(), manager.get(), cancel_test_page_url,
engagement_scores, engagement_scores, WebappInstallSource::COUNT,
"addPromptListener(PromptAction.CANCEL_PROMPT)", RENDERER_CANCELLED, false, false);
WebappInstallSource::COUNT, RENDERER_CANCELLED, false);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
...@@ -587,7 +573,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -587,7 +573,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
// First run through: expect the manager to end up stopped in the pending // First run through: expect the manager to end up stopped in the pending
// state, without showing a banner. // state, without showing a banner.
TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url, TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url,
std::string(), false /* expected_will_show */, false /* expected_will_show */,
State::PENDING_ENGAGEMENT); State::PENDING_ENGAGEMENT);
// Trigger an engagement increase that signals observers and expect the banner // Trigger an engagement increase that signals observers and expect the banner
...@@ -598,7 +584,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -598,7 +584,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
base::Unretained(service), base::Unretained(service),
browser()->tab_strip_model()->GetActiveWebContents(), browser()->tab_strip_model()->GetActiveWebContents(),
ui::PageTransition::PAGE_TRANSITION_TYPED), ui::PageTransition::PAGE_TRANSITION_TYPED),
std::string(), true /* expected_will_show */, State::COMPLETE); true /* expected_will_show */, State::COMPLETE);
histograms.ExpectTotalCount(banners::kMinutesHistogram, 1); histograms.ExpectTotalCount(banners::kMinutesHistogram, 1);
histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
...@@ -619,12 +605,12 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CheckOnLoadThenNavigate) { ...@@ -619,12 +605,12 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CheckOnLoadThenNavigate) {
// First run through: expect the manager to end up stopped in the pending // First run through: expect the manager to end up stopped in the pending
// state, without showing a banner. // state, without showing a banner.
TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url, TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url,
std::string(), false /* expected_will_show */, false /* expected_will_show */,
State::PENDING_ENGAGEMENT); State::PENDING_ENGAGEMENT);
// Navigate and expect Stop() to be called. // Navigate and expect Stop() to be called.
TriggerBannerFlowWithNavigation(browser(), manager.get(), GURL("about:blank"), TriggerBannerFlowWithNavigation(browser(), manager.get(), GURL("about:blank"),
std::string(), false /* expected_will_show */, false /* expected_will_show */,
State::INACTIVE); State::INACTIVE);
histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
...@@ -648,12 +634,12 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -648,12 +634,12 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
// Navigate and expect the manager to end up waiting for prompt to be called. // Navigate and expect the manager to end up waiting for prompt to be called.
TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url, TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url,
std::string(), false /* expected_will_show */, false /* expected_will_show */,
State::PENDING_PROMPT); State::PENDING_PROMPT);
// Navigate and expect Stop() to be called. // Navigate and expect Stop() to be called.
TriggerBannerFlowWithNavigation(browser(), manager.get(), GURL("about:blank"), TriggerBannerFlowWithNavigation(browser(), manager.get(), GURL("about:blank"),
std::string(), false /* expected_will_show */, false /* expected_will_show */,
State::INACTIVE); State::INACTIVE);
histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
...@@ -671,23 +657,21 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -671,23 +657,21 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
SiteEngagementService* service = SiteEngagementService* service =
SiteEngagementService::Get(browser()->profile()); SiteEngagementService::Get(browser()->profile());
GURL test_url = GURL test_url = embedded_test_server()->GetURL(
embedded_test_server()->GetURL("/banners/manifest_test_page.html"); "/banners/prompt_no_preventdefault_test_page.html");
service->ResetBaseScoreForURL(test_url, 10); service->ResetBaseScoreForURL(test_url, 10);
// Navigate to page and get the pipeline started. // Navigate to page and get the pipeline started.
TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url, TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url,
"addPromptListener(PromptAction.STASH_EVENT)",
false /* expected_will_show */, false /* expected_will_show */,
State::PENDING_PROMPT); State::PENDING_PROMPT);
// Now let the page call prompt without a gesture, an error should be // Now let the page call prompt without a gesture, an error should be
// generated. // generated.
TriggerBannerFlow( TriggerBannerFlow(browser(), manager.get(),
browser(), manager.get(), base::BindOnce(&ExecuteScript, browser(), "callPrompt();",
base::BindOnce(&ExecuteScript, browser(), "callStashedPrompt();", false /* with_gesture */),
false /* with_gesture */), false /* expected_will_show */, State::COMPLETE);
std::string(), false /* expected_will_show */, State::COMPLETE);
histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
...@@ -704,22 +688,20 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -704,22 +688,20 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
SiteEngagementService* service = SiteEngagementService* service =
SiteEngagementService::Get(browser()->profile()); SiteEngagementService::Get(browser()->profile());
GURL test_url = GURL test_url = embedded_test_server()->GetURL(
embedded_test_server()->GetURL("/banners/manifest_test_page.html"); "/banners/prompt_no_preventdefault_test_page.html");
service->ResetBaseScoreForURL(test_url, 10); service->ResetBaseScoreForURL(test_url, 10);
// Navigate to page and get the pipeline started. // Navigate to page and get the pipeline started.
TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url, TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url,
"addPromptListener(PromptAction.STASH_EVENT)",
false /* expected_will_show */, false /* expected_will_show */,
State::PENDING_PROMPT); State::PENDING_PROMPT);
// Now let the page call prompt with a gesture. The banner should be shown. // Now let the page call prompt with a gesture. The banner should be shown.
TriggerBannerFlow( TriggerBannerFlow(browser(), manager.get(),
browser(), manager.get(), base::BindOnce(&ExecuteScript, browser(), "callPrompt();",
base::BindOnce(&ExecuteScript, browser(), "callStashedPrompt();", true /* with_gesture */),
true /* with_gesture */), true /* expected_will_show */, State::COMPLETE);
std::string(), true /* expected_will_show */, State::COMPLETE);
histograms.ExpectTotalCount(banners::kMinutesHistogram, 1); histograms.ExpectTotalCount(banners::kMinutesHistogram, 1);
histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
...@@ -736,22 +718,20 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -736,22 +718,20 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
SiteEngagementService* service = SiteEngagementService* service =
SiteEngagementService::Get(browser()->profile()); SiteEngagementService::Get(browser()->profile());
GURL test_url = GURL test_url = embedded_test_server()->GetURL(
embedded_test_server()->GetURL("/banners/manifest_test_page.html"); "/banners/prompt_no_preventdefault_test_page.html");
service->ResetBaseScoreForURL(test_url, 10); service->ResetBaseScoreForURL(test_url, 10);
// Navigate to page and get the pipeline started. // Navigate to page and get the pipeline started.
TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url, TriggerBannerFlowWithNavigation(browser(), manager.get(), test_url,
"addPromptListener(PromptAction.STASH_EVENT)",
false /* expected_will_show */, false /* expected_will_show */,
State::PENDING_PROMPT); State::PENDING_PROMPT);
// Call prompt to show the banner. // Call prompt to show the banner.
TriggerBannerFlow( TriggerBannerFlow(browser(), manager.get(),
browser(), manager.get(), base::BindOnce(&ExecuteScript, browser(), "callPrompt();",
base::BindOnce(&ExecuteScript, browser(), "callStashedPrompt();", true /* with_gesture */),
true /* with_gesture */), true /* expected_will_show */, State::COMPLETE);
std::string(), true /* expected_will_show */, State::COMPLETE);
// Dismiss the banner. // Dismiss the banner.
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -761,11 +741,10 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, ...@@ -761,11 +741,10 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
run_loop.Run(); run_loop.Run();
// Call prompt again to show the banner again. // Call prompt again to show the banner again.
TriggerBannerFlow( TriggerBannerFlow(browser(), manager.get(),
browser(), manager.get(), base::BindOnce(&ExecuteScript, browser(), "callPrompt();",
base::BindOnce(&ExecuteScript, browser(), "callStashedPrompt();", true /* with_gesture */),
true /* with_gesture */), true /* expected_will_show */, State::COMPLETE);
std::string(), true /* expected_will_show */, State::COMPLETE);
histograms.ExpectTotalCount(banners::kMinutesHistogram, 1); histograms.ExpectTotalCount(banners::kMinutesHistogram, 1);
histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
......
<!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 @@ ...@@ -2,71 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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() { function initialize() {
navigator.serviceWorker.register('service_worker.js'); 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) { window.addEventListener('appinstalled', () => {
case PromptAction.CALL_PROMPT_DELAYED: window.document.title = 'Got appinstalled';
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;
}
}); });
} }
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
<script src="main.js"></script> <script src="main.js"></script>
</head> </head>
<body onload="initialize()"> <body onload="initialize()">
Do-nothing page with a service worker, but no manifest. Do-nothing page with a service worker, but no manifest.
</body> </body>
</html> </html>
\ No newline at end of file
<html> <html>
<head> <head>
<title>Web app banner test page</title>
<link rel="manifest" href="manifest.json" /> <link rel="manifest" href="manifest.json" />
<script> <script>
navigator.serviceWorker.register('service_worker_no_fetch_handler.js'); navigator.serviceWorker.register('service_worker_no_fetch_handler.js');
</script> </script>
</head> </head>
<body> <body>
Do-nothing page with a service worker missing a fetch handler. Page with a service worker missing a fetch handler.
</body> </body>
</html> </html>
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
<link rel="manifest" href="play_app_manifest.json" /> <link rel="manifest" href="play_app_manifest.json" />
</head> </head>
<body> <body>
Do-nothing page with a manifest specifying a native Play app. Do-nothing page with a manifest requesting a native app banner.
</body> </body>
</html> </html>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<title>Native app banner test page</title> <title>Native app banner test page</title>
<link rel="manifest" href="play_app_url_manifest.json" /> <link rel="manifest" href="play_app_url_manifest.json" />
</head> </head>
<body> <body onload="initialize()">
Do-nothing page with a manifest specifying a native Play app by URL. Do-nothing page with a service worker.
</body> </body>
</html> </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