1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/profile_sync_service.h"
6 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
7 #include "chrome/browser/sync/test/integration/sync_test.h"
8 #include "sync/internal_api/public/base/model_type.h"
9 #include "sync/internal_api/public/read_node.h"
10 #include "sync/internal_api/public/read_transaction.h"
12 // This file contains tests that exercise enabling and disabling data
17 class EnableDisableSingleClientTest
: public SyncTest
{
19 EnableDisableSingleClientTest() : SyncTest(SINGLE_CLIENT
) {}
20 ~EnableDisableSingleClientTest() override
{}
22 // Don't use self-notifications as they can trigger additional sync cycles.
23 bool TestUsesSelfNotifications() override
{ return false; }
26 DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest
);
29 bool DoesTopLevelNodeExist(syncer::UserShare
* user_share
,
30 syncer::ModelType type
) {
31 syncer::ReadTransaction
trans(FROM_HERE
, user_share
);
32 syncer::ReadNode
node(&trans
);
33 return node
.InitTypeRoot(type
) == syncer::BaseNode::INIT_OK
;
36 bool IsUnready(const sync_driver::DataTypeStatusTable
& data_type_status_table
,
37 syncer::ModelType type
) {
38 return data_type_status_table
.GetUnreadyErrorTypes().Has(type
);
41 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest
, EnableOneAtATime
) {
42 ASSERT_TRUE(SetupClients());
44 // Setup sync with no enabled types.
45 ASSERT_TRUE(GetClient(0)->SetupSync(syncer::ModelTypeSet()));
47 const syncer::ModelTypeSet registered_types
=
48 GetSyncService(0)->GetRegisteredDataTypes();
49 syncer::UserShare
* user_share
= GetSyncService(0)->GetUserShare();
50 const sync_driver::DataTypeStatusTable
& data_type_status_table
=
51 GetSyncService(0)->data_type_status_table();
52 for (syncer::ModelTypeSet::Iterator it
= registered_types
.First();
53 it
.Good(); it
.Inc()) {
54 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(it
.Get()));
56 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
57 // SESSIONS is lumped together with PROXY_TABS and
58 // HISTORY_DELETE_DIRECTIVES.
59 // Favicons are lumped together with PROXY_TABS and
60 // HISTORY_DELETE_DIRECTIVES.
61 if (it
.Get() == syncer::AUTOFILL_PROFILE
|| it
.Get() == syncer::SESSIONS
) {
65 if (!syncer::ProxyTypes().Has(it
.Get())) {
66 ASSERT_TRUE(DoesTopLevelNodeExist(user_share
, it
.Get()) ||
67 IsUnready(data_type_status_table
, it
.Get()))
68 << syncer::ModelTypeToString(it
.Get());
71 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
72 if (it
.Get() == syncer::AUTOFILL
) {
73 ASSERT_TRUE(DoesTopLevelNodeExist(user_share
,
74 syncer::AUTOFILL_PROFILE
));
75 } else if (it
.Get() == syncer::HISTORY_DELETE_DIRECTIVES
||
76 it
.Get() == syncer::PROXY_TABS
) {
77 ASSERT_TRUE(DoesTopLevelNodeExist(user_share
,
83 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest
, DisableOneAtATime
) {
84 ASSERT_TRUE(SetupClients());
86 // Setup sync with no disabled types.
87 ASSERT_TRUE(GetClient(0)->SetupSync());
89 const syncer::ModelTypeSet registered_types
=
90 GetSyncService(0)->GetRegisteredDataTypes();
92 syncer::UserShare
* user_share
= GetSyncService(0)->GetUserShare();
94 const sync_driver::DataTypeStatusTable
& data_type_status_table
=
95 GetSyncService(0)->data_type_status_table();
97 // Make sure all top-level nodes exist first.
98 for (syncer::ModelTypeSet::Iterator it
= registered_types
.First();
99 it
.Good(); it
.Inc()) {
100 if (!syncer::ProxyTypes().Has(it
.Get())) {
101 ASSERT_TRUE(DoesTopLevelNodeExist(user_share
, it
.Get()) ||
102 IsUnready(data_type_status_table
, it
.Get()));
106 for (syncer::ModelTypeSet::Iterator it
= registered_types
.First();
107 it
.Good(); it
.Inc()) {
108 // SUPERVISED_USERS and SUPERVISED_USER_SHARED_SETTINGS are always synced.
109 if (it
.Get() == syncer::SUPERVISED_USERS
||
110 it
.Get() == syncer::SUPERVISED_USER_SHARED_SETTINGS
||
111 it
.Get() == syncer::SYNCED_NOTIFICATIONS
||
112 it
.Get() == syncer::SYNCED_NOTIFICATION_APP_INFO
)
115 // Device info cannot be disabled.
116 if (it
.Get() == syncer::DEVICE_INFO
)
119 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it
.Get()));
121 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
122 // SESSIONS is lumped together with PROXY_TABS and TYPED_URLS.
123 // HISTORY_DELETE_DIRECTIVES is lumped together with TYPED_URLS.
124 // PRIORITY_PREFERENCES is lumped together with PREFERENCES.
125 // Favicons are lumped together with PROXY_TABS and
126 // HISTORY_DELETE_DIRECTIVES.
127 if (it
.Get() == syncer::AUTOFILL_PROFILE
||
128 it
.Get() == syncer::SESSIONS
||
129 it
.Get() == syncer::HISTORY_DELETE_DIRECTIVES
||
130 it
.Get() == syncer::PRIORITY_PREFERENCES
||
131 it
.Get() == syncer::FAVICON_IMAGES
||
132 it
.Get() == syncer::FAVICON_TRACKING
) {
136 syncer::UserShare
* user_share
=
137 GetSyncService(0)->GetUserShare();
139 ASSERT_FALSE(DoesTopLevelNodeExist(user_share
, it
.Get()))
140 << syncer::ModelTypeToString(it
.Get());
142 if (it
.Get() == syncer::AUTOFILL
) {
143 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
144 ASSERT_FALSE(DoesTopLevelNodeExist(user_share
, syncer::AUTOFILL_PROFILE
));
145 } else if (it
.Get() == syncer::TYPED_URLS
) {
146 ASSERT_FALSE(DoesTopLevelNodeExist(user_share
,
147 syncer::HISTORY_DELETE_DIRECTIVES
));
148 // SESSIONS should be enabled only if PROXY_TABS is.
149 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::PROXY_TABS
),
150 DoesTopLevelNodeExist(user_share
, syncer::SESSIONS
));
151 } else if (it
.Get() == syncer::PROXY_TABS
) {
152 // SESSIONS should be enabled only if TYPED_URLS is.
153 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::TYPED_URLS
),
154 DoesTopLevelNodeExist(user_share
, syncer::SESSIONS
));
155 } else if (it
.Get() == syncer::PREFERENCES
) {
156 ASSERT_FALSE(DoesTopLevelNodeExist(user_share
,
157 syncer::PRIORITY_PREFERENCES
));