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

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

Issue 2156113002: Replace AppBannerDataFetcher with InstallableManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@banner-refactor
Patch Set: Naming, includes Created 4 years, 4 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 2015 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_data_fetcher.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/location.h"
9 #include "base/run_loop.h" 8 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
11 #include "base/task_runner.h" 10 #include "base/task_runner.h"
12 #include "base/test/histogram_tester.h" 11 #include "base/test/histogram_tester.h"
13 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
14 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h" 13 #include "chrome/browser/banners/app_banner_manager.h"
15 #include "chrome/browser/banners/app_banner_metrics.h" 14 #include "chrome/browser/banners/app_banner_metrics.h"
16 #include "chrome/browser/banners/app_banner_settings_helper.h" 15 #include "chrome/browser/banners/app_banner_settings_helper.h"
16 #include "chrome/browser/installable/installable_manager.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
23 #include "content/public/test/test_navigation_observer.h"
24 #include "net/test/embedded_test_server/embedded_test_server.h" 23 #include "net/test/embedded_test_server/embedded_test_server.h"
25 24
26 namespace banners { 25 namespace banners {
27 26
28 class TestObserver : public AppBannerDataFetcher::Observer { 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
29 // methods to capture this information.
30 class AppBannerManagerTest : public AppBannerManager {
29 public: 31 public:
30 TestObserver(AppBannerDataFetcher* fetcher, base::Closure quit_closure) 32 explicit AppBannerManagerTest(content::WebContents* web_contents)
31 : fetcher_(fetcher), 33 : AppBannerManager(web_contents) {}
32 quit_closure_(quit_closure) { 34 ~AppBannerManagerTest() override {}
33 fetcher_->AddObserverForTesting(this);
34 }
35
36 virtual ~TestObserver() {
37 if (fetcher_)
38 fetcher_->RemoveObserverForTesting(this);
39 }
40
41 void OnDecidedWhetherToShow(AppBannerDataFetcher* fetcher,
42 bool will_show) override {
43 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
44 ASSERT_FALSE(will_show_.get());
45 will_show_.reset(new bool(will_show));
46 }
47
48 void OnFetcherDestroyed(AppBannerDataFetcher* fetcher) override {
49 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
50 fetcher_ = nullptr;
51 }
52 35
53 bool will_show() { return will_show_.get() && *will_show_; } 36 bool will_show() { return will_show_.get() && *will_show_; }
54 37
38 bool is_active() { return AppBannerManager::is_active(); }
39
40 // Set the page transition of each banner request.
41 void set_page_transition_(ui::PageTransition transition) {
42 last_transition_type_ = transition;
43 }
44
45 using AppBannerManager::RequestAppBanner;
46 void RequestAppBanner(const GURL& validated_url,
47 bool is_debug_mode,
48 base::Closure quit_closure) {
49 will_show_.reset(nullptr);
50 quit_closure_ = quit_closure;
51 AppBannerManager::RequestAppBanner(validated_url, is_debug_mode);
52 }
53
54 protected:
55 void Stop() override {
56 AppBannerManager::Stop();
57 ASSERT_FALSE(will_show_.get());
58 will_show_.reset(new bool(false));
59 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
60 }
61
62 void ShowBanner() override {
63 ASSERT_FALSE(will_show_.get());
64 will_show_.reset(new bool(true));
65 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
66 }
67
68 void DidStartNavigation(content::NavigationHandle* handle) override {
69 // Do nothing to ensure we never observe the site engagement service.
70 }
71
72 void DidFinishLoad(content::RenderFrameHost* render_frame_host,
73 const GURL& validated_url) override {
74 // Do nothing else to ensure the banner pipeline doesn't start.
75 validated_url_ = validated_url;
76 }
77
55 private: 78 private:
56 AppBannerDataFetcher* fetcher_;
57 base::Closure quit_closure_; 79 base::Closure quit_closure_;
58 std::unique_ptr<bool> will_show_; 80 std::unique_ptr<bool> will_show_;
59 }; 81 };
60 82
61 class AppBannerDataFetcherBrowserTest : public InProcessBrowserTest, 83 class AppBannerManagerBrowserTest : public InProcessBrowserTest {
62 public AppBannerDataFetcher::Delegate {
63 public: 84 public:
64 AppBannerDataFetcherBrowserTest() : weak_factory_(this) {
65 }
66
67 void SetUpOnMainThread() override { 85 void SetUpOnMainThread() override {
68 AppBannerSettingsHelper::SetEngagementWeights(1, 1); 86 AppBannerSettingsHelper::SetEngagementWeights(1, 1);
69 AppBannerSettingsHelper::SetTotalEngagementToTrigger(2); 87 AppBannerSettingsHelper::SetTotalEngagementToTrigger(2);
70 ASSERT_TRUE(embedded_test_server()->Start()); 88 ASSERT_TRUE(embedded_test_server()->Start());
71 InProcessBrowserTest::SetUpOnMainThread(); 89 InProcessBrowserTest::SetUpOnMainThread();
72 } 90 }
73 91
74 bool HandleNonWebApp(const std::string& platform,
75 const GURL& url,
76 const std::string& id,
77 bool is_debug_mode) override {
78 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
79 non_web_platform_ = platform;
80 return false;
81 }
82
83 void SetUpCommandLine(base::CommandLine* command_line) override { 92 void SetUpCommandLine(base::CommandLine* command_line) override {
84 command_line->AppendSwitch(
85 switches::kEnableExperimentalWebPlatformFeatures);
86 // Make sure app banners are disabled in the browser, otherwise they will 93 // Make sure app banners are disabled in the browser, otherwise they will
87 // interfere with the test. 94 // interfere with the test.
88 command_line->AppendSwitch(switches::kDisableAddToShelf); 95 command_line->AppendSwitch(switches::kDisableAddToShelf);
89 } 96 }
90 97
91 protected: 98 protected:
92 void RunFetcher(const GURL& url, 99 void RequestAppBanner(AppBannerManagerTest* manager,
93 const std::string& expected_non_web_platform, 100 const GURL& url,
94 ui::PageTransition transition, 101 base::RunLoop& run_loop,
95 bool expected_to_show) { 102 ui::PageTransition transition,
96 content::WebContents* web_contents = 103 bool expected_to_show) {
97 browser()->tab_strip_model()->GetActiveWebContents();
98 scoped_refptr<AppBannerDataFetcherDesktop> fetcher(
99 new AppBannerDataFetcherDesktop(
100 web_contents, weak_factory_.GetWeakPtr(), 128, 128, false));
101
102 base::HistogramTester histograms; 104 base::HistogramTester histograms;
103 base::RunLoop run_loop; 105 manager->set_page_transition_(transition);
104 quit_closure_ = run_loop.QuitClosure(); 106 manager->RequestAppBanner(url, false, run_loop.QuitClosure());
105 std::unique_ptr<TestObserver> observer(
106 new TestObserver(fetcher.get(), run_loop.QuitClosure()));
107 fetcher->Start(url, transition);
108 run_loop.Run(); 107 run_loop.Run();
109 108
110 EXPECT_EQ(expected_non_web_platform, non_web_platform_); 109 EXPECT_EQ(expected_to_show, manager->will_show());
111 EXPECT_EQ(expected_to_show, observer->will_show()); 110 ASSERT_FALSE(manager->is_active());
112 ASSERT_FALSE(fetcher->is_active());
113 111
114 // If showing the banner, ensure that the minutes histogram is recorded. 112 // If showing the banner, ensure that the minutes histogram is recorded.
115 histograms.ExpectTotalCount(banners::kMinutesHistogram, 113 histograms.ExpectTotalCount(banners::kMinutesHistogram,
116 (observer->will_show() ? 1 : 0)); 114 (manager->will_show() ? 1 : 0));
117 } 115 }
118 116
119 void RunBannerTest(const std::string& manifest_page, 117 void RunBannerTest(const std::string& url,
120 ui::PageTransition transition, 118 ui::PageTransition transition,
121 unsigned int unshown_repetitions, 119 unsigned int unshown_repetitions,
122 bool expectation) { 120 bool expectation) {
123 std::string valid_page(manifest_page); 121 std::string valid_page(url);
124 GURL test_url = embedded_test_server()->GetURL(valid_page); 122 GURL test_url = embedded_test_server()->GetURL(valid_page);
125 content::WebContents* web_contents = 123 content::WebContents* web_contents =
126 browser()->tab_strip_model()->GetActiveWebContents(); 124 browser()->tab_strip_model()->GetActiveWebContents();
125 std::unique_ptr<AppBannerManagerTest> manager(
126 new AppBannerManagerTest(web_contents));
127 127
128 for (unsigned int i = 0; i < unshown_repetitions; ++i) { 128 for (unsigned int i = 0; i < unshown_repetitions; ++i) {
129 ui_test_utils::NavigateToURL(browser(), test_url); 129 ui_test_utils::NavigateToURL(browser(), test_url);
130 RunFetcher(web_contents->GetURL(), std::string(), transition, false); 130 base::RunLoop run_loop;
131 AppBannerDataFetcher::SetTimeDeltaForTesting(i+1); 131 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(),
132 run_loop, transition, false);
133 AppBannerManager::SetTimeDeltaForTesting(i + 1);
132 } 134 }
133 135
134 // On the final loop, check whether the banner triggered or not as expected. 136 // On the final loop, check whether the banner triggered or not as expected.
135 ui_test_utils::NavigateToURL(browser(), test_url); 137 ui_test_utils::NavigateToURL(browser(), test_url);
136 RunFetcher(web_contents->GetURL(), std::string(), transition, expectation); 138 base::RunLoop run_loop;
139 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(),
140 run_loop, transition, expectation);
137 } 141 }
138
139 private:
140 std::string non_web_platform_;
141 base::Closure quit_closure_;
142 base::WeakPtrFactory<AppBannerDataFetcherBrowserTest> weak_factory_;
143 }; 142 };
144 143 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerCreatedDirect) {
145 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest,
146 WebAppBannerCreatedDirect) {
147 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, 144 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED,
148 1, true); 145 1, true);
149 } 146 }
150 147
151 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 148 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
152 WebAppBannerCreatedDirectLargerTotal) { 149 WebAppBannerCreatedDirectLargerTotal) {
153 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); 150 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4);
154 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, 151 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED,
155 3, true); 152 3, true);
156 } 153 }
157 154
158 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 155 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
159 WebAppBannerCreatedDirectSmallerTotal) { 156 WebAppBannerCreatedDirectSmallerTotal) {
160 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); 157 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1);
161 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED, 158 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_TYPED,
162 0, true); 159 0, true);
163 } 160 }
164 161
165 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 162 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
166 WebAppBannerCreatedDirectSingle) { 163 WebAppBannerCreatedDirectSingle) {
167 AppBannerSettingsHelper::SetEngagementWeights(2, 1); 164 AppBannerSettingsHelper::SetEngagementWeights(2, 1);
168 RunBannerTest("/banners/manifest_test_page.html", 165 RunBannerTest("/banners/manifest_test_page.html",
169 ui::PAGE_TRANSITION_GENERATED, 0, true); 166 ui::PAGE_TRANSITION_GENERATED, 0, true);
170 } 167 }
171 168
172 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 169 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
173 WebAppBannerCreatedDirectMultiple) { 170 WebAppBannerCreatedDirectMultiple) {
174 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); 171 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1);
175 RunBannerTest("/banners/manifest_test_page.html", 172 RunBannerTest("/banners/manifest_test_page.html",
176 ui::PAGE_TRANSITION_GENERATED, 3, true); 173 ui::PAGE_TRANSITION_GENERATED, 3, true);
177 } 174 }
178 175
179 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 176 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
180 WebAppBannerCreatedDirectMultipleLargerTotal) { 177 WebAppBannerCreatedDirectMultipleLargerTotal) {
181 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); 178 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1);
182 AppBannerSettingsHelper::SetTotalEngagementToTrigger(3); 179 AppBannerSettingsHelper::SetTotalEngagementToTrigger(3);
183 RunBannerTest("/banners/manifest_test_page.html", 180 RunBannerTest("/banners/manifest_test_page.html",
184 ui::PAGE_TRANSITION_GENERATED, 5, true); 181 ui::PAGE_TRANSITION_GENERATED, 5, true);
185 } 182 }
186 183
187 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 184 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
188 WebAppBannerCreatedDirectMultipleSmallerTotal) { 185 WebAppBannerCreatedDirectMultipleSmallerTotal) {
189 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1); 186 AppBannerSettingsHelper::SetEngagementWeights(0.5, 1);
190 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); 187 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1);
191 RunBannerTest("/banners/manifest_test_page.html", 188 RunBannerTest("/banners/manifest_test_page.html",
192 ui::PAGE_TRANSITION_GENERATED, 1, true); 189 ui::PAGE_TRANSITION_GENERATED, 1, true);
193 } 190 }
194 191
195 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 192 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
196 WebAppBannerCreatedIndirect) { 193 WebAppBannerCreatedIndirect) {
197 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 194 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 1,
198 1, true); 195 true);
199 } 196 }
200 197
201 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 198 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
202 WebAppBannerCreatedIndirectLargerTotal) { 199 WebAppBannerCreatedIndirectLargerTotal) {
203 AppBannerSettingsHelper::SetTotalEngagementToTrigger(5); 200 AppBannerSettingsHelper::SetTotalEngagementToTrigger(5);
204 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 201 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 4,
205 4, true); 202 true);
206 } 203 }
207 204
208 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 205 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
209 WebAppBannerCreatedIndirectSmallerTotal) { 206 WebAppBannerCreatedIndirectSmallerTotal) {
210 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1); 207 AppBannerSettingsHelper::SetTotalEngagementToTrigger(1);
211 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 208 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 0,
212 0, true); 209 true);
213 } 210 }
214 211
215 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 212 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
216 WebAppBannerCreatedIndirectSingle) { 213 WebAppBannerCreatedIndirectSingle) {
217 AppBannerSettingsHelper::SetEngagementWeights(1, 3); 214 AppBannerSettingsHelper::SetEngagementWeights(1, 3);
218 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_RELOAD, 215 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_RELOAD,
219 0, true); 216 0, true);
220 } 217 }
221 218
222 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 219 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
223 WebAppBannerCreatedIndirectMultiple) { 220 WebAppBannerCreatedIndirectMultiple) {
224 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); 221 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5);
225 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 222 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 3,
226 3, true); 223 true);
227 } 224 }
228 225
229 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 226 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
230 WebAppBannerCreatedIndirectMultipleLargerTotal) { 227 WebAppBannerCreatedIndirectMultipleLargerTotal) {
231 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); 228 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5);
232 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4); 229 AppBannerSettingsHelper::SetTotalEngagementToTrigger(4);
233 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 230 RunBannerTest("/banners/manifest_test_page.html", ui::PAGE_TRANSITION_LINK, 7,
234 7, true); 231 true);
235 } 232 }
236 233
237 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 234 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
238 WebAppBannerCreatedVarious) { 235 WebAppBannerCreatedVarious) {
239 AppBannerSettingsHelper::SetEngagementWeights(0.5, 0.25); 236 AppBannerSettingsHelper::SetEngagementWeights(0.5, 0.25);
240 237
241 std::string valid_page("/banners/manifest_test_page.html"); 238 std::string valid_page("/banners/manifest_test_page.html");
242 GURL test_url = embedded_test_server()->GetURL(valid_page); 239 GURL test_url = embedded_test_server()->GetURL(valid_page);
243 content::WebContents* web_contents = 240 content::WebContents* web_contents =
244 browser()->tab_strip_model()->GetActiveWebContents(); 241 browser()->tab_strip_model()->GetActiveWebContents();
245 242
243 std::unique_ptr<AppBannerManagerTest> manager(
244 new AppBannerManagerTest(web_contents));
245
246 // Add a direct nav on day 1. 246 // Add a direct nav on day 1.
247 ui_test_utils::NavigateToURL(browser(), test_url); 247 {
248 RunFetcher(web_contents->GetURL(), std::string(), ui::PAGE_TRANSITION_TYPED, 248 base::RunLoop run_loop;
249 false); 249 ui_test_utils::NavigateToURL(browser(), test_url);
250 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(),
251 run_loop, ui::PAGE_TRANSITION_TYPED, false);
252 }
250 253
251 // Add an indirect nav on day 1 which is ignored. 254 // Add an indirect nav on day 1 which is ignored.
252 ui_test_utils::NavigateToURL(browser(), test_url); 255 {
253 RunFetcher(web_contents->GetURL(), std::string(), ui::PAGE_TRANSITION_LINK, 256 base::RunLoop run_loop;
254 false); 257 ui_test_utils::NavigateToURL(browser(), test_url);
255 AppBannerDataFetcher::SetTimeDeltaForTesting(1); 258 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(),
259 run_loop, ui::PAGE_TRANSITION_LINK, false);
260 AppBannerManager::SetTimeDeltaForTesting(1);
261 }
256 262
257 // Add an indirect nav on day 2. 263 // Add an indirect nav on day 2.
258 ui_test_utils::NavigateToURL(browser(), test_url); 264 {
259 RunFetcher(web_contents->GetURL(), std::string(), 265 base::RunLoop run_loop;
260 ui::PAGE_TRANSITION_MANUAL_SUBFRAME, false); 266 ui_test_utils::NavigateToURL(browser(), test_url);
267 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(),
268 run_loop, ui::PAGE_TRANSITION_MANUAL_SUBFRAME, false);
269 }
261 270
262 // Add a direct nav on day 2 which overrides. 271 // Add a direct nav on day 2 which overrides.
263 ui_test_utils::NavigateToURL(browser(), test_url); 272 {
264 RunFetcher(web_contents->GetURL(), std::string(), 273 base::RunLoop run_loop;
265 ui::PAGE_TRANSITION_GENERATED, false); 274 ui_test_utils::NavigateToURL(browser(), test_url);
266 AppBannerDataFetcher::SetTimeDeltaForTesting(2); 275 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(),
276 run_loop, ui::PAGE_TRANSITION_GENERATED, false);
277 AppBannerManager::SetTimeDeltaForTesting(2);
278 }
267 279
268 // Add a direct nav on day 3. 280 // Add a direct nav on day 3.
269 ui_test_utils::NavigateToURL(browser(), test_url); 281 {
270 RunFetcher(web_contents->GetURL(), std::string(), 282 base::RunLoop run_loop;
271 ui::PAGE_TRANSITION_GENERATED, false); 283 ui_test_utils::NavigateToURL(browser(), test_url);
272 AppBannerDataFetcher::SetTimeDeltaForTesting(3); 284 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(),
285 run_loop, ui::PAGE_TRANSITION_GENERATED, false);
286 AppBannerManager::SetTimeDeltaForTesting(3);
287 }
273 288
274 // Add an indirect nav on day 4. 289 // Add an indirect nav on day 4.
275 ui_test_utils::NavigateToURL(browser(), test_url); 290 {
276 RunFetcher(web_contents->GetURL(), std::string(), 291 base::RunLoop run_loop;
277 ui::PAGE_TRANSITION_FORM_SUBMIT, false); 292 ui_test_utils::NavigateToURL(browser(), test_url);
278 293 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(),
294 run_loop, ui::PAGE_TRANSITION_FORM_SUBMIT, false);
295 }
279 // Add a direct nav on day 4 which should trigger the banner. 296 // Add a direct nav on day 4 which should trigger the banner.
280 ui_test_utils::NavigateToURL(browser(), test_url); 297 {
281 RunFetcher(web_contents->GetURL(), std::string(), 298 base::RunLoop run_loop;
282 ui::PAGE_TRANSITION_TYPED, true); 299 ui_test_utils::NavigateToURL(browser(), test_url);
300 RequestAppBanner(manager.get(), web_contents->GetLastCommittedURL(),
301 run_loop, ui::PAGE_TRANSITION_TYPED, true);
302 }
283 } 303 }
284 304
285 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 305 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
286 WebAppBannerNoTypeInManifest) { 306 WebAppBannerNoTypeInManifest) {
287 RunBannerTest("/banners/manifest_no_type_test_page.html", 307 RunBannerTest("/banners/manifest_no_type_test_page.html",
288 ui::PAGE_TRANSITION_TYPED, 1, true); 308 ui::PAGE_TRANSITION_TYPED, 1, true);
289 } 309 }
290 310
291 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, 311 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest,
292 WebAppBannerNoTypeInManifestCapsExtension) { 312 WebAppBannerNoTypeInManifestCapsExtension) {
293 RunBannerTest("/banners/manifest_no_type_caps_test_page.html", 313 RunBannerTest("/banners/manifest_no_type_caps_test_page.html",
294 ui::PAGE_TRANSITION_TYPED, 1, true); 314 ui::PAGE_TRANSITION_TYPED, 1, true);
295 } 315 }
296 316
297 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, PlayAppManifest) { 317 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) {
298 std::string valid_page("/banners/play_app_test_page.html");
299 GURL test_url = embedded_test_server()->GetURL(valid_page);
300 content::WebContents* web_contents =
301 browser()->tab_strip_model()->GetActiveWebContents();
302
303 // Native banners do not require the SW, so we can just load the URL.
304 ui_test_utils::NavigateToURL(browser(), test_url);
305 std::string play_platform("play");
306 RunFetcher(web_contents->GetURL(), play_platform, ui::PAGE_TRANSITION_TYPED,
307 false);
308
309 // The logic to get the details for a play app banner are only on android
310 // builds, so this test does not check that the banner is shown.
311 }
312
313 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, NoManifest) {
314 RunBannerTest("/banners/no_manifest_test_page.html", 318 RunBannerTest("/banners/no_manifest_test_page.html",
315 ui::PAGE_TRANSITION_TYPED, 1, false); 319 ui::PAGE_TRANSITION_TYPED, 1, false);
316 } 320 }
317 321
318 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, MissingManifest) { 322 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, MissingManifest) {
319 RunBannerTest("/banners/manifest_bad_link.html", 323 RunBannerTest("/banners/manifest_bad_link.html", ui::PAGE_TRANSITION_TYPED, 1,
320 ui::PAGE_TRANSITION_TYPED, 1, false); 324 false);
321 } 325 }
322 326
323 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, CancelBannerDirect) { 327 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerDirect) {
324 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, 328 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 1,
325 false); 329 false);
326 } 330 }
327 331
328 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, CancelBannerIndirect) { 332 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, CancelBannerIndirect) {
329 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5); 333 AppBannerSettingsHelper::SetEngagementWeights(1, 0.5);
330 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 3, 334 RunBannerTest("/banners/cancel_test_page.html", ui::PAGE_TRANSITION_TYPED, 3,
331 false); 335 false);
332 } 336 }
333 337
334 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, PromptBanner) { 338 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBanner) {
335 RunBannerTest("/banners/prompt_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, 339 RunBannerTest("/banners/prompt_test_page.html", ui::PAGE_TRANSITION_TYPED, 1,
336 true); 340 true);
337 } 341 }
338 342
339 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, PromptBannerInHandler) { 343 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, PromptBannerInHandler) {
340 RunBannerTest("/banners/prompt_in_handler_test_page.html", 344 RunBannerTest("/banners/prompt_in_handler_test_page.html",
341 ui::PAGE_TRANSITION_TYPED, 1, true); 345 ui::PAGE_TRANSITION_TYPED, 1, true);
342 } 346 }
343 347
344 IN_PROC_BROWSER_TEST_F(AppBannerDataFetcherBrowserTest, WebAppBannerInIFrame) { 348 IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerInIFrame) {
345 RunBannerTest("/banners/iframe_test_page.html", ui::PAGE_TRANSITION_TYPED, 1, 349 RunBannerTest("/banners/iframe_test_page.html", ui::PAGE_TRANSITION_TYPED, 1,
346 false); 350 false);
347 } 351 }
348 352
349 } // namespace banners 353 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_manager.cc ('k') | chrome/browser/banners/app_banner_manager_desktop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698