Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Himanshu Jaju | 115ec0b | 2019-10-30 11:59:39 | [diff] [blame] | 2 | // 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 Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 7 | #include "base/test/scoped_feature_list.h" |
Alex Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 8 | #include "chrome/browser/sharing/fake_device_info.h" |
Alex Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 9 | #include "chrome/browser/sharing/features.h" |
Alex Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 10 | #include "chrome/browser/sharing/proto/sharing_message.pb.h" |
| 11 | #include "chrome/browser/sharing/sharing_constants.h" |
Victor Hugo Vianna Silva | e92e300 | 2021-07-26 14:38:50 | [diff] [blame] | 12 | #include "components/sync/protocol/device_info_specifics.pb.h" |
| 13 | #include "components/sync/protocol/sync_enums.pb.h" |
Victor Hugo Vianna Silva | e500900 | 2022-08-31 13:36:39 | [diff] [blame] | 14 | #include "components/sync/test/test_sync_service.h" |
Himanshu Jaju | 115ec0b | 2019-10-30 11:59:39 | [diff] [blame] | 15 | #include "components/sync_device_info/device_info.h" |
| 16 | #include "testing/gtest/include/gtest/gtest.h" |
| 17 | |
| 18 | namespace { |
Alex Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 19 | |
Alex Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 20 | const char kDeviceGuid[] = "test_guid"; |
| 21 | const char kDeviceName[] = "test_name"; |
| 22 | const char kVapidFCMToken[] = "test_vapid_fcm_token"; |
| 23 | const char kVapidP256dh[] = "test_vapid_p256_dh"; |
| 24 | const char kVapidAuthSecret[] = "test_vapid_auth_secret"; |
| 25 | const char kSenderIdFCMToken[] = "test_sender_id_fcm_token"; |
| 26 | const char kSenderIdP256dh[] = "test_sender_id_p256_dh"; |
| 27 | const char kSenderIdAuthSecret[] = "test_sender_id_auth_secret"; |
| 28 | |
Alex Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 29 | class 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 Jaju | 115ec0b | 2019-10-30 11:59:39 | [diff] [blame] | 38 | } // namespace |
| 39 | |
Naomi Musgrave | d9fc0bf | 2020-04-22 18:46:26 | [diff] [blame] | 40 | TEST_F(SharingUtilsTest, SyncEnabled_FullySynced) { |
| 41 | // Disable transport mode required features. |
Alex Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 42 | scoped_feature_list_.InitWithFeatures( |
Naomi Musgrave | d9fc0bf | 2020-04-22 18:46:26 | [diff] [blame] | 43 | /*enabled_features=*/{}, |
| 44 | /*disabled_features=*/{kSharingSendViaSync}); |
Alex Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 45 | test_sync_service_.SetTransportState( |
| 46 | syncer::SyncService::TransportState::ACTIVE); |
Naomi Musgrave | d9fc0bf | 2020-04-22 18:46:26 | [diff] [blame] | 47 | // PREFERENCES is actively synced. |
| 48 | test_sync_service_.SetActiveDataTypes( |
| 49 | {syncer::DEVICE_INFO, syncer::PREFERENCES}); |
Alex Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 50 | |
| 51 | EXPECT_TRUE(IsSyncEnabledForSharing(&test_sync_service_)); |
| 52 | EXPECT_FALSE(IsSyncDisabledForSharing(&test_sync_service_)); |
| 53 | } |
| 54 | |
Naomi Musgrave | d9fc0bf | 2020-04-22 18:46:26 | [diff] [blame] | 55 | TEST_F(SharingUtilsTest, SyncDisabled_FullySynced_MissingDataTypes) { |
Alex Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 56 | // Disable transport mode required features. |
| 57 | scoped_feature_list_.InitWithFeatures( |
| 58 | /*enabled_features=*/{}, |
Naomi Musgrave | d9fc0bf | 2020-04-22 18:46:26 | [diff] [blame] | 59 | /*disabled_features=*/{kSharingSendViaSync}); |
Alex Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 60 | test_sync_service_.SetTransportState( |
| 61 | syncer::SyncService::TransportState::ACTIVE); |
Naomi Musgrave | d9fc0bf | 2020-04-22 18:46:26 | [diff] [blame] | 62 | // 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 | |
| 69 | TEST_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 Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 77 | test_sync_service_.SetActiveDataTypes( |
Naomi Musgrave | d9fc0bf | 2020-04-22 18:46:26 | [diff] [blame] | 78 | {syncer::DEVICE_INFO, syncer::SHARING_MESSAGE}); |
Alex Chau | 2badb80 | 2019-11-15 13:47:03 | [diff] [blame] | 79 | |
| 80 | EXPECT_TRUE(IsSyncEnabledForSharing(&test_sync_service_)); |
| 81 | EXPECT_FALSE(IsSyncDisabledForSharing(&test_sync_service_)); |
| 82 | } |
| 83 | |
| 84 | TEST_F(SharingUtilsTest, SyncDisabled_SigninOnly_MissingDataTypes) { |
|
|