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

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: more rebase 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 c91909c80abcc34c0b14921c5293a677312ebc37..942b7e0cc7a87d1b2d36687b1b147756134b431a 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>
@@ -19,20 +19,20 @@
#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/network_quality_provider_stub.h"
-#include "components/offline_pages/background/offliner.h"
-#include "components/offline_pages/background/offliner_factory.h"
-#include "components/offline_pages/background/offliner_factory_stub.h"
-#include "components/offline_pages/background/offliner_policy.h"
-#include "components/offline_pages/background/offliner_stub.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/background/scheduler_stub.h"
-#include "components/offline_pages/offline_page_feature.h"
+#include "components/offline_pages/core/background/device_conditions.h"
+#include "components/offline_pages/core/background/network_quality_provider_stub.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_factory_stub.h"
+#include "components/offline_pages/core/background/offliner_policy.h"
+#include "components/offline_pages/core/background/offliner_stub.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/background/scheduler_stub.h"
+#include "components/offline_pages/core/offline_page_feature.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace offline_pages {
@@ -105,8 +105,7 @@ class ObserverStub : public RequestCoordinator::Observer {
SavePageRequest::RequestState state_;
};
-class RequestCoordinatorTest
- : public testing::Test {
+class RequestCoordinatorTest : public testing::Test {
public:
RequestCoordinatorTest();
~RequestCoordinatorTest() override;
@@ -115,13 +114,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(); }
@@ -132,9 +127,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();
@@ -172,9 +165,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);
@@ -232,9 +223,7 @@ class RequestCoordinatorTest
coordinator_->SetDeviceConditionsForTest(device_conditions);
}
- void WaitForCallback() {
- waiter_.Wait();
- }
+ void WaitForCallback() { waiter_.Wait(); }
void AdvanceClockBy(base::TimeDelta delta) {
task_runner_->FastForwardBy(delta);
@@ -309,8 +298,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 NetworkQualityProviderStub());
@@ -384,7 +373,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);
}
@@ -427,10 +417,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.
@@ -455,10 +445,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(
@@ -507,9 +497,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();
@@ -529,8 +518,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())
@@ -543,8 +532,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
@@ -554,9 +543,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.
@@ -572,8 +560,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.
@@ -597,9 +585,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
@@ -652,8 +639,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
@@ -956,15 +943,14 @@ TEST_F(RequestCoordinatorTest, EnableForOffliner) {
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
@@ -980,7 +966,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
@@ -1002,10 +989,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.
@@ -1015,7 +1002,8 @@ TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) {
AdvanceClockBy(base::TimeDelta::FromSeconds(
coordinator()
->policy()
- ->GetSinglePageTimeLimitForImmediateLoadInSeconds() - 1));
+ ->GetSinglePageTimeLimitForImmediateLoadInSeconds() -
+ 1));
PumpLoop();
// Verify still busy.
@@ -1057,9 +1045,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.
@@ -1190,10 +1177,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
@@ -1244,10 +1231,10 @@ 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());
}
@@ -1264,10 +1251,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