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

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

Issue 2548903002: [OfflinePages] Classifies PRERENDERING_FAILED cases whether to TryNext (Closed)
Patch Set: Added a PrerenderingLoader unittest Created 4 years 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 PumpLoop(); 236 PumpLoop();
237 EXPECT_TRUE(loader()->IsIdle()); 237 EXPECT_TRUE(loader()->IsIdle());
238 EXPECT_FALSE(loader()->IsLoaded()); 238 EXPECT_FALSE(loader()->IsLoaded());
239 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED, 239 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED,
240 callback_load_status()); 240 callback_load_status());
241 EXPECT_FALSE(test_adapter()->IsActive()); 241 EXPECT_FALSE(test_adapter()->IsActive());
242 } 242 }
243 243
244 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoContent) { 244 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoContent) {
245 test_adapter()->Configure(nullptr /* web_contents */, 245 test_adapter()->Configure(nullptr /* web_contents */,
246 prerender::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); 246 prerender::FINAL_STATUS_CACHE_OR_HISTORY_CLEARED);
247 GURL gurl("http://testit.sea"); 247 GURL gurl("http://testit.sea");
248 EXPECT_TRUE(loader()->IsIdle()); 248 EXPECT_TRUE(loader()->IsIdle());
249 EXPECT_TRUE(loader()->LoadPage( 249 EXPECT_TRUE(loader()->LoadPage(
250 gurl, 250 gurl,
251 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 251 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
252 EXPECT_FALSE(loader()->IsIdle()); 252 EXPECT_FALSE(loader()->IsIdle());
253 EXPECT_FALSE(loader()->IsLoaded()); 253 EXPECT_FALSE(loader()->IsLoaded());
254 254
255 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded(); 255 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
256 PumpLoop(); 256 PumpLoop();
(...skipping 26 matching lines...) Expand all
283 // We did not provide any WebContents for the callback so expect did not load. 283 // We did not provide any WebContents for the callback so expect did not load.
284 // FinalStatus is non-retryable failure. 284 // FinalStatus is non-retryable failure.
285 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY, 285 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY,
286 callback_load_status()); 286 callback_load_status());
287 287
288 // Stopped event causes no harm. 288 // Stopped event causes no harm.
289 test_adapter()->GetObserver()->OnPrerenderStop(); 289 test_adapter()->GetObserver()->OnPrerenderStop();
290 PumpLoop(); 290 PumpLoop();
291 } 291 }
292 292
293 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoNext) {
294 test_adapter()->Configure(nullptr /* web_contents */,
295 prerender::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED);
296 GURL gurl("http://testit.sea");
297 EXPECT_TRUE(loader()->IsIdle());
298 EXPECT_TRUE(loader()->LoadPage(
299 gurl,
300 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
301 EXPECT_FALSE(loader()->IsIdle());
302 EXPECT_FALSE(loader()->IsLoaded());
303
304 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
305 PumpLoop();
306 EXPECT_TRUE(loader()->IsIdle());
307 EXPECT_TRUE(callback_called());
308 // We did not provide any WebContents for the callback so expect did not load.
309 // FinalStatus is non-next failure.
310 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED_NO_NEXT,
311 callback_load_status());
312
313 // Stopped event causes no harm.
314 test_adapter()->GetObserver()->OnPrerenderStop();
315 PumpLoop();
316 }
317
293 TEST_F(PrerenderingLoaderTest, LoadPageLoadCanceled) { 318 TEST_F(PrerenderingLoaderTest, LoadPageLoadCanceled) {
294 test_adapter()->Configure(nullptr /* web_contents */, 319 test_adapter()->Configure(nullptr /* web_contents */,
295 prerender::FINAL_STATUS_CANCELLED); 320 prerender::FINAL_STATUS_CANCELLED);
296 GURL gurl("http://testit.sea"); 321 GURL gurl("http://testit.sea");
297 EXPECT_TRUE(loader()->IsIdle()); 322 EXPECT_TRUE(loader()->IsIdle());
298 EXPECT_TRUE(loader()->LoadPage( 323 EXPECT_TRUE(loader()->LoadPage(
299 gurl, 324 gurl,
300 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 325 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
301 EXPECT_FALSE(loader()->IsIdle()); 326 EXPECT_FALSE(loader()->IsIdle());
302 EXPECT_FALSE(loader()->IsLoaded()); 327 EXPECT_FALSE(loader()->IsLoaded());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 test_adapter()->FailStart(); 408 test_adapter()->FailStart();
384 GURL gurl("http://testit.sea"); 409 GURL gurl("http://testit.sea");
385 EXPECT_TRUE(loader()->IsIdle()); 410 EXPECT_TRUE(loader()->IsIdle());
386 EXPECT_FALSE(loader()->LoadPage( 411 EXPECT_FALSE(loader()->LoadPage(
387 gurl, 412 gurl,
388 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 413 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
389 EXPECT_TRUE(loader()->IsIdle()); 414 EXPECT_TRUE(loader()->IsIdle());
390 } 415 }
391 416
392 } // namespace offline_pages 417 } // 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