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

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: Fixed a comment Created 4 years, 3 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 test_adapter()->GetObserver()->OnPrerenderStart(); 221 test_adapter()->GetObserver()->OnPrerenderStart();
222 PumpLoop(); 222 PumpLoop();
223 EXPECT_FALSE(loader()->IsIdle()); 223 EXPECT_FALSE(loader()->IsIdle());
224 EXPECT_FALSE(loader()->IsLoaded()); 224 EXPECT_FALSE(loader()->IsLoaded());
225 225
226 test_adapter()->GetObserver()->OnPrerenderStopLoading(); 226 test_adapter()->GetObserver()->OnPrerenderStopLoading();
227 PumpLoop(); 227 PumpLoop();
228 EXPECT_FALSE(loader()->IsIdle()); 228 EXPECT_FALSE(loader()->IsIdle());
229 EXPECT_TRUE(loader()->IsLoaded()); 229 EXPECT_TRUE(loader()->IsLoaded());
230 EXPECT_TRUE(callback_called()); 230 EXPECT_TRUE(callback_called());
231 EXPECT_EQ(Offliner::RequestStatus::LOADED, callback_load_status()); 231 EXPECT_EQ(Offliner::RequestStatus::LOADED, callback_load_status());
232 232
233 // Consider Prerenderer stops (eg, times out) before Loader is done with it. 233 // Consider Prerenderer stops (eg, times out) before Loader is done with it.
234 test_adapter()->GetObserver()->OnPrerenderStop(); 234 test_adapter()->GetObserver()->OnPrerenderStop();
235 PumpLoop(); 235 PumpLoop();
236 EXPECT_TRUE(loader()->IsIdle()); 236 EXPECT_TRUE(loader()->IsIdle());
237 EXPECT_FALSE(loader()->IsLoaded()); 237 EXPECT_FALSE(loader()->IsLoaded());
238 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED, 238 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED,
239 callback_load_status()); 239 callback_load_status());
240 } 240 }
241 241
242 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoContent) { 242 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoContent) {
243 test_adapter()->Configure( 243 test_adapter()->Configure(nullptr /* web_contents */,
244 nullptr /* web_contents */, 244 prerender::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED);
245 prerender::FinalStatus::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED);
246 GURL gurl("http://testit.sea"); 245 GURL gurl("http://testit.sea");
247 EXPECT_TRUE(loader()->IsIdle()); 246 EXPECT_TRUE(loader()->IsIdle());
248 EXPECT_TRUE(loader()->LoadPage( 247 EXPECT_TRUE(loader()->LoadPage(
249 gurl, 248 gurl,
250 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 249 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
251 EXPECT_FALSE(loader()->IsIdle()); 250 EXPECT_FALSE(loader()->IsIdle());
252 EXPECT_FALSE(loader()->IsLoaded()); 251 EXPECT_FALSE(loader()->IsLoaded());
253 252
254 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded(); 253 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
255 PumpLoop(); 254 PumpLoop();
256 EXPECT_TRUE(loader()->IsIdle()); 255 EXPECT_TRUE(loader()->IsIdle());
257 EXPECT_TRUE(callback_called()); 256 EXPECT_TRUE(callback_called());
258 // We did not provide any WebContents for the callback so expect did not load. 257 // We did not provide any WebContents for the callback so expect did not load.
259 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED, 258 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED,
260 callback_load_status()); 259 callback_load_status());
261 260
262 // Stopped event causes no harm. 261 // Stopped event causes no harm.
263 test_adapter()->GetObserver()->OnPrerenderStop(); 262 test_adapter()->GetObserver()->OnPrerenderStop();
264 PumpLoop(); 263 PumpLoop();
265 } 264 }
266 265
266 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoRetry) {
267 test_adapter()->Configure(nullptr /* web_contents */,
268 prerender::FINAL_STATUS_SAFE_BROWSING);
269 GURL gurl("http://testit.sea");
270 EXPECT_TRUE(loader()->IsIdle());
271 EXPECT_TRUE(loader()->LoadPage(
272 gurl,
273 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
274 EXPECT_FALSE(loader()->IsIdle());
275 EXPECT_FALSE(loader()->IsLoaded());
276
277 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
278 PumpLoop();
279 EXPECT_TRUE(loader()->IsIdle());
280 EXPECT_TRUE(callback_called());
281 // We did not provide any WebContents for the callback so expect did not load.
282 // FinalStatus is non-retryable failure.
283 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY,
284 callback_load_status());
285
286 // Stopped event causes no harm.
287 test_adapter()->GetObserver()->OnPrerenderStop();
288 PumpLoop();
289 }
290
291 TEST_F(PrerenderingLoaderTest, LoadPageLoadCanceled) {
292 test_adapter()->Configure(nullptr /* web_contents */,
293 prerender::FINAL_STATUS_CANCELLED);
294 GURL gurl("http://testit.sea");
295 EXPECT_TRUE(loader()->IsIdle());
296 EXPECT_TRUE(loader()->LoadPage(
297 gurl,
298 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
299 EXPECT_FALSE(loader()->IsIdle());
300 EXPECT_FALSE(loader()->IsLoaded());
301
302 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
303 PumpLoop();
304 EXPECT_TRUE(loader()->IsIdle());
305 EXPECT_TRUE(callback_called());
306 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED,
307 callback_load_status());
308
309 // Stopped event causes no harm.
310 test_adapter()->GetObserver()->OnPrerenderStop();
311 PumpLoop();
312 }
313
267 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedUnsupportedScheme) { 314 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedUnsupportedScheme) {
268 test_adapter()->Configure( 315 test_adapter()->Configure(nullptr /* web_contents */,
269 nullptr /* web_contents */, 316 prerender::FINAL_STATUS_UNSUPPORTED_SCHEME);
270 prerender::FinalStatus::FINAL_STATUS_UNSUPPORTED_SCHEME);
271 GURL gurl("http://testit.sea"); 317 GURL gurl("http://testit.sea");
272 EXPECT_TRUE(loader()->IsIdle()); 318 EXPECT_TRUE(loader()->IsIdle());
273 EXPECT_TRUE(loader()->LoadPage( 319 EXPECT_TRUE(loader()->LoadPage(
274 gurl, 320 gurl,
275 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 321 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
276 EXPECT_FALSE(loader()->IsIdle()); 322 EXPECT_FALSE(loader()->IsIdle());
277 EXPECT_FALSE(loader()->IsLoaded()); 323 EXPECT_FALSE(loader()->IsLoaded());
278 324
279 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded(); 325 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
280 PumpLoop(); 326 PumpLoop();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 test_adapter()->FailStart(); 381 test_adapter()->FailStart();
336 GURL gurl("http://testit.sea"); 382 GURL gurl("http://testit.sea");
337 EXPECT_TRUE(loader()->IsIdle()); 383 EXPECT_TRUE(loader()->IsIdle());
338 EXPECT_FALSE(loader()->LoadPage( 384 EXPECT_FALSE(loader()->LoadPage(
339 gurl, 385 gurl,
340 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 386 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
341 EXPECT_TRUE(loader()->IsIdle()); 387 EXPECT_TRUE(loader()->IsIdle());
342 } 388 }
343 389
344 } // namespace offline_pages 390 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698