Commit 77176051 authored by Sophie Chang's avatar Sophie Chang Committed by Commit Bot

Remove data saver only restriction for optimization hints component installation

Bug: 1087123
Change-Id: I7d29b30f7293df52ea5f2690f8daa1bc3f8bbb6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2277087Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784430}
parent 60bf2aef
......@@ -17,7 +17,6 @@
#include "components/optimization_guide/optimization_guide_constants.h"
#include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/optimization_guide_service.h"
#include "components/prefs/pref_service.h"
using component_updater::ComponentUpdateService;
......@@ -136,16 +135,15 @@ OptimizationHintsComponentInstallerPolicy::GetMimeTypes() const {
}
void RegisterOptimizationHintsComponent(ComponentUpdateService* cus,
bool is_off_the_record_profile,
PrefService* profile_prefs) {
if (!optimization_guide::features::IsOptimizationHintsEnabled()) {
bool is_off_the_record_profile) {
if (is_off_the_record_profile) {
return;
}
if (!data_reduction_proxy::DataReductionProxySettings::
IsDataSaverEnabledByUser(is_off_the_record_profile, profile_prefs)) {
if (!optimization_guide::features::IsOptimizationHintsEnabled()) {
return;
}
auto installer = base::MakeRefCounted<ComponentInstaller>(
std::make_unique<OptimizationHintsComponentInstallerPolicy>());
installer->Register(cus, base::OnceClosure());
......
......@@ -12,8 +12,6 @@
#include "base/gtest_prod_util.h"
#include "components/component_updater/component_installer.h"
class PrefService;
namespace base {
class FilePath;
class Version;
......@@ -59,8 +57,7 @@ class OptimizationHintsComponentInstallerPolicy
};
void RegisterOptimizationHintsComponent(ComponentUpdateService* cus,
bool is_off_the_record_profile,
PrefService* profile_prefs);
bool is_off_the_record_profile);
} // namespace component_updater
......
......@@ -19,8 +19,6 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "components/component_updater/mock_component_updater_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/optimization_guide/optimization_guide_constants.h"
#include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/optimization_guide_service.h"
......@@ -88,16 +86,10 @@ class OptimizationHintsComponentInstallerTest : public PlatformTest {
TestingBrowserProcess::GetGlobal()->SetOptimizationGuideService(
std::move(optimization_guide_service));
policy_ = std::make_unique<OptimizationHintsComponentInstallerPolicy>();
drp_test_context_ =
data_reduction_proxy::DataReductionProxyTestContext::Builder()
.WithMockConfig()
.Build();
}
void TearDown() override {
TestingBrowserProcess::GetGlobal()->SetOptimizationGuideService(nullptr);
drp_test_context_->DestroySettings();
PlatformTest::TearDown();
}
......@@ -109,18 +101,10 @@ class OptimizationHintsComponentInstallerTest : public PlatformTest {
return component_install_dir_.GetPath();
}
TestingPrefServiceSimple* profile_prefs() {
return drp_test_context_->pref_service();
}
base::Version ruleset_format_version() {
return policy_->ruleset_format_version_;
}
void SetDataSaverEnabled(bool enabled) {
drp_test_context_->SetDataReductionProxyEnabled(enabled);
}
void CreateTestOptimizationHints(const std::string& hints_content) {
base::FilePath hints_path = component_install_dir().Append(
optimization_guide::kUnindexedHintsFileName);
......@@ -156,9 +140,6 @@ class OptimizationHintsComponentInstallerTest : public PlatformTest {
std::unique_ptr<OptimizationHintsComponentInstallerPolicy> policy_;
std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext>
drp_test_context_;
TestOptimizationGuideService* optimization_guide_service_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(OptimizationHintsComponentInstallerTest);
......@@ -172,47 +153,33 @@ TEST_F(OptimizationHintsComponentInstallerTest,
std::unique_ptr<OptimizationHintsMockComponentUpdateService> cus(
new OptimizationHintsMockComponentUpdateService());
EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(0);
RegisterOptimizationHintsComponent(cus.get(), false, profile_prefs());
RegisterOptimizationHintsComponent(cus.get(), false);
RunUntilIdle();
}
TEST_F(OptimizationHintsComponentInstallerTest,
ComponentRegistrationWhenFeatureEnabledButDataSaverDisabled) {
ComponentRegistrationWhenFeatureEnabled) {
base::test::ScopedFeatureList scoped_list;
scoped_list.InitAndEnableFeature(
optimization_guide::features::kOptimizationHints);
SetDataSaverEnabled(false);
std::unique_ptr<OptimizationHintsMockComponentUpdateService> cus(
new OptimizationHintsMockComponentUpdateService());
EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(0);
RegisterOptimizationHintsComponent(cus.get(), false, profile_prefs());
EXPECT_CALL(*cus, RegisterComponent(testing::_))
.Times(1)
.WillOnce(testing::Return(true));
RegisterOptimizationHintsComponent(cus.get(), false);
RunUntilIdle();
}
TEST_F(OptimizationHintsComponentInstallerTest,
ComponentRegistrationWhenFeatureEnabledButNoProfilePrefs) {
ComponentRegistrationWhenFeatureEnabledButOffTheRecordProfile) {
base::test::ScopedFeatureList scoped_list;
scoped_list.InitAndEnableFeature(
optimization_guide::features::kOptimizationHints);
std::unique_ptr<OptimizationHintsMockComponentUpdateService> cus(
new OptimizationHintsMockComponentUpdateService());
EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(0);
RegisterOptimizationHintsComponent(cus.get(), false, nullptr);
RunUntilIdle();
}
TEST_F(OptimizationHintsComponentInstallerTest,
ComponentRegistrationWhenFeatureEnabledAndDataSaverEnabled) {
base::test::ScopedFeatureList scoped_list;
scoped_list.InitAndEnableFeature(
optimization_guide::features::kOptimizationHints);
SetDataSaverEnabled(true);
std::unique_ptr<OptimizationHintsMockComponentUpdateService> cus(
new OptimizationHintsMockComponentUpdateService());
EXPECT_CALL(*cus, RegisterComponent(testing::_))
.Times(1)
.WillOnce(testing::Return(true));
RegisterOptimizationHintsComponent(cus.get(), false, profile_prefs());
RegisterOptimizationHintsComponent(cus.get(), true);
RunUntilIdle();
}
......
......@@ -120,8 +120,7 @@ void RegisterComponentsForUpdate(bool is_off_the_record_profile,
g_browser_process->floc_blocklist_service());
RegisterOnDeviceHeadSuggestComponent(
cus, g_browser_process->GetApplicationLocale());
RegisterOptimizationHintsComponent(cus, is_off_the_record_profile,
profile_prefs);
RegisterOptimizationHintsComponent(cus, is_off_the_record_profile);
base::FilePath path;
if (base::PathService::Get(chrome::DIR_USER_DATA, &path)) {
......
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