1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/commerce/core/mock_account_checker.h"
#include "components/commerce/core/pref_names.h"
#include "components/optimization_guide/core/feature_registry/feature_registration.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
namespace commerce {
MockAccountChecker::MockAccountChecker()
: AccountChecker("", "", nullptr, nullptr, nullptr, nullptr) {
// Default to an account checker with the fewest restrictions.
SetSignedIn(true);
SetAllSyncTypesEnabled(true);
SetAnonymizedUrlDataCollectionEnabled(true);
SetIsSubjectToParentalControls(false);
SetCanUseModelExecutionFeatures(true);
SetSyncAvailable(true);
// Default pref service can be overwritten by SetPrefs below.
default_pref_service_ = std::make_unique<TestingPrefServiceSimple>();
RegisterCommercePrefs(default_pref_service_->registry());
SetPrefs(default_pref_service_.get());
}
MockAccountChecker::~MockAccountChecker() = default;
void MockAccountChecker::SetSignedIn(bool signed_in) {
ON_CALL(*this, IsSignedIn).WillByDefault(testing::Return(signed_in));
}
void MockAccountChecker::SetAllSyncTypesEnabled(bool enabled) {
ON_CALL(*this, IsSyncTypeEnabled).WillByDefault(testing::Return(enabled));
}
void MockAccountChecker::SetSyncAvailable(bool available) {
ON_CALL(*this, IsSyncAvailable).WillByDefault(testing::Return(available));
}
void MockAccountChecker::SetAnonymizedUrlDataCollectionEnabled(bool enabled) {
ON_CALL(*this, IsAnonymizedUrlDataCollectionEnabled)
.WillByDefault(testing::Return(enabled));
}
void MockAccountChecker::SetIsSubjectToParentalControls(
bool subject_to_parental_controls) {
ON_CALL(*this, IsSubjectToParentalControls)
.WillByDefault(testing::Return(subject_to_parental_controls));
}
void MockAccountChecker::SetCanUseModelExecutionFeatures(
bool can_use_model_execution_features) {
ON_CALL(*this, CanUseModelExecutionFeatures)
.WillByDefault(testing::Return(can_use_model_execution_features));
}
void MockAccountChecker::SetCountry(std::string country) {
ON_CALL(*this, GetCountry).WillByDefault(testing::Return(country));
}
void MockAccountChecker::SetLocale(std::string locale) {
ON_CALL(*this, GetLocale).WillByDefault(testing::Return(locale));
}
void MockAccountChecker::SetPrefs(PrefService* prefs) {
ON_CALL(*this, GetPrefs).WillByDefault(testing::Return(prefs));
}
void MockAccountChecker::RegisterCommercePrefs(PrefRegistrySimple* registry) {
RegisterPrefs(registry);
registry->RegisterIntegerPref(
optimization_guide::prefs::kProductSpecificationsEnterprisePolicyAllowed,
0);
}
} // namespace commerce
|