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 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 namespace banners { | 25 namespace banners { |
26 | 26 |
27 // All calls to RequestAppBanner should terminate in one of Stop() (not showing | 27 // All calls to RequestAppBanner should terminate in one of Stop() (not showing |
28 // banner) or ShowBanner(). This browser test uses this and overrides those two | 28 // banner) or ShowBanner(). This browser test uses this and overrides those two |
29 // methods to capture this information. | 29 // methods to capture this information. |
30 class AppBannerManagerTest : public AppBannerManager { | 30 class AppBannerManagerTest : public AppBannerManager { |
31 public: | 31 public: |
32 explicit AppBannerManagerTest(content::WebContents* web_contents) | 32 explicit AppBannerManagerTest(content::WebContents* web_contents) |
33 : AppBannerManager(web_contents) {} | 33 : AppBannerManager(web_contents) {} |
34 ~AppBannerManagerTest() override {} | 34 ~AppBannerManagerTest() override { } |
benwells
2016/08/11 04:47:34
Nit: leave as {}
dominickn
2016/08/11 07:00:19
Done.
| |
35 | 35 |
36 bool will_show() { return will_show_.get() && *will_show_; } | 36 bool will_show() { return will_show_.get() && *will_show_; } |
37 | 37 |
38 bool is_active() { return AppBannerManager::is_active(); } | 38 bool is_active() { return AppBannerManager::is_active(); } |
39 | 39 |
40 // Set the page transition of each banner request. | 40 // Set the page transition of each banner request. |
41 void set_page_transition_(ui::PageTransition transition) { | 41 void set_page_transition_(ui::PageTransition transition) { |
42 last_transition_type_ = transition; | 42 last_transition_type_ = transition; |
43 } | 43 } |
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 protected: | 54 protected: |
55 void Stop() override { | 55 void Stop() override { |
56 AppBannerManager::Stop(); | 56 AppBannerManager::Stop(); |
57 ASSERT_FALSE(will_show_.get()); | 57 ASSERT_FALSE(will_show_.get()); |
58 will_show_.reset(new bool(false)); | 58 will_show_.reset(new bool(false)); |
59 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); | 59 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); |
60 } | 60 } |
61 | 61 |
62 void ShowBanner() override { | 62 void ShowBanner() override { |
63 // Fake the call to TrackInstallableErrorCode here - this is usually called | |
64 // in platform-specific code which is not exposed here. | |
65 TrackInstallableErrorCode(SHOWING_WEB_APP_BANNER); | |
63 ASSERT_FALSE(will_show_.get()); | 66 ASSERT_FALSE(will_show_.get()); |
64 will_show_.reset(new bool(true)); | 67 will_show_.reset(new bool(true)); |
65 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); | 68 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); |
66 } | 69 } |
67 | 70 |
68 void DidStartNavigation(content::NavigationHandle* handle) override { | 71 void DidStartNavigation(content::NavigationHandle* handle) override { |
69 // Do nothing to ensure we never observe the site engagement service. | 72 // Do nothing to ensure we never observe the site engagement service. |
70 } | 73 } |
71 | 74 |
72 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 75 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
(...skipping 21 matching lines...) Expand all Loading... | |
94 // interfere with the test. | 97 // interfere with the test. |
95 command_line->AppendSwitch(switches::kDisableAddToShelf); | 98 command_line->AppendSwitch(switches::kDisableAddToShelf); |
96 } | 99 } |
97 | 100 |
98 protected: | 101 protected: |
99 void RequestAppBanner(AppBannerManagerTest* manager, | 102 void RequestAppBanner(AppBannerManagerTest* manager, |
100 const GURL& url, | 103 const GURL& url, |
101 base::RunLoop& run_loop, | 104 base::RunLoop& run_loop, |
102 ui::PageTransition transition, | 105 ui::PageTransition transition, |
103 bool expected_to_show) { | 106 bool expected_to_show) { |
104 base::HistogramTester histograms; | |
105 manager->set_page_transition_(transition); | 107 manager->set_page_transition_(transition); |
106 manager->RequestAppBanner(url, false, run_loop.QuitClosure()); | 108 manager->RequestAppBanner(url, false, run_loop.QuitClosure()); |
107 run_loop.Run(); | 109 run_loop.Run(); |
108 | 110 |
109 EXPECT_EQ(expected_to_show, manager->will_show()); | 111 EXPECT_EQ(expected_to_show, manager->will_show()); |
110 ASSERT_FALSE(manager->is_active()); | 112 ASSERT_FALSE(manager->is_active()); |
111 | 113 |
112 // If showing the banner, ensure that the minutes histogram is recorded. | 114 // If showing the banner, ensure that the minutes histogram is recorded. |
113 histograms.ExpectTotalCount(banners::kMinutesHistogram, | 115 histograms_.ExpectTotalCount(banners::kMinutesHistogram, |
114 (manager->will_show() ? 1 : 0)); | 116 (manager->will_show() ? 1 : 0)); |
115 } | 117 } |
116 | 118 |
117 void RunBannerTest(const std::string& url, | 119 void RunBannerTest(const std::string& url, |
118 ui::PageTransition transition, | 120 ui::PageTransition transition, |
119 unsigned int unshown_repetitions, | 121 unsigned int unshown_repetitions, |
120 bool expectation) { | 122 InstallableErrorCode expected_code_for_histogram, |
123 bool expected_to_show) { | |
121 std::string valid_page(url); | 124 std::string valid_page(url); |
122 GURL test_url = embedded_test_server()->GetURL(valid_page); | 125 GURL test_url = embedded_test_server()->GetURL(valid_page); |
123 content::WebContents* web_contents = | 126 content::WebContents* web_contents = |
124 browser()->tab_strip_model()->GetActiveWebContents(); | 127 browser()->tab_strip_model()->GetActiveWebContents(); |
125 std::unique_ptr<AppBannerManagerTest> manager( | 128 std::unique_ptr<AppBannerManagerTest> manager( |
126 new AppBannerManagerTest(web_contents)); | 129 new AppBannerManagerTest(web_contents)); |
127 | 130 |
128 for (unsigned int i = 0; i < unshown_repetitions; ++i) { | 131 for (unsigned int i = 0; i < unshown_repetitions; ++i) { |
129 ui_test_utils::NavigateToURL(browser(), test_url); | 132 ui_test_utils::NavigateToURL(browser(), test_url); |
130 base::RunLoop run_loop; | 133 base::RunLoop run_loop; |
131 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 134 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
132 run_loop, transition, false); | 135 run_loop, transition, false); |
136 CheckInstallableErrorCodeHistogram(INSUFFICIENT_ENGAGEMENT, i+1, i+1); | |
gone
2016/08/10 21:02:51
Should be consistent about the i+1 vs i + 1 below.
dominickn
2016/08/11 07:00:19
Done.
| |
133 AppBannerManager::SetTimeDeltaForTesting(i + 1); | 137 AppBannerManager::SetTimeDeltaForTesting(i + 1); |
134 } | 138 } |
135 | 139 |
136 // On the final loop, check whether the banner triggered or not as expected. | 140 // On the final loop, check whether the banner triggered or not as expected. |
137 ui_test_utils::NavigateToURL(browser(), test_url); | 141 ui_test_utils::NavigateToURL(browser(), test_url); |
138 base::RunLoop run_loop; | 142 base::RunLoop run_loop; |
139 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 143 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
140 run_loop, transition, expectation); | 144 run_loop, transition, expected_to_show); |
145 // Navigate to ensure the InstallableErrorCodeHistogram is logged. | |
146 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
147 CheckInstallableErrorCodeHistogram(expected_code_for_histogram, 1, | |
148 unshown_repetitions + 1); | |
141 } | 149 } |
150 | |
151 void CheckInstallableErrorCodeHistogram(InstallableErrorCode expected_code, | |
152 int expected_count, int total_count) { | |
153 histograms_.ExpectBucketCount(banners::kInstallableErrorCodeHistogram, | |
154 expected_code, expected_count); | |
155 histograms_.ExpectTotalCount(banners::kInstallableErrorCodeHistogram, | |
156 total_count); | |
157 } | |
158 | |
159 private: | |
160 base::HistogramTester histograms_; | |
142 }; | 161 }; |
143 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreatedDirect) { | 162 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreatedDirect) { |
144 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, | 163 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, |
145 1, true); | 164 1, SHOWING_WEB_APP_BANNER, true); |
146 } | 165 } |
147 | 166 |
148 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 167 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
149 WebAppBannerCreatedDirectLargerTotal) { | 168 WebAppBannerCreatedDirectLargerTotal) { |
150 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); | 169 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); |
151 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, | 170 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, |
152 3, true); | 171 3, SHOWING_WEB_APP_BANNER, true); |
153 } | 172 } |
154 | 173 |
155 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 174 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
156 WebAppBannerCreatedDirectSmallerTotal) { | 175 WebAppBannerCreatedDirectSmallerTotal) { |
157 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); | 176 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); |
158 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, | 177 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, |
159 0, true); | 178 0, SHOWING_WEB_APP_BANNER, true); |
160 } | 179 } |
161 | 180 |
162 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 181 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
163 WebAppBannerCreatedDirectSingle) { | 182 WebAppBannerCreatedDirectSingle) { |
164 AppBannerSettingsHelper::SetEngagementWeights(2, 1); | 183 AppBannerSettingsHelper::SetEngagementWeights(2, 1); |
165 RunBannerTest("/banners/manifest_test_page.html", | 184 RunBannerTest("/banners/manifest_test_page.html", |
166 ui::PAGE_TRANSITION_GENERATED, 0, true); | 185 ui::PAGE_TRANSITION_GENERATED, 0, SHOWING_WEB_APP_BANNER, true); |
167 } | 186 } |
168 | 187 |
169 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 188 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
170 WebAppBannerCreatedDirectMultiple) { | 189 WebAppBannerCreatedDirectMultiple) { |
171 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); | 190 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); |
172 RunBannerTest("/banners/manifest_test_page.html", | 191 RunBannerTest("/banners/manifest_test_page.html", |
173 ui::PAGE_TRANSITION_GENERATED, 3, true); | 192 ui::PAGE_TRANSITION_GENERATED, 3, SHOWING_WEB_APP_BANNER, true); |
174 } | 193 } |
175 | 194 |
176 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 195 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
177 WebAppBannerCreatedDirectMultipleLargerTotal) { | 196 WebAppBannerCreatedDirectMultipleLargerTotal) { |
178 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); | 197 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); |
179 AppBannerSettingsHelper::SetTotalEngagementToTrigger(3); | 198 AppBannerSettingsHelper::SetTotalEngagementToTrigger(3); |
180 RunBannerTest("/banners/manifest_test_page.html", | 199 RunBannerTest("/banners/manifest_test_page.html", |
181 ui::PAGE_TRANSITION_GENERATED, 5, true); | 200 ui::PAGE_TRANSITION_GENERATED, 5, SHOWING_WEB_APP_BANNER, true); |
182 } | 201 } |
183 | 202 |
184 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 203 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
185 WebAppBannerCreatedDirectMultipleSmallerTotal) { | 204 WebAppBannerCreatedDirectMultipleSmallerTotal) { |
186 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); | 205 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); |
187 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); | 206 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); |
188 RunBannerTest("/banners/manifest_test_page.html", | 207 RunBannerTest("/banners/manifest_test_page.html", |
189 ui::PAGE_TRANSITION_GENERATED, 1, true); | 208 ui::PAGE_TRANSITION_GENERATED, 1, SHOWING_WEB_APP_BANNER, true); |
190 } | 209 } |
191 | 210 |
192 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 211 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
193 WebAppBannerCreatedIndirect) { | 212 WebAppBannerCreatedIndirect) { |
194 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 1, | 213 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 1, |
195 true); | 214 SHOWING_WEB_APP_BANNER, true); |
196 } | 215 } |
197 | 216 |
198 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 217 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
199 WebAppBannerCreatedIndirectLargerTotal) { | 218 WebAppBannerCreatedIndirectLargerTotal) { |
200 AppBannerSettingsHelper::SetTotalEngagementToTrigger(5); | 219 AppBannerSettingsHelper::SetTotalEngagementToTrigger(5); |
201 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 4, | 220 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 4, |
202 true); | 221 SHOWING_WEB_APP_BANNER, true); |
203 } | 222 } |
204 | 223 |
205 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 224 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
206 WebAppBannerCreatedIndirectSmallerTotal) { | 225 WebAppBannerCreatedIndirectSmallerTotal) { |
207 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); | 226 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); |
208 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 0, | 227 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 0, |
209 true); | 228 SHOWING_WEB_APP_BANNER, true); |
210 } | 229 } |
211 | 230 |
212 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 231 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
213 WebAppBannerCreatedIndirectSingle) { | 232 WebAppBannerCreatedIndirectSingle) { |
214 AppBannerSettingsHelper::SetEngagementWeights(1, 3); | 233 AppBannerSettingsHelper::SetEngagementWeights(1, 3); |
215 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_RELOAD, | 234 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_RELOAD, |
216 0, true); | 235 0, SHOWING_WEB_APP_BANNER, true); |
217 } | 236 } |
218 | 237 |
219 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 238 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
220 WebAppBannerCreatedIndirectMultiple) { | 239 WebAppBannerCreatedIndirectMultiple) { |
221 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); | 240 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); |
222 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 3, | 241 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 3, |
223 true); | 242 SHOWING_WEB_APP_BANNER, true); |
224 } | 243 } |
225 | 244 |
226 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 245 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
227 WebAppBannerCreatedIndirectMultipleLargerTotal) { | 246 WebAppBannerCreatedIndirectMultipleLargerTotal) { |
228 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); | 247 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); |
229 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); | 248 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); |
230 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 7, | 249 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 7, |
231 true); | 250 SHOWING_WEB_APP_BANNER, true); |
232 } | 251 } |
233 | 252 |
234 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 253 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
235 WebAppBannerCreatedVarious) { | 254 WebAppBannerCreatedVarious) { |
236 AppBannerSettingsHelper::SetEngagementWeights(0.5, 0.25); | 255 AppBannerSettingsHelper::SetEngagementWeights(0.5, 0.25); |
237 | 256 |
238 std::string valid_page("/banners/manifest_test_page.html"); | 257 std::string valid_page("/banners/manifest_test_page.html"); |
239 GURL test_url = embedded_test_server()->GetURL(valid_page); | 258 GURL test_url = embedded_test_server()->GetURL(valid_page); |
240 content::WebContents* web_contents = | 259 content::WebContents* web_contents = |
241 browser()->tab_strip_model()->GetActiveWebContents(); | 260 browser()->tab_strip_model()->GetActiveWebContents(); |
242 | 261 |
243 std::unique_ptr<AppBannerManagerTest> manager( | 262 std::unique_ptr<AppBannerManagerTest> manager( |
244 new AppBannerManagerTest(web_contents)); | 263 new AppBannerManagerTest(web_contents)); |
245 | 264 |
246 // Add a direct nav on day 1. | 265 // Add a direct nav on day 1. |
247 { | 266 { |
248 base::RunLoop run_loop; | 267 base::RunLoop run_loop; |
249 ui_test_utils::NavigateToURL(browser(), test_url); | 268 ui_test_utils::NavigateToURL(browser(), test_url); |
250 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 269 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
251 run_loop, ui::PAGE_TRANSITION_TYPED, false); | 270 run_loop, ui::PAGE_TRANSITION_TYPED, false); |
271 CheckInstallableErrorCodeHistogram(INSUFFICIENT_ENGAGEMENT, 1, 1); | |
252 } | 272 } |
253 | 273 |
254 // Add an indirect nav on day 1 which is ignored. | 274 // Add an indirect nav on day 1 which is ignored. |
255 { | 275 { |
256 base::RunLoop run_loop; | 276 base::RunLoop run_loop; |
257 ui_test_utils::NavigateToURL(browser(), test_url); | 277 ui_test_utils::NavigateToURL(browser(), test_url); |
258 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 278 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
259 run_loop, ui::PAGE_TRANSITION_LINK, false); | 279 run_loop, ui::PAGE_TRANSITION_LINK, false); |
280 CheckInstallableErrorCodeHistogram(INSUFFICIENT_ENGAGEMENT, 2, 2); | |
260 AppBannerManager::SetTimeDeltaForTesting(1); | 281 AppBannerManager::SetTimeDeltaForTesting(1); |
261 } | 282 } |
262 | 283 |
263 // Add an indirect nav on day 2. | 284 // Add an indirect nav on day 2. |
264 { | 285 { |
265 base::RunLoop run_loop; | 286 base::RunLoop run_loop; |
266 ui_test_utils::NavigateToURL(browser(), test_url); | 287 ui_test_utils::NavigateToURL(browser(), test_url); |
267 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 288 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
268 run_loop, ui::PAGE_TRANSITION_MANUAL_SUBFRAME, false); | 289 run_loop, ui::PAGE_TRANSITION_MANUAL_SUBFRAME, false); |
290 CheckInstallableErrorCodeHistogram(INSUFFICIENT_ENGAGEMENT, 3, 3); | |
269 } | 291 } |
270 | 292 |
271 // Add a direct nav on day 2 which overrides. | 293 // Add a direct nav on day 2 which overrides. |
272 { | 294 { |
273 base::RunLoop run_loop; | 295 base::RunLoop run_loop; |
274 ui_test_utils::NavigateToURL(browser(), test_url); | 296 ui_test_utils::NavigateToURL(browser(), test_url); |
275 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 297 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
276 run_loop, ui::PAGE_TRANSITION_GENERATED, false); | 298 run_loop, ui::PAGE_TRANSITION_GENERATED, false); |
299 CheckInstallableErrorCodeHistogram(INSUFFICIENT_ENGAGEMENT, 4, 4); | |
277 AppBannerManager::SetTimeDeltaForTesting(2); | 300 AppBannerManager::SetTimeDeltaForTesting(2); |
278 } | 301 } |
279 | 302 |
280 // Add a direct nav on day 3. | 303 // Add a direct nav on day 3. |
281 { | 304 { |
282 base::RunLoop run_loop; | 305 base::RunLoop run_loop; |
283 ui_test_utils::NavigateToURL(browser(), test_url); | 306 ui_test_utils::NavigateToURL(browser(), test_url); |
284 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 307 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
285 run_loop, ui::PAGE_TRANSITION_GENERATED, false); | 308 run_loop, ui::PAGE_TRANSITION_GENERATED, false); |
309 CheckInstallableErrorCodeHistogram(INSUFFICIENT_ENGAGEMENT, 5, 5); | |
286 AppBannerManager::SetTimeDeltaForTesting(3); | 310 AppBannerManager::SetTimeDeltaForTesting(3); |
287 } | 311 } |
288 | 312 |
289 // Add an indirect nav on day 4. | 313 // Add an indirect nav on day 4. |
290 { | 314 { |
291 base::RunLoop run_loop; | 315 base::RunLoop run_loop; |
292 ui_test_utils::NavigateToURL(browser(), test_url); | 316 ui_test_utils::NavigateToURL(browser(), test_url); |
293 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 317 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
294 run_loop, ui::PAGE_TRANSITION_FORM_SUBMIT, false); | 318 run_loop, ui::PAGE_TRANSITION_FORM_SUBMIT, false); |
319 CheckInstallableErrorCodeHistogram(INSUFFICIENT_ENGAGEMENT, 6, 6); | |
295 } | 320 } |
321 | |
296 // Add a direct nav on day 4 which should trigger the banner. | 322 // Add a direct nav on day 4 which should trigger the banner. |
297 { | 323 { |
298 base::RunLoop run_loop; | 324 base::RunLoop run_loop; |
299 ui_test_utils::NavigateToURL(browser(), test_url); | 325 ui_test_utils::NavigateToURL(browser(), test_url); |
300 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), | 326 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(), |
301 run_loop, ui::PAGE_TRANSITION_TYPED, true); | 327 run_loop, ui::PAGE_TRANSITION_TYPED, true); |
328 CheckInstallableErrorCodeHistogram(SHOWING_WEB_APP_BANNER, 1, 7); | |
302 } | 329 } |
303 } | 330 } |
304 | 331 |
305 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 332 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
306 WebAppBannerNoTypeInManifest) { | 333 WebAppBannerNoTypeInManifest) { |
307 RunBannerTest("/banners/manifest_no_type_test_page.html", | 334 RunBannerTest("/banners/manifest_no_type_test_page.html", |
308 ui::PAGE_TRANSITION_TYPED, 1, true); | 335 ui::PAGE_TRANSITION_TYPED, 1, SHOWING_WEB_APP_BANNER, true); |
309 } | 336 } |
310 | 337 |
311 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, | 338 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, |
312 WebAppBannerNoTypeInManifestCapsExtension) { | 339 WebAppBannerNoTypeInManifestCapsExtension) { |
313 RunBannerTest("/banners/manifest_no_type_caps_test_page.html", | 340 RunBannerTest("/banners/manifest_no_type_caps_test_page.html", |
314 ui::PAGE_TRANSITION_TYPED, 1, true); | 341 ui::PAGE_TRANSITION_TYPED, 1, SHOWING_WEB_APP_BANNER, true); |
315 } | 342 } |
316 | 343 |
317 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) { | 344 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) { |
318 RunBannerTest("/banners/no_manifest_test_page.html", | 345 RunBannerTest("/banners/no_manifest_test_page.html", |
319 ui::PAGE_TRANSITION_TYPED, 1, false); | 346 ui::PAGE_TRANSITION_TYPED, 0, NO_MANIFEST, false); |
320 } | 347 } |
321 | 348 |
322 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) { | 349 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) { |
323 RunBannerTest("/banners/manifest_bad_link.html", ui::PAGE_TRANSITION_TYPED, 1, | 350 RunBannerTest("/banners/manifest_bad_link.html", ui::PAGE_TRANSITION_TYPED, 0, |
324 false); | 351 MANIFEST_EMPTY, false); |
325 } | 352 } |
326 | 353 |
327 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) { | 354 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) { |
328 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, | 355 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, |
329 false); | 356 RENDERER_CANCELLED, false); |
330 } | 357 } |
331 | 358 |
332 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerIndirect) { | 359 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerIndirect) { |
333 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); | 360 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); |
334 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 3, | 361 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_LINK, 3, |
335 false); | 362 RENDERER_CANCELLED, false); |
336 } | 363 } |
337 | 364 |
338 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBanner) { | 365 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBanner) { |
339 RunBannerTest("/banners/prompt_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, | 366 RunBannerTest("/banners/prompt_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, |
340 true); | 367 SHOWING_WEB_APP_BANNER, true); |
341 } | 368 } |
342 | 369 |
343 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBannerInHandler) { | 370 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBannerInHandler) { |
344 RunBannerTest("/banners/prompt_in_handler_test_page.html", | 371 RunBannerTest("/banners/prompt_in_handler_test_page.html", |
345 ui::PAGE_TRANSITION_TYPED, 1, true); | 372 ui::PAGE_TRANSITION_TYPED, 1, SHOWING_WEB_APP_BANNER, true); |
346 } | 373 } |
347 | 374 |
348 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) { | 375 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) { |
349 RunBannerTest("/banners/iframe_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, | 376 RunBannerTest("/banners/iframe_test_page.html", ui::PAGE_TRANSITION_TYPED, 0, |
350 false); | 377 NO_MANIFEST, false); |
351 } | 378 } |
352 | 379 |
353 } // namespace banners | 380 } // namespace banners |
OLD | NEW |