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

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_loader_unittest.cc

Issue 2361883002: [Offline Pages] Adds classification of some prerender FinalStatus codes as canceled operations or a… (Closed)
Patch Set: Merge Created 4 years, 2 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 "chrome/browser/android/offline_pages/prerendering_loader.h" 5 #include "chrome/browser/android/offline_pages/prerendering_loader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 10 matching lines...) Expand all
21 // Adapter that intercepts prerender stack calls for testing. 21 // Adapter that intercepts prerender stack calls for testing.
22 class TestAdapter : public PrerenderAdapter { 22 class TestAdapter : public PrerenderAdapter {
23 public: 23 public:
24 explicit TestAdapter(PrerenderAdapter::Observer* observer) 24 explicit TestAdapter(PrerenderAdapter::Observer* observer)
25 : PrerenderAdapter(observer), 25 : PrerenderAdapter(observer),
26 active_(false), 26 active_(false),
27 disabled_(false), 27 disabled_(false),
28 fail_start_(false), 28 fail_start_(false),
29 observer_(observer), 29 observer_(observer),
30 web_contents_(nullptr), 30 web_contents_(nullptr),
31 final_status_(prerender::FinalStatus::FINAL_STATUS_MAX) {} 31 final_status_(prerender::FINAL_STATUS_MAX) {}
32 ~TestAdapter() override {} 32 ~TestAdapter() override {}
33 33
34 // PrerenderAdapter implementation. 34 // PrerenderAdapter implementation.
35 bool CanPrerender() const override; 35 bool CanPrerender() const override;
36 bool StartPrerender( 36 bool StartPrerender(
37 content::BrowserContext* browser_context, 37 content::BrowserContext* browser_context,
38 const GURL& url, 38 const GURL& url,
39 content::SessionStorageNamespace* session_storage_namespace, 39 content::SessionStorageNamespace* session_storage_namespace,
40 const gfx::Size& size) override; 40 const gfx::Size& size) override;
41 content::WebContents* GetWebContents() const override; 41 content::WebContents* GetWebContents() const override;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 TEST_F(PrerenderingLoaderTest, StopLoadingWhenIdle) { 179 TEST_F(PrerenderingLoaderTest, StopLoadingWhenIdle) {
180 EXPECT_TRUE(loader()->IsIdle()); 180 EXPECT_TRUE(loader()->IsIdle());
181 loader()->StopLoading(); 181 loader()->StopLoading();
182 EXPECT_TRUE(loader()->IsIdle()); 182 EXPECT_TRUE(loader()->IsIdle());
183 } 183 }
184 184
185 TEST_F(PrerenderingLoaderTest, LoadPageLoadSucceededFromDomContentLoaded) { 185 TEST_F(PrerenderingLoaderTest, LoadPageLoadSucceededFromDomContentLoaded) {
186 test_adapter()->Configure( 186 test_adapter()->Configure(
187 content::WebContentsTester::CreateTestWebContents(profile(), NULL), 187 content::WebContentsTester::CreateTestWebContents(profile(), NULL),
188 prerender::FinalStatus::FINAL_STATUS_USED); 188 prerender::FINAL_STATUS_USED);
189 GURL gurl("http://testit.sea"); 189 GURL gurl("http://testit.sea");
190 EXPECT_TRUE(loader()->IsIdle()); 190 EXPECT_TRUE(loader()->IsIdle());
191 EXPECT_FALSE(loader()->IsLoaded()); 191 EXPECT_FALSE(loader()->IsLoaded());
192 EXPECT_TRUE(loader()->LoadPage( 192 EXPECT_TRUE(loader()->LoadPage(
193 gurl, 193 gurl,
194 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 194 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
195 195
196 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded(); 196 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
197 // Skip SnapshotController's wait time and emulate StartSnapshot call. 197 // Skip SnapshotController's wait time and emulate StartSnapshot call.
198 loader()->StartSnapshot(); 198 loader()->StartSnapshot();
199 PumpLoop(); 199 PumpLoop();
200 EXPECT_FALSE(loader()->IsIdle()); 200 EXPECT_FALSE(loader()->IsIdle());
201 EXPECT_TRUE(loader()->IsLoaded()); 201 EXPECT_TRUE(loader()->IsLoaded());
202 EXPECT_TRUE(callback_called()); 202 EXPECT_TRUE(callback_called());
203 EXPECT_EQ(Offliner::RequestStatus::LOADED, callback_load_status()); 203 EXPECT_EQ(Offliner::RequestStatus::LOADED, callback_load_status());
204 204
205 loader()->StopLoading(); 205 loader()->StopLoading();
206 EXPECT_TRUE(loader()->IsIdle()); 206 EXPECT_TRUE(loader()->IsIdle());
207 EXPECT_FALSE(loader()->IsLoaded()); 207 EXPECT_FALSE(loader()->IsLoaded());
208 } 208 }
209 209
210 TEST_F(PrerenderingLoaderTest, LoadPageLoadSucceededFromPrerenderStopLoading) { 210 TEST_F(PrerenderingLoaderTest, LoadPageLoadSucceededFromPrerenderStopLoading) {
211 test_adapter()->Configure( 211 test_adapter()->Configure(
212 content::WebContentsTester::CreateTestWebContents(profile(), NULL), 212 content::WebContentsTester::CreateTestWebContents(profile(), NULL),
213 prerender::FinalStatus::FINAL_STATUS_USED); 213 prerender::FINAL_STATUS_USED);
214 GURL gurl("http://testit.sea"); 214 GURL gurl("http://testit.sea");
215 EXPECT_TRUE(loader()->IsIdle()); 215 EXPECT_TRUE(loader()->IsIdle());
216 EXPECT_FALSE(loader()->IsLoaded()); 216 EXPECT_FALSE(loader()->IsLoaded());
217 EXPECT_TRUE(loader()->LoadPage( 217 EXPECT_TRUE(loader()->LoadPage(
218 gurl, 218 gurl,
219 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 219 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
220 220
221 PumpLoop(); 221 PumpLoop();
222 EXPECT_FALSE(loader()->IsIdle()); 222 EXPECT_FALSE(loader()->IsIdle());
223 EXPECT_FALSE(loader()->IsLoaded()); 223 EXPECT_FALSE(loader()->IsLoaded());
224 224
225 test_adapter()->GetObserver()->OnPrerenderStopLoading(); 225 test_adapter()->GetObserver()->OnPrerenderStopLoading();
226 PumpLoop(); 226 PumpLoop();
227 EXPECT_FALSE(loader()->IsIdle()); 227 EXPECT_FALSE(loader()->IsIdle());
228 EXPECT_TRUE(loader()->IsLoaded()); 228 EXPECT_TRUE(loader()->IsLoaded());
229 EXPECT_TRUE(callback_called()); 229 EXPECT_TRUE(callback_called());
230 EXPECT_EQ(Offliner::RequestStatus::LOADED, callback_load_status()); 230 EXPECT_EQ(Offliner::RequestStatus::LOADED, callback_load_status());
231 231
232 // Consider Prerenderer stops (eg, times out) before Loader is done with it. 232 // Consider Prerenderer stops (eg, times out) before Loader is done with it.
233 test_adapter()->GetObserver()->OnPrerenderStop(); 233 test_adapter()->GetObserver()->OnPrerenderStop();
234 PumpLoop(); 234 PumpLoop();
235 EXPECT_TRUE(loader()->IsIdle()); 235 EXPECT_TRUE(loader()->IsIdle());
236 EXPECT_FALSE(loader()->IsLoaded()); 236 EXPECT_FALSE(loader()->IsLoaded());
237 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED, 237 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED,
238 callback_load_status()); 238 callback_load_status());
239 } 239 }
240 240
241 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoContent) { 241 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoContent) {
242 test_adapter()->Configure( 242 test_adapter()->Configure(nullptr /* web_contents */,
243 nullptr /* web_contents */, 243 prerender::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED);
244 prerender::FinalStatus::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED);
245 GURL gurl("http://testit.sea"); 244 GURL gurl("http://testit.sea");
246 EXPECT_TRUE(loader()->IsIdle()); 245 EXPECT_TRUE(loader()->IsIdle());
247 EXPECT_TRUE(loader()->LoadPage( 246 EXPECT_TRUE(loader()->LoadPage(
248 gurl, 247 gurl,
249 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 248 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
250 EXPECT_FALSE(loader()->IsIdle()); 249 EXPECT_FALSE(loader()->IsIdle());
251 EXPECT_FALSE(loader()->IsLoaded()); 250 EXPECT_FALSE(loader()->IsLoaded());
252 251
253 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded(); 252 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
254 PumpLoop(); 253 PumpLoop();
255 EXPECT_TRUE(loader()->IsIdle()); 254 EXPECT_TRUE(loader()->IsIdle());
256 EXPECT_TRUE(callback_called()); 255 EXPECT_TRUE(callback_called());
257 // We did not provide any WebContents for the callback so expect did not load. 256 // We did not provide any WebContents for the callback so expect did not load.
258 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED, 257 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED,
259 callback_load_status()); 258 callback_load_status());
260 259
261 // Stopped event causes no harm. 260 // Stopped event causes no harm.
262 test_adapter()->GetObserver()->OnPrerenderStop(); 261 test_adapter()->GetObserver()->OnPrerenderStop();
263 PumpLoop(); 262 PumpLoop();
264 } 263 }
265 264
265 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoRetry) {
266 test_adapter()->Configure(nullptr /* web_contents */,
267 prerender::FINAL_STATUS_SAFE_BROWSING);
268 GURL gurl("http://testit.sea");
269 EXPECT_TRUE(loader()->IsIdle());
270 EXPECT_TRUE(loader()->LoadPage(
271 gurl,
272 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
273 EXPECT_FALSE(loader()->IsIdle());
274 EXPECT_FALSE(loader()->IsLoaded());
275
276 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
277 PumpLoop();
278 EXPECT_TRUE(loader()->IsIdle());
279 EXPECT_TRUE(callback_called());
280 // We did not provide any WebContents for the callback so expect did not load.
281 // FinalStatus is non-retryable failure.
282 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY,
283 callback_load_status());
284
285 // Stopped event causes no harm.
286 test_adapter()->GetObserver()->OnPrerenderStop();
287 PumpLoop();
288 }
289
290 TEST_F(PrerenderingLoaderTest, LoadPageLoadCanceled) {
291 test_adapter()->Configure(nullptr /* web_contents */,
292 prerender::FINAL_STATUS_CANCELLED);
293 GURL gurl("http://testit.sea");
294 EXPECT_TRUE(loader()->IsIdle());
295 EXPECT_TRUE(loader()->LoadPage(
296 gurl,
297 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
298 EXPECT_FALSE(loader()->IsIdle());
299 EXPECT_FALSE(loader()->IsLoaded());
300
301 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
302 PumpLoop();
303 EXPECT_TRUE(loader()->IsIdle());
304 EXPECT_TRUE(callback_called());
305 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED,
306 callback_load_status());
307
308 // Stopped event causes no harm.
309 test_adapter()->GetObserver()->OnPrerenderStop();
310 PumpLoop();
311 }
312
266 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedUnsupportedScheme) { 313 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedUnsupportedScheme) {
267 test_adapter()->Configure( 314 test_adapter()->Configure(nullptr /* web_contents */,
268 nullptr /* web_contents */, 315 prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
269 prerender::FinalStatus::FINAL_STATUS_UNSUPPORTED_SCHEME);
270 GURL gurl("http://testit.sea"); 316 GURL gurl("http://testit.sea");
271 EXPECT_TRUE(loader()->IsIdle()); 317 EXPECT_TRUE(loader()->IsIdle());
272 EXPECT_TRUE(loader()->LoadPage( 318 EXPECT_TRUE(loader()->LoadPage(
273 gurl, 319 gurl,
274 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 320 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
275 EXPECT_FALSE(loader()->IsIdle()); 321 EXPECT_FALSE(loader()->IsIdle());
276 EXPECT_FALSE(loader()->IsLoaded()); 322 EXPECT_FALSE(loader()->IsLoaded());
277 323
278 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded(); 324 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
279 PumpLoop(); 325 PumpLoop();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 test_adapter()->FailStart(); 380 test_adapter()->FailStart();
335 GURL gurl("http://testit.sea"); 381 GURL gurl("http://testit.sea");
336 EXPECT_TRUE(loader()->IsIdle()); 382 EXPECT_TRUE(loader()->IsIdle());
337 EXPECT_FALSE(loader()->LoadPage( 383 EXPECT_FALSE(loader()->LoadPage(
338 gurl, 384 gurl,
339 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 385 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
340 EXPECT_TRUE(loader()->IsIdle()); 386 EXPECT_TRUE(loader()->IsIdle());
341 } 387 }
342 388
343 } // namespace offline_pages 389 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/prerendering_loader.cc ('k') | components/offline_pages/background/offliner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698