enable_disable_test.cc revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
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
15namespace {
16
17class 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
28bool 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
35IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, EnableOneAtATime) {
36  ASSERT_TRUE(SetupClients());
37
38  // Setup sync with no enabled types.
39  ASSERT_TRUE(GetClient(0)->SetupSync(syncer::ModelTypeSet()));
40
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()));
47
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) {
54      continue;
55    }
56
57    if (!syncer::ProxyTypes().Has(it.Get())) {
58      ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()))
59          << syncer::ModelTypeToString(it.Get());
60    }
61
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,
69                                        syncer::SESSIONS));
70    }
71  }
72}
73
74IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) {
75  ASSERT_TRUE(SetupClients());
76
77  // Setup sync with no disabled types.
78  ASSERT_TRUE(GetClient(0)->SetupSync());
79
80  const syncer::ModelTypeSet registered_types =
81      GetSyncService((0))->GetRegisteredDataTypes();
82
83  syncer::UserShare* user_share = GetSyncService((0))->GetUserShare();
84
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()));
90    }
91  }
92
93  for (syncer::ModelTypeSet::Iterator it = registered_types.First();
94       it.Good(); it.Inc()) {
95    // MANAGED_USERS and MANAGED_USER_SETTINGS are always synced.
96    if (it.Get() == syncer::MANAGED_USERS ||
97        it.Get() == syncer::MANAGED_USER_SHARED_SETTINGS ||
98        it.Get() == syncer::SYNCED_NOTIFICATIONS ||
99        it.Get() == syncer::SYNCED_NOTIFICATION_APP_INFO)
100      continue;
101
102    ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it.Get()));
103
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) {
116      continue;
117    }
118
119    syncer::UserShare* user_share =
120        GetSyncService((0))->GetUserShare();
121
122    ASSERT_FALSE(DoesTopLevelNodeExist(user_share, it.Get()))
123        << syncer::ModelTypeToString(it.Get());
124
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));
141    }
142  }
143}
144
145}  // namespace
146