blob: 931aadb4d4f20f3908523293e464a7e30b253c86 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2019 The Chromium Authors
Himanshu Jaju115ec0b2019-10-30 11:59:392// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/sharing/sharing_utils.h"
6
Alex Chau2badb802019-11-15 13:47:037#include "base/test/scoped_feature_list.h"
Alex Chau328eeb932020-04-22 11:06:358#include "chrome/browser/sharing/fake_device_info.h"
Alex Chau2badb802019-11-15 13:47:039#include "chrome/browser/sharing/features.h"
Alex Chau328eeb932020-04-22 11:06:3510#include "chrome/browser/sharing/proto/sharing_message.pb.h"
11#include "chrome/browser/sharing/sharing_constants.h"
Victor Hugo Vianna Silvae92e3002021-07-26 14:38:5012#include "components/sync/protocol/device_info_specifics.pb.h"
13#include "components/sync/protocol/sync_enums.pb.h"
Victor Hugo Vianna Silvae5009002022-08-31 13:36:3914#include "components/sync/test/test_sync_service.h"
Himanshu Jaju115ec0b2019-10-30 11:59:3915#include "components/sync_device_info/device_info.h"
16#include "testing/gtest/include/gtest/gtest.h"
17
18namespace {
Alex Chau2badb802019-11-15 13:47:0319
Alex Chau328eeb932020-04-22 11:06:3520const char kDeviceGuid[] = "test_guid";
21const char kDeviceName[] = "test_name";
22const char kVapidFCMToken[] = "test_vapid_fcm_token";
23const char kVapidP256dh[] = "test_vapid_p256_dh";
24const char kVapidAuthSecret[] = "test_vapid_auth_secret";
25const char kSenderIdFCMToken[] = "test_sender_id_fcm_token";
26const char kSenderIdP256dh[] = "test_sender_id_p256_dh";
27const char kSenderIdAuthSecret[] = "test_sender_id_auth_secret";
28
Alex Chau2badb802019-11-15 13:47:0329class SharingUtilsTest : public testing::Test {
30 public:
31 SharingUtilsTest() = default;
32
33 protected:
34 base::test::ScopedFeatureList scoped_feature_list_;
35 syncer::TestSyncService test_sync_service_;
36};
37
Himanshu Jaju115ec0b2019-10-30 11:59:3938} // namespace
39
Naomi Musgraved9fc0bf2020-04-22 18:46:2640TEST_F(SharingUtilsTest, SyncEnabled_FullySynced) {
41 // Disable transport mode required features.
Alex Chau2badb802019-11-15 13:47:0342 scoped_feature_list_.InitWithFeatures(
Naomi Musgraved9fc0bf2020-04-22 18:46:2643 /*enabled_features=*/{},
44 /*disabled_features=*/{kSharingSendViaSync});
Alex Chau2badb802019-11-15 13:47:0345 test_sync_service_.SetTransportState(
46 syncer::SyncService::TransportState::ACTIVE);
Naomi Musgraved9fc0bf2020-04-22 18:46:2647 // PREFERENCES is actively synced.
48 test_sync_service_.SetActiveDataTypes(
49 {syncer::DEVICE_INFO, syncer::PREFERENCES});
Alex Chau2badb802019-11-15 13:47:0350
51 EXPECT_TRUE(IsSyncEnabledForSharing(&test_sync_service_));
52 EXPECT_FALSE(IsSyncDisabledForSharing(&test_sync_service_));
53}
54
Naomi Musgraved9fc0bf2020-04-22 18:46:2655TEST_F(SharingUtilsTest, SyncDisabled_FullySynced_MissingDataTypes) {
Alex Chau2badb802019-11-15 13:47:0356 // Disable transport mode required features.
57 scoped_feature_list_.InitWithFeatures(
58 /*enabled_features=*/{},
Naomi Musgraved9fc0bf2020-04-22 18:46:2659 /*disabled_features=*/{kSharingSendViaSync});
Alex Chau2badb802019-11-15 13:47:0360 test_sync_service_.SetTransportState(
61 syncer::SyncService::TransportState::ACTIVE);
Naomi Musgraved9fc0bf2020-04-22 18:46:2662 // Missing PREFERENCES.
63 test_sync_service_.SetActiveDataTypes({syncer::DEVICE_INFO});
64
65 EXPECT_FALSE(IsSyncEnabledForSharing(&test_sync_service_));
66 EXPECT_TRUE(IsSyncDisabledForSharing(&test_sync_service_));
67}
68
69TEST_F(SharingUtilsTest, SyncEnabled_SigninOnly) {
70 // Enable transport mode required features.
71 scoped_feature_list_.InitWithFeatures(
72 /*enabled_features=*/{kSharingSendViaSync},
73 /*disabled_features=*/{});
74 test_sync_service_.SetTransportState(
75 syncer::SyncService::TransportState::ACTIVE);
76 // SHARING_MESSAGE is actively synced.
Alex Chau2badb802019-11-15 13:47:0377 test_sync_service_.SetActiveDataTypes(
Naomi Musgraved9fc0bf2020-04-22 18:46:2678 {syncer::DEVICE_INFO, syncer::SHARING_MESSAGE});
Alex Chau2badb802019-11-15 13:47:0379
80 EXPECT_TRUE(IsSyncEnabledForSharing(&test_sync_service_));
81 EXPECT_FALSE(IsSyncDisabledForSharing(&test_sync_service_));
82}
83
84TEST_F(SharingUtilsTest, SyncDisabled_SigninOnly_MissingDataTypes) {