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

Unified Diff: components/offline_pages/core/background/request_coordinator_unittest.cc

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: update Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/core/background/request_coordinator_unittest.cc
diff --git a/components/offline_pages/background/request_coordinator_unittest.cc b/components/offline_pages/core/background/request_coordinator_unittest.cc
similarity index 91%
rename from components/offline_pages/background/request_coordinator_unittest.cc
rename to components/offline_pages/core/background/request_coordinator_unittest.cc
index 4eb8a8268ecc55dc79cec33d37e453bd8290e990..dcc701104ae2b4c913bd813ee07690d010a309d2 100644
--- a/components/offline_pages/background/request_coordinator_unittest.cc
+++ b/components/offline_pages/core/background/request_coordinator_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/offline_pages/background/request_coordinator.h"
+#include "components/offline_pages/core/background/request_coordinator.h"
#include <memory>
#include <string>
@@ -18,16 +18,16 @@
#include "base/test/test_mock_time_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
-#include "components/offline_pages/background/device_conditions.h"
-#include "components/offline_pages/background/offliner.h"
-#include "components/offline_pages/background/offliner_factory.h"
-#include "components/offline_pages/background/offliner_policy.h"
-#include "components/offline_pages/background/pick_request_task_factory.h"
-#include "components/offline_pages/background/request_queue.h"
-#include "components/offline_pages/background/request_queue_in_memory_store.h"
-#include "components/offline_pages/background/save_page_request.h"
-#include "components/offline_pages/background/scheduler.h"
-#include "components/offline_pages/offline_page_feature.h"
+#include "components/offline_pages/core/background/device_conditions.h"
+#include "components/offline_pages/core/background/offliner.h"
+#include "components/offline_pages/core/background/offliner_factory.h"
+#include "components/offline_pages/core/background/offliner_policy.h"
+#include "components/offline_pages/core/background/pick_request_task_factory.h"
+#include "components/offline_pages/core/background/request_queue.h"
+#include "components/offline_pages/core/background/request_queue_in_memory_store.h"
+#include "components/offline_pages/core/background/save_page_request.h"
+#include "components/offline_pages/core/background/scheduler.h"
+#include "components/offline_pages/core/offline_page_feature.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace offline_pages {
@@ -73,13 +73,11 @@ class SchedulerStub : public Scheduler {
}
// Unschedules the currently scheduled task, if any.
- void Unschedule() override {
- unschedule_called_ = true;
- }
+ void Unschedule() override { unschedule_called_ = true; }
bool schedule_called() const { return schedule_called_; }
- bool backup_schedule_called() const { return backup_schedule_called_;}
+ bool backup_schedule_called() const { return backup_schedule_called_; }
bool unschedule_called() const { return unschedule_called_; }
@@ -96,7 +94,10 @@ class SchedulerStub : public Scheduler {
class OfflinerStub : public Offliner {
public:
OfflinerStub()
- : request_(kRequestId1, kUrl1, kClientId1, base::Time::Now(),
+ : request_(kRequestId1,
+ kUrl1,
+ kClientId1,
+ base::Time::Now(),
kUserRequested),
disable_loading_(false),
enable_callback_(false),
@@ -120,13 +121,9 @@ class OfflinerStub : public Offliner {
void Cancel() override { cancel_called_ = true; }
- void disable_loading() {
- disable_loading_ = true;
- }
+ void disable_loading() { disable_loading_ = true; }
- void enable_callback(bool enable) {
- enable_callback_ = enable;
- }
+ void enable_callback(bool enable) { enable_callback_ = enable; }
bool cancel_called() { return cancel_called_; }
@@ -229,8 +226,7 @@ class ObserverStub : public RequestCoordinator::Observer {
SavePageRequest::RequestState state_;
};
-class RequestCoordinatorTest
- : public testing::Test {
+class RequestCoordinatorTest : public testing::Test {
public:
RequestCoordinatorTest();
~RequestCoordinatorTest() override;
@@ -239,13 +235,9 @@ class RequestCoordinatorTest
void PumpLoop();
- RequestCoordinator* coordinator() {
- return coordinator_.get();
- }
+ RequestCoordinator* coordinator() { return coordinator_.get(); }
- bool is_busy() {
- return coordinator_->is_busy();
- }
+ bool is_busy() { return coordinator_->is_busy(); }
bool is_starting() { return coordinator_->is_starting(); }
@@ -256,9 +248,7 @@ class RequestCoordinatorTest
}
// Callback function which releases a wait for it.
- void WaitingCallbackFunction(bool result) {
- waiter_.Signal();
- }
+ void WaitingCallbackFunction(bool result) { waiter_.Signal(); }
net::NetworkChangeNotifier::ConnectionType GetConnectionType() {
return coordinator()->GetConnectionType();
@@ -296,9 +286,7 @@ class RequestCoordinatorTest
return last_remove_results_;
}
- void DisableLoading() {
- offliner_->disable_loading();
- }
+ void DisableLoading() { offliner_->disable_loading(); }
void EnableOfflinerCallback(bool enable) {
offliner_->enable_callback(enable);
@@ -356,9 +344,7 @@ class RequestCoordinatorTest
coordinator_->SetDeviceConditionsForTest(device_conditions);
}
- void WaitForCallback() {
- waiter_.Wait();
- }
+ void WaitForCallback() { waiter_.Wait(); }
void AdvanceClockBy(base::TimeDelta delta) {
task_runner_->FastForwardBy(delta);
@@ -430,8 +416,8 @@ void RequestCoordinatorTest::SetUp() {
// Save the offliner for use by the tests.
offliner_ = reinterpret_cast<OfflinerStub*>(
offliner_factory->GetOffliner(policy.get()));
- std::unique_ptr<RequestQueueInMemoryStore>
- store(new RequestQueueInMemoryStore());
+ std::unique_ptr<RequestQueueInMemoryStore> store(
+ new RequestQueueInMemoryStore());
std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store)));
std::unique_ptr<Scheduler> scheduler_stub(new SchedulerStub());
network_quality_estimator_.reset(new NetworkQualityEstimatorStub());
@@ -505,7 +491,8 @@ void RequestCoordinatorTest::SetupForOfflinerDoneCallbackTest(
}
void RequestCoordinatorTest::SendOfflinerDoneCallback(
- const SavePageRequest& request, Offliner::RequestStatus status) {
+ const SavePageRequest& request,
+ Offliner::RequestStatus status) {
// Using the fact that the test class is a friend, call to the callback
coordinator_->OfflinerDoneCallback(request, status);
}
@@ -538,10 +525,10 @@ TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) {
TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) {
// Start processing for this request.
- EXPECT_NE(
- coordinator()->SavePageLater(
- kUrl1, kClientId1, kUserRequested,
- RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
+ EXPECT_NE(coordinator()->SavePageLater(
+ kUrl1, kClientId1, kUserRequested,
+ RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
+ 0);
// Ensure that the forthcoming request does not finish - we simulate it being
// in progress by asking it to skip making the completion callback.
@@ -566,10 +553,10 @@ TEST_F(RequestCoordinatorTest, SavePageLater) {
// would invoke user request callback.
coordinator()->SetImmediateScheduleCallbackForTest(immediate_callback());
- EXPECT_NE(
- coordinator()->SavePageLater(
- kUrl1, kClientId1, kUserRequested,
- RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
+ EXPECT_NE(coordinator()->SavePageLater(
+ kUrl1, kClientId1, kUserRequested,
+ RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
+ 0);
// Expect that a request got placed on the queue.
coordinator()->queue()->GetRequests(base::Bind(
@@ -608,9 +595,8 @@ TEST_F(RequestCoordinatorTest, SavePageLaterFailed) {
RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0);
// Expect that a request got placed on the queue.
- coordinator()->queue()->GetRequests(
- base::Bind(&RequestCoordinatorTest::GetRequestsDone,
- base::Unretained(this)));
+ coordinator()->queue()->GetRequests(base::Bind(
+ &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
// Wait for callbacks to finish, both request queue and offliner.
PumpLoop();
@@ -630,8 +616,8 @@ TEST_F(RequestCoordinatorTest, SavePageLaterFailed) {
EXPECT_EQ(kClientId1, last_requests().at(0)->client_id());
// Expect that the scheduler got notified.
- SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>(
- coordinator()->scheduler());
+ SchedulerStub* scheduler_stub =
+ reinterpret_cast<SchedulerStub*>(coordinator()->scheduler());
EXPECT_TRUE(scheduler_stub->schedule_called());
EXPECT_EQ(coordinator()
->GetTriggerConditions(last_requests()[0]->user_requested())
@@ -644,8 +630,8 @@ TEST_F(RequestCoordinatorTest, SavePageLaterFailed) {
TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) {
// Add a request to the queue, wait for callbacks to finish.
- offline_pages::SavePageRequest request(
- kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
+ offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
+ base::Time::Now(), kUserRequested);
SetupForOfflinerDoneCallbackTest(&request);
// Call the OfflinerDoneCallback to simulate the page being completed, wait
@@ -655,9 +641,8 @@ TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) {
EXPECT_TRUE(immediate_schedule_callback_called());
// Verify the request gets removed from the queue, and wait for callbacks.
- coordinator()->queue()->GetRequests(
- base::Bind(&RequestCoordinatorTest::GetRequestsDone,
- base::Unretained(this)));
+ coordinator()->queue()->GetRequests(base::Bind(
+ &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
PumpLoop();
// We should not find any requests in the queue anymore.
@@ -673,8 +658,8 @@ TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) {
TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) {
// Add a request to the queue, wait for callbacks to finish.
- offline_pages::SavePageRequest request(
- kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
+ offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
+ base::Time::Now(), kUserRequested);
request.set_completed_attempt_count(kMaxCompletedTries - 1);
SetupForOfflinerDoneCallbackTest(&request);
// Stop processing before completing the second request on the queue.
@@ -698,9 +683,8 @@ TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) {
// and verifying that there is no attempt to pick another request following
// this failure code.
- coordinator()->queue()->GetRequests(
- base::Bind(&RequestCoordinatorTest::GetRequestsDone,
- base::Unretained(this)));
+ coordinator()->queue()->GetRequests(base::Bind(
+ &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
PumpLoop();
// Now just one request in the queue since failed request removed
@@ -753,8 +737,8 @@ TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) {
TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) {
// Add a request to the queue, wait for callbacks to finish.
- offline_pages::SavePageRequest request(
- kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
+ offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
+ base::Time::Now(), kUserRequested);
SetupForOfflinerDoneCallbackTest(&request);
// Call the OfflinerDoneCallback to simulate the request failed, wait
@@ -1033,15 +1017,14 @@ TEST_F(RequestCoordinatorTest, MarkRequestCompleted) {
TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) {
// Build a request to use with the pre-renderer, and put it on the queue.
- offline_pages::SavePageRequest request(
- kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
+ offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
+ base::Time::Now(), kUserRequested);
// Set request to allow one more completed attempt.
int max_tries = coordinator()->policy()->GetMaxCompletedTries();
request.set_completed_attempt_count(max_tries - 1);
coordinator()->queue()->AddRequest(
- request,
- base::Bind(&RequestCoordinatorTest::AddRequestDone,
- base::Unretained(this)));
+ request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
+ base::Unretained(this)));
PumpLoop();
// Ensure that the new request does not finish - we simulate it being
@@ -1057,7 +1040,8 @@ TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) {
AdvanceClockBy(base::TimeDelta::FromSeconds(
coordinator()
->policy()
- ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() + 1));
+ ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() +
+ 1));
PumpLoop();
// Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner
@@ -1079,10 +1063,10 @@ TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) {
// in progress by asking it to skip making the completion callback.
EnableOfflinerCallback(false);
- EXPECT_NE(
- coordinator()->SavePageLater(
- kUrl1, kClientId1, kUserRequested,
- RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
+ EXPECT_NE(coordinator()->SavePageLater(
+ kUrl1, kClientId1, kUserRequested,
+ RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
+ 0);
PumpLoop();
// Verify that immediate start from adding the request did happen.
@@ -1092,7 +1076,8 @@ TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) {
AdvanceClockBy(base::TimeDelta::FromSeconds(
coordinator()
->policy()
- ->GetSinglePageTimeLimitForImmediateLoadInSeconds() - 1));
+ ->GetSinglePageTimeLimitForImmediateLoadInSeconds() -
+ 1));
PumpLoop();
// Verify still busy.
@@ -1134,9 +1119,8 @@ TEST_F(RequestCoordinatorTest, TimeBudgetExceeded) {
// TryNextRequest should decide that there is no more work to be done,
// and call back to the scheduler, even though there is another request in the
// queue. Both requests should be left in the queue.
- coordinator()->queue()->GetRequests(
- base::Bind(&RequestCoordinatorTest::GetRequestsDone,
- base::Unretained(this)));
+ coordinator()->queue()->GetRequests(base::Bind(
+ &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
PumpLoop();
// We should find two requests in the queue.
@@ -1267,10 +1251,10 @@ TEST_F(RequestCoordinatorTest,
// Turn off the callback so that the request stops before processing in
// PumpLoop.
EnableOfflinerCallback(false);
- EXPECT_NE(
- coordinator()->SavePageLater(
- kUrl1, kClientId1, kUserRequested,
- RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
+ EXPECT_NE(coordinator()->SavePageLater(
+ kUrl1, kClientId1, kUserRequested,
+ RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
+ 0);
PumpLoop();
// Now whether processing triggered immediately depends on whether test
@@ -1321,16 +1305,15 @@ TEST_F(RequestCoordinatorTest,
TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) {
SetNetworkConnected(false);
- EXPECT_NE(
- coordinator()->SavePageLater(
- kUrl1, kClientId1, kUserRequested,
- RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
+ EXPECT_NE(coordinator()->SavePageLater(
+ kUrl1, kClientId1, kUserRequested,
+ RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
+ 0);
PumpLoop();
EXPECT_FALSE(is_busy());
}
-TEST_F(RequestCoordinatorTest,
- SavePageDoesStartProcessingWhenPoorlyConnected) {
+TEST_F(RequestCoordinatorTest, SavePageDoesStartProcessingWhenPoorlyConnected) {
// If low end device, pretend it is not so that immediate start can happen.
SetIsLowEndDeviceForTest(false);
// Set specific network type for 2G with poor effective connection.
@@ -1343,10 +1326,10 @@ TEST_F(RequestCoordinatorTest,
// PumpLoop.
EnableOfflinerCallback(false);
- EXPECT_NE(
- coordinator()->SavePageLater(
- kUrl1, kClientId1, kUserRequested,
- RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
+ EXPECT_NE(coordinator()->SavePageLater(
+ kUrl1, kClientId1, kUserRequested,
+ RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
+ 0);
PumpLoop();
EXPECT_TRUE(is_busy());
}

Powered by Google App Engine
This is Rietveld 408576698