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

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

Issue 2104393002: Adds UMA for PrerenderingOffliner request processing result status. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds note about interim offliner status codes and performs DCHECK that offliner does not return the… Created 4 years, 5 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 EXPECT_FALSE(loader()->IsIdle()); 216 EXPECT_FALSE(loader()->IsIdle());
217 EXPECT_TRUE(loader()->IsLoaded()); 217 EXPECT_TRUE(loader()->IsLoaded());
218 EXPECT_TRUE(callback_called()); 218 EXPECT_TRUE(callback_called());
219 EXPECT_EQ(Offliner::RequestStatus::LOADED, callback_load_status()); 219 EXPECT_EQ(Offliner::RequestStatus::LOADED, callback_load_status());
220 220
221 // Consider Prerenderer stops (eg, times out) before Loader is done with it. 221 // Consider Prerenderer stops (eg, times out) before Loader is done with it.
222 test_adapter()->GetObserver()->OnPrerenderStop(); 222 test_adapter()->GetObserver()->OnPrerenderStop();
223 PumpLoop(); 223 PumpLoop();
224 EXPECT_TRUE(loader()->IsIdle()); 224 EXPECT_TRUE(loader()->IsIdle());
225 EXPECT_FALSE(loader()->IsLoaded()); 225 EXPECT_FALSE(loader()->IsLoaded());
226 EXPECT_EQ(Offliner::RequestStatus::CANCELED, callback_load_status()); 226 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED,
227 callback_load_status());
227 } 228 }
228 229
229 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoContent) { 230 TEST_F(PrerenderingLoaderTest, LoadPageLoadFailedNoContent) {
230 test_adapter()->Configure( 231 test_adapter()->Configure(
231 nullptr /* web_contents */, 232 nullptr /* web_contents */,
232 prerender::FinalStatus::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); 233 prerender::FinalStatus::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED);
233 GURL gurl("http://testit.sea"); 234 GURL gurl("http://testit.sea");
234 EXPECT_TRUE(loader()->IsIdle()); 235 EXPECT_TRUE(loader()->IsIdle());
235 EXPECT_TRUE(loader()->LoadPage( 236 EXPECT_TRUE(loader()->LoadPage(
236 gurl, 237 gurl,
237 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 238 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
238 EXPECT_FALSE(loader()->IsIdle()); 239 EXPECT_FALSE(loader()->IsIdle());
239 EXPECT_FALSE(loader()->IsLoaded()); 240 EXPECT_FALSE(loader()->IsLoaded());
240 241
241 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded(); 242 test_adapter()->GetObserver()->OnPrerenderDomContentLoaded();
242 PumpLoop(); 243 PumpLoop();
243 EXPECT_TRUE(loader()->IsIdle()); 244 EXPECT_TRUE(loader()->IsIdle());
244 EXPECT_TRUE(callback_called()); 245 EXPECT_TRUE(callback_called());
245 // We did not provide any WebContents for the callback so expect did not load. 246 // We did not provide any WebContents for the callback so expect did not load.
246 EXPECT_EQ(Offliner::RequestStatus::FAILED, callback_load_status()); 247 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED,
248 callback_load_status());
247 249
248 // Stopped event causes no harm. 250 // Stopped event causes no harm.
249 test_adapter()->GetObserver()->OnPrerenderStop(); 251 test_adapter()->GetObserver()->OnPrerenderStop();
250 PumpLoop(); 252 PumpLoop();
251 } 253 }
252 254
253 TEST_F(PrerenderingLoaderTest, LoadPageLoadCanceledFromStopLoading) { 255 TEST_F(PrerenderingLoaderTest, LoadPageLoadCanceledFromStopLoading) {
254 GURL gurl("http://testit.sea"); 256 GURL gurl("http://testit.sea");
255 EXPECT_TRUE(loader()->IsIdle()); 257 EXPECT_TRUE(loader()->IsIdle());
256 EXPECT_TRUE(loader()->LoadPage( 258 EXPECT_TRUE(loader()->LoadPage(
257 gurl, 259 gurl,
258 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 260 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
259 EXPECT_FALSE(loader()->IsIdle()); 261 EXPECT_FALSE(loader()->IsIdle());
260 EXPECT_FALSE(loader()->IsLoaded()); 262 EXPECT_FALSE(loader()->IsLoaded());
261 263
262 loader()->StopLoading(); 264 loader()->StopLoading();
263 PumpLoop(); 265 PumpLoop();
264 EXPECT_TRUE(loader()->IsIdle()); 266 EXPECT_TRUE(loader()->IsIdle());
265 EXPECT_TRUE(callback_called()); 267 EXPECT_FALSE(callback_called());
266 EXPECT_EQ(Offliner::RequestStatus::CANCELED, callback_load_status());
267 } 268 }
268 269
269 TEST_F(PrerenderingLoaderTest, LoadPageNotAcceptedWhenNotIdle) { 270 TEST_F(PrerenderingLoaderTest, LoadPageNotAcceptedWhenNotIdle) {
270 GURL gurl("http://testit.sea"); 271 GURL gurl("http://testit.sea");
271 EXPECT_TRUE(loader()->IsIdle()); 272 EXPECT_TRUE(loader()->IsIdle());
272 EXPECT_TRUE(loader()->LoadPage( 273 EXPECT_TRUE(loader()->LoadPage(
273 gurl, 274 gurl,
274 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 275 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
275 EXPECT_FALSE(loader()->IsIdle()); 276 EXPECT_FALSE(loader()->IsIdle());
276 EXPECT_FALSE(loader()->IsLoaded()); 277 EXPECT_FALSE(loader()->IsLoaded());
277 278
278 // Now try another load while first is still active. 279 // Now try another load while first is still active.
279 EXPECT_FALSE(loader()->LoadPage( 280 EXPECT_FALSE(loader()->LoadPage(
280 gurl, 281 gurl,
281 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 282 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
282 EXPECT_FALSE(loader()->IsIdle()); 283 EXPECT_FALSE(loader()->IsIdle());
283 } 284 }
284 285
285 TEST_F(PrerenderingLoaderTest, LoadPageNotAcceptedWhenPrerenderingDisabled) { 286 TEST_F(PrerenderingLoaderTest, LoadPageNotAcceptedWhenPrerenderingDisabled) {
286 test_adapter()->Disable(); 287 test_adapter()->Disable();
287 GURL gurl("http://testit.sea"); 288 GURL gurl("http://testit.sea");
288 EXPECT_TRUE(loader()->IsIdle()); 289 EXPECT_TRUE(loader()->IsIdle());
289 EXPECT_FALSE(loader()->LoadPage( 290 EXPECT_FALSE(loader()->LoadPage(
290 gurl, 291 gurl,
291 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this)))); 292 base::Bind(&PrerenderingLoaderTest::OnLoadDone, base::Unretained(this))));
292 EXPECT_TRUE(loader()->IsIdle()); 293 EXPECT_TRUE(loader()->IsIdle());
293 } 294 }
294 295
295 } // namespace offline_pages 296 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698