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

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

Issue 2566453002: [OfflinePages] Rename PRERENDERING_* result terminology to LOADING_* (Closed)
Patch Set: Updated histogram enum 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_offliner.h" 5 #include "chrome/browser/android/offline_pages/prerendering_offliner.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 bool CanPrerender() override { return can_prerender_; } 56 bool CanPrerender() override { return can_prerender_; }
57 bool IsIdle() override { return !mock_loading_ && !mock_loaded_; } 57 bool IsIdle() override { return !mock_loading_ && !mock_loaded_; }
58 bool IsLoaded() override { return mock_loaded_; } 58 bool IsLoaded() override { return mock_loaded_; }
59 59
60 void CompleteLoadingAsFailed() { 60 void CompleteLoadingAsFailed() {
61 DCHECK(mock_loading_); 61 DCHECK(mock_loading_);
62 mock_loading_ = false; 62 mock_loading_ = false;
63 mock_loaded_ = false; 63 mock_loaded_ = false;
64 base::ThreadTaskRunnerHandle::Get()->PostTask( 64 base::ThreadTaskRunnerHandle::Get()->PostTask(
65 FROM_HERE, base::Bind(load_page_callback_, 65 FROM_HERE,
66 Offliner::RequestStatus::PRERENDERING_FAILED, 66 base::Bind(load_page_callback_, Offliner::RequestStatus::LOADING_FAILED,
67 nullptr /* web_contents */)); 67 nullptr /* web_contents */));
68 } 68 }
69 69
70 void CompleteLoadingAsLoaded() { 70 void CompleteLoadingAsLoaded() {
71 DCHECK(mock_loading_); 71 DCHECK(mock_loading_);
72 mock_loading_ = false; 72 mock_loading_ = false;
73 mock_loaded_ = true; 73 mock_loaded_ = true;
74 base::ThreadTaskRunnerHandle::Get()->PostTask( 74 base::ThreadTaskRunnerHandle::Get()->PostTask(
75 FROM_HERE, 75 FROM_HERE,
76 base::Bind(load_page_callback_, Offliner::RequestStatus::LOADED, 76 base::Bind(load_page_callback_, Offliner::RequestStatus::LOADED,
77 content::WebContentsTester::CreateTestWebContents( 77 content::WebContentsTester::CreateTestWebContents(
78 new TestingProfile(), NULL))); 78 new TestingProfile(), NULL)));
79 } 79 }
80 80
81 void CompleteLoadingAsCanceled() { 81 void CompleteLoadingAsCanceled() {
82 DCHECK(!IsIdle()); 82 DCHECK(!IsIdle());
83 mock_loading_ = false; 83 mock_loading_ = false;
84 mock_loaded_ = false; 84 mock_loaded_ = false;
85 base::ThreadTaskRunnerHandle::Get()->PostTask( 85 base::ThreadTaskRunnerHandle::Get()->PostTask(
86 FROM_HERE, base::Bind(load_page_callback_, 86 FROM_HERE, base::Bind(load_page_callback_,
87 Offliner::RequestStatus::PRERENDERING_CANCELED, 87 Offliner::RequestStatus::LOADING_CANCELED,
88 nullptr /* web_contents */)); 88 nullptr /* web_contents */));
89 } 89 }
90 90
91 void DisablePrerendering() { can_prerender_ = false; } 91 void DisablePrerendering() { can_prerender_ = false; }
92 const LoadPageCallback& load_page_callback() { return load_page_callback_; } 92 const LoadPageCallback& load_page_callback() { return load_page_callback_; }
93 93
94 private: 94 private:
95 bool can_prerender_; 95 bool can_prerender_;
96 bool mock_loading_; 96 bool mock_loading_;
97 bool mock_loaded_; 97 bool mock_loaded_;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 base::Time creation_time = base::Time::Now(); 248 base::Time creation_time = base::Time::Now();
249 SavePageRequest request( 249 SavePageRequest request(
250 kRequestId, kHttpUrl, kClientId, creation_time, kUserRequested); 250 kRequestId, kHttpUrl, kClientId, creation_time, kUserRequested);
251 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); 251 EXPECT_TRUE(offliner()->LoadAndSave(request, callback()));
252 EXPECT_FALSE(loader()->IsIdle()); 252 EXPECT_FALSE(loader()->IsIdle());
253 EXPECT_EQ(Offliner::RequestStatus::UNKNOWN, request_status()); 253 EXPECT_EQ(Offliner::RequestStatus::UNKNOWN, request_status());
254 254
255 loader()->CompleteLoadingAsFailed(); 255 loader()->CompleteLoadingAsFailed();
256 PumpLoop(); 256 PumpLoop();
257 EXPECT_TRUE(completion_callback_called()); 257 EXPECT_TRUE(completion_callback_called());
258 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_FAILED, request_status()); 258 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED, request_status());
259 EXPECT_TRUE(loader()->IsIdle()); 259 EXPECT_TRUE(loader()->IsIdle());
260 EXPECT_FALSE(SaveInProgress()); 260 EXPECT_FALSE(SaveInProgress());
261 } 261 }
262 262
263 TEST_F(PrerenderingOfflinerTest, CancelWhenLoading) { 263 TEST_F(PrerenderingOfflinerTest, CancelWhenLoading) {
264 base::Time creation_time = base::Time::Now(); 264 base::Time creation_time = base::Time::Now();
265 SavePageRequest request( 265 SavePageRequest request(
266 kRequestId, kHttpUrl, kClientId, creation_time, kUserRequested); 266 kRequestId, kHttpUrl, kClientId, creation_time, kUserRequested);
267 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); 267 EXPECT_TRUE(offliner()->LoadAndSave(request, callback()));
268 EXPECT_FALSE(loader()->IsIdle()); 268 EXPECT_FALSE(loader()->IsIdle());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 354
355 loader()->CompleteLoadingAsLoaded(); 355 loader()->CompleteLoadingAsLoaded();
356 PumpLoop(); 356 PumpLoop();
357 EXPECT_FALSE(completion_callback_called()); 357 EXPECT_FALSE(completion_callback_called());
358 EXPECT_TRUE(loader()->IsLoaded()); 358 EXPECT_TRUE(loader()->IsLoaded());
359 EXPECT_TRUE(SaveInProgress()); 359 EXPECT_TRUE(SaveInProgress());
360 360
361 loader()->CompleteLoadingAsCanceled(); 361 loader()->CompleteLoadingAsCanceled();
362 PumpLoop(); 362 PumpLoop();
363 EXPECT_TRUE(completion_callback_called()); 363 EXPECT_TRUE(completion_callback_called());
364 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED, request_status()); 364 EXPECT_EQ(Offliner::RequestStatus::LOADING_CANCELED, request_status());
365 EXPECT_FALSE(loader()->IsLoaded()); 365 EXPECT_FALSE(loader()->IsLoaded());
366 // Note: save still in progress since it does not support canceling. 366 // Note: save still in progress since it does not support canceling.
367 EXPECT_TRUE(SaveInProgress()); 367 EXPECT_TRUE(SaveInProgress());
368 } 368 }
369 369
370 TEST_F(PrerenderingOfflinerTest, ForegroundTransitionCancelsOnLowEndDevice) { 370 TEST_F(PrerenderingOfflinerTest, ForegroundTransitionCancelsOnLowEndDevice) {
371 offliner()->SetLowEndDeviceForTesting(true); 371 offliner()->SetLowEndDeviceForTesting(true);
372 372
373 base::Time creation_time = base::Time::Now(); 373 base::Time creation_time = base::Time::Now();
374 SavePageRequest request( 374 SavePageRequest request(
(...skipping 19 matching lines...) Expand all
394 EXPECT_FALSE(loader()->IsIdle()); 394 EXPECT_FALSE(loader()->IsIdle());
395 395
396 offliner()->SetApplicationStateForTesting( 396 offliner()->SetApplicationStateForTesting(
397 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); 397 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES);
398 398
399 // Loader still loading since not low-end device. 399 // Loader still loading since not low-end device.
400 EXPECT_FALSE(loader()->IsIdle()); 400 EXPECT_FALSE(loader()->IsIdle());
401 } 401 }
402 402
403 } // namespace offline_pages 403 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698