[synapse] Use IsSettingVisible for compare
In order to display settings for enterprise-disabled AI features, each feature needs to expose separate IsEnabled and IsSettingsVisible methods. Bug: 377721164 Change-Id: I97927797d44fa9043efcc3b12ea181b6cb65d386 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6085006 Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org> Reviewed-by: Ayman Almadhoun <ayman@chromium.org> Reviewed-by: Zaina Al-Mashni <zalmashni@google.com> Reviewed-by: Matthew Jones <mdjones@chromium.org> Commit-Queue: Christian Dullweber <dullweber@chromium.org> Cr-Commit-Position: refs/heads/main@{#1395884}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f6f86f23bc
commit
9375cc2d51
chrome/browser/ui/webui/settings
components/commerce/core
@ -594,8 +594,12 @@ SettingsUI::SettingsUI(content::WebUI* web_ui)
|
||||
: customize_chrome::IsWallpaperSearchEnabledForProfile(profile)},
|
||||
{"showHistorySearchControl",
|
||||
history_embeddings::IsHistoryEmbeddingsSettingVisible(profile)},
|
||||
{"showCompareControl", commerce::CanFetchProductSpecificationsData(
|
||||
shopping_service->GetAccountChecker())},
|
||||
{"showCompareControl",
|
||||
use_is_setting_visible
|
||||
? commerce::IsProductSpecificationsSettingVisible(
|
||||
shopping_service->GetAccountChecker())
|
||||
: commerce::CanFetchProductSpecificationsData(
|
||||
shopping_service->GetAccountChecker())},
|
||||
};
|
||||
|
||||
bool show_ai_page = show_ai_settings_for_testing;
|
||||
|
@ -4,16 +4,34 @@
|
||||
|
||||
#include "components/commerce/core/feature_utils.h"
|
||||
|
||||
#include "base/feature_list.h"
|
||||
#include "components/commerce/core/account_checker.h"
|
||||
#include "components/commerce/core/commerce_feature_list.h"
|
||||
#include "components/commerce/core/pref_names.h"
|
||||
#include "components/commerce/core/product_specifications/product_specifications_service.h"
|
||||
#include "components/optimization_guide/core/feature_registry/feature_registration.h"
|
||||
#include "components/optimization_guide/core/optimization_guide_features.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/sync/base/data_type.h"
|
||||
#include "components/sync/base/user_selectable_type.h"
|
||||
|
||||
namespace commerce {
|
||||
namespace {
|
||||
bool CanFetchProductSpecificationsData(AccountChecker* account_checker,
|
||||
bool skip_enterprise_check) {
|
||||
// msbb, enterprise, parental controls, sync type, and model execution
|
||||
// features.
|
||||
return account_checker &&
|
||||
(skip_enterprise_check || IsProductSpecificationsAllowedForEnterprise(
|
||||
account_checker->GetPrefs())) &&
|
||||
account_checker->IsSignedIn() &&
|
||||
account_checker->IsAnonymizedUrlDataCollectionEnabled() &&
|
||||
!account_checker->IsSubjectToParentalControls() &&
|
||||
account_checker->CanUseModelExecutionFeatures() &&
|
||||
IsSyncingProductSpecifications(account_checker) &&
|
||||
CanLoadProductSpecificationsFullPageUi(account_checker);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool IsShoppingListEligible(AccountChecker* account_checker) {
|
||||
if (!commerce::IsRegionLockedFeatureEnabled(
|
||||
@ -121,17 +139,15 @@ bool CanManageProductSpecificationsSets(
|
||||
}
|
||||
|
||||
bool CanFetchProductSpecificationsData(AccountChecker* account_checker) {
|
||||
// msbb, enterprise, parental controls, sync type, and model execution
|
||||
// features.
|
||||
return account_checker &&
|
||||
IsProductSpecificationsAllowedForEnterprise(
|
||||
account_checker->GetPrefs()) &&
|
||||
account_checker->IsSignedIn() &&
|
||||
account_checker->IsAnonymizedUrlDataCollectionEnabled() &&
|
||||
!account_checker->IsSubjectToParentalControls() &&
|
||||
account_checker->CanUseModelExecutionFeatures() &&
|
||||
IsSyncingProductSpecifications(account_checker) &&
|
||||
CanLoadProductSpecificationsFullPageUi(account_checker);
|
||||
return CanFetchProductSpecificationsData(account_checker,
|
||||
/*skip_enterprise_check=*/false);
|
||||
}
|
||||
|
||||
bool IsProductSpecificationsSettingVisible(AccountChecker* account_checker) {
|
||||
DCHECK(base::FeatureList::IsEnabled(
|
||||
optimization_guide::features::kAiSettingsPageEnterpriseDisabledUi));
|
||||
return CanFetchProductSpecificationsData(account_checker,
|
||||
/*skip_enterprise_check=*/true);
|
||||
}
|
||||
|
||||
} // namespace commerce
|
||||
|
@ -57,6 +57,9 @@ bool CanManageProductSpecificationsSets(
|
||||
// may still be able to manage their sets.
|
||||
bool CanFetchProductSpecificationsData(AccountChecker* account_checker);
|
||||
|
||||
// Returns whether we should show the settings UI for product specifications.
|
||||
bool IsProductSpecificationsSettingVisible(AccountChecker* account_checker);
|
||||
|
||||
} // namespace commerce
|
||||
|
||||
#endif // COMPONENTS_COMMERCE_CORE_FEATURE_UTILS_H_
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "components/commerce/core/product_specifications/product_specifications_set.h"
|
||||
#include "components/commerce/core/test_utils.h"
|
||||
#include "components/optimization_guide/core/feature_registry/feature_registration.h"
|
||||
#include "components/optimization_guide/core/optimization_guide_features.h"
|
||||
#include "components/prefs/testing_pref_service.h"
|
||||
#include "components/sync/base/data_type.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -141,20 +142,28 @@ TEST_F(FeatureUtilsTest, CanFetchProductSpecificationsData_NoMSBB) {
|
||||
}
|
||||
|
||||
TEST_F(FeatureUtilsTest, CanFetchProductSpecificationsData_NoSync) {
|
||||
test_features_.InitAndEnableFeature(kProductSpecifications);
|
||||
test_features_.InitWithFeatures(
|
||||
{kProductSpecifications,
|
||||
optimization_guide::features::kAiSettingsPageEnterpriseDisabledUi},
|
||||
{});
|
||||
SetupProductSpecificationsEnabled();
|
||||
|
||||
// We should be able to fetch data before turning off sync.
|
||||
ASSERT_TRUE(CanFetchProductSpecificationsData(account_checker_.get()));
|
||||
ASSERT_TRUE(IsProductSpecificationsSettingVisible(account_checker_.get()));
|
||||
|
||||
ON_CALL(*account_checker_, IsSyncTypeEnabled)
|
||||
.WillByDefault(testing::Return(false));
|
||||
|
||||
ASSERT_FALSE(CanFetchProductSpecificationsData(account_checker_.get()));
|
||||
ASSERT_FALSE(IsProductSpecificationsSettingVisible(account_checker_.get()));
|
||||
}
|
||||
|
||||
TEST_F(FeatureUtilsTest, CanFetchProductSpecificationsData_NoEnterprise) {
|
||||
test_features_.InitAndEnableFeature(kProductSpecifications);
|
||||
TEST_F(FeatureUtilsTest,
|
||||
CanFetchProductSpecificationsData_NoEnterpriseNoSettings) {
|
||||
test_features_.InitWithFeatures(
|
||||
{kProductSpecifications},
|
||||
{optimization_guide::features::kAiSettingsPageEnterpriseDisabledUi});
|
||||
SetupProductSpecificationsEnabled();
|
||||
|
||||
// We should be able to fetch data before turning off enterprise.
|
||||
@ -171,6 +180,31 @@ TEST_F(FeatureUtilsTest, CanFetchProductSpecificationsData_NoEnterprise) {
|
||||
ASSERT_FALSE(CanFetchProductSpecificationsData(account_checker_.get()));
|
||||
}
|
||||
|
||||
TEST_F(FeatureUtilsTest,
|
||||
CanFetchProductSpecificationsData_NoEnterpriseWithSettings) {
|
||||
test_features_.InitWithFeatures(
|
||||
{kProductSpecifications,
|
||||
optimization_guide::features::kAiSettingsPageEnterpriseDisabledUi},
|
||||
{});
|
||||
SetupProductSpecificationsEnabled();
|
||||
|
||||
// We should be able to fetch data before turning off enterprise.
|
||||
ASSERT_TRUE(CanFetchProductSpecificationsData(account_checker_.get()));
|
||||
ASSERT_TRUE(IsProductSpecificationsSettingVisible(account_checker_.get()));
|
||||
|
||||
// 1 is enabled but without logging.
|
||||
SetTabCompareEnterprisePolicyPref(prefs_.get(), 1);
|
||||
|
||||
ASSERT_TRUE(CanFetchProductSpecificationsData(account_checker_.get()));
|
||||
ASSERT_TRUE(IsProductSpecificationsSettingVisible(account_checker_.get()));
|
||||
|
||||
// 2 is the disabled enterprise state for the feature.
|
||||
SetTabCompareEnterprisePolicyPref(prefs_.get(), 2);
|
||||
|
||||
ASSERT_FALSE(CanFetchProductSpecificationsData(account_checker_.get()));
|
||||
ASSERT_TRUE(IsProductSpecificationsSettingVisible(account_checker_.get()));
|
||||
}
|
||||
|
||||
TEST_F(FeatureUtilsTest,
|
||||
CanFetchProductSpecificationsData_EnterpriseQualityLogging) {
|
||||
test_features_.InitAndEnableFeature(kProductSpecifications);
|
||||
|
Reference in New Issue
Block a user