enable_disable_test.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 if (it.Get() == syncer::AUTOFILL_PROFILE) { 61 continue; 62 } 63 64 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get())) 65 << syncer::ModelTypeToString(it.Get()); 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 } 72 } 73 74 EnableNotifications(); 75} 76 77IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) { 78 ASSERT_TRUE(SetupClients()); 79 80 // Setup sync with no disabled types. 81 ASSERT_TRUE(GetClient(0)->SetupSync()); 82 83 // TODO(rlarocque, 97780): It should be possible to disable notifications 84 // before calling SetupSync(). We should move this line back to the top 85 // of this function when this is supported. 86 DisableNotifications(); 87 88 const syncer::ModelTypeSet registered_types = 89 GetClient(0)->service()->GetRegisteredDataTypes(); 90 91 syncer::UserShare* user_share = GetClient(0)->service()->GetUserShare(); 92 93 // Make sure all top-level nodes exist first. 94 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 95 it.Good(); it.Inc()) { 96 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get())); 97 } 98 99 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); 100 it.Good(); it.Inc()) { 101 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it.Get())); 102 103 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 104 if (it.Get() == syncer::AUTOFILL_PROFILE) { 105 continue; 106 } 107 108 syncer::UserShare* user_share = 109 GetClient(0)->service()->GetUserShare(); 110 111 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, it.Get())) 112 << syncer::ModelTypeToString(it.Get()); 113 114 // AUTOFILL_PROFILE is lumped together with AUTOFILL. 115 if (it.Get() == syncer::AUTOFILL) { 116 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, 117 syncer::AUTOFILL_PROFILE)); 118 } 119 } 120 121 EnableNotifications(); 122} 123 124} // namespace 125