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

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: Remove is_active_or_pending 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
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // pipeline to trigger on the last one; otherwise, nothing is expected to 173 // pipeline to trigger on the last one; otherwise, nothing is expected to
176 // happen. 174 // happen.
177 int iterations = 0; 175 int iterations = 0;
178 SiteEngagementService* service = 176 SiteEngagementService* service =
179 SiteEngagementService::Get(browser->profile()); 177 SiteEngagementService::Get(browser->profile());
180 for (double engagement : engagement_scores) { 178 for (double engagement : engagement_scores) {
181 if (iterations > 0) { 179 if (iterations > 0) {
182 ui_test_utils::NavigateToURL(browser, test_url); 180 ui_test_utils::NavigateToURL(browser, test_url);
183 181
184 EXPECT_FALSE(manager->will_show()); 182 EXPECT_FALSE(manager->will_show());
185 EXPECT_FALSE(manager->is_active_or_pending()); 183 EXPECT_TRUE(manager->is_inactive());
186 184
187 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0); 185 histograms.ExpectTotalCount(banners::kMinutesHistogram, 0);
188 histograms.ExpectTotalCount(banners::kInstallableStatusCodeHistogram, 186 histograms.ExpectTotalCount(banners::kInstallableStatusCodeHistogram,
189 0); 187 0);
190 } 188 }
191 service->ResetBaseScoreForURL(test_url, engagement); 189 service->ResetBaseScoreForURL(test_url, engagement);
192 ++iterations; 190 ++iterations;
193 } 191 }
194 192
195 // On the final loop, we expect the banner pipeline to trigger - the 193 // On the final loop, we expect the banner pipeline to trigger - the
196 // navigation should generate the final engagement to show the banner. Spin 194 // navigation should generate the final engagement to show the banner. Spin
197 // the run loop and wait for the manager to finish. 195 // the run loop and wait for the manager to finish.
198 base::RunLoop run_loop; 196 base::RunLoop run_loop;
199 manager->clear_will_show(); 197 manager->clear_will_show();
200 manager->Prepare(run_loop.QuitClosure()); 198 manager->Prepare(run_loop.QuitClosure());
201 chrome::NavigateParams nav_params(browser, test_url, transition); 199 chrome::NavigateParams nav_params(browser, test_url, transition);
202 ui_test_utils::NavigateToURL(&nav_params); 200 ui_test_utils::NavigateToURL(&nav_params);
203 run_loop.Run(); 201 run_loop.Run();
204 202
205 EXPECT_EQ(expected_to_show, manager->will_show()); 203 EXPECT_EQ(expected_to_show, manager->will_show());
206 EXPECT_FALSE(manager->is_active_or_pending()); 204
205 // Generally the manager will be in the complete state, however some test
206 // cases navigate the page, causing the state to go back to INACTIVE.
207 EXPECT_TRUE(manager->is_complete() || manager->is_inactive());
207 208
208 // Check the tab title; this allows the test page to send data back out to 209 // Check the tab title; this allows the test page to send data back out to
209 // be inspected by the test case. 210 // be inspected by the test case.
210 if (!expected_tab_title.empty()) { 211 if (!expected_tab_title.empty()) {
211 base::string16 title; 212 base::string16 title;
212 EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser, &title)); 213 EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser, &title));
213 EXPECT_EQ(expected_tab_title, title); 214 EXPECT_EQ(expected_tab_title, title);
214 } 215 }
215 216
216 // If in incognito, ensure that nothing is recorded. 217 // If in incognito, ensure that nothing is recorded.
(...skipping 258 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());
benwells 2017/06/27 22:55:58 not necessary as is_complete is checked two lines
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
« chrome/browser/banners/app_banner_manager.cc ('K') | « 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