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/test/integration/sync_test.h" 6 7 #include "chrome/browser/sync/profile_sync_service_harness.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 EnableDisableTest : public SyncTest { 18 public: 19 explicit EnableDisableTest(TestType test_type) : SyncTest(test_type) {} 20 virtual ~EnableDisableTest() {} 21 private: 22 DISALLOW_COPY_AND_ASSIGN(EnableDisableTest); 23 }; 24 25 class EnableDisableSingleClientTest : public EnableDisableTest { 26 public: 27 EnableDisableSingleClientTest() : EnableDisableTest(SINGLE_CLIENT) {} 28 virtual ~EnableDisableSingleClientTest() {} 29 private: 30 DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest); 31 }; 32 33 bool DoesTopLevelNodeExist(syncer::UserShare* user_share, 34 syncer::ModelType type) { 35 syncer::ReadTransaction trans(FROM_HERE, user_share); 36 syncer::ReadNode node(&trans); 37 return node.InitByTagLookup(syncer::ModelTypeToRootTag(type)) == 38 syncer::BaseNode::INIT_OK; 39 } 40 41 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, EnableOneAtATime) { 42 ASSERT_TRUE(SetupClients()); 43 44 // Setup sync with no enabled types. 45 ASSERT_TRUE(GetClient(0)->SetupSync(syncer::ModelTypeSet())); 46 47 // TODO(rlarocque, 97780): It should be possible to disable notifications 48 // before calling SetupSync(). We should move this line back to the top 49 // of this function when this is supported. 50 DisableNotifications(); 51 52 const syncer::ModelTypeSet registered_types = 53 GetClient(0)->service()->GetRegisteredDataTypes(); 54 syncer::UserShare* user_share = GetClient(0)->service()->GetUserShare(); 55 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 56 it.Good(); it.Inc()) { 57 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(it.Get())); 58 59 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 60 // SESSIONS is lumped together with PROXY_TABS and 61 // HISTORY_DELETE_DIRECTIVES. 62 // Favicons are lumped together with PROXY_TABS and 63 // HISTORY_DELETE_DIRECTIVES. 64 if (it.Get() == syncer::AUTOFILL_PROFILE || it.Get() == syncer::SESSIONS) { 65 continue; 66 } 67 68 if (!syncer::ProxyTypes().Has(it.Get())) { 69 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get())) 70 << syncer::ModelTypeToString(it.Get()); 71 } 72 73 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 74 if (it.Get() == syncer::AUTOFILL) { 75 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, 76 syncer::AUTOFILL_PROFILE)); 77 } else if (it.Get() == syncer::HISTORY_DELETE_DIRECTIVES || 78 it.Get() == syncer::PROXY_TABS) { 79 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, 80 syncer::SESSIONS)); 81 } 82 } 83 84 EnableNotifications(); 85 } 86 87 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) { 88 ASSERT_TRUE(SetupClients()); 89 90 // Setup sync with no disabled types. 91 ASSERT_TRUE(GetClient(0)->SetupSync()); 92 93 // TODO(rlarocque, 97780): It should be possible to disable notifications 94 // before calling SetupSync(). We should move this line back to the top 95 // of this function when this is supported. 96 DisableNotifications(); 97 98 const syncer::ModelTypeSet registered_types = 99 GetClient(0)->service()->GetRegisteredDataTypes(); 100 101 syncer::UserShare* user_share = GetClient(0)->service()->GetUserShare(); 102 103 // Make sure all top-level nodes exist first. 104 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 105 it.Good(); it.Inc()) { 106 if (!syncer::ProxyTypes().Has(it.Get())) { 107 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get())); 108 } 109 } 110 111 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 112 it.Good(); it.Inc()) { 113 // MANAGED_USERS is always synced. 114 if (it.Get() == syncer::MANAGED_USERS || 115 it.Get() == syncer::SYNCED_NOTIFICATIONS) 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 GetClient(0)->service()->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 EnableNotifications(); 161 } 162 163 } // namespace 164