enable_disable_test.cc revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
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 // TODO(pvalenzuela): Switch to SINGLE_CLIENT once FakeServer 20 // supports this scenario. 21 EnableDisableSingleClientTest() : SyncTest(SINGLE_CLIENT_LEGACY) {} 22 virtual ~EnableDisableSingleClientTest() {} 23 private: 24 DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest); 25}; 26 27bool DoesTopLevelNodeExist(syncer::UserShare* user_share, 28 syncer::ModelType type) { 29 syncer::ReadTransaction trans(FROM_HERE, user_share); 30 syncer::ReadNode node(&trans); 31 return node.InitByTagLookup(syncer::ModelTypeToRootTag(type)) == 32 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 // TODO(rlarocque, 97780): It should be possible to disable notifications 42 // before calling SetupSync(). We should move this line back to the top 43 // of this function when this is supported. 44 DisableNotifications(); 45 46 const syncer::ModelTypeSet registered_types = 47 GetSyncService((0))->GetRegisteredDataTypes(); 48 syncer::UserShare* user_share = GetSyncService((0))->GetUserShare(); 49 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 50 it.Good(); it.Inc()) { 51 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(it.Get())); 52 53 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 54 // SESSIONS is lumped together with PROXY_TABS and 55 // HISTORY_DELETE_DIRECTIVES. 56 // Favicons are lumped together with PROXY_TABS and 57 // HISTORY_DELETE_DIRECTIVES. 58 if (it.Get() == syncer::AUTOFILL_PROFILE || it.Get() == syncer::SESSIONS) { 59 continue; 60 } 61 62 if (!syncer::ProxyTypes().Has(it.Get())) { 63 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get())) 64 << syncer::ModelTypeToString(it.Get()); 65 } 66 67 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 68 if (it.Get() == syncer::AUTOFILL) { 69 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, 70 syncer::AUTOFILL_PROFILE)); 71 } else if (it.Get() == syncer::HISTORY_DELETE_DIRECTIVES || 72 it.Get() == syncer::PROXY_TABS) { 73 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, 74 syncer::SESSIONS)); 75 } 76 } 77 78 EnableNotifications(); 79} 80 81IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) { 82 ASSERT_TRUE(SetupClients()); 83 84 // Setup sync with no disabled types. 85 ASSERT_TRUE(GetClient(0)->SetupSync()); 86 87 // TODO(rlarocque, 97780): It should be possible to disable notifications 88 // before calling SetupSync(). We should move this line back to the top 89 // of this function when this is supported. 90 DisableNotifications(); 91 92 const syncer::ModelTypeSet registered_types = 93 GetSyncService((0))->GetRegisteredDataTypes(); 94 95 syncer::UserShare* user_share = GetSyncService((0))->GetUserShare(); 96 97 // Make sure all top-level nodes exist first. 98 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 99 it.Good(); it.Inc()) { 100 if (!syncer::ProxyTypes().Has(it.Get())) { 101 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get())); 102 } 103 } 104 105 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 106 it.Good(); it.Inc()) { 107 // MANAGED_USERS and MANAGED_USER_SETTINGS are always synced. 108 if (it.Get() == syncer::MANAGED_USERS || 109 it.Get() == syncer::MANAGED_USER_SHARED_SETTINGS || 110 it.Get() == syncer::SYNCED_NOTIFICATIONS || 111 it.Get() == syncer::SYNCED_NOTIFICATION_APP_INFO) 112 continue; 113 114 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it.Get())); 115 116 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 117 // SESSIONS is lumped together with PROXY_TABS and TYPED_URLS. 118 // HISTORY_DELETE_DIRECTIVES is lumped together with TYPED_URLS. 119 // PRIORITY_PREFERENCES is lumped together with PREFERENCES. 120 // Favicons are lumped together with PROXY_TABS and 121 // HISTORY_DELETE_DIRECTIVES. 122 if (it.Get() == syncer::AUTOFILL_PROFILE || 123 it.Get() == syncer::SESSIONS || 124 it.Get() == syncer::HISTORY_DELETE_DIRECTIVES || 125 it.Get() == syncer::PRIORITY_PREFERENCES || 126 it.Get() == syncer::FAVICON_IMAGES || 127 it.Get() == syncer::FAVICON_TRACKING) { 128 continue; 129 } 130 131 syncer::UserShare* user_share = 132 GetSyncService((0))->GetUserShare(); 133 134 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, it.Get())) 135 << syncer::ModelTypeToString(it.Get()); 136 137 if (it.Get() == syncer::AUTOFILL) { 138 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 139 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, syncer::AUTOFILL_PROFILE)); 140 } else if (it.Get() == syncer::TYPED_URLS) { 141 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, 142 syncer::HISTORY_DELETE_DIRECTIVES)); 143 // SESSIONS should be enabled only if PROXY_TABS is. 144 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::PROXY_TABS), 145 DoesTopLevelNodeExist(user_share, syncer::SESSIONS)); 146 } else if (it.Get() == syncer::PROXY_TABS) { 147 // SESSIONS should be enabled only if TYPED_URLS is. 148 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::TYPED_URLS), 149 DoesTopLevelNodeExist(user_share, syncer::SESSIONS)); 150 } else if (it.Get() == syncer::PREFERENCES) { 151 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, 152 syncer::PRIORITY_PREFERENCES)); 153 } 154 } 155 156 EnableNotifications(); 157} 158 159} // namespace 160