Commit e63f5191 authored by Alex Chau's avatar Alex Chau Committed by Commit Bot

Check if sync is toggled on in IsReceivingEnabledByUserOnThisDevice

- As DeviceInfo will sync for transport-only device in M79,
  send_tab_to_self should be disabled for transport-only devices as tabs
  is not yet syncing in transprot-only mode

Bug: 1014705
Change-Id: I084e88a04f643ccdf6c000461b34da2399492d1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865248
Commit-Queue: Alex Chau <alexchau@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarRamya Nagarajan <ramyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706865}
parent 6eb4340f
......@@ -63,6 +63,7 @@ source_set("test_support") {
source_set("unit_tests") {
testonly = true
sources = [
"features_unittest.cc",
"send_tab_to_self_bridge_unittest.cc",
"send_tab_to_self_entry_unittest.cc",
]
......@@ -74,6 +75,7 @@ source_set("unit_tests") {
"//components/send_tab_to_self/proto:send_tab_to_self_proto",
"//components/sync:test_support",
"//components/sync_device_info:test_support",
"//components/sync_preferences:test_support",
"//testing/gtest",
"//url",
]
......
include_rules = [
"+components/history",
"+components/infobars",
"+components/keyed_service/core",
"+components/sync",
"+components/sync_device_info",
"+components/sync_preferences",
"+components/version_info",
"+components/history",
"+content/public/browser",
"+google_apis",
]
......@@ -16,8 +16,16 @@ const base::Feature kSendTabToSelfWhenSignedIn{
"SendTabToSelfWhenSignedIn", base::FEATURE_DISABLED_BY_DEFAULT};
bool IsReceivingEnabledByUserOnThisDevice(PrefService* prefs) {
// TODO(crbug.com/1015322): SyncPrefs is used directly instead of methods in
// SyncService due to a dependency of ProfileSyncService on
// DeviceInfoSyncService. IsReceivingEnabledByUserOnThisDevice is ultimately
// used by DeviceInfoSyncClient which is owend by DeviceInfoSyncService.
syncer::SyncPrefs sync_prefs(prefs);
return sync_prefs.GetSelectedTypes().Has(syncer::UserSelectableType::kTabs);
// As per documentation in SyncUserSettings, IsSyncRequested indicates user
// wants Sync to run, when combined with IsFirstSetupComplete, indicates
// whether user has consented to Sync.
return sync_prefs.IsSyncRequested() && sync_prefs.IsFirstSetupComplete() &&
sync_prefs.GetSelectedTypes().Has(syncer::UserSelectableType::kTabs);
}
bool EnabledOnSignIn() {
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/send_tab_to_self/features.h"
#include <memory>
#include "base/test/task_environment.h"
#include "components/sync/base/sync_prefs.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace send_tab_to_self {
namespace {
class SendTabToSelfFeaturesTest : public testing::Test {
public:
SendTabToSelfFeaturesTest() {
syncer::SyncPrefs::RegisterProfilePrefs(prefs_.registry());
sync_prefs_ = std::make_unique<syncer::SyncPrefs>(&prefs_);
}
protected:
sync_preferences::TestingPrefServiceSyncable prefs_;
std::unique_ptr<syncer::SyncPrefs> sync_prefs_;
base::test::TaskEnvironment task_environment_;
};
TEST_F(SendTabToSelfFeaturesTest,
IsReceivingEnabledByUserOnThisDevice_Enabled) {
sync_prefs_->SetSyncRequested(true);
sync_prefs_->SetFirstSetupComplete();
sync_prefs_->SetSelectedTypes(
/*keep_everything_synced=*/false,
/*registered_types=*/syncer::UserSelectableTypeSet::All(),
/*selected_types=*/{syncer::UserSelectableType::kTabs});
EXPECT_TRUE(IsReceivingEnabledByUserOnThisDevice(&prefs_));
}
TEST_F(SendTabToSelfFeaturesTest,
IsReceivingEnabledByUserOnThisDevice_SyncNotRequested) {
sync_prefs_->SetSyncRequested(false);
sync_prefs_->SetFirstSetupComplete();
sync_prefs_->SetSelectedTypes(
/*keep_everything_synced=*/false,
/*registered_types=*/syncer::UserSelectableTypeSet::All(),
/*selected_types=*/{syncer::UserSelectableType::kTabs});
EXPECT_FALSE(IsReceivingEnabledByUserOnThisDevice(&prefs_));
}
TEST_F(SendTabToSelfFeaturesTest,
IsReceivingEnabledByUserOnThisDevice_FirstSetupNotCompleted) {
sync_prefs_->SetSyncRequested(true);
// Skip setting FirstSetupComplete.
sync_prefs_->SetSelectedTypes(
/*keep_everything_synced=*/false,
/*registered_types=*/syncer::UserSelectableTypeSet::All(),
/*selected_types=*/{syncer::UserSelectableType::kTabs});
EXPECT_FALSE(IsReceivingEnabledByUserOnThisDevice(&prefs_));
}
TEST_F(SendTabToSelfFeaturesTest,
IsReceivingEnabledByUserOnThisDevice_TabsNotSelected) {
sync_prefs_->SetSyncRequested(true);
sync_prefs_->SetFirstSetupComplete();
sync_prefs_->SetSelectedTypes(
/*keep_everything_synced=*/false,
/*registered_types=*/syncer::UserSelectableTypeSet::All(),
/*selected_types=*/{});
EXPECT_FALSE(IsReceivingEnabledByUserOnThisDevice(&prefs_));
}
} // namespace
} // namespace send_tab_to_self
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