Index: chrome/browser/banners/app_banner_manager_browsertest.cc |
diff --git a/chrome/browser/banners/app_banner_manager_browsertest.cc b/chrome/browser/banners/app_banner_manager_browsertest.cc |
index c4a174a8801dc04c8639af6386e00a875bc885be..157637560be3318d435787694492ba47f397605a 100644 |
--- a/chrome/browser/banners/app_banner_manager_browsertest.cc |
+++ b/chrome/browser/banners/app_banner_manager_browsertest.cc |
@@ -51,6 +51,8 @@ class AppBannerManagerTest : public AppBannerManager { |
AppBannerManager::RequestAppBanner(validated_url, is_debug_mode); |
} |
+ bool need_to_log_status() { return need_to_log_status_; } |
+ |
protected: |
void Stop() override { |
AppBannerManager::Stop(); |
@@ -60,6 +62,9 @@ class AppBannerManagerTest : public AppBannerManager { |
} |
void ShowBanner() override { |
+ // Fake the call to ReportStatus here - this is usually called in |
+ // platform-specific code which is not exposed here. |
+ ReportStatus(nullptr, SHOWING_WEB_APP_BANNER); |
ASSERT_FALSE(will_show_.get()); |
will_show_.reset(new bool(true)); |
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); |
@@ -76,6 +81,8 @@ class AppBannerManagerTest : public AppBannerManager { |
} |
private: |
+ bool IsDebugMode() const override { return false; } |
+ |
base::Closure quit_closure_; |
std::unique_ptr<bool> will_show_; |
}; |
@@ -101,7 +108,6 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest { |
base::RunLoop& run_loop, |
ui::PageTransition transition, |
bool expected_to_show) { |
- base::HistogramTester histograms; |
manager->set_page_transition_(transition); |
manager->RequestAppBanner(url, false, run_loop.QuitClosure()); |
run_loop.Run(); |
@@ -110,14 +116,15 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest { |
ASSERT_FALSE(manager->is_active()); |
// If showing the banner, ensure that the minutes histogram is recorded. |
- histograms.ExpectTotalCount(banners::kMinutesHistogram, |
+ histograms_.ExpectTotalCount(banners::kMinutesHistogram, |
(manager->will_show() ? 1 : 0)); |
} |
void RunBannerTest(const std::string& url, |
ui::PageTransition transition, |
unsigned int unshown_repetitions, |
- bool expectation) { |
+ InstallableStatusCode expected_code_for_histogram, |
+ bool expected_to_show) { |
std::string valid_page(url); |
GURL test_url = embedded_test_server()->GetURL(valid_page); |
content::WebContents* web_contents = |
@@ -125,52 +132,70 @@ class AppBannerManagerBrowserTest : public InProcessBrowserTest { |
std::unique_ptr<AppBannerManagerTest> manager( |
new AppBannerManagerTest(web_contents)); |
- for (unsigned int i = 0; i < unshown_repetitions; ++i) { |
+ for (unsigned int i = 1; i <= unshown_repetitions; ++i) { |
ui_test_utils::NavigateToURL(browser(), test_url); |
base::RunLoop run_loop; |
RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
run_loop, transition, false); |
- AppBannerManager::SetTimeDeltaForTesting(i + 1); |
+ CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, i, i); |
+ AppBannerManager::SetTimeDeltaForTesting(i); |
} |
// On the final loop, check whether the banner triggered or not as expected. |
ui_test_utils::NavigateToURL(browser(), test_url); |
base::RunLoop run_loop; |
RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
- run_loop, transition, expectation); |
+ run_loop, transition, expected_to_show); |
+ // Navigate to ensure the InstallableStatusCodeHistogram is logged. |
+ ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
+ CheckInstallableStatusCodeHistogram(expected_code_for_histogram, 1, |
+ unshown_repetitions + 1); |
+ EXPECT_FALSE(manager->need_to_log_status()); |
+ } |
+ |
+ void CheckInstallableStatusCodeHistogram(InstallableStatusCode expected_code, |
+ int expected_count, |
+ int total_count) { |
+ histograms_.ExpectBucketCount(banners::kInstallableStatusCodeHistogram, |
+ expected_code, expected_count); |
+ histograms_.ExpectTotalCount(banners::kInstallableStatusCodeHistogram, |
+ total_count); |
} |
+ |
+ private: |
+ base::HistogramTester histograms_; |
}; |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreatedDirect) { |
RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, |
- 1, true); |
+ 1, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerCreatedDirectLargerTotal) { |
AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); |
RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, |
- 3, true); |
+ 3, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerCreatedDirectSmallerTotal) { |
AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); |
RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, |
- 0, true); |
+ 0, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerCreatedDirectSingle) { |
AppBannerSettingsHelper::SetEngagementWeights(2, 1); |
RunBannerTest("/banners/manifest_test_page.html", |
- ui::PAGE_TRANSITION_GENERATED, 0, true); |
+ ui::PAGE_TRANSITION_GENERATED, 0, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerCreatedDirectMultiple) { |
AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); |
RunBannerTest("/banners/manifest_test_page.html", |
- ui::PAGE_TRANSITION_GENERATED, 3, true); |
+ ui::PAGE_TRANSITION_GENERATED, 3, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
@@ -178,7 +203,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); |
AppBannerSettingsHelper::SetTotalEngagementToTrigger(3); |
RunBannerTest("/banners/manifest_test_page.html", |
- ui::PAGE_TRANSITION_GENERATED, 5, true); |
+ ui::PAGE_TRANSITION_GENERATED, 5, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
@@ -186,41 +211,41 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); |
AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); |
RunBannerTest("/banners/manifest_test_page.html", |
- ui::PAGE_TRANSITION_GENERATED, 1, true); |
+ ui::PAGE_TRANSITION_GENERATED, 1, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerCreatedIndirect) { |
RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 1, |
- true); |
+ SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerCreatedIndirectLargerTotal) { |
AppBannerSettingsHelper::SetTotalEngagementToTrigger(5); |
RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 4, |
- true); |
+ SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerCreatedIndirectSmallerTotal) { |
AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); |
RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 0, |
- true); |
+ SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerCreatedIndirectSingle) { |
AppBannerSettingsHelper::SetEngagementWeights(1, 3); |
RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_RELOAD, |
- 0, true); |
+ 0, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerCreatedIndirectMultiple) { |
AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); |
RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 3, |
- true); |
+ SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
@@ -228,7 +253,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); |
AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); |
RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 7, |
- true); |
+ SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
@@ -249,6 +274,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
ui_test_utils::NavigateToURL(browser(), test_url); |
RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
run_loop, ui::PAGE_TRANSITION_TYPED, false); |
+ CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 1, 1); |
+ EXPECT_FALSE(manager->need_to_log_status()); |
} |
// Add an indirect nav on day 1 which is ignored. |
@@ -257,6 +284,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
ui_test_utils::NavigateToURL(browser(), test_url); |
RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
run_loop, ui::PAGE_TRANSITION_LINK, false); |
+ CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 2, 2); |
+ EXPECT_FALSE(manager->need_to_log_status()); |
AppBannerManager::SetTimeDeltaForTesting(1); |
} |
@@ -266,6 +295,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
ui_test_utils::NavigateToURL(browser(), test_url); |
RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
run_loop, ui::PAGE_TRANSITION_MANUAL_SUBFRAME, false); |
+ CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 3, 3); |
+ EXPECT_FALSE(manager->need_to_log_status()); |
} |
// Add a direct nav on day 2 which overrides. |
@@ -274,6 +305,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
ui_test_utils::NavigateToURL(browser(), test_url); |
RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
run_loop, ui::PAGE_TRANSITION_GENERATED, false); |
+ CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 4, 4); |
+ EXPECT_FALSE(manager->need_to_log_status()); |
AppBannerManager::SetTimeDeltaForTesting(2); |
} |
@@ -283,6 +316,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
ui_test_utils::NavigateToURL(browser(), test_url); |
RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
run_loop, ui::PAGE_TRANSITION_GENERATED, false); |
+ CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 5, 5); |
+ EXPECT_FALSE(manager->need_to_log_status()); |
AppBannerManager::SetTimeDeltaForTesting(3); |
} |
@@ -292,62 +327,67 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
ui_test_utils::NavigateToURL(browser(), test_url); |
RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
run_loop, ui::PAGE_TRANSITION_FORM_SUBMIT, false); |
+ EXPECT_FALSE(manager->need_to_log_status()); |
+ CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 6, 6); |
} |
+ |
// Add a direct nav on day 4 which should trigger the banner. |
{ |
base::RunLoop run_loop; |
ui_test_utils::NavigateToURL(browser(), test_url); |
RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
run_loop, ui::PAGE_TRANSITION_TYPED, true); |
+ EXPECT_FALSE(manager->need_to_log_status()); |
+ CheckInstallableStatusCodeHistogram(SHOWING_WEB_APP_BANNER, 1, 7); |
} |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerNoTypeInManifest) { |
RunBannerTest("/banners/manifest_no_type_test_page.html", |
- ui::PAGE_TRANSITION_TYPED, 1, true); |
+ ui::PAGE_TRANSITION_TYPED, 1, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
WebAppBannerNoTypeInManifestCapsExtension) { |
RunBannerTest("/banners/manifest_no_type_caps_test_page.html", |
- ui::PAGE_TRANSITION_TYPED, 1, true); |
+ ui::PAGE_TRANSITION_TYPED, 1, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) { |
RunBannerTest("/banners/no_manifest_test_page.html", |
- ui::PAGE_TRANSITION_TYPED, 1, false); |
+ ui::PAGE_TRANSITION_TYPED, 0, NO_MANIFEST, false); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) { |
- RunBannerTest("/banners/manifest_bad_link.html", ui::PAGE_TRANSITION_TYPED, 1, |
- false); |
+ RunBannerTest("/banners/manifest_bad_link.html", ui::PAGE_TRANSITION_TYPED, 0, |
+ MANIFEST_EMPTY, false); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) { |
RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, |
- false); |
+ RENDERER_CANCELLED, false); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerIndirect) { |
AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); |
- RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 3, |
- false); |
+ RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_LINK, 3, |
+ RENDERER_CANCELLED, false); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBanner) { |
RunBannerTest("/banners/prompt_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, |
- true); |
+ SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBannerInHandler) { |
RunBannerTest("/banners/prompt_in_handler_test_page.html", |
- ui::PAGE_TRANSITION_TYPED, 1, true); |
+ ui::PAGE_TRANSITION_TYPED, 1, SHOWING_WEB_APP_BANNER, true); |
} |
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) { |
- RunBannerTest("/banners/iframe_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, |
- false); |
+ RunBannerTest("/banners/iframe_test_page.html", ui::PAGE_TRANSITION_TYPED, 0, |
+ NO_MANIFEST, false); |
} |
} // namespace banners |