OLD | NEW |
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 "chrome/browser/banners/app_banner_manager.h" | 5 #include "chrome/browser/banners/app_banner_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/task_runner.h" | 10 #include "base/task_runner.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 using AppBannerManager::RequestAppBanner; | 45 using AppBannerManager::RequestAppBanner; |
46 void RequestAppBanner(const GURL& validated_url, | 46 void RequestAppBanner(const GURL& validated_url, |
47 bool is_debug_mode, | 47 bool is_debug_mode, |
48 base::Closure quit_closure) { | 48 base::Closure quit_closure) { |
49 will_show_.reset(nullptr); | 49 will_show_.reset(nullptr); |
50 quit_closure_ = quit_closure; | 50 quit_closure_ = quit_closure; |
51 AppBannerManager::RequestAppBanner(validated_url, is_debug_mode); | 51 AppBannerManager::RequestAppBanner(validated_url, is_debug_mode); |
52 } | 52 } |
53 | 53 |
| 54 bool need_to_log_status() { return need_to_log_status_; } |
| 55 |
54 protected: | 56 protected: |
55 void Stop() override { | 57 void Stop() override { |
56 AppBannerManager::Stop(); | 58 AppBannerManager::Stop(); |
57 ASSERT_FALSE(will_show_.get()); | 59 ASSERT_FALSE(will_show_.get()); |
58 will_show_.reset(new bool(false)); | 60 will_show_.reset(new bool(false)); |
59 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); | 61 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); |
60 } | 62 } |
61 | 63 |
62 void ShowBanner() override { | 64 void ShowBanner() override { |
| 65 // Fake the call to ReportStatus here - this is usually called in |
| 66 // platform-specific code which is not exposed here. |
| 67 ReportStatus(nullptr, SHOWING_WEB_APP_BANNER); |
63 ASSERT_FALSE(will_show_.get()); | 68 ASSERT_FALSE(will_show_.get()); |
64 will_show_.reset(new bool(true)); | 69 will_show_.reset(new bool(true)); |
65 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); | 70 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); |
66 } | 71 } |
67 | 72 |
68 void DidStartNavigation(content::NavigationHandle* handle) override { | 73 void DidStartNavigation(content::NavigationHandle* handle) override { |
69 // Do nothing to ensure we never observe the site engagement service. | 74 // Do nothing to ensure we never observe the site engagement service. |
70 } | 75 } |
71 | 76 |
72 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 77 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
73 const GURL& validated_url) override { | 78 const GURL& validated_url) override { |
74 // Do nothing else to ensure the banner pipeline doesn't start. | 79 // Do nothing else to ensure the banner pipeline doesn't start. |
75 validated_url_ = validated_url; | 80 validated_url_ = validated_url; |
76 } | 81 } |
77 | 82 |
78 private: | 83 private: |
| 84 bool IsDebugMode() const override { return false; } |
| 85 |
79 base::Closure quit_closure_; | 86 base::Closure quit_closure_; |
80 std::unique_ptr<bool> will_show_; | 87 std::unique_ptr<bool> will_show_; |
81 }; | 88 }; |
82 | 89 |
83 class AppBannerManagerBrowserTest : public InProcessBrowserTest { | 90 class AppBannerManagerBrowserTest : public InProcessBrowserTest { |
84 public: | 91 public: |
85 void SetUpOnMainThread() override { | 92 void SetUpOnMainThread() override { |
86 AppBannerSettingsHelper::SetEngagementWeights(1, 1); | 93 AppBannerSettingsHelper::SetEngagementWeights(1, 1); |
87 AppBannerSettingsHelper::SetTotalEngagementToTrigger(2); | 94 AppBannerSettingsHelper::SetTotalEngagementToTrigger(2); |
88 ASSERT_TRUE(embedded_test_server()->Start()); | 95 ASSERT_TRUE(embedded_test_server()->Start()); |
89 InProcessBrowserTest::SetUpOnMainThread(); | 96 InProcessBrowserTest::SetUpOnMainThread(); |
90 } | 97 } |
91 | 98 |
92 void SetUpCommandLine(base::CommandLine* command_line) override { | 99 void SetUpCommandLine(base::CommandLine* command_line) override { |
93 // Make sure app banners are disabled in the browser, otherwise they will | 100 // Make sure app banners are disabled in the browser, otherwise they will |
94 // interfere with the test. | 101 // interfere with the test. |
95 command_line->AppendSwitch(switches::kDisableAddToShelf); | 102 command_line->AppendSwitch(switches::kDisableAddToShelf); |
96 } | 103 } |
97 | 104 |
98 protected: | 105 protected: |
99 void RequestAppBanner(AppBannerManagerTest* manager, | 106 void RequestAppBanner(AppBannerManagerTest* manager, |
100 const GURL& url, | 107 const GURL& url, |
101 base::RunLoop& run_loop, | 108 base::RunLoop& run_loop, |
102 ui::PageTransition transition, | 109 ui::PageTransition transition, |
103 bool expected_to_show) { | 110 bool expected_to_show) { |
104 base::HistogramTester histograms; | |
105 manager->set_page_transition_(transition); | 111 manager->set_page_transition_(transition); |
106 manager->RequestAppBanner(url, false, run_loop.QuitClosure()); | 112 manager->RequestAppBanner(url, false, run_loop.QuitClosure()); |
107 run_loop.Run(); | 113 run_loop.Run(); |
108 | 114 |
109 EXPECT_EQ(expected_to_show, manager->will_show()); | 115 EXPECT_EQ(expected_to_show, manager->will_show()); |
110 ASSERT_FALSE(manager->is_active()); | 116 ASSERT_FALSE(manager->is_active()); |
111 | 117 |
112 // If showing the banner, ensure that the minutes histogram is recorded. | 118 // If showing the banner, ensure that the minutes histogram is recorded. |
113 histograms.ExpectTotalCount(banners::kMinutesHistogram, | 119 histograms_.ExpectTotalCount(banners::kMinutesHistogram, |
114 (manager->will_show() ? 1 : 0)); | 120 (manager->will_show() ? 1 : 0)); |
115 } | 121 } |
116 | 122 |
117 void RunBannerTest(const std::string& url, | 123 void RunBannerTest(const std::string& url, |
118 ui::PageTransition transition, | 124 ui::PageTransition transition, |
119 unsigned int unshown_repetitions, | 125 unsigned int unshown_repetitions, |
120 bool expectation) { | 126 InstallableStatusCode expected_code_for_histogram, |
| 127 bool expected_to_show) { |
121 std::string valid_page(url); | 128 std::string valid_page(url); |
122 GURL test_url = embedded_test_server()->GetURL(valid_page); | 129 GURL test_url = embedded_test_server()->GetURL(valid_page); |
123 content::WebContents* web_contents = | 130 content::WebContents* web_contents = |
124 browser()->tab_strip_model()->GetActiveWebContents(); | 131 browser()->tab_strip_model()->GetActiveWebContents(); |
125 std::unique_ptr<AppBannerManagerTest> manager( | 132 std::unique_ptr<AppBannerManagerTest> manager( |
126 new AppBannerManagerTest(web_contents)); | 133 new AppBannerManagerTest(web_contents)); |
127 | 134 |
128 for (unsigned int i = 0; i < unshown_repetitions; ++i) { | 135 for (unsigned int i = 1; i <= unshown_repetitions; ++i) { |
129 ui_test_utils::NavigateToURL(browser(), test_url); | 136 ui_test_utils::NavigateToURL(browser(), test_url); |
130 base::RunLoop run_loop; | 137 base::RunLoop run_loop; |
131 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 138 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
132 run_loop, transition, false); | 139 run_loop, transition, false); |
133 AppBannerManager::SetTimeDeltaForTesting(i + 1); | 140 CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, i, i); |
| 141 AppBannerManager::SetTimeDeltaForTesting(i); |
134 } | 142 } |
135 | 143 |
136 // On the final loop, check whether the banner triggered or not as expected. | 144 // On the final loop, check whether the banner triggered or not as expected. |
137 ui_test_utils::NavigateToURL(browser(), test_url); | 145 ui_test_utils::NavigateToURL(browser(), test_url); |
138 base::RunLoop run_loop; | 146 base::RunLoop run_loop; |
139 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 147 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
140 run_loop, transition, expectation); | 148 run_loop, transition, expected_to_show); |
| 149 // Navigate to ensure the InstallableStatusCodeHistogram is logged. |
| 150 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 151 CheckInstallableStatusCodeHistogram(expected_code_for_histogram, 1, |
| 152 unshown_repetitions + 1); |
| 153 EXPECT_FALSE(manager->need_to_log_status()); |
141 } | 154 } |
| 155 |
| 156 void CheckInstallableStatusCodeHistogram(InstallableStatusCode expected_code, |
| 157 int expected_count, |
| 158 int total_count) { |
| 159 histograms_.ExpectBucketCount(banners::kInstallableStatusCodeHistogram, |
| 160 expected_code, expected_count); |
| 161 histograms_.ExpectTotalCount(banners::kInstallableStatusCodeHistogram, |
| 162 total_count); |
| 163 } |
| 164 |
| 165 private: |
| 166 base::HistogramTester histograms_; |
142 }; | 167 }; |
143 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreatedDirect) { | 168 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreatedDirect) { |
144 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, | 169 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, |
145 1, true); | 170 1, SHOWING_WEB_APP_BANNER, true); |
146 } | 171 } |
147 | 172 |
148 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 173 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
149 WebAppBannerCreatedDirectLargerTotal) { | 174 WebAppBannerCreatedDirectLargerTotal) { |
150 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); | 175 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); |
151 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, | 176 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, |
152 3, true); | 177 3, SHOWING_WEB_APP_BANNER, true); |
153 } | 178 } |
154 | 179 |
155 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 180 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
156 WebAppBannerCreatedDirectSmallerTotal) { | 181 WebAppBannerCreatedDirectSmallerTotal) { |
157 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); | 182 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); |
158 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, | 183 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, |
159 0, true); | 184 0, SHOWING_WEB_APP_BANNER, true); |
160 } | 185 } |
161 | 186 |
162 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 187 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
163 WebAppBannerCreatedDirectSingle) { | 188 WebAppBannerCreatedDirectSingle) { |
164 AppBannerSettingsHelper::SetEngagementWeights(2, 1); | 189 AppBannerSettingsHelper::SetEngagementWeights(2, 1); |
165 RunBannerTest("/banners/manifest_test_page.html", | 190 RunBannerTest("/banners/manifest_test_page.html", |
166 ui::PAGE_TRANSITION_GENERATED, 0, true); | 191 ui::PAGE_TRANSITION_GENERATED, 0, SHOWING_WEB_APP_BANNER, true); |
167 } | 192 } |
168 | 193 |
169 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 194 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
170 WebAppBannerCreatedDirectMultiple) { | 195 WebAppBannerCreatedDirectMultiple) { |
171 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); | 196 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); |
172 RunBannerTest("/banners/manifest_test_page.html", | 197 RunBannerTest("/banners/manifest_test_page.html", |
173 ui::PAGE_TRANSITION_GENERATED, 3, true); | 198 ui::PAGE_TRANSITION_GENERATED, 3, SHOWING_WEB_APP_BANNER, true); |
174 } | 199 } |
175 | 200 |
176 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 201 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
177 WebAppBannerCreatedDirectMultipleLargerTotal) { | 202 WebAppBannerCreatedDirectMultipleLargerTotal) { |
178 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); | 203 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); |
179 AppBannerSettingsHelper::SetTotalEngagementToTrigger(3); | 204 AppBannerSettingsHelper::SetTotalEngagementToTrigger(3); |
180 RunBannerTest("/banners/manifest_test_page.html", | 205 RunBannerTest("/banners/manifest_test_page.html", |
181 ui::PAGE_TRANSITION_GENERATED, 5, true); | 206 ui::PAGE_TRANSITION_GENERATED, 5, SHOWING_WEB_APP_BANNER, true); |
182 } | 207 } |
183 | 208 |
184 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 209 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
185 WebAppBannerCreatedDirectMultipleSmallerTotal) { | 210 WebAppBannerCreatedDirectMultipleSmallerTotal) { |
186 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); | 211 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); |
187 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); | 212 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); |
188 RunBannerTest("/banners/manifest_test_page.html", | 213 RunBannerTest("/banners/manifest_test_page.html", |
189 ui::PAGE_TRANSITION_GENERATED, 1, true); | 214 ui::PAGE_TRANSITION_GENERATED, 1, SHOWING_WEB_APP_BANNER, true); |
190 } | 215 } |
191 | 216 |
192 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 217 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
193 WebAppBannerCreatedIndirect) { | 218 WebAppBannerCreatedIndirect) { |
194 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 1, | 219 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 1, |
195 true); | 220 SHOWING_WEB_APP_BANNER, true); |
196 } | 221 } |
197 | 222 |
198 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 223 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
199 WebAppBannerCreatedIndirectLargerTotal) { | 224 WebAppBannerCreatedIndirectLargerTotal) { |
200 AppBannerSettingsHelper::SetTotalEngagementToTrigger(5); | 225 AppBannerSettingsHelper::SetTotalEngagementToTrigger(5); |
201 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 4, | 226 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 4, |
202 true); | 227 SHOWING_WEB_APP_BANNER, true); |
203 } | 228 } |
204 | 229 |
205 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 230 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
206 WebAppBannerCreatedIndirectSmallerTotal) { | 231 WebAppBannerCreatedIndirectSmallerTotal) { |
207 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); | 232 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); |
208 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 0, | 233 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 0, |
209 true); | 234 SHOWING_WEB_APP_BANNER, true); |
210 } | 235 } |
211 | 236 |
212 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 237 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
213 WebAppBannerCreatedIndirectSingle) { | 238 WebAppBannerCreatedIndirectSingle) { |
214 AppBannerSettingsHelper::SetEngagementWeights(1, 3); | 239 AppBannerSettingsHelper::SetEngagementWeights(1, 3); |
215 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_RELOAD, | 240 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_RELOAD, |
216 0, true); | 241 0, SHOWING_WEB_APP_BANNER, true); |
217 } | 242 } |
218 | 243 |
219 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 244 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
220 WebAppBannerCreatedIndirectMultiple) { | 245 WebAppBannerCreatedIndirectMultiple) { |
221 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); | 246 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); |
222 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 3, | 247 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 3, |
223 true); | 248 SHOWING_WEB_APP_BANNER, true); |
224 } | 249 } |
225 | 250 |
226 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 251 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
227 WebAppBannerCreatedIndirectMultipleLargerTotal) { | 252 WebAppBannerCreatedIndirectMultipleLargerTotal) { |
228 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); | 253 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); |
229 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); | 254 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); |
230 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 7, | 255 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 7, |
231 true); | 256 SHOWING_WEB_APP_BANNER, true); |
232 } | 257 } |
233 | 258 |
234 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 259 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
235 WebAppBannerCreatedVarious) { | 260 WebAppBannerCreatedVarious) { |
236 AppBannerSettingsHelper::SetEngagementWeights(0.5, 0.25); | 261 AppBannerSettingsHelper::SetEngagementWeights(0.5, 0.25); |
237 | 262 |
238 std::string valid_page("/banners/manifest_test_page.html"); | 263 std::string valid_page("/banners/manifest_test_page.html"); |
239 GURL test_url = embedded_test_server()->GetURL(valid_page); | 264 GURL test_url = embedded_test_server()->GetURL(valid_page); |
240 content::WebContents* web_contents = | 265 content::WebContents* web_contents = |
241 browser()->tab_strip_model()->GetActiveWebContents(); | 266 browser()->tab_strip_model()->GetActiveWebContents(); |
242 | 267 |
243 std::unique_ptr<AppBannerManagerTest> manager( | 268 std::unique_ptr<AppBannerManagerTest> manager( |
244 new AppBannerManagerTest(web_contents)); | 269 new AppBannerManagerTest(web_contents)); |
245 | 270 |
246 // Add a direct nav on day 1. | 271 // Add a direct nav on day 1. |
247 { | 272 { |
248 base::RunLoop run_loop; | 273 base::RunLoop run_loop; |
249 ui_test_utils::NavigateToURL(browser(), test_url); | 274 ui_test_utils::NavigateToURL(browser(), test_url); |
250 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 275 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
251 run_loop, ui::PAGE_TRANSITION_TYPED, false); | 276 run_loop, ui::PAGE_TRANSITION_TYPED, false); |
| 277 CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 1, 1); |
| 278 EXPECT_FALSE(manager->need_to_log_status()); |
252 } | 279 } |
253 | 280 |
254 // Add an indirect nav on day 1 which is ignored. | 281 // Add an indirect nav on day 1 which is ignored. |
255 { | 282 { |
256 base::RunLoop run_loop; | 283 base::RunLoop run_loop; |
257 ui_test_utils::NavigateToURL(browser(), test_url); | 284 ui_test_utils::NavigateToURL(browser(), test_url); |
258 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 285 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
259 run_loop, ui::PAGE_TRANSITION_LINK, false); | 286 run_loop, ui::PAGE_TRANSITION_LINK, false); |
| 287 CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 2, 2); |
| 288 EXPECT_FALSE(manager->need_to_log_status()); |
260 AppBannerManager::SetTimeDeltaForTesting(1); | 289 AppBannerManager::SetTimeDeltaForTesting(1); |
261 } | 290 } |
262 | 291 |
263 // Add an indirect nav on day 2. | 292 // Add an indirect nav on day 2. |
264 { | 293 { |
265 base::RunLoop run_loop; | 294 base::RunLoop run_loop; |
266 ui_test_utils::NavigateToURL(browser(), test_url); | 295 ui_test_utils::NavigateToURL(browser(), test_url); |
267 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 296 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
268 run_loop, ui::PAGE_TRANSITION_MANUAL_SUBFRAME, false); | 297 run_loop, ui::PAGE_TRANSITION_MANUAL_SUBFRAME, false); |
| 298 CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 3, 3); |
| 299 EXPECT_FALSE(manager->need_to_log_status()); |
269 } | 300 } |
270 | 301 |
271 // Add a direct nav on day 2 which overrides. | 302 // Add a direct nav on day 2 which overrides. |
272 { | 303 { |
273 base::RunLoop run_loop; | 304 base::RunLoop run_loop; |
274 ui_test_utils::NavigateToURL(browser(), test_url); | 305 ui_test_utils::NavigateToURL(browser(), test_url); |
275 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 306 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
276 run_loop, ui::PAGE_TRANSITION_GENERATED, false); | 307 run_loop, ui::PAGE_TRANSITION_GENERATED, false); |
| 308 CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 4, 4); |
| 309 EXPECT_FALSE(manager->need_to_log_status()); |
277 AppBannerManager::SetTimeDeltaForTesting(2); | 310 AppBannerManager::SetTimeDeltaForTesting(2); |
278 } | 311 } |
279 | 312 |
280 // Add a direct nav on day 3. | 313 // Add a direct nav on day 3. |
281 { | 314 { |
282 base::RunLoop run_loop; | 315 base::RunLoop run_loop; |
283 ui_test_utils::NavigateToURL(browser(), test_url); | 316 ui_test_utils::NavigateToURL(browser(), test_url); |
284 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 317 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
285 run_loop, ui::PAGE_TRANSITION_GENERATED, false); | 318 run_loop, ui::PAGE_TRANSITION_GENERATED, false); |
| 319 CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 5, 5); |
| 320 EXPECT_FALSE(manager->need_to_log_status()); |
286 AppBannerManager::SetTimeDeltaForTesting(3); | 321 AppBannerManager::SetTimeDeltaForTesting(3); |
287 } | 322 } |
288 | 323 |
289 // Add an indirect nav on day 4. | 324 // Add an indirect nav on day 4. |
290 { | 325 { |
291 base::RunLoop run_loop; | 326 base::RunLoop run_loop; |
292 ui_test_utils::NavigateToURL(browser(), test_url); | 327 ui_test_utils::NavigateToURL(browser(), test_url); |
293 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 328 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
294 run_loop, ui::PAGE_TRANSITION_FORM_SUBMIT, false); | 329 run_loop, ui::PAGE_TRANSITION_FORM_SUBMIT, false); |
| 330 EXPECT_FALSE(manager->need_to_log_status()); |
| 331 CheckInstallableStatusCodeHistogram(INSUFFICIENT_ENGAGEMENT, 6, 6); |
295 } | 332 } |
| 333 |
296 // Add a direct nav on day 4 which should trigger the banner. | 334 // Add a direct nav on day 4 which should trigger the banner. |
297 { | 335 { |
298 base::RunLoop run_loop; | 336 base::RunLoop run_loop; |
299 ui_test_utils::NavigateToURL(browser(), test_url); | 337 ui_test_utils::NavigateToURL(browser(), test_url); |
300 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 338 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
301 run_loop, ui::PAGE_TRANSITION_TYPED, true); | 339 run_loop, ui::PAGE_TRANSITION_TYPED, true); |
| 340 EXPECT_FALSE(manager->need_to_log_status()); |
| 341 CheckInstallableStatusCodeHistogram(SHOWING_WEB_APP_BANNER, 1, 7); |
302 } | 342 } |
303 } | 343 } |
304 | 344 |
305 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 345 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
306 WebAppBannerNoTypeInManifest) { | 346 WebAppBannerNoTypeInManifest) { |
307 RunBannerTest("/banners/manifest_no_type_test_page.html", | 347 RunBannerTest("/banners/manifest_no_type_test_page.html", |
308 ui::PAGE_TRANSITION_TYPED, 1, true); | 348 ui::PAGE_TRANSITION_TYPED, 1, SHOWING_WEB_APP_BANNER, true); |
309 } | 349 } |
310 | 350 |
311 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 351 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
312 WebAppBannerNoTypeInManifestCapsExtension) { | 352 WebAppBannerNoTypeInManifestCapsExtension) { |
313 RunBannerTest("/banners/manifest_no_type_caps_test_page.html", | 353 RunBannerTest("/banners/manifest_no_type_caps_test_page.html", |
314 ui::PAGE_TRANSITION_TYPED, 1, true); | 354 ui::PAGE_TRANSITION_TYPED, 1, SHOWING_WEB_APP_BANNER, true); |
315 } | 355 } |
316 | 356 |
317 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) { | 357 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) { |
318 RunBannerTest("/banners/no_manifest_test_page.html", | 358 RunBannerTest("/banners/no_manifest_test_page.html", |
319 ui::PAGE_TRANSITION_TYPED, 1, false); | 359 ui::PAGE_TRANSITION_TYPED, 0, NO_MANIFEST, false); |
320 } | 360 } |
321 | 361 |
322 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) { | 362 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) { |
323 RunBannerTest("/banners/manifest_bad_link.html", ui::PAGE_TRANSITION_TYPED, 1, | 363 RunBannerTest("/banners/manifest_bad_link.html", ui::PAGE_TRANSITION_TYPED, 0, |
324 false); | 364 MANIFEST_EMPTY, false); |
325 } | 365 } |
326 | 366 |
327 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) { | 367 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) { |
328 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, | 368 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, |
329 false); | 369 RENDERER_CANCELLED, false); |
330 } | 370 } |
331 | 371 |
332 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerIndirect) { | 372 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerIndirect) { |
333 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); | 373 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); |
334 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 3, | 374 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_LINK, 3, |
335 false); | 375 RENDERER_CANCELLED, false); |
336 } | 376 } |
337 | 377 |
338 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBanner) { | 378 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBanner) { |
339 RunBannerTest("/banners/prompt_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, | 379 RunBannerTest("/banners/prompt_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, |
340 true); | 380 SHOWING_WEB_APP_BANNER, true); |
341 } | 381 } |
342 | 382 |
343 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBannerInHandler) { | 383 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBannerInHandler) { |
344 RunBannerTest("/banners/prompt_in_handler_test_page.html", | 384 RunBannerTest("/banners/prompt_in_handler_test_page.html", |
345 ui::PAGE_TRANSITION_TYPED, 1, true); | 385 ui::PAGE_TRANSITION_TYPED, 1, SHOWING_WEB_APP_BANNER, true); |
346 } | 386 } |
347 | 387 |
348 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) { | 388 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) { |
349 RunBannerTest("/banners/iframe_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, | 389 RunBannerTest("/banners/iframe_test_page.html", ui::PAGE_TRANSITION_TYPED, 0, |
350 false); | 390 NO_MANIFEST, false); |
351 } | 391 } |
352 | 392 |
353 } // namespace banners | 393 } // namespace banners |
OLD | NEW |