enable_disable_test.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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 15namespace { 16 17class 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 25class EnableDisableSingleClientTest : public EnableDisableTest { 26 public: 27 EnableDisableSingleClientTest() : EnableDisableTest(SINGLE_CLIENT) {} 28 virtual ~EnableDisableSingleClientTest() {} 29 private: 30 DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest); 31}; 32 33bool 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 41IN_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 if (it.Get() == syncer::AUTOFILL_PROFILE || it.Get() == syncer::SESSIONS) { 63 continue; 64 } 65 66 if (!syncer::ProxyTypes().Has(it.Get())) { 67 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get())) 68 << syncer::ModelTypeToString(it.Get()); 69 } 70 71 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 72 if (it.Get() == syncer::AUTOFILL) { 73 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, 74 syncer::AUTOFILL_PROFILE)); 75 } else if (it.Get() == syncer::HISTORY_DELETE_DIRECTIVES || 76 it.Get() == syncer::PROXY_TABS) { 77 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, 78 syncer::SESSIONS)); 79 } 80 } 81 82 EnableNotifications(); 83} 84 85IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) { 86 ASSERT_TRUE(SetupClients()); 87 88 // Setup sync with no disabled types. 89 ASSERT_TRUE(GetClient(0)->SetupSync()); 90 91 // TODO(rlarocque, 97780): It should be possible to disable notifications 92 // before calling SetupSync(). We should move this line back to the top 93 // of this function when this is supported. 94 DisableNotifications(); 95 96 const syncer::ModelTypeSet registered_types = 97 GetClient(0)->service()->GetRegisteredDataTypes(); 98 99 syncer::UserShare* user_share = GetClient(0)->service()->GetUserShare(); 100 101 // Make sure all top-level nodes exist first. 102 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 103 it.Good(); it.Inc()) { 104 if (!syncer::ProxyTypes().Has(it.Get())) { 105 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get())); 106 } 107 } 108 109 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 110 it.Good(); it.Inc()) { 111 // MANAGED_USERS is always synced. 112 if (it.Get() == syncer::MANAGED_USERS) 113 continue; 114 115 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it.Get())); 116 117 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 118 // SESSIONS is lumped together with PROXY_TABS and TYPED_URLS. 119 // HISTORY_DELETE_DIRECTIVES is lumped together with TYPED_URLS. 120 // PRIORITY_PREFERENCES is lumped together with PREFERENCES. 121 if (it.Get() == syncer::AUTOFILL_PROFILE || 122 it.Get() == syncer::SESSIONS || 123 it.Get() == syncer::HISTORY_DELETE_DIRECTIVES || 124 it.Get() == syncer::PRIORITY_PREFERENCES) { 125 continue; 126 } 127 128 syncer::UserShare* user_share = 129 GetClient(0)->service()->GetUserShare(); 130 131 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, it.Get())) 132 << syncer::ModelTypeToString(it.Get()); 133 134 if (it.Get() == syncer::AUTOFILL) { 135 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 136 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, syncer::AUTOFILL_PROFILE)); 137 } else if (it.Get() == syncer::TYPED_URLS) { 138 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, 139 syncer::HISTORY_DELETE_DIRECTIVES)); 140 // SESSIONS should be enabled only if PROXY_TABS is. 141 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::PROXY_TABS), 142 DoesTopLevelNodeExist(user_share, syncer::SESSIONS)); 143 } else if (it.Get() == syncer::PROXY_TABS) { 144 // SESSIONS should be enabled only if TYPED_URLS is. 145 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::TYPED_URLS), 146 DoesTopLevelNodeExist(user_share, syncer::SESSIONS)); 147 } else if (it.Get() == syncer::PREFERENCES) { 148 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, 149 syncer::PRIORITY_PREFERENCES)); 150 } 151 } 152 153 EnableNotifications(); 154} 155 156} // namespace 157