1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sync/service/sync_service_utils.h"
#include "components/sync/base/data_type.h"
#include "components/sync/service/sync_service.h"
#include "components/sync/test/test_sync_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
TEST(SyncServiceUtilsTest, UploadToGoogleDisabledIfSyncNotAllowed) {
TestSyncService service;
// If sync is not allowed, uploading should never be enabled, even if all the
// data types are enabled.
service.SetAllowedByEnterprisePolicy(false);
service.GetUserSettings()->SetSelectedTypes(
/*sync_everything=*/true,
/*types=*/UserSelectableTypeSet::All());
EXPECT_EQ(UploadState::NOT_ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// Once sync gets allowed (e.g. policy is updated), uploading should not be
// disabled anymore (though not necessarily active yet).
service.SetAllowedByEnterprisePolicy(true);
service.SetMaxTransportState(
syncer::SyncService::TransportState::START_DEFERRED);
EXPECT_NE(UploadState::NOT_ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
}
TEST(SyncServiceUtilsTest,
UploadToGoogleInitializingUntilConfiguredAndActiveAndSyncCycleComplete) {
TestSyncService service;
service.SetMaxTransportState(
syncer::SyncService::TransportState::START_DEFERRED);
service.GetUserSettings()->SetSelectedTypes(
/*sync_everything=*/true,
/*types=*/UserSelectableTypeSet::All());
service.SetEmptyLastCycleSnapshot();
// By default, if sync isn't disabled, we should be INITIALIZING.
EXPECT_EQ(UploadState::INITIALIZING,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// Finished configuration is not enough, still INITIALIZING.
service.SetMaxTransportState(syncer::SyncService::TransportState::ACTIVE);
EXPECT_EQ(UploadState::INITIALIZING,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// Only after a sync cycle has been completed is upload actually ACTIVE.
service.SetNonEmptyLastCycleSnapshot();
EXPECT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
}
TEST(SyncServiceUtilsTest, UploadToGoogleDisabledForDataType) {
TestSyncService service;
service.SetNonEmptyLastCycleSnapshot();
// Sync is enabled only for a specific data type.
service.GetUserSettings()->SetSelectedTypes(
/*sync_everything=*/false,
/*types=*/{syncer::UserSelectableType::kBookmarks});
// Sanity check: Upload is ACTIVE for this data type.
ASSERT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// ...but not for other types.
EXPECT_EQ(
UploadState::NOT_ACTIVE,
GetUploadToGoogleState(&service, syncer::HISTORY_DELETE_DIRECTIVES));
EXPECT_EQ(UploadState::NOT_ACTIVE,
GetUploadToGoogleState(&service, syncer::PREFERENCES));
}
TEST(SyncServiceUtilsTest, UploadToGoogleDisabledForDataTypeThatFailedToStart) {
TestSyncService service;
service.SetNonEmptyLastCycleSnapshot();
// Sync is enabled for some data types.
service.GetUserSettings()->SetSelectedTypes(
/*sync_everything=*/false,
/*types=*/{syncer::UserSelectableType::kBookmarks,
syncer::UserSelectableType::kPreferences});
// But one of them fails to actually start up!
service.SetFailedDataTypes({syncer::PREFERENCES});
// Sanity check: Upload is ACTIVE for the data type that did start up.
ASSERT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// ...but not for the type that failed.
EXPECT_EQ(UploadState::NOT_ACTIVE,
GetUploadToGoogleState(&service, syncer::PREFERENCES));
}
TEST(SyncServiceUtilsTest, UploadToGoogleDisabledIfLocalSyncEnabled) {
TestSyncService service;
service.GetUserSettings()->SetSelectedTypes(
/*sync_everything=*/true,
/*types=*/UserSelectableTypeSet::All());
service.SetNonEmptyLastCycleSnapshot();
// Sanity check: Upload is active now.
ASSERT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// If we're in "local sync" mode, uploading should never be enabled, even if
// configuration is done and all the data types are enabled.
service.SetLocalSyncEnabled(true);
EXPECT_EQ(UploadState::NOT_ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
}
TEST(SyncServiceUtilsTest, UploadToGoogleDisabledOnPersistentAuthError) {
TestSyncService service;
service.GetUserSettings()->SetSelectedTypes(
/*sync_everything=*/true,
/*types=*/UserSelectableTypeSet::All());
service.SetNonEmptyLastCycleSnapshot();
// Sanity check: Upload is active now.
ASSERT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// On a persistent error, uploading is not considered active anymore (even
// though Sync may still be considered active).
service.SetPersistentAuthError();
EXPECT_EQ(UploadState::NOT_ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// Once the auth error is resolved (e.g. user re-authenticated), uploading is
// active again.
service.ClearAuthError();
EXPECT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
}
TEST(SyncServiceUtilsTest, UploadToGoogleDisabledIfCustomPassphraseInUse) {
TestSyncService service;
service.GetUserSettings()->SetSelectedTypes(
/*sync_everything=*/true,
/*types=*/UserSelectableTypeSet::All());
service.SetNonEmptyLastCycleSnapshot();
// Sanity check: Upload is ACTIVE, even for data types that are always
// encrypted implicitly (PASSWORDS).
ASSERT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
ASSERT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::PASSWORDS));
ASSERT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::DEVICE_INFO));
// Once a custom passphrase is in use, upload should be considered disabled:
// Even if we're technically still uploading, Google can't inspect the data.
service.SetIsUsingExplicitPassphrase(true);
EXPECT_EQ(UploadState::NOT_ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
EXPECT_EQ(UploadState::NOT_ACTIVE,
GetUploadToGoogleState(&service, syncer::PASSWORDS));
// But unencryptable types like DEVICE_INFO are still active.
EXPECT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::DEVICE_INFO));
}
TEST(SyncServiceUtilsTest, UploadToGoogleEnabledInTransportMode) {
TestSyncService service;
service.GetUserSettings()->SetSelectedTypes(
/*sync_everything=*/true,
/*types=*/UserSelectableTypeSet::All());
service.SetNonEmptyLastCycleSnapshot();
// Sanity check: Everything's looking good, so upload is considered active.
ASSERT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// Sign in without kSync consent. With this, only Sync-the-transport (not
// Sync-the-feature) can run.
service.SetSignedIn(signin::ConsentLevel::kSignin);
ASSERT_FALSE(service.CanSyncFeatureStart());
// Regardless, if the datatype is active, it means uploading data is also
// allowed.
EXPECT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
}
TEST(SyncServiceUtilsTest, UploadToGoogleEnabledDespiteInitialSetupIncomplete) {
TestSyncService service;
service.GetUserSettings()->SetSelectedTypes(
/*sync_everything=*/true,
/*types=*/UserSelectableTypeSet::All());
service.SetNonEmptyLastCycleSnapshot();
// Sanity check: Everything's looking good, so upload is considered active.
ASSERT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
// Clear the first-setup-complete bit.
service.GetUserSettings()->ClearInitialSyncFeatureSetupComplete();
// Regardless, if the datatype is active, it means uploading data is also
// allowed.
EXPECT_EQ(UploadState::ACTIVE,
GetUploadToGoogleState(&service, syncer::BOOKMARKS));
}
} // namespace syncer
|