OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(akalin): Rename this file to migration_test.cc. | 5 // TODO(akalin): Rename this file to migration_test.cc. |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 8 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sync/profile_sync_service_harness.h" | 10 #include "chrome/browser/sync/profile_sync_service_harness.h" |
11 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" | 11 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
12 #include "chrome/browser/sync/test/integration/sync_test.h" | 12 #include "chrome/browser/sync/test/integration/sync_test.h" |
13 #include "chrome/browser/sync/test/integration/preferences_helper.h" | 13 #include "chrome/browser/sync/test/integration/preferences_helper.h" |
14 #include "chrome/browser/translate/translate_prefs.h" | 14 #include "chrome/browser/translate/translate_prefs.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
17 | 17 |
18 using bookmarks_helper::AddURL; | 18 using bookmarks_helper::AddURL; |
19 using bookmarks_helper::IndexedURL; | 19 using bookmarks_helper::IndexedURL; |
20 using bookmarks_helper::IndexedURLTitle; | 20 using bookmarks_helper::IndexedURLTitle; |
21 | 21 |
22 using preferences_helper::BooleanPrefMatches; | 22 using preferences_helper::BooleanPrefMatches; |
23 using preferences_helper::ChangeBooleanPref; | 23 using preferences_helper::ChangeBooleanPref; |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Utility functions to make a model type set out of a small number of | 27 // Utility functions to make a model type set out of a small number of |
28 // model types. | 28 // model types. |
29 | 29 |
30 syncable::ModelEnumSet MakeSet(syncable::ModelType type) { | 30 syncable::ModelTypeSet MakeSet(syncable::ModelType type) { |
31 return syncable::ModelEnumSet(type); | 31 return syncable::ModelTypeSet(type); |
32 } | 32 } |
33 | 33 |
34 syncable::ModelEnumSet MakeSet(syncable::ModelType type1, | 34 syncable::ModelTypeSet MakeSet(syncable::ModelType type1, |
35 syncable::ModelType type2) { | 35 syncable::ModelType type2) { |
36 return syncable::ModelEnumSet(type1, type2); | 36 return syncable::ModelTypeSet(type1, type2); |
37 } | 37 } |
38 | 38 |
39 // An ordered list of model types sets to migrate. Used by | 39 // An ordered list of model types sets to migrate. Used by |
40 // RunMigrationTest(). | 40 // RunMigrationTest(). |
41 typedef std::deque<syncable::ModelEnumSet> MigrationList; | 41 typedef std::deque<syncable::ModelTypeSet> MigrationList; |
42 | 42 |
43 // Utility functions to make a MigrationList out of a small number of | 43 // Utility functions to make a MigrationList out of a small number of |
44 // model types / model type sets. | 44 // model types / model type sets. |
45 | 45 |
46 MigrationList MakeList(syncable::ModelEnumSet model_types) { | 46 MigrationList MakeList(syncable::ModelTypeSet model_types) { |
47 return MigrationList(1, model_types); | 47 return MigrationList(1, model_types); |
48 } | 48 } |
49 | 49 |
50 MigrationList MakeList(syncable::ModelEnumSet model_types1, | 50 MigrationList MakeList(syncable::ModelTypeSet model_types1, |
51 syncable::ModelEnumSet model_types2) { | 51 syncable::ModelTypeSet model_types2) { |
52 MigrationList migration_list; | 52 MigrationList migration_list; |
53 migration_list.push_back(model_types1); | 53 migration_list.push_back(model_types1); |
54 migration_list.push_back(model_types2); | 54 migration_list.push_back(model_types2); |
55 return migration_list; | 55 return migration_list; |
56 } | 56 } |
57 | 57 |
58 MigrationList MakeList(syncable::ModelType type) { | 58 MigrationList MakeList(syncable::ModelType type) { |
59 return MakeList(MakeSet(type)); | 59 return MakeList(MakeSet(type)); |
60 } | 60 } |
61 | 61 |
62 MigrationList MakeList(syncable::ModelType type1, | 62 MigrationList MakeList(syncable::ModelType type1, |
63 syncable::ModelType type2) { | 63 syncable::ModelType type2) { |
64 return MakeList(MakeSet(type1), MakeSet(type2)); | 64 return MakeList(MakeSet(type1), MakeSet(type2)); |
65 } | 65 } |
66 | 66 |
67 class MigrationTest : public SyncTest { | 67 class MigrationTest : public SyncTest { |
68 public: | 68 public: |
69 explicit MigrationTest(TestType test_type) : SyncTest(test_type) {} | 69 explicit MigrationTest(TestType test_type) : SyncTest(test_type) {} |
70 virtual ~MigrationTest() {} | 70 virtual ~MigrationTest() {} |
71 | 71 |
72 // TODO(akalin): Add more MODIFY_(data type) trigger methods, as | 72 // TODO(akalin): Add more MODIFY_(data type) trigger methods, as |
73 // well as a poll-based trigger method. | 73 // well as a poll-based trigger method. |
74 enum TriggerMethod { MODIFY_PREF, MODIFY_BOOKMARK, TRIGGER_NOTIFICATION }; | 74 enum TriggerMethod { MODIFY_PREF, MODIFY_BOOKMARK, TRIGGER_NOTIFICATION }; |
75 | 75 |
76 syncable::ModelEnumSet GetPreferredDataTypes() { | 76 syncable::ModelTypeSet GetPreferredDataTypes() { |
77 const syncable::ModelEnumSet preferred_data_types = | 77 const syncable::ModelTypeSet preferred_data_types = |
78 GetClient(0)->service()->GetPreferredDataTypes(); | 78 GetClient(0)->service()->GetPreferredDataTypes(); |
79 // Make sure all clients have the same preferred data types. | 79 // Make sure all clients have the same preferred data types. |
80 for (int i = 1; i < num_clients(); ++i) { | 80 for (int i = 1; i < num_clients(); ++i) { |
81 const syncable::ModelEnumSet other_preferred_data_types = | 81 const syncable::ModelTypeSet other_preferred_data_types = |
82 GetClient(i)->service()->GetPreferredDataTypes(); | 82 GetClient(i)->service()->GetPreferredDataTypes(); |
83 EXPECT_TRUE(preferred_data_types.Equals(other_preferred_data_types)); | 83 EXPECT_TRUE(preferred_data_types.Equals(other_preferred_data_types)); |
84 } | 84 } |
85 return preferred_data_types; | 85 return preferred_data_types; |
86 } | 86 } |
87 | 87 |
88 // Returns a MigrationList with every enabled data type in its own | 88 // Returns a MigrationList with every enabled data type in its own |
89 // set. | 89 // set. |
90 MigrationList GetPreferredDataTypesList() { | 90 MigrationList GetPreferredDataTypesList() { |
91 MigrationList migration_list; | 91 MigrationList migration_list; |
92 const syncable::ModelEnumSet preferred_data_types = | 92 const syncable::ModelTypeSet preferred_data_types = |
93 GetPreferredDataTypes(); | 93 GetPreferredDataTypes(); |
94 for (syncable::ModelEnumSet::Iterator it = | 94 for (syncable::ModelTypeSet::Iterator it = |
95 preferred_data_types.First(); it.Good(); it.Inc()) { | 95 preferred_data_types.First(); it.Good(); it.Inc()) { |
96 migration_list.push_back(MakeSet(it.Get())); | 96 migration_list.push_back(MakeSet(it.Get())); |
97 } | 97 } |
98 return migration_list; | 98 return migration_list; |
99 } | 99 } |
100 | 100 |
101 // Trigger a migration for the given types with the given method. | 101 // Trigger a migration for the given types with the given method. |
102 void TriggerMigration(syncable::ModelEnumSet model_types, | 102 void TriggerMigration(syncable::ModelTypeSet model_types, |
103 TriggerMethod trigger_method) { | 103 TriggerMethod trigger_method) { |
104 switch (trigger_method) { | 104 switch (trigger_method) { |
105 case MODIFY_PREF: | 105 case MODIFY_PREF: |
106 // Unlike MODIFY_BOOKMARK, MODIFY_PREF doesn't cause a | 106 // Unlike MODIFY_BOOKMARK, MODIFY_PREF doesn't cause a |
107 // notification to happen (since model association on a | 107 // notification to happen (since model association on a |
108 // boolean pref clobbers the local value), so it doesn't work | 108 // boolean pref clobbers the local value), so it doesn't work |
109 // for anything but single-client tests. | 109 // for anything but single-client tests. |
110 ASSERT_EQ(1, num_clients()); | 110 ASSERT_EQ(1, num_clients()); |
111 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 111 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
112 ChangeBooleanPref(0, prefs::kShowHomeButton); | 112 ChangeBooleanPref(0, prefs::kShowHomeButton); |
113 break; | 113 break; |
114 case MODIFY_BOOKMARK: | 114 case MODIFY_BOOKMARK: |
115 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0)))); | 115 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0)))); |
116 break; | 116 break; |
117 case TRIGGER_NOTIFICATION: | 117 case TRIGGER_NOTIFICATION: |
118 TriggerNotification(model_types); | 118 TriggerNotification(model_types); |
119 break; | 119 break; |
120 default: | 120 default: |
121 ADD_FAILURE(); | 121 ADD_FAILURE(); |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 // Block until all clients have completed migration for the given | 125 // Block until all clients have completed migration for the given |
126 // types. | 126 // types. |
127 void AwaitMigration(syncable::ModelEnumSet migrate_types) { | 127 void AwaitMigration(syncable::ModelTypeSet migrate_types) { |
128 for (int i = 0; i < num_clients(); ++i) { | 128 for (int i = 0; i < num_clients(); ++i) { |
129 ASSERT_TRUE(GetClient(i)->AwaitMigration(migrate_types)); | 129 ASSERT_TRUE(GetClient(i)->AwaitMigration(migrate_types)); |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 bool ShouldRunMigrationTest() const { | 133 bool ShouldRunMigrationTest() const { |
134 if (!ServerSupportsNotificationControl() || | 134 if (!ServerSupportsNotificationControl() || |
135 !ServerSupportsErrorTriggering()) { | 135 !ServerSupportsErrorTriggering()) { |
136 LOG(WARNING) << "Test skipped in this server environment."; | 136 LOG(WARNING) << "Test skipped in this server environment."; |
137 return false; | 137 return false; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, | 286 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, |
287 AllTypesWithNigoriIndividually) { | 287 AllTypesWithNigoriIndividually) { |
288 ASSERT_TRUE(SetupClients()); | 288 ASSERT_TRUE(SetupClients()); |
289 MigrationList migration_list = GetPreferredDataTypesList(); | 289 MigrationList migration_list = GetPreferredDataTypesList(); |
290 migration_list.push_front(MakeSet(syncable::NIGORI)); | 290 migration_list.push_front(MakeSet(syncable::NIGORI)); |
291 RunSingleClientMigrationTest(migration_list, MODIFY_BOOKMARK); | 291 RunSingleClientMigrationTest(migration_list, MODIFY_BOOKMARK); |
292 } | 292 } |
293 | 293 |
294 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, AllTypesWithNigoriAtOnce) { | 294 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, AllTypesWithNigoriAtOnce) { |
295 ASSERT_TRUE(SetupClients()); | 295 ASSERT_TRUE(SetupClients()); |
296 syncable::ModelEnumSet all_types = GetPreferredDataTypes(); | 296 syncable::ModelTypeSet all_types = GetPreferredDataTypes(); |
297 all_types.Put(syncable::NIGORI); | 297 all_types.Put(syncable::NIGORI); |
298 RunSingleClientMigrationTest(MakeList(all_types), MODIFY_PREF); | 298 RunSingleClientMigrationTest(MakeList(all_types), MODIFY_PREF); |
299 } | 299 } |
300 | 300 |
301 class MigrationTwoClientTest : public MigrationTest { | 301 class MigrationTwoClientTest : public MigrationTest { |
302 public: | 302 public: |
303 MigrationTwoClientTest() : MigrationTest(TWO_CLIENT) {} | 303 MigrationTwoClientTest() : MigrationTest(TWO_CLIENT) {} |
304 virtual ~MigrationTwoClientTest() {} | 304 virtual ~MigrationTwoClientTest() {} |
305 | 305 |
306 // Helper function that verifies that preferences sync still works. | 306 // Helper function that verifies that preferences sync still works. |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 449 |
450 // Phase 5: Verify that preferences can still be synchronized. | 450 // Phase 5: Verify that preferences can still be synchronized. |
451 VerifyPrefSync(); | 451 VerifyPrefSync(); |
452 | 452 |
453 // Phase 6: Verify that sessions are registered and enabled. | 453 // Phase 6: Verify that sessions are registered and enabled. |
454 ASSERT_TRUE(GetClient(0)->IsTypeRunning(syncable::SESSIONS)); | 454 ASSERT_TRUE(GetClient(0)->IsTypeRunning(syncable::SESSIONS)); |
455 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); | 455 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); |
456 } | 456 } |
457 | 457 |
458 } // namespace | 458 } // namespace |
OLD | NEW |