Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / enable_disable_test.cc
blobc1ef8a8f1738f7dccc6d3d542352505e1a9f7c71
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/test/integration/profile_sync_service_harness.h"
6 #include "chrome/browser/sync/test/integration/sync_test.h"
7 #include "sync/internal_api/public/base/model_type.h"
8 #include "sync/internal_api/public/read_node.h"
9 #include "sync/internal_api/public/read_transaction.h"
11 // This file contains tests that exercise enabling and disabling data
12 // types.
14 namespace {
16 class EnableDisableTest : public SyncTest {
17 public:
18 explicit EnableDisableTest(TestType test_type) : SyncTest(test_type) {}
19 virtual ~EnableDisableTest() {}
20 private:
21 DISALLOW_COPY_AND_ASSIGN(EnableDisableTest);
24 class EnableDisableSingleClientTest : public EnableDisableTest {
25 public:
26 EnableDisableSingleClientTest() : EnableDisableTest(SINGLE_CLIENT) {}
27 virtual ~EnableDisableSingleClientTest() {}
28 private:
29 DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest);
32 bool DoesTopLevelNodeExist(syncer::UserShare* user_share,
33 syncer::ModelType type) {
34 syncer::ReadTransaction trans(FROM_HERE, user_share);
35 syncer::ReadNode node(&trans);
36 return node.InitByTagLookup(syncer::ModelTypeToRootTag(type)) ==
37 syncer::BaseNode::INIT_OK;
40 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, EnableOneAtATime) {
41 ASSERT_TRUE(SetupClients());
43 // Setup sync with no enabled types.
44 ASSERT_TRUE(GetClient(0)->SetupSync(syncer::ModelTypeSet()));
46 // TODO(rlarocque, 97780): It should be possible to disable notifications
47 // before calling SetupSync(). We should move this line back to the top
48 // of this function when this is supported.
49 DisableNotifications();
51 const syncer::ModelTypeSet registered_types =
52 GetClient(0)->service()->GetRegisteredDataTypes();
53 syncer::UserShare* user_share = GetClient(0)->service()->GetUserShare();
54 for (syncer::ModelTypeSet::Iterator it = registered_types.First();
55 it.Good(); it.Inc()) {
56 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(it.Get()));
58 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
59 // SESSIONS is lumped together with PROXY_TABS and
60 // HISTORY_DELETE_DIRECTIVES.
61 // Favicons are lumped together with PROXY_TABS and
62 // HISTORY_DELETE_DIRECTIVES.
63 if (it.Get() == syncer::AUTOFILL_PROFILE || it.Get() == syncer::SESSIONS) {
64 continue;
67 if (!syncer::ProxyTypes().Has(it.Get())) {
68 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()))
69 << syncer::ModelTypeToString(it.Get());
72 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
73 if (it.Get() == syncer::AUTOFILL) {
74 ASSERT_TRUE(DoesTopLevelNodeExist(user_share,
75 syncer::AUTOFILL_PROFILE));
76 } else if (it.Get() == syncer::HISTORY_DELETE_DIRECTIVES ||
77 it.Get() == syncer::PROXY_TABS) {
78 ASSERT_TRUE(DoesTopLevelNodeExist(user_share,
79 syncer::SESSIONS));
83 EnableNotifications();
86 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) {
87 ASSERT_TRUE(SetupClients());
89 // Setup sync with no disabled types.
90 ASSERT_TRUE(GetClient(0)->SetupSync());
92 // TODO(rlarocque, 97780): It should be possible to disable notifications
93 // before calling SetupSync(). We should move this line back to the top
94 // of this function when this is supported.
95 DisableNotifications();
97 const syncer::ModelTypeSet registered_types =
98 GetClient(0)->service()->GetRegisteredDataTypes();
100 syncer::UserShare* user_share = GetClient(0)->service()->GetUserShare();
102 // Make sure all top-level nodes exist first.
103 for (syncer::ModelTypeSet::Iterator it = registered_types.First();
104 it.Good(); it.Inc()) {
105 if (!syncer::ProxyTypes().Has(it.Get())) {
106 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()));
110 for (syncer::ModelTypeSet::Iterator it = registered_types.First();
111 it.Good(); it.Inc()) {
112 // MANAGED_USERS is always synced.
113 if (it.Get() == syncer::MANAGED_USERS ||
114 it.Get() == syncer::SYNCED_NOTIFICATIONS)
115 continue;
117 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it.Get()));
119 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
120 // SESSIONS is lumped together with PROXY_TABS and TYPED_URLS.
121 // HISTORY_DELETE_DIRECTIVES is lumped together with TYPED_URLS.
122 // PRIORITY_PREFERENCES is lumped together with PREFERENCES.
123 // Favicons are lumped together with PROXY_TABS and
124 // HISTORY_DELETE_DIRECTIVES.
125 if (it.Get() == syncer::AUTOFILL_PROFILE ||
126 it.Get() == syncer::SESSIONS ||
127 it.Get() == syncer::HISTORY_DELETE_DIRECTIVES ||
128 it.Get() == syncer::PRIORITY_PREFERENCES ||
129 it.Get() == syncer::FAVICON_IMAGES ||
130 it.Get() == syncer::FAVICON_TRACKING) {
131 continue;
134 syncer::UserShare* user_share =
135 GetClient(0)->service()->GetUserShare();
137 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, it.Get()))
138 << syncer::ModelTypeToString(it.Get());
140 if (it.Get() == syncer::AUTOFILL) {
141 // AUTOFILL_PROFILE is lumped together with AUTOFILL.
142 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, syncer::AUTOFILL_PROFILE));
143 } else if (it.Get() == syncer::TYPED_URLS) {
144 ASSERT_FALSE(DoesTopLevelNodeExist(user_share,
145 syncer::HISTORY_DELETE_DIRECTIVES));
146 // SESSIONS should be enabled only if PROXY_TABS is.
147 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::PROXY_TABS),
148 DoesTopLevelNodeExist(user_share, syncer::SESSIONS));
149 } else if (it.Get() == syncer::PROXY_TABS) {
150 // SESSIONS should be enabled only if TYPED_URLS is.
151 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::TYPED_URLS),
152 DoesTopLevelNodeExist(user_share, syncer::SESSIONS));
153 } else if (it.Get() == syncer::PREFERENCES) {
154 ASSERT_FALSE(DoesTopLevelNodeExist(user_share,
155 syncer::PRIORITY_PREFERENCES));
159 EnableNotifications();
162 } // namespace