enable_disable_test.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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/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" 10 11// This file contains tests that exercise enabling and disabling data 12// types. 13 14namespace { 15 16class 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); 22}; 23 24class EnableDisableSingleClientTest : public EnableDisableTest { 25 public: 26 EnableDisableSingleClientTest() : EnableDisableTest(SINGLE_CLIENT) {} 27 virtual ~EnableDisableSingleClientTest() {} 28 private: 29 DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest); 30}; 31 32bool 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; 38} 39 40IN_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 // 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(); 50 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())); 57 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; 65 } 66 67 if (!syncer::ProxyTypes().Has(it.Get())) { 68 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get())) 69 << syncer::ModelTypeToString(it.Get()); 70 } 71 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)); 80 } 81 } 82 83 EnableNotifications(); 84} 85 86IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) { 87 ASSERT_TRUE(SetupClients()); 88 89 // Setup sync with no disabled types. 90 ASSERT_TRUE(GetClient(0)->SetupSync()); 91 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(); 96 97 const syncer::ModelTypeSet registered_types = 98 GetClient(0)->service()->GetRegisteredDataTypes(); 99 100 syncer::UserShare* user_share = GetClient(0)->service()->GetUserShare(); 101 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())); 107 } 108 } 109 110 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 111 it.Good(); it.Inc()) { 112 // MANAGED_USERS and MANAGED_USER_SETTINGS are always synced. 113 if (it.Get() == syncer::MANAGED_USERS || 114 it.Get() == syncer::MANAGED_USER_SHARED_SETTINGS || 115 it.Get() == syncer::SYNCED_NOTIFICATIONS || 116 it.Get() == syncer::SYNCED_NOTIFICATION_APP_INFO) 117 continue; 118 119 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it.Get())); 120 121 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 122 // SESSIONS is lumped together with PROXY_TABS and TYPED_URLS. 123 // HISTORY_DELETE_DIRECTIVES is lumped together with TYPED_URLS. 124 // PRIORITY_PREFERENCES is lumped together with PREFERENCES. 125 // Favicons are lumped together with PROXY_TABS and 126 // HISTORY_DELETE_DIRECTIVES. 127 if (it.Get() == syncer::AUTOFILL_PROFILE || 128 it.Get() == syncer::SESSIONS || 129 it.Get() == syncer::HISTORY_DELETE_DIRECTIVES || 130 it.Get() == syncer::PRIORITY_PREFERENCES || 131 it.Get() == syncer::FAVICON_IMAGES || 132 it.Get() == syncer::FAVICON_TRACKING) { 133 continue; 134 } 135 136 syncer::UserShare* user_share = 137 GetClient(0)->service()->GetUserShare(); 138 139 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, it.Get())) 140 << syncer::ModelTypeToString(it.Get()); 141 142 if (it.Get() == syncer::AUTOFILL) { 143 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 144 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, syncer::AUTOFILL_PROFILE)); 145 } else if (it.Get() == syncer::TYPED_URLS) { 146 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, 147 syncer::HISTORY_DELETE_DIRECTIVES)); 148 // SESSIONS should be enabled only if PROXY_TABS is. 149 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::PROXY_TABS), 150 DoesTopLevelNodeExist(user_share, syncer::SESSIONS)); 151 } else if (it.Get() == syncer::PROXY_TABS) { 152 // SESSIONS should be enabled only if TYPED_URLS is. 153 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::TYPED_URLS), 154 DoesTopLevelNodeExist(user_share, syncer::SESSIONS)); 155 } else if (it.Get() == syncer::PREFERENCES) { 156 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, 157 syncer::PRIORITY_PREFERENCES)); 158 } 159 } 160 161 EnableNotifications(); 162} 163 164} // namespace 165