Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(738)

Side by Side Diff: chrome/browser/banners/app_banner_manager_browsertest.cc

Issue 2944283002: Replace --add-to-shelf flag with kAppBanners feature. (Closed)
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/banners/app_banner_manager_desktop.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 DISALLOW_COPY_AND_ASSIGN(AppBannerManagerTest); 109 DISALLOW_COPY_AND_ASSIGN(AppBannerManagerTest);
110 }; 110 };
111 111
112 class AppBannerManagerBrowserTest : public InProcessBrowserTest { 112 class AppBannerManagerBrowserTest : public InProcessBrowserTest {
113 public: 113 public:
114 void SetUpOnMainThread() override { 114 void SetUpOnMainThread() override {
115 AppBannerSettingsHelper::SetTotalEngagementToTrigger(10); 115 AppBannerSettingsHelper::SetTotalEngagementToTrigger(10);
116 SiteEngagementScore::SetParamValuesForTesting(); 116 SiteEngagementScore::SetParamValuesForTesting();
117 ASSERT_TRUE(embedded_test_server()->Start()); 117 ASSERT_TRUE(embedded_test_server()->Start());
118 }
119 118
120 void SetUpCommandLine(base::CommandLine* command_line) override {
121 // Make sure app banners are disabled in the browser, otherwise they will 119 // Make sure app banners are disabled in the browser, otherwise they will
122 // interfere with the test. 120 // interfere with the test.
123 command_line->AppendSwitch(switches::kDisableAddToShelf); 121 feature_list_.InitAndDisableFeature(features::kAppBanners);
122 InProcessBrowserTest::SetUpOnMainThread();
124 } 123 }
125 124
126 protected: 125 protected:
127 // Returns a test server URL to page |page_url| with |manifest_url| injected 126 // Returns a test server URL to page |page_url| with |manifest_url| injected
128 // as the manifest tag. 127 // as the manifest tag.
129 std::string GetURLOfPageWithManifest(const std::string& page_url, 128 std::string GetURLOfPageWithManifest(const std::string& page_url,
130 const std::string& manifest_url) { 129 const std::string& manifest_url) {
131 return page_url + embedded_test_server()->GetURL(manifest_url).spec(); 130 return page_url + embedded_test_server()->GetURL(manifest_url).spec();
132 } 131 }
133 132
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); 217 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
219 histograms.ExpectTotalCount(banners::kInstallableStatusCodeHistogram, 0); 218 histograms.ExpectTotalCount(banners::kInstallableStatusCodeHistogram, 0);
220 } else { 219 } else {
221 histograms.ExpectTotalCount(banners::kMinutesHistogram, 220 histograms.ExpectTotalCount(banners::kMinutesHistogram,
222 (manager->will_show() ? 1 : 0)); 221 (manager->will_show() ? 1 : 0));
223 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, 222 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
224 expected_code_for_histogram, 1); 223 expected_code_for_histogram, 1);
225 EXPECT_FALSE(manager->need_to_log_status()); 224 EXPECT_FALSE(manager->need_to_log_status());
226 } 225 }
227 } 226 }
227
228 base::test::ScopedFeatureList feature_list_;
228 }; 229 };
229 230
230 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreated) { 231 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreated) {
231 std::unique_ptr<AppBannerManagerTest> manager( 232 std::unique_ptr<AppBannerManagerTest> manager(
232 CreateAppBannerManager(browser())); 233 CreateAppBannerManager(browser()));
233 std::vector<double> engagement_scores{0, 10}; 234 std::vector<double> engagement_scores{0, 10};
234 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", 235 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
235 engagement_scores, SHOWING_WEB_APP_BANNER, true); 236 engagement_scores, SHOWING_WEB_APP_BANNER, true);
236 } 237 }
237 238
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 CreateAppBannerManager(incognito_browser)); 392 CreateAppBannerManager(incognito_browser));
392 std::vector<double> engagement_scores{10}; 393 std::vector<double> engagement_scores{10};
393 RunBannerTest(incognito_browser, manager.get(), 394 RunBannerTest(incognito_browser, manager.get(),
394 "/banners/manifest_test_page.html", engagement_scores, 395 "/banners/manifest_test_page.html", engagement_scores,
395 IN_INCOGNITO, false); 396 IN_INCOGNITO, false);
396 } 397 }
397 398
398 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, 399 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
399 CheckOnLoadWithSufficientEngagement) { 400 CheckOnLoadWithSufficientEngagement) {
400 base::test::ScopedFeatureList feature_list; 401 base::test::ScopedFeatureList feature_list;
401 feature_list.InitAndEnableFeature( 402 feature_list.InitWithFeatures({features::kCheckInstallabilityForBannerOnLoad},
402 features::kCheckInstallabilityForBannerOnLoad); 403 {features::kAppBanners});
403 std::unique_ptr<AppBannerManagerTest> manager( 404 std::unique_ptr<AppBannerManagerTest> manager(
404 CreateAppBannerManager(browser())); 405 CreateAppBannerManager(browser()));
405 std::vector<double> engagement_scores{10}; 406 std::vector<double> engagement_scores{10};
406 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", 407 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
407 engagement_scores, SHOWING_WEB_APP_BANNER, true); 408 engagement_scores, SHOWING_WEB_APP_BANNER, true);
408 } 409 }
409 410
410 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, 411 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
411 CheckOnLoadWithSufficientEngagementCancelDirect) { 412 CheckOnLoadWithSufficientEngagementCancelDirect) {
412 base::test::ScopedFeatureList feature_list; 413 base::test::ScopedFeatureList feature_list;
413 feature_list.InitAndEnableFeature( 414 feature_list.InitWithFeatures({features::kCheckInstallabilityForBannerOnLoad},
414 features::kCheckInstallabilityForBannerOnLoad); 415 {features::kAppBanners});
415 std::unique_ptr<AppBannerManagerTest> manager( 416 std::unique_ptr<AppBannerManagerTest> manager(
416 CreateAppBannerManager(browser())); 417 CreateAppBannerManager(browser()));
417 std::vector<double> engagement_scores{10}; 418 std::vector<double> engagement_scores{10};
418 RunBannerTest(browser(), manager.get(), "/banners/cancel_test_page.html", 419 RunBannerTest(browser(), manager.get(), "/banners/cancel_test_page.html",
419 engagement_scores, RENDERER_CANCELLED, false); 420 engagement_scores, RENDERER_CANCELLED, false);
420 } 421 }
421 422
422 IN_PROC_BROWSER_TEST_F( 423 IN_PROC_BROWSER_TEST_F(
423 AppBannerManagerBrowserTest, 424 AppBannerManagerBrowserTest,
424 CheckOnLoadWithSufficientEngagementCancelBannerAfterPromptInHandler) { 425 CheckOnLoadWithSufficientEngagementCancelBannerAfterPromptInHandler) {
425 base::test::ScopedFeatureList feature_list; 426 base::test::ScopedFeatureList feature_list;
426 feature_list.InitAndEnableFeature( 427 feature_list.InitWithFeatures({features::kCheckInstallabilityForBannerOnLoad},
427 features::kCheckInstallabilityForBannerOnLoad); 428 {features::kAppBanners});
428 std::unique_ptr<AppBannerManagerTest> manager( 429 std::unique_ptr<AppBannerManagerTest> manager(
429 CreateAppBannerManager(browser())); 430 CreateAppBannerManager(browser()));
430 std::vector<double> engagement_scores{10}; 431 std::vector<double> engagement_scores{10};
431 RunBannerTest(browser(), manager.get(), 432 RunBannerTest(browser(), manager.get(),
432 "/banners/prompt_in_handler_test_page.html", engagement_scores, 433 "/banners/prompt_in_handler_test_page.html", engagement_scores,
433 SHOWING_WEB_APP_BANNER, true); 434 SHOWING_WEB_APP_BANNER, true);
434 std::string cancel_test_page_url = 435 std::string cancel_test_page_url =
435 GetURLOfPageWithManifest("/banners/cancel_test_page.html?manifest=", 436 GetURLOfPageWithManifest("/banners/cancel_test_page.html?manifest=",
436 "/banners/manifest_different_start_url.json"); 437 "/banners/manifest_different_start_url.json");
437 RunBannerTest(browser(), manager.get(), cancel_test_page_url, 438 RunBannerTest(browser(), manager.get(), cancel_test_page_url,
438 engagement_scores, RENDERER_CANCELLED, false); 439 engagement_scores, RENDERER_CANCELLED, false);
439 } 440 }
440 441
441 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, 442 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
442 CheckOnLoadWithoutSufficientEngagement) { 443 CheckOnLoadWithoutSufficientEngagement) {
443 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); 444 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1);
444 SiteEngagementService* service = 445 SiteEngagementService* service =
445 SiteEngagementService::Get(browser()->profile()); 446 SiteEngagementService::Get(browser()->profile());
446 base::test::ScopedFeatureList feature_list; 447 base::test::ScopedFeatureList feature_list;
447 feature_list.InitAndEnableFeature( 448 feature_list.InitWithFeatures({features::kCheckInstallabilityForBannerOnLoad},
448 features::kCheckInstallabilityForBannerOnLoad); 449 {features::kAppBanners});
449 std::unique_ptr<AppBannerManagerTest> manager( 450 std::unique_ptr<AppBannerManagerTest> manager(
450 CreateAppBannerManager(browser())); 451 CreateAppBannerManager(browser()));
451 452
452 base::HistogramTester histograms; 453 base::HistogramTester histograms;
453 GURL test_url = 454 GURL test_url =
454 embedded_test_server()->GetURL("/banners/manifest_test_page.html"); 455 embedded_test_server()->GetURL("/banners/manifest_test_page.html");
455 service->ResetBaseScoreForURL(test_url, 0); 456 service->ResetBaseScoreForURL(test_url, 0);
456 457
457 // First run through: expect the manager to end up stopped in the pending 458 // First run through: expect the manager to end up stopped in the pending
458 // state, without showing a banner. 459 // state, without showing a banner.
(...skipping 26 matching lines...) Expand all
485 EXPECT_FALSE(manager->need_to_log_status()); 486 EXPECT_FALSE(manager->need_to_log_status());
486 EXPECT_TRUE(manager->is_complete()); 487 EXPECT_TRUE(manager->is_complete());
487 488
488 histograms.ExpectTotalCount(banners::kMinutesHistogram, 1); 489 histograms.ExpectTotalCount(banners::kMinutesHistogram, 1);
489 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, 490 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
490 SHOWING_WEB_APP_BANNER, 1); 491 SHOWING_WEB_APP_BANNER, 1);
491 } 492 }
492 493
493 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CheckOnLoadThenNavigate) { 494 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CheckOnLoadThenNavigate) {
494 base::test::ScopedFeatureList feature_list; 495 base::test::ScopedFeatureList feature_list;
495 feature_list.InitAndEnableFeature( 496 feature_list.InitWithFeatures({features::kCheckInstallabilityForBannerOnLoad},
496 features::kCheckInstallabilityForBannerOnLoad); 497 {features::kAppBanners});
497 std::unique_ptr<AppBannerManagerTest> manager( 498 std::unique_ptr<AppBannerManagerTest> manager(
498 CreateAppBannerManager(browser())); 499 CreateAppBannerManager(browser()));
499 500
500 base::HistogramTester histograms; 501 base::HistogramTester histograms;
501 GURL test_url = 502 GURL test_url =
502 embedded_test_server()->GetURL("/banners/manifest_test_page.html"); 503 embedded_test_server()->GetURL("/banners/manifest_test_page.html");
503 504
504 // First run through: expect the manager to end up stopped in the pending 505 // First run through: expect the manager to end up stopped in the pending
505 // state, without showing a banner. 506 // state, without showing a banner.
506 { 507 {
(...skipping 20 matching lines...) Expand all
527 EXPECT_FALSE(manager->will_show()); 528 EXPECT_FALSE(manager->will_show());
528 EXPECT_FALSE(manager->is_active_or_pending()); 529 EXPECT_FALSE(manager->is_active_or_pending());
529 EXPECT_FALSE(manager->need_to_log_status()); 530 EXPECT_FALSE(manager->need_to_log_status());
530 531
531 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); 532 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
532 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, 533 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
533 INSUFFICIENT_ENGAGEMENT, 1); 534 INSUFFICIENT_ENGAGEMENT, 1);
534 } 535 }
535 536
536 } // namespace banners 537 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/banners/app_banner_manager_desktop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698