Commit 314887c4 authored by Xi Han's avatar Xi Han Committed by Commit Bot

Run PrefetchBackgroundTaskTest in reduced mode.

In this CL, we update the flag to enable running PrefetchBackgroundTask in
reduced mode.

Bug: 933358
Change-Id: I43a063cd47da9003b911825a1646464237645b6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1622872
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663036}
parent 85ba1317
......@@ -12,7 +12,6 @@ import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.DeviceConditions;
import org.chromium.chrome.browser.background_task_scheduler.NativeBackgroundTask;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.components.background_task_scheduler.TaskIds;
import org.chromium.components.background_task_scheduler.TaskParameters;
......@@ -32,10 +31,11 @@ public class PrefetchBackgroundTask extends NativeBackgroundTask {
private static final int MINIMUM_BATTERY_PERCENTAGE_FOR_PREFETCHING = 50;
private static boolean sSkipConditionCheckingForTesting;
private static boolean sAlwaysSupportServiceManagerOnlyForTesting;
private long mNativeTask;
private TaskFinishedCallback mTaskFinishedCallback;
private Profile mProfile;
// We update this when we call TaskFinishedCallback, so that subsequent calls to
// onStopTask* can respond the same way. This is possible due to races with the JobScheduler.
// Defaults to true so that we are rescheduled automatically if somehow we were unable to start
......@@ -90,6 +90,11 @@ public class PrefetchBackgroundTask extends NativeBackgroundTask {
sSkipConditionCheckingForTesting = true;
}
@VisibleForTesting
static void alwaysSupportServiceManagerOnlyForTesting() {
sAlwaysSupportServiceManagerOnlyForTesting = true;
}
@Override
protected void onStartTaskWithNative(
Context context, TaskParameters taskParameters, TaskFinishedCallback callback) {
......@@ -196,8 +201,9 @@ public class PrefetchBackgroundTask extends NativeBackgroundTask {
@Override
protected boolean supportsServiceManagerOnly() {
return FeatureUtilities.isServiceManagerForBackgroundPrefetchEnabled()
&& FeatureUtilities.isFeedEnabled();
if (sAlwaysSupportServiceManagerOnlyForTesting) return true;
return FeatureUtilities.isServiceManagerForBackgroundPrefetchEnabled();
}
@VisibleForTesting
......
......@@ -11,6 +11,7 @@ import static org.junit.Assert.assertTrue;
import android.content.Context;
import android.support.test.filters.SmallTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -40,7 +41,8 @@ import java.util.concurrent.TimeUnit;
/** Unit tests for {@link PrefetchBackgroundTask}. */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
"enable-features=OfflinePagesPrefetching"})
"enable-features=OfflinePagesPrefetching,NetworkService,AllowStartingServiceManagerOnly,"
+ "InterestFeedContentSuggestions"})
public class PrefetchBackgroundTaskTest {
private static final double BACKOFF_JITTER_FACTOR = 0.33;
private static final int SEMAPHORE_TIMEOUT_MS = 5000;
......@@ -182,11 +184,20 @@ public class PrefetchBackgroundTaskTest {
@Before
public void setUp() throws Exception {
ServicificationBackgroundService.launchChromeInBackground(true /*serviceManagerOnlyMode*/);
ServicificationBackgroundService.assertOnlyServiceManagerStarted();
TestThreadUtils.runOnUiThreadBlocking(() -> {
mScheduler = new TestBackgroundTaskScheduler();
BackgroundTaskSchedulerFactory.setSchedulerForTesting(mScheduler);
});
OfflineTestUtil.setPrefetchingEnabledByServer(true);
PrefetchBackgroundTask.alwaysSupportServiceManagerOnlyForTesting();
}
@After
public void tearDown() {
ServicificationBackgroundService.assertOnlyServiceManagerStarted();
}
private void scheduleTask(int additionalDelaySeconds) {
......
......@@ -45,7 +45,10 @@
#include "components/offline_pages/core/prefetch/suggested_articles_observer.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/service_manager/public/cpp/connector.h"
namespace offline_pages {
......@@ -108,6 +111,14 @@ std::unique_ptr<KeyedService> PrefetchServiceFactory::BuildServiceInstanceFor(
auto prefetch_dispatcher =
std::make_unique<PrefetchDispatcherImpl>(profile_key->GetPrefs());
// Starts the network service if it hasn't yet. This is because when network
// service is enabled in the reduced mode, it only starts upon request.
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
service_manager::Connector* connector =
content::ServiceManagerConnection::GetForProcess()->GetConnector();
content::GetNetworkServiceFromConnector(connector);
}
auto* system_network_context_manager =
SystemNetworkContextManager::GetInstance();
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment