Upstream version 11.39.264.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / enable_disable_test.cc
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.
4
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"
11
12 // This file contains tests that exercise enabling and disabling data
13 // types.
14
15 namespace {
16
17 class EnableDisableSingleClientTest : public SyncTest {
18  public:
19   EnableDisableSingleClientTest() : SyncTest(SINGLE_CLIENT) {}
20   virtual ~EnableDisableSingleClientTest() {}
21
22   // Don't use self-notifications as they can trigger additional sync cycles.
23   virtual bool TestUsesSelfNotifications() OVERRIDE { return false; }
24  private:
25   DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest);
26 };
27
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;
33 }
34
35 bool IsUnready(const sync_driver::DataTypeStatusTable& data_type_status_table,
36                syncer::ModelType type) {
37   return data_type_status_table.GetUnreadyErrorTypes().Has(type);
38 }
39
40 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, EnableOneAtATime) {
41   ASSERT_TRUE(SetupClients());
42
43   // Setup sync with no enabled types.
44   ASSERT_TRUE(GetClient(0)->SetupSync(syncer::ModelTypeSet()));
45
46   const syncer::ModelTypeSet registered_types =
47       GetSyncService(0)->GetRegisteredDataTypes();
48   syncer::UserShare* user_share = GetSyncService(0)->GetUserShare();
49   const sync_driver::DataTypeStatusTable& data_type_status_table =
50       GetSyncService(0)->data_type_status_table();
51   for (syncer::ModelTypeSet::Iterator it = registered_types.First();
52        it.Good(); it.Inc()) {
53     ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(it.Get()));
54
55     // AUTOFILL_PROFILE is lumped together with AUTOFILL.
56     // SESSIONS is lumped together with PROXY_TABS and
57     // HISTORY_DELETE_DIRECTIVES.
58     // Favicons are lumped together with PROXY_TABS and
59     // HISTORY_DELETE_DIRECTIVES.
60     if (it.Get() == syncer::AUTOFILL_PROFILE || it.Get() == syncer::SESSIONS) {
61       continue;
62     }
63
64     if (!syncer::ProxyTypes().Has(it.Get())) {
65       ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()) ||
66                   IsUnready(data_type_status_table, it.Get()))
67           << syncer::ModelTypeToString(it.Get());
68     }
69
70     // AUTOFILL_PROFILE is lumped together with AUTOFILL.
71     if (it.Get() == syncer::AUTOFILL) {
72       ASSERT_TRUE(DoesTopLevelNodeExist(user_share,
73                                         syncer::AUTOFILL_PROFILE));
74     } else if (it.Get() == syncer::HISTORY_DELETE_DIRECTIVES ||
75                it.Get() == syncer::PROXY_TABS) {
76       ASSERT_TRUE(DoesTopLevelNodeExist(user_share,
77                                         syncer::SESSIONS));
78     }
79   }
80 }
81
82 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) {
83   ASSERT_TRUE(SetupClients());
84
85   // Setup sync with no disabled types.
86   ASSERT_TRUE(GetClient(0)->SetupSync());
87
88   const syncer::ModelTypeSet registered_types =
89       GetSyncService(0)->GetRegisteredDataTypes();
90
91   syncer::UserShare* user_share = GetSyncService(0)->GetUserShare();
92
93   const sync_driver::DataTypeStatusTable& data_type_status_table =
94       GetSyncService(0)->data_type_status_table();
95
96   // Make sure all top-level nodes exist first.
97   for (syncer::ModelTypeSet::Iterator it = registered_types.First();
98        it.Good(); it.Inc()) {
99     if (!syncer::ProxyTypes().Has(it.Get())) {
100       ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()) ||
101                   IsUnready(data_type_status_table, it.Get()));
102     }
103   }
104
105   for (syncer::ModelTypeSet::Iterator it = registered_types.First();
106        it.Good(); it.Inc()) {
107     // SUPERVISED_USERS and SUPERVISED_USER_SHARED_SETTINGS are always synced.
108     if (it.Get() == syncer::SUPERVISED_USERS ||
109         it.Get() == syncer::SUPERVISED_USER_SHARED_SETTINGS ||
110         it.Get() == syncer::SYNCED_NOTIFICATIONS ||
111         it.Get() == syncer::SYNCED_NOTIFICATION_APP_INFO)
112       continue;
113
114     // Device info cannot be disabled.
115     if (it.Get() == syncer::DEVICE_INFO)
116       continue;
117
118     ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it.Get()));
119
120     // AUTOFILL_PROFILE is lumped together with AUTOFILL.
121     // SESSIONS is lumped together with PROXY_TABS and TYPED_URLS.
122     // HISTORY_DELETE_DIRECTIVES is lumped together with TYPED_URLS.
123     // PRIORITY_PREFERENCES is lumped together with PREFERENCES.
124     // Favicons are lumped together with PROXY_TABS and
125     // HISTORY_DELETE_DIRECTIVES.
126     if (it.Get() == syncer::AUTOFILL_PROFILE ||
127         it.Get() == syncer::SESSIONS ||
128         it.Get() == syncer::HISTORY_DELETE_DIRECTIVES ||
129         it.Get() == syncer::PRIORITY_PREFERENCES ||
130         it.Get() == syncer::FAVICON_IMAGES ||
131         it.Get() == syncer::FAVICON_TRACKING) {
132       continue;
133     }
134
135     syncer::UserShare* user_share =
136         GetSyncService(0)->GetUserShare();
137
138     ASSERT_FALSE(DoesTopLevelNodeExist(user_share, it.Get()))
139         << syncer::ModelTypeToString(it.Get());
140
141     if (it.Get() == syncer::AUTOFILL) {
142       // AUTOFILL_PROFILE is lumped together with AUTOFILL.
143       ASSERT_FALSE(DoesTopLevelNodeExist(user_share, syncer::AUTOFILL_PROFILE));
144     } else if (it.Get() == syncer::TYPED_URLS) {
145       ASSERT_FALSE(DoesTopLevelNodeExist(user_share,
146                                          syncer::HISTORY_DELETE_DIRECTIVES));
147       // SESSIONS should be enabled only if PROXY_TABS is.
148       ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::PROXY_TABS),
149                 DoesTopLevelNodeExist(user_share, syncer::SESSIONS));
150     } else if (it.Get() == syncer::PROXY_TABS) {
151       // SESSIONS should be enabled only if TYPED_URLS is.
152       ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::TYPED_URLS),
153                 DoesTopLevelNodeExist(user_share, syncer::SESSIONS));
154     } else if (it.Get() == syncer::PREFERENCES) {
155       ASSERT_FALSE(DoesTopLevelNodeExist(user_share,
156                                          syncer::PRIORITY_PREFERENCES));
157     }
158   }
159 }
160
161 }  // namespace