Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable password sync by default #27268

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "brave/components/brave_rewards/common/buildflags/buildflags.h"
#include "brave/components/brave_rewards/common/features.h"
#include "brave/components/brave_shields/core/common/features.h"
#include "brave/components/brave_sync/features.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/brave_wallet/common/features.h"
#include "brave/components/de_amp/common/features.h"
Expand Down Expand Up @@ -1003,6 +1004,14 @@
"corners, padding, and a drop shadow", \
kOsWin | kOsLinux | kOsMac, \
FEATURE_VALUE_TYPE(features::kBraveWebViewRoundedCorners), \
}, \
{ \
"brave-sync-default-passwords", \
"Enable password syncing by default", \
"Turn on password syncing when Sync is enabled.", \
kOsAll, \
FEATURE_VALUE_TYPE( \
brave_sync::features::kBraveSyncDefaultPasswords), \
}) \
BRAVE_NATIVE_WALLET_FEATURE_ENTRIES \
BRAVE_NEWS_FEATURE_ENTRIES \
Expand Down
3 changes: 3 additions & 0 deletions components/brave_sync/features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
namespace brave_sync::features {

BASE_FEATURE(kBraveSync, "BraveSync", base::FEATURE_ENABLED_BY_DEFAULT);
BASE_FEATURE(kBraveSyncDefaultPasswords,
"BraveSyncDefaultPasswords",
base::FEATURE_DISABLED_BY_DEFAULT);

} // namespace brave_sync::features
1 change: 1 addition & 0 deletions components/brave_sync/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace brave_sync {
namespace features {

BASE_DECLARE_FEATURE(kBraveSync);
BASE_DECLARE_FEATURE(kBraveSyncDefaultPasswords);

} // namespace features
} // namespace brave_sync
Expand Down
1 change: 1 addition & 0 deletions components/sync/service/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ source_set("unit_tests") {
deps = [
"//base/test:test_support",
"//brave/components/brave_sync:crypto",
"//brave/components/brave_sync:features",
"//brave/components/brave_sync:network_time_helper",
"//brave/components/brave_sync:p3a",
"//brave/components/brave_sync:prefs",
Expand Down
8 changes: 6 additions & 2 deletions components/sync/service/brave_sync_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/strings/string_util.h"
#include "brave/components/brave_sync/brave_sync_p3a.h"
#include "brave/components/brave_sync/crypto/crypto.h"
#include "brave/components/brave_sync/features.h"
#include "brave/components/sync/service/brave_sync_auth_manager.h"
#include "brave/components/sync/service/sync_service_impl_delegate.h"
#include "build/build_config.h"
Expand Down Expand Up @@ -42,7 +43,6 @@ BraveSyncServiceImpl::BraveSyncServiceImpl(
brave_sync::Prefs::GetSeedPath(),
base::BindRepeating(&BraveSyncServiceImpl::OnBraveSyncPrefsChanged,
base::Unretained(this)));

bool failed_to_decrypt = false;
GetBraveSyncAuthManager()->DeriveSigningKeys(
brave_sync_prefs_.GetSeed(&failed_to_decrypt));
Expand Down Expand Up @@ -165,7 +165,7 @@ void BraveSyncServiceImpl::OnBraveSyncPrefsChanged(const std::string& path) {

if (!seed.empty()) {
GetBraveSyncAuthManager()->DeriveSigningKeys(seed);
// Default enabled types: Bookmarks
// Default enabled types: Bookmarks, Passwords

// Related Chromium change: 33441a0f3f9a591693157f2fd16852ce072e6f9d
// We need to acquire setup handle before change selected types.
Expand All @@ -175,6 +175,10 @@ void BraveSyncServiceImpl::OnBraveSyncPrefsChanged(const std::string& path) {

syncer::UserSelectableTypeSet selected_types;
selected_types.Put(UserSelectableType::kBookmarks);
if (base::FeatureList::IsEnabled(
brave_sync::features::kBraveSyncDefaultPasswords)) {
selected_types.Put(UserSelectableType::kPasswords);
}
GetUserSettings()->SetSelectedTypes(false, selected_types);

brave_sync_prefs_.ClearLeaveChainDetails();
Expand Down
49 changes: 47 additions & 2 deletions components/sync/service/brave_sync_service_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include "base/memory/raw_ptr.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "brave/components/brave_sync/brave_sync_p3a.h"
#include "brave/components/brave_sync/features.h"
#include "brave/components/history/core/browser/sync/brave_history_data_type_controller.h"
#include "brave/components/history/core/browser/sync/brave_history_delete_directives_data_type_controller.h"
#include "brave/components/sync/service/sync_service_impl_delegate.h"
Expand All @@ -23,6 +25,7 @@
#include "components/os_crypt/sync/os_crypt_mocker.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/signin/public/identity_manager/accounts_in_cookie_jar_info.h"
#include "components/sync/base/data_type.h"
#include "components/sync/engine/nigori/key_derivation_params.h"
#include "components/sync/engine/nigori/nigori.h"
#include "components/sync/model/type_entities_count.h"
Expand Down Expand Up @@ -55,7 +58,7 @@ constexpr char kValidSyncCode[] =
"exotic ill sure question trial squirrel glove celery "
"awkward push jelly logic broccoli almost grocery drift";

// Taken from anonimous namespace from sync_service_crypto_unittest.cc
// Taken from anonymous namespace from sync_service_crypto_unittest.cc
sync_pb::EncryptedData MakeEncryptedData(
const std::string& passphrase,
const KeyDerivationParams& derivation_params) {
Expand Down Expand Up @@ -98,7 +101,9 @@ class SyncServiceObserverMock : public SyncServiceObserver {
class BraveSyncServiceImplTest : public testing::Test {
public:
BraveSyncServiceImplTest()
: brave_sync_prefs_(sync_service_impl_bundle_.pref_service()),
: task_environment_(
base::test::SingleThreadTaskEnvironment::TimeSource::MOCK_TIME),
brave_sync_prefs_(sync_service_impl_bundle_.pref_service()),
sync_prefs_(sync_service_impl_bundle_.pref_service()) {
sync_service_impl_bundle_.identity_test_env()
->SetAutomaticIssueOfAccessTokens(true);
Expand All @@ -118,6 +123,8 @@ class BraveSyncServiceImplTest : public testing::Test {
std::unique_ptr<SyncClientMock> sync_client =
sync_service_impl_bundle_.CreateSyncClientMock();

ON_CALL(*sync_client, IsPasswordSyncAllowed).WillByDefault(Return(true));

auto sync_service_delegate(std::make_unique<SyncServiceImplDelegateMock>());
sync_service_delegate_ = sync_service_delegate.get();

Expand Down Expand Up @@ -712,6 +719,44 @@ TEST_F(BraveSyncServiceImplTest, NoLeaveDetailsWhenInitializeIOS) {
EXPECT_FALSE(brave_sync_prefs()->GetLeaveChainDetails().empty());
}

class BraveSyncServiceImpl_EnableDefaultPasswordSyncingTest
: public BraveSyncServiceImplTest {
public:
BraveSyncServiceImpl_EnableDefaultPasswordSyncingTest() {
scoped_feature_list_.InitAndEnableFeature(
brave_sync::features::kBraveSyncDefaultPasswords);
}

protected:
base::test::ScopedFeatureList scoped_feature_list_;
};

TEST_F(BraveSyncServiceImpl_EnableDefaultPasswordSyncingTest,
BookmarksAndPasswordsAfterSetup) {
OSCryptMocker::SetUp();
CreateSyncService(DataTypeSet({BOOKMARKS, PASSWORDS}));
EXPECT_FALSE(engine());
brave_sync_service_impl()->SetSyncCode(kValidSyncCode);
task_environment_.FastForwardUntilNoTasksRemain();

auto sync_blocker = brave_sync_service_impl()->GetSetupInProgressHandle();
brave_sync_service_impl()
->GetUserSettings()
->SetInitialSyncFeatureSetupComplete(
syncer::SyncFirstSetupCompleteSource::ADVANCED_FLOW_CONFIRM);
EXPECT_TRUE(engine());

EXPECT_FALSE(
brave_sync_service_impl()->GetUserSettings()->IsSyncEverythingEnabled());
auto selected_types =
brave_sync_service_impl()->GetUserSettings()->GetSelectedTypes();
EXPECT_EQ(selected_types.size(), 2u);
EXPECT_TRUE(selected_types.Has(UserSelectableType::kBookmarks));
EXPECT_TRUE(selected_types.Has(UserSelectableType::kPasswords));

OSCryptMocker::TearDown();
}

namespace {
enum class GACookiesMethodType {
kOnAccountsCookieDeletedByUserAction,
Expand Down
Loading