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

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

Issue 2957063002: Update app banner state machine to use more states. (Closed)
Patch Set: Feedback 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/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_or_pending() { 57 bool is_inactive() { return AppBannerManager::is_inactive(); }
58 return AppBannerManager::is_active_or_pending();
59 }
60 58
61 bool is_complete() { return AppBannerManager::is_complete(); } 59 bool is_complete() { return AppBannerManager::is_complete(); }
62 60
63 bool is_pending_engagement() { 61 bool is_pending_engagement() {
64 return AppBannerManager::is_pending_engagement(); 62 return AppBannerManager::is_pending_engagement();
65 } 63 }
66 64
67 bool need_to_log_status() { return need_to_log_status_; } 65 bool need_to_log_status() { return need_to_log_status_; }
68 66
69 void Prepare(base::Closure quit_closure) { 67 void Prepare(base::Closure quit_closure) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // pipeline to trigger on the last one; otherwise, nothing is expected to 171 // pipeline to trigger on the last one; otherwise, nothing is expected to
174 // happen. 172 // happen.
175 int iterations = 0; 173 int iterations = 0;
176 SiteEngagementService* service = 174 SiteEngagementService* service =
177 SiteEngagementService::Get(browser->profile()); 175 SiteEngagementService::Get(browser->profile());
178 for (double engagement : engagement_scores) { 176 for (double engagement : engagement_scores) {
179 if (iterations > 0) { 177 if (iterations > 0) {
180 ui_test_utils::NavigateToURL(browser, test_url); 178 ui_test_utils::NavigateToURL(browser, test_url);
181 179
182 EXPECT_FALSE(manager->will_show()); 180 EXPECT_FALSE(manager->will_show());
183 EXPECT_FALSE(manager->is_active_or_pending()); 181 EXPECT_TRUE(manager->is_inactive());
184 182
185 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); 183 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
186 histograms.ExpectTotalCount(banners::kInstallableStatusCodeHistogram, 184 histograms.ExpectTotalCount(banners::kInstallableStatusCodeHistogram,
187 0); 185 0);
188 } 186 }
189 service->ResetBaseScoreForURL(test_url, engagement); 187 service->ResetBaseScoreForURL(test_url, engagement);
190 ++iterations; 188 ++iterations;
191 } 189 }
192 190
193 // On the final loop, we expect the banner pipeline to trigger - the 191 // On the final loop, we expect the banner pipeline to trigger - the
194 // navigation should generate the final engagement to show the banner. Spin 192 // navigation should generate the final engagement to show the banner. Spin
195 // the run loop and wait for the manager to finish. 193 // the run loop and wait for the manager to finish.
196 base::RunLoop run_loop; 194 base::RunLoop run_loop;
197 manager->clear_will_show(); 195 manager->clear_will_show();
198 manager->Prepare(run_loop.QuitClosure()); 196 manager->Prepare(run_loop.QuitClosure());
199 chrome::NavigateParams nav_params(browser, test_url, transition); 197 chrome::NavigateParams nav_params(browser, test_url, transition);
200 ui_test_utils::NavigateToURL(&nav_params); 198 ui_test_utils::NavigateToURL(&nav_params);
201 run_loop.Run(); 199 run_loop.Run();
202 200
203 EXPECT_EQ(expected_to_show, manager->will_show()); 201 EXPECT_EQ(expected_to_show, manager->will_show());
204 EXPECT_FALSE(manager->is_active_or_pending()); 202
203 // Generally the manager will be in the complete state, however some test
204 // cases navigate the page, causing the state to go back to INACTIVE.
205 EXPECT_TRUE(manager->is_complete() || manager->is_inactive());
205 206
206 // Check the tab title; this allows the test page to send data back out to 207 // Check the tab title; this allows the test page to send data back out to
207 // be inspected by the test case. 208 // be inspected by the test case.
208 if (!expected_tab_title.empty()) { 209 if (!expected_tab_title.empty()) {
209 base::string16 title; 210 base::string16 title;
210 EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser, &title)); 211 EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser, &title));
211 EXPECT_EQ(expected_tab_title, title); 212 EXPECT_EQ(expected_tab_title, title);
212 } 213 }
213 214
214 // If in incognito, ensure that nothing is recorded. 215 // If in incognito, ensure that nothing is recorded.
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 base::RunLoop run_loop; 476 base::RunLoop run_loop;
476 manager->clear_will_show(); 477 manager->clear_will_show();
477 manager->Prepare(run_loop.QuitClosure()); 478 manager->Prepare(run_loop.QuitClosure());
478 service->HandleNavigation( 479 service->HandleNavigation(
479 browser()->tab_strip_model()->GetActiveWebContents(), 480 browser()->tab_strip_model()->GetActiveWebContents(),
480 ui::PageTransition::PAGE_TRANSITION_TYPED); 481 ui::PageTransition::PAGE_TRANSITION_TYPED);
481 run_loop.Run(); 482 run_loop.Run();
482 } 483 }
483 484
484 EXPECT_TRUE(manager->will_show()); 485 EXPECT_TRUE(manager->will_show());
485 EXPECT_FALSE(manager->is_active_or_pending());
486 EXPECT_FALSE(manager->need_to_log_status()); 486 EXPECT_FALSE(manager->need_to_log_status());
487 EXPECT_TRUE(manager->is_complete()); 487 EXPECT_TRUE(manager->is_complete());
488 488
489 histograms.ExpectTotalCount(banners::kMinutesHistogram, 1); 489 histograms.ExpectTotalCount(banners::kMinutesHistogram, 1);
490 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, 490 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
491 SHOWING_WEB_APP_BANNER, 1); 491 SHOWING_WEB_APP_BANNER, 1);
492 } 492 }
493 493
494 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CheckOnLoadThenNavigate) { 494 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CheckOnLoadThenNavigate) {
495 base::test::ScopedFeatureList feature_list; 495 base::test::ScopedFeatureList feature_list;
(...skipping 23 matching lines...) Expand all
519 // Navigate and expect Stop() to be called. 519 // Navigate and expect Stop() to be called.
520 { 520 {
521 base::RunLoop run_loop; 521 base::RunLoop run_loop;
522 manager->clear_will_show(); 522 manager->clear_will_show();
523 manager->Prepare(run_loop.QuitClosure()); 523 manager->Prepare(run_loop.QuitClosure());
524 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 524 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
525 run_loop.Run(); 525 run_loop.Run();
526 } 526 }
527 527
528 EXPECT_FALSE(manager->will_show()); 528 EXPECT_FALSE(manager->will_show());
529 EXPECT_FALSE(manager->is_active_or_pending()); 529 EXPECT_TRUE(manager->is_inactive());
530 EXPECT_FALSE(manager->need_to_log_status()); 530 EXPECT_FALSE(manager->need_to_log_status());
531 531
532 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); 532 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
533 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram, 533 histograms.ExpectUniqueSample(banners::kInstallableStatusCodeHistogram,
534 INSUFFICIENT_ENGAGEMENT, 1); 534 INSUFFICIENT_ENGAGEMENT, 1);
535 } 535 }
536 536
537 } // 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