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 virtual ~EnableDisableSingleClientTest() {}
22 // Don't use self-notifications as they can trigger additional sync cycles.
23 virtual bool TestUsesSelfNotifications() OVERRIDE { return false; }
25 DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest);
28 bool DoesTopLevelNodeExist(syncer::UserShare* user_share,
29 syncer::ModelType type) {
30 syncer::ReadTransaction trans(FROM_HERE, user_share);
31 syncer::ReadNode node(&trans);
32 return node.InitTypeRoot(type) == syncer::BaseNode::INIT_OK;
35 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, EnableOneAtATime) {
36 ASSERT_TRUE(SetupClients());
38 // Setup sync with no enabled types.
39 ASSERT_TRUE(GetClient(0)->SetupSync(syncer::ModelTypeSet()));
41 const syncer::ModelTypeSet registered_types =
42 GetSyncService((0))->GetRegisteredDataTypes();
43 syncer::UserShare* user_share = GetSyncService((0))->GetUserShare();
44 for (syncer::ModelTypeSet::Iterator it = registered_types.First();
45 it.Good(); it.Inc()) {
46 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(it.Get()));
48 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
49 // SESSIONS is lumped together with PROXY_TABS and
50 // HISTORY_DELETE_DIRECTIVES.
51 // Favicons are lumped together with PROXY_TABS and
52 // HISTORY_DELETE_DIRECTIVES.
53 if (it.Get() == syncer::AUTOFILL_PROFILE || it.Get() == syncer::SESSIONS) {
57 if (!syncer::ProxyTypes().Has(it.Get())) {
58 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()))
59 << syncer::ModelTypeToString(it.Get());
62 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
63 if (it.Get() == syncer::AUTOFILL) {
64 ASSERT_TRUE(DoesTopLevelNodeExist(user_share,
65 syncer::AUTOFILL_PROFILE));
66 } else if (it.Get() == syncer::HISTORY_DELETE_DIRECTIVES ||
67 it.Get() == syncer::PROXY_TABS) {
68 ASSERT_TRUE(DoesTopLevelNodeExist(user_share,
74 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) {
75 ASSERT_TRUE(SetupClients());
77 // Setup sync with no disabled types.
78 ASSERT_TRUE(GetClient(0)->SetupSync());
80 const syncer::ModelTypeSet registered_types =
81 GetSyncService((0))->GetRegisteredDataTypes();
83 syncer::UserShare* user_share = GetSyncService((0))->GetUserShare();
85 // Make sure all top-level nodes exist first.
86 for (syncer::ModelTypeSet::Iterator it = registered_types.First();
87 it.Good(); it.Inc()) {
88 if (!syncer::ProxyTypes().Has(it.Get())) {
89 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()));
93 for (syncer::ModelTypeSet::Iterator it = registered_types.First();
94 it.Good(); it.Inc()) {
95 // SUPERVISED_USERS and SUPERVISED_USER_SHARED_SETTINGS are always synced.
96 if (it.Get() == syncer::SUPERVISED_USERS ||
97 it.Get() == syncer::SUPERVISED_USER_SHARED_SETTINGS ||
98 it.Get() == syncer::SYNCED_NOTIFICATIONS ||
99 it.Get() == syncer::SYNCED_NOTIFICATION_APP_INFO)
102 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it.Get()));
104 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
105 // SESSIONS is lumped together with PROXY_TABS and TYPED_URLS.
106 // HISTORY_DELETE_DIRECTIVES is lumped together with TYPED_URLS.
107 // PRIORITY_PREFERENCES is lumped together with PREFERENCES.
108 // Favicons are lumped together with PROXY_TABS and
109 // HISTORY_DELETE_DIRECTIVES.
110 if (it.Get() == syncer::AUTOFILL_PROFILE ||
111 it.Get() == syncer::SESSIONS ||
112 it.Get() == syncer::HISTORY_DELETE_DIRECTIVES ||
113 it.Get() == syncer::PRIORITY_PREFERENCES ||
114 it.Get() == syncer::FAVICON_IMAGES ||
115 it.Get() == syncer::FAVICON_TRACKING) {
119 syncer::UserShare* user_share =
120 GetSyncService((0))->GetUserShare();
122 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, it.Get()))
123 << syncer::ModelTypeToString(it.Get());
125 if (it.Get() == syncer::AUTOFILL) {
126 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
127 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, syncer::AUTOFILL_PROFILE));
128 } else if (it.Get() == syncer::TYPED_URLS) {
129 ASSERT_FALSE(DoesTopLevelNodeExist(user_share,
130 syncer::HISTORY_DELETE_DIRECTIVES));
131 // SESSIONS should be enabled only if PROXY_TABS is.
132 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::PROXY_TABS),
133 DoesTopLevelNodeExist(user_share, syncer::SESSIONS));
134 } else if (it.Get() == syncer::PROXY_TABS) {
135 // SESSIONS should be enabled only if TYPED_URLS is.
136 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::TYPED_URLS),
137 DoesTopLevelNodeExist(user_share, syncer::SESSIONS));
138 } else if (it.Get() == syncer::PREFERENCES) {
139 ASSERT_FALSE(DoesTopLevelNodeExist(user_share,
140 syncer::PRIORITY_PREFERENCES));