Skip to content

Commit c890abc

Browse files
authored
Fixed issue of unable to switch on the passwords sync on Android (uplift to 1.73.x) (#26919)
Uplift of #26876 (squashed) to release
1 parent 5e4342c commit c890abc

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at https://mozilla.org/MPL/2.0/. */
5+
6+
#include "components/sync/service/sync_prefs.h"
7+
8+
#define SetPasswordSyncAllowed SetPasswordSyncAllowed_ChromiumImpl
9+
10+
#include "src/components/sync/service/sync_prefs.cc"
11+
12+
#undef SetPasswordSyncAllowed
13+
14+
namespace syncer {
15+
16+
void SyncPrefs::SetPasswordSyncAllowed(bool allowed) {}
17+
18+
} // namespace syncer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at https://mozilla.org/MPL/2.0/. */
5+
6+
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SERVICE_SYNC_PREFS_H_
7+
#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SERVICE_SYNC_PREFS_H_
8+
9+
void SetPasswordSyncAllowed(bool allowed);
10+
11+
#define SetPasswordSyncAllowed \
12+
SetPasswordSyncAllowed_ChromiumImpl(bool allowed); \
13+
void SetPasswordSyncAllowed
14+
15+
#include "src/components/sync/service/sync_prefs.h" // IWYU pragma: export
16+
17+
#undef SetPasswordSyncAllowed
18+
19+
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SERVICE_SYNC_PREFS_H_

components/brave_sync/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,6 @@ source_set("unit_tests") {
157157
"//components/os_crypt/sync:test_support",
158158
"//components/prefs:test_support",
159159
"//components/sync/base",
160+
"//components/sync/service",
160161
]
161162
}

components/brave_sync/brave_sync_prefs_unittest.cc

+32
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "testing/gmock/include/gmock/gmock.h"
1818
#include "testing/gtest/include/gtest/gtest.h"
1919

20+
#if BUILDFLAG(IS_ANDROID)
21+
#include "components/sync/service/sync_prefs.h"
22+
#endif
23+
2024
namespace brave_sync {
2125

2226
namespace {
@@ -33,6 +37,10 @@ class BraveSyncPrefsTest : public testing::Test {
3337
BraveSyncPrefsTest() {
3438
brave_sync::Prefs::RegisterProfilePrefs(pref_service_.registry());
3539
brave_sync_prefs_ = std::make_unique<brave_sync::Prefs>(&pref_service_);
40+
#if BUILDFLAG(IS_ANDROID)
41+
syncer::SyncPrefs::RegisterProfilePrefs(pref_service_.registry());
42+
sync_prefs_ = std::make_unique<syncer::SyncPrefs>(&pref_service_);
43+
#endif
3644
}
3745

3846
brave_sync::Prefs* brave_sync_prefs() { return brave_sync_prefs_.get(); }
@@ -42,6 +50,10 @@ class BraveSyncPrefsTest : public testing::Test {
4250
base::test::SingleThreadTaskEnvironment task_environment_;
4351
TestingPrefServiceSimple pref_service_;
4452
std::unique_ptr<brave_sync::Prefs> brave_sync_prefs_;
53+
54+
#if BUILDFLAG(IS_ANDROID)
55+
std::unique_ptr<syncer::SyncPrefs> sync_prefs_;
56+
#endif
4557
};
4658

4759
#if BUILDFLAG(IS_APPLE)
@@ -127,4 +139,24 @@ TEST_F(BraveSyncPrefsTest, LeaveChainDetailsMaxLenIOS) {
127139
EXPECT_EQ(details.size(), max_len);
128140
}
129141

142+
#if BUILDFLAG(IS_ANDROID)
143+
// This test is a modified upstream's
144+
// SyncPrefsTest.PasswordSyncAllowed_ExplicitValue
145+
TEST_F(BraveSyncPrefsTest, PasswordSyncAllowedExplicitValue) {
146+
using syncer::UserSelectableType;
147+
using syncer::UserSelectableTypeSet;
148+
149+
// Make passwords explicitly enabled (no default value).
150+
sync_prefs_->SetSelectedTypesForSyncingUser(
151+
/*keep_everything_synced=*/false,
152+
/*registered_types=*/UserSelectableTypeSet::All(),
153+
/*selected_types=*/{UserSelectableType::kPasswords});
154+
155+
sync_prefs_->SetPasswordSyncAllowed(false);
156+
157+
EXPECT_TRUE(sync_prefs_->GetSelectedTypesForSyncingUser().Has(
158+
UserSelectableType::kPasswords));
159+
}
160+
#endif
161+
130162
} // namespace brave_sync

0 commit comments

Comments
 (0)