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

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

Issue 2957523003: Start banner pipeline immediately after navigating, if enough engagement (Closed)
Patch Set: Simpler per Dom's suggestion Created 3 years, 6 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/banners/app_banner_manager.cc ('k') | no next file » | 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 if (validated_url == GURL("about:blank")) 47 if (validated_url == GURL("about:blank"))
48 return; 48 return;
49 49
50 AppBannerManager::RequestAppBanner(validated_url, is_debug_mode); 50 AppBannerManager::RequestAppBanner(validated_url, is_debug_mode);
51 } 51 }
52 52
53 bool will_show() { return will_show_.get() && *will_show_; } 53 bool will_show() { return will_show_.get() && *will_show_; }
54 54
55 void clear_will_show() { will_show_.reset(); } 55 void clear_will_show() { will_show_.reset(); }
56 56
57 bool is_active() { return AppBannerManager::is_active(); } 57 bool is_active_or_pending() {
58 return AppBannerManager::is_active_or_pending();
59 }
58 60
59 bool is_complete() { return AppBannerManager::is_complete(); } 61 bool is_complete() { return AppBannerManager::is_complete(); }
60 62
61 bool is_pending_engagement() { 63 bool is_pending_engagement() {
62 return AppBannerManager::is_pending_engagement(); 64 return AppBannerManager::is_pending_engagement();
63 } 65 }
64 66
65 bool need_to_log_status() { return need_to_log_status_; } 67 bool need_to_log_status() { return need_to_log_status_; }
66 68
67 void Prepare(base::Closure quit_closure) { 69 void Prepare(base::Closure quit_closure) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 148 }
147 149
148 void RunBannerTest(Browser* browser, 150 void RunBannerTest(Browser* browser,
149 AppBannerManagerTest* manager, 151 AppBannerManagerTest* manager,
150 const std::string& url, 152 const std::string& url,
151 const std::vector<double>& engagement_scores, 153 const std::vector<double>& engagement_scores,
152 InstallableStatusCode expected_code_for_histogram, 154 InstallableStatusCode expected_code_for_histogram,
153 bool expected_to_show) { 155 bool expected_to_show) {
154 RunBannerTest(browser, manager, url, engagement_scores, 156 RunBannerTest(browser, manager, url, engagement_scores,
155 expected_code_for_histogram, expected_to_show, 157 expected_code_for_histogram, expected_to_show,
156 base::string16()); 158 base::string16(), ui::PAGE_TRANSITION_TYPED);
157 } 159 }
158 160
159 void RunBannerTest(Browser* browser, 161 void RunBannerTest(Browser* browser,
160 AppBannerManagerTest* manager, 162 AppBannerManagerTest* manager,
161 const std::string& url, 163 const std::string& url,
162 const std::vector<double>& engagement_scores, 164 const std::vector<double>& engagement_scores,
163 InstallableStatusCode expected_code_for_histogram, 165 InstallableStatusCode expected_code_for_histogram,
164 bool expected_to_show, 166 bool expected_to_show,
165 const base::string16 expected_tab_title) { 167 const base::string16 expected_tab_title,
168 ui::PageTransition transition) {
166 base::HistogramTester histograms; 169 base::HistogramTester histograms;
167 GURL test_url = embedded_test_server()->GetURL(url); 170 GURL test_url = embedded_test_server()->GetURL(url);
168 171
169 manager->clear_will_show(); 172 manager->clear_will_show();
170 173
171 // Loop through the vector of engagement scores. We only expect the banner 174 // Loop through the vector of engagement scores. We only expect the banner
172 // pipeline to trigger on the last one; otherwise, nothing is expected to 175 // pipeline to trigger on the last one; otherwise, nothing is expected to
173 // happen. 176 // happen.
174 int iterations = 0; 177 int iterations = 0;
175 SiteEngagementService* service = 178 SiteEngagementService* service =
176 SiteEngagementService::Get(browser->profile()); 179 SiteEngagementService::Get(browser->profile());
177 for (double engagement : engagement_scores) { 180 for (double engagement : engagement_scores) {
178 if (iterations > 0) { 181 if (iterations > 0) {
179 ui_test_utils::NavigateToURL(browser, test_url); 182 ui_test_utils::NavigateToURL(browser, test_url);
180 183
181 EXPECT_FALSE(manager->will_show()); 184 EXPECT_FALSE(manager->will_show());
182 EXPECT_FALSE(manager->is_active()); 185 EXPECT_FALSE(manager->is_active_or_pending());
183 186
184 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); 187 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
185 histograms.ExpectTotalCount(banners::kInstallableStatusCodeHistogram, 188 histograms.ExpectTotalCount(banners::kInstallableStatusCodeHistogram,
186 0); 189 0);
187 } 190 }
188 service->ResetBaseScoreForURL(test_url, engagement); 191 service->ResetBaseScoreForURL(test_url, engagement);
189 ++iterations; 192 ++iterations;
190 } 193 }
191 194
192 // On the final loop, we expect the banner pipeline to trigger - the 195 // On the final loop, we expect the banner pipeline to trigger - the
193 // navigation should generate the final engagement to show the banner. Spin 196 // navigation should generate the final engagement to show the banner. Spin
194 // the run loop and wait for the manager to finish. 197 // the run loop and wait for the manager to finish.
195 base::RunLoop run_loop; 198 base::RunLoop run_loop;
196 manager->clear_will_show(); 199 manager->clear_will_show();
197 manager->Prepare(run_loop.QuitClosure()); 200 manager->Prepare(run_loop.QuitClosure());
198 ui_test_utils::NavigateToURL(browser, test_url); 201 chrome::NavigateParams nav_params(browser, test_url, transition);
202 ui_test_utils::NavigateToURL(&nav_params);
199 run_loop.Run(); 203 run_loop.Run();
200 204
201 EXPECT_EQ(expected_to_show, manager->will_show()); 205 EXPECT_EQ(expected_to_show, manager->will_show());
202 EXPECT_FALSE(manager->is_active()); 206 EXPECT_FALSE(manager->is_active_or_pending());
203 207
204 // Check the tab title; this allows the test page to send data back out to 208 // Check the tab title; this allows the test page to send data back out to
205 // be inspected by the test case. 209 // be inspected by the test case.
206 if (!expected_tab_title.empty()) { 210 if (!expected_tab_title.empty()) {
207 base::string16 title; 211 base::string16 title;
208 EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser, &title)); 212 EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser, &title));
209 EXPECT_EQ(expected_tab_title, title); 213 EXPECT_EQ(expected_tab_title, title);
210 } 214 }
211 215
212 // If in incognito, ensure that nothing is recorded. 216 // If in incognito, ensure that nothing is recorded.
(...skipping 18 matching lines...) Expand all
231 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", 235 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
232 engagement_scores, SHOWING_WEB_APP_BANNER, true); 236 engagement_scores, SHOWING_WEB_APP_BANNER, true);
233 } 237 }
234 238
235 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, 239 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
236 WebAppBannerCreatedImmediately) { 240 WebAppBannerCreatedImmediately) {
237 std::unique_ptr<AppBannerManagerTest> manager( 241 std::unique_ptr<AppBannerManagerTest> manager(
238 CreateAppBannerManager(browser())); 242 CreateAppBannerManager(browser()));
239 std::vector<double> engagement_scores{10}; 243 std::vector<double> engagement_scores{10};
240 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", 244 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
241 engagement_scores, SHOWING_WEB_APP_BANNER, true); 245 engagement_scores, SHOWING_WEB_APP_BANNER, true,
246 base::string16(), ui::PAGE_TRANSITION_LINK);
242 } 247 }
243 248
244 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, 249 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
245 WebAppBannerCreatedAfterSeveralVisits) { 250 WebAppBannerCreatedAfterSeveralVisits) {
246 std::unique_ptr<AppBannerManagerTest> manager( 251 std::unique_ptr<AppBannerManagerTest> manager(
247 CreateAppBannerManager(browser())); 252 CreateAppBannerManager(browser()));
248 std::vector<double> engagement_scores{0, 1, 2, 3, 4, 5, 10}; 253 std::vector<double> engagement_scores{0, 1, 2, 3, 4, 5, 10};
249 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html", 254 RunBannerTest(browser(), manager.get(), "/banners/manifest_test_page.html",
250 engagement_scores, SHOWING_WEB_APP_BANNER, true); 255 engagement_scores, SHOWING_WEB_APP_BANNER, true);
251 } 256 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 std::unique_ptr<AppBannerManagerTest> manager( 326 std::unique_ptr<AppBannerManagerTest> manager(
322 CreateAppBannerManager(browser())); 327 CreateAppBannerManager(browser()));
323 std::vector<double> engagement_scores{0, 5, 10}; 328 std::vector<double> engagement_scores{0, 5, 10};
324 329
325 // Expect that the page sets the tab title to indicate that it got the event 330 // Expect that the page sets the tab title to indicate that it got the event
326 // twice: once for addEventListener('beforeinstallprompt'), and once for the 331 // twice: once for addEventListener('beforeinstallprompt'), and once for the
327 // onbeforeinstallprompt attribute. 332 // onbeforeinstallprompt attribute.
328 RunBannerTest(browser(), manager.get(), 333 RunBannerTest(browser(), manager.get(),
329 "/banners/beforeinstallprompt_test_page.html", 334 "/banners/beforeinstallprompt_test_page.html",
330 engagement_scores, SHOWING_WEB_APP_BANNER, true, 335 engagement_scores, SHOWING_WEB_APP_BANNER, true,
331 base::ASCIIToUTF16("Got beforeinstallprompt: listener, attr")); 336 base::ASCIIToUTF16("Got beforeinstallprompt: listener, attr"),
337 ui::PAGE_TRANSITION_TYPED);
332 } 338 }
333 339
334 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) { 340 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) {
335 std::unique_ptr<AppBannerManagerTest> manager( 341 std::unique_ptr<AppBannerManagerTest> manager(
336 CreateAppBannerManager(browser())); 342 CreateAppBannerManager(browser()));
337 std::vector<double> engagement_scores{10}; 343 std::vector<double> engagement_scores{10};
338 RunBannerTest(browser(), manager.get(), "/banners/cancel_test_page.html", 344 RunBannerTest(browser(), manager.get(), "/banners/cancel_test_page.html",
339 engagement_scores, RENDERER_CANCELLED, false); 345 engagement_scores, RENDERER_CANCELLED, false);
340 } 346 }
341 347
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 // state, without showing a banner. 459 // state, without showing a banner.
454 { 460 {
455 base::RunLoop run_loop; 461 base::RunLoop run_loop;
456 manager->clear_will_show(); 462 manager->clear_will_show();
457 manager->Prepare(run_loop.QuitClosure()); 463 manager->Prepare(run_loop.QuitClosure());
458 ui_test_utils::NavigateToURL(browser(), test_url); 464 ui_test_utils::NavigateToURL(browser(), test_url);
459 run_loop.Run(); 465 run_loop.Run();
460 } 466 }
461 467
462 EXPECT_FALSE(manager->will_show()); 468 EXPECT_FALSE(manager->will_show());
463 EXPECT_FALSE(manager->is_active());
464 EXPECT_TRUE(manager->is_pending_engagement()); 469 EXPECT_TRUE(manager->is_pending_engagement());
465 EXPECT_TRUE(manager->need_to_log_status()); 470 EXPECT_TRUE(manager->need_to_log_status());
466 471
467 // Trigger an engagement increase that signals observers and expect the banner 472 // Trigger an engagement increase that signals observers and expect the banner
468 // to be shown. 473 // to be shown.
469 { 474 {
470 base::RunLoop run_loop; 475 base::RunLoop run_loop;
471 manager->clear_will_show(); 476 manager->clear_will_show();
472 manager->Prepare(run_loop.QuitClosure()); 477 manager->Prepare(run_loop.QuitClosure());
473 service->HandleNavigation( 478 service->HandleNavigation(
474 browser()->tab_strip_model()->GetActiveWebContents(), 479 browser()->tab_strip_model()->GetActiveWebContents(),
475 ui::PageTransition::PAGE_TRANSITION_TYPED); 480 ui::PageTransition::PAGE_TRANSITION_TYPED);
476 run_loop.Run(); 481 run_loop.Run();
477 } 482 }
478 483
479 EXPECT_TRUE(manager->will_show()); 484 EXPECT_TRUE(manager->will_show());
480 EXPECT_FALSE(manager->is_active()); 485 EXPECT_FALSE(manager->is_active_or_pending());
481 EXPECT_FALSE(manager->need_to_log_status()); 486 EXPECT_FALSE(manager->need_to_log_status());
482 EXPECT_TRUE(manager->is_complete()); 487 EXPECT_TRUE(manager->is_complete());
483 488
484 histograms.ExpectTotalCount(banners::kMinutesHistogram, 1); 489 histograms.ExpectTotalCount(banners::kMinutesHistogram, 1);
485 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, 490 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
486 SHOWING_WEB_APP_BANNER, 1); 491 SHOWING_WEB_APP_BANNER, 1);
487 } 492 }
488 493
489 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CheckOnLoadThenNavigate) { 494 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CheckOnLoadThenNavigate) {
490 base::test::ScopedFeatureList feature_list; 495 base::test::ScopedFeatureList feature_list;
(...skipping 10 matching lines...) Expand all
501 // state, without showing a banner. 506 // state, without showing a banner.
502 { 507 {
503 base::RunLoop run_loop; 508 base::RunLoop run_loop;
504 manager->clear_will_show(); 509 manager->clear_will_show();
505 manager->Prepare(run_loop.QuitClosure()); 510 manager->Prepare(run_loop.QuitClosure());
506 ui_test_utils::NavigateToURL(browser(), test_url); 511 ui_test_utils::NavigateToURL(browser(), test_url);
507 run_loop.Run(); 512 run_loop.Run();
508 } 513 }
509 514
510 EXPECT_FALSE(manager->will_show()); 515 EXPECT_FALSE(manager->will_show());
511 EXPECT_FALSE(manager->is_active());
512 EXPECT_TRUE(manager->is_pending_engagement()); 516 EXPECT_TRUE(manager->is_pending_engagement());
513 EXPECT_TRUE(manager->need_to_log_status()); 517 EXPECT_TRUE(manager->need_to_log_status());
514 518
515 // Navigate and expect Stop() to be called. 519 // Navigate and expect Stop() to be called.
516 { 520 {
517 base::RunLoop run_loop; 521 base::RunLoop run_loop;
518 manager->clear_will_show(); 522 manager->clear_will_show();
519 manager->Prepare(run_loop.QuitClosure()); 523 manager->Prepare(run_loop.QuitClosure());
520 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 524 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
521 run_loop.Run(); 525 run_loop.Run();
522 } 526 }
523 527
524 EXPECT_FALSE(manager->will_show()); 528 EXPECT_FALSE(manager->will_show());
525 EXPECT_FALSE(manager->is_active()); 529 EXPECT_FALSE(manager->is_active_or_pending());
526 EXPECT_FALSE(manager->need_to_log_status()); 530 EXPECT_FALSE(manager->need_to_log_status());
527 531
528 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); 532 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
529 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, 533 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
530 INSUFFICIENT_ENGAGEMENT, 1); 534 INSUFFICIENT_ENGAGEMENT, 1);
531 } 535 }
532 536
533 } // namespace banners 537 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698