OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/macros.h" | 5 #include "base/macros.h" |
6 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 6 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
7 #include "chrome/browser/sync/test/integration/sync_test.h" | 7 #include "chrome/browser/sync/test/integration/sync_test.h" |
8 #include "components/browser_sync/profile_sync_service.h" | 8 #include "components/browser_sync/profile_sync_service.h" |
9 #include "components/sync/base/model_type.h" | 9 #include "components/sync/base/model_type.h" |
10 #include "components/sync/syncable/read_node.h" | 10 #include "components/sync/syncable/read_node.h" |
11 #include "components/sync/syncable/read_transaction.h" | 11 #include "components/sync/syncable/read_transaction.h" |
12 | 12 |
13 // This file contains tests that exercise enabling and disabling data | 13 // This file contains tests that exercise enabling and disabling data |
14 // types. | 14 // types. |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 using syncer::ModelTypeSet; | |
19 | |
18 class EnableDisableSingleClientTest : public SyncTest { | 20 class EnableDisableSingleClientTest : public SyncTest { |
19 public: | 21 public: |
20 EnableDisableSingleClientTest() : SyncTest(SINGLE_CLIENT) {} | 22 EnableDisableSingleClientTest() : SyncTest(SINGLE_CLIENT) {} |
21 ~EnableDisableSingleClientTest() override {} | 23 ~EnableDisableSingleClientTest() override {} |
22 | 24 |
23 // Don't use self-notifications as they can trigger additional sync cycles. | 25 // Don't use self-notifications as they can trigger additional sync cycles. |
24 bool TestUsesSelfNotifications() override { return false; } | 26 bool TestUsesSelfNotifications() override { return false; } |
25 | 27 |
26 private: | 28 private: |
27 DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest); | 29 DISALLOW_COPY_AND_ASSIGN(EnableDisableSingleClientTest); |
28 }; | 30 }; |
29 | 31 |
30 bool DoesTopLevelNodeExist(syncer::UserShare* user_share, | 32 bool DoesTopLevelNodeExist(syncer::UserShare* user_share, |
31 syncer::ModelType type) { | 33 syncer::ModelType type) { |
32 syncer::ReadTransaction trans(FROM_HERE, user_share); | 34 syncer::ReadTransaction trans(FROM_HERE, user_share); |
33 syncer::ReadNode node(&trans); | 35 syncer::ReadNode node(&trans); |
34 return node.InitTypeRoot(type) == syncer::BaseNode::INIT_OK; | 36 return node.InitTypeRoot(type) == syncer::BaseNode::INIT_OK; |
35 } | 37 } |
36 | 38 |
37 bool IsUnready(const syncer::DataTypeStatusTable& data_type_status_table, | 39 bool IsUnready(const syncer::DataTypeStatusTable& data_type_status_table, |
38 syncer::ModelType type) { | 40 syncer::ModelType type) { |
39 return data_type_status_table.GetUnreadyErrorTypes().Has(type); | 41 return data_type_status_table.GetUnreadyErrorTypes().Has(type); |
40 } | 42 } |
41 | 43 |
44 // The current approach this test class takes is to examine the Directory and | |
45 // check for root nodes to see if a type is currently enabled. While this works | |
46 // for things in the directory, it does not work for USS types. USS does not | |
47 // have any general data access mechanism, at least yet. Until that exists, | |
48 // simply omit types that may be USS from these cases. | |
49 ModelTypeSet UnifiedSyncServiceTypes() { | |
50 ModelTypeSet set; | |
51 set.Put(syncer::DEVICE_INFO); | |
52 return set; | |
maxbogue
2016/12/19 20:55:45
Can't you just do return ModelTypeSet(syncer::Devi
skym
2016/12/20 16:11:21
Done.
| |
53 } | |
54 | |
42 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, EnableOneAtATime) { | 55 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, EnableOneAtATime) { |
43 ASSERT_TRUE(SetupClients()); | 56 ASSERT_TRUE(SetupClients()); |
44 | 57 |
45 // Setup sync with no enabled types. | 58 // Setup sync with no enabled types. |
46 ASSERT_TRUE(GetClient(0)->SetupSync(syncer::ModelTypeSet())); | 59 ASSERT_TRUE(GetClient(0)->SetupSync(ModelTypeSet())); |
47 | 60 |
48 syncer::UserShare* user_share = GetSyncService(0)->GetUserShare(); | 61 syncer::UserShare* user_share = GetSyncService(0)->GetUserShare(); |
49 const syncer::DataTypeStatusTable& data_type_status_table = | 62 const syncer::DataTypeStatusTable& data_type_status_table = |
50 GetSyncService(0)->data_type_status_table(); | 63 GetSyncService(0)->data_type_status_table(); |
51 | 64 |
52 const syncer::ModelTypeSet registered_types = | 65 const ModelTypeSet registered_types = |
53 GetSyncService(0)->GetRegisteredDataTypes(); | 66 GetSyncService(0)->GetRegisteredDataTypes(); |
54 const syncer::ModelTypeSet registered_user_types = | 67 const ModelTypeSet registered_directory_types = |
68 Difference(registered_types, UnifiedSyncServiceTypes()); | |
69 const ModelTypeSet registered_directory_user_types = | |
55 Intersection(registered_types, syncer::UserSelectableTypes()); | 70 Intersection(registered_types, syncer::UserSelectableTypes()); |
56 for (syncer::ModelTypeSet::Iterator it = registered_user_types.First(); | 71 for (ModelTypeSet::Iterator it = registered_directory_user_types.First(); |
57 it.Good(); it.Inc()) { | 72 it.Good(); it.Inc()) { |
58 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(it.Get())); | 73 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(it.Get())); |
59 | 74 |
60 // AUTOFILL_PROFILE is lumped together with AUTOFILL. | 75 // AUTOFILL_PROFILE is lumped together with AUTOFILL. |
61 // SESSIONS is lumped together with PROXY_TABS and | 76 // SESSIONS is lumped together with PROXY_TABS and |
62 // HISTORY_DELETE_DIRECTIVES. | 77 // HISTORY_DELETE_DIRECTIVES. |
63 // Favicons are lumped together with PROXY_TABS and | 78 // Favicons are lumped together with PROXY_TABS and |
64 // HISTORY_DELETE_DIRECTIVES. | 79 // HISTORY_DELETE_DIRECTIVES. |
65 if (it.Get() == syncer::AUTOFILL_PROFILE || it.Get() == syncer::SESSIONS) { | 80 if (it.Get() == syncer::AUTOFILL_PROFILE || it.Get() == syncer::SESSIONS) { |
66 continue; | 81 continue; |
(...skipping 16 matching lines...) Expand all Loading... | |
83 } | 98 } |
84 } | 99 } |
85 } | 100 } |
86 | 101 |
87 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) { | 102 IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) { |
88 ASSERT_TRUE(SetupClients()); | 103 ASSERT_TRUE(SetupClients()); |
89 | 104 |
90 // Setup sync with no disabled types. | 105 // Setup sync with no disabled types. |
91 ASSERT_TRUE(GetClient(0)->SetupSync()); | 106 ASSERT_TRUE(GetClient(0)->SetupSync()); |
92 | 107 |
93 const syncer::ModelTypeSet registered_types = | 108 const ModelTypeSet registered_types = |
94 GetSyncService(0)->GetRegisteredDataTypes(); | 109 GetSyncService(0)->GetRegisteredDataTypes(); |
110 const ModelTypeSet registered_directory_types = | |
111 Difference(registered_types, UnifiedSyncServiceTypes()); | |
95 | 112 |
96 syncer::UserShare* user_share = GetSyncService(0)->GetUserShare(); | 113 syncer::UserShare* user_share = GetSyncService(0)->GetUserShare(); |
97 | 114 |
98 const syncer::DataTypeStatusTable& data_type_status_table = | 115 const syncer::DataTypeStatusTable& data_type_status_table = |
99 GetSyncService(0)->data_type_status_table(); | 116 GetSyncService(0)->data_type_status_table(); |
100 | 117 |
101 // Make sure all top-level nodes exist first. | 118 // Make sure all top-level nodes exist first. |
102 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); | 119 for (ModelTypeSet::Iterator it = registered_directory_types.First(); |
103 it.Good(); it.Inc()) { | 120 it.Good(); it.Inc()) { |
104 if (!syncer::ProxyTypes().Has(it.Get())) { | 121 if (!syncer::ProxyTypes().Has(it.Get())) { |
105 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()) || | 122 ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()) || |
106 IsUnready(data_type_status_table, it.Get())); | 123 IsUnready(data_type_status_table, it.Get())); |
107 } | 124 } |
108 } | 125 } |
109 | 126 |
110 for (syncer::ModelTypeSet::Iterator it = registered_types.First(); | 127 for (ModelTypeSet::Iterator it = registered_directory_types.First(); |
111 it.Good(); it.Inc()) { | 128 it.Good(); it.Inc()) { |
112 // SUPERVISED_USERS and SUPERVISED_USER_SHARED_SETTINGS are always synced. | 129 // SUPERVISED_USERS and SUPERVISED_USER_SHARED_SETTINGS are always synced. |
113 if (it.Get() == syncer::SUPERVISED_USERS || | 130 if (it.Get() == syncer::SUPERVISED_USERS || |
114 it.Get() == syncer::SUPERVISED_USER_SHARED_SETTINGS || | 131 it.Get() == syncer::SUPERVISED_USER_SHARED_SETTINGS || |
115 it.Get() == syncer::SYNCED_NOTIFICATIONS || | 132 it.Get() == syncer::SYNCED_NOTIFICATIONS || |
116 it.Get() == syncer::SYNCED_NOTIFICATION_APP_INFO) | 133 it.Get() == syncer::SYNCED_NOTIFICATION_APP_INFO) |
117 continue; | 134 continue; |
118 | 135 |
119 // Device info cannot be disabled. | 136 // Device info cannot be disabled. |
120 if (it.Get() == syncer::DEVICE_INFO) | 137 if (it.Get() == syncer::DEVICE_INFO) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::TYPED_URLS), | 174 ASSERT_EQ(GetClient(0)->IsTypePreferred(syncer::TYPED_URLS), |
158 DoesTopLevelNodeExist(user_share, syncer::SESSIONS)); | 175 DoesTopLevelNodeExist(user_share, syncer::SESSIONS)); |
159 } else if (it.Get() == syncer::PREFERENCES) { | 176 } else if (it.Get() == syncer::PREFERENCES) { |
160 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, | 177 ASSERT_FALSE(DoesTopLevelNodeExist(user_share, |
161 syncer::PRIORITY_PREFERENCES)); | 178 syncer::PRIORITY_PREFERENCES)); |
162 } | 179 } |
163 } | 180 } |
164 } | 181 } |
165 | 182 |
166 } // namespace | 183 } // namespace |
OLD | NEW |