Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: chrome/browser/sync/test/integration/migration_errors_test.cc

Issue 8772074: [Sync] Convert syncable/ directory to ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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::ModelTypeSet MakeSet(syncable::ModelType type) { 30 syncable::ModelEnumSet MakeSet(syncable::ModelType type) {
31 syncable::ModelTypeSet model_types; 31 return syncable::ModelEnumSet(type);
32 model_types.insert(type);
33 return model_types;
34 } 32 }
35 33
36 syncable::ModelTypeSet MakeSet(syncable::ModelType type1, 34 syncable::ModelEnumSet MakeSet(syncable::ModelType type1,
37 syncable::ModelType type2) { 35 syncable::ModelType type2) {
38 syncable::ModelTypeSet model_types; 36 return syncable::ModelEnumSet(type1, type2);
39 model_types.insert(type1);
40 model_types.insert(type2);
41 return model_types;
42 } 37 }
43 38
44 // An ordered list of model types sets to migrate. Used by 39 // An ordered list of model types sets to migrate. Used by
45 // RunMigrationTest(). 40 // RunMigrationTest().
46 typedef std::deque<syncable::ModelTypeSet> MigrationList; 41 typedef std::deque<syncable::ModelEnumSet> MigrationList;
47 42
48 // 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
49 // model types / model type sets. 44 // model types / model type sets.
50 45
51 MigrationList MakeList(const syncable::ModelTypeSet& model_types) { 46 MigrationList MakeList(syncable::ModelEnumSet model_types) {
52 return MigrationList(1, model_types); 47 return MigrationList(1, model_types);
53 } 48 }
54 49
55 MigrationList MakeList(const syncable::ModelTypeSet& model_types1, 50 MigrationList MakeList(syncable::ModelEnumSet model_types1,
56 const syncable::ModelTypeSet& model_types2) { 51 syncable::ModelEnumSet model_types2) {
57 MigrationList migration_list; 52 MigrationList migration_list;
58 migration_list.push_back(model_types1); 53 migration_list.push_back(model_types1);
59 migration_list.push_back(model_types2); 54 migration_list.push_back(model_types2);
60 return migration_list; 55 return migration_list;
61 } 56 }
62 57
63 MigrationList MakeList(syncable::ModelType type) { 58 MigrationList MakeList(syncable::ModelType type) {
64 return MakeList(MakeSet(type)); 59 return MakeList(MakeSet(type));
65 } 60 }
66 61
67 MigrationList MakeList(syncable::ModelType type1, 62 MigrationList MakeList(syncable::ModelType type1,
68 syncable::ModelType type2) { 63 syncable::ModelType type2) {
69 return MakeList(MakeSet(type1), MakeSet(type2)); 64 return MakeList(MakeSet(type1), MakeSet(type2));
70 } 65 }
71 66
72 class MigrationTest : public SyncTest { 67 class MigrationTest : public SyncTest {
73 public: 68 public:
74 explicit MigrationTest(TestType test_type) : SyncTest(test_type) {} 69 explicit MigrationTest(TestType test_type) : SyncTest(test_type) {}
75 virtual ~MigrationTest() {} 70 virtual ~MigrationTest() {}
76 71
77 // TODO(akalin): Add more MODIFY_(data type) trigger methods, as 72 // TODO(akalin): Add more MODIFY_(data type) trigger methods, as
78 // well as a poll-based trigger method. 73 // well as a poll-based trigger method.
79 enum TriggerMethod { MODIFY_PREF, MODIFY_BOOKMARK, TRIGGER_NOTIFICATION }; 74 enum TriggerMethod { MODIFY_PREF, MODIFY_BOOKMARK, TRIGGER_NOTIFICATION };
80 75
81 syncable::ModelTypeSet GetPreferredDataTypes() { 76 syncable::ModelEnumSet GetPreferredDataTypes() {
82 syncable::ModelTypeSet preferred_data_types; 77 syncable::ModelTypeSet preferred_data_types;
83 GetClient(0)->service()->GetPreferredDataTypes(&preferred_data_types); 78 GetClient(0)->service()->GetPreferredDataTypes(&preferred_data_types);
84 // Make sure all clients have the same preferred data types. 79 // Make sure all clients have the same preferred data types.
85 for (int i = 1; i < num_clients(); ++i) { 80 for (int i = 1; i < num_clients(); ++i) {
86 syncable::ModelTypeSet other_preferred_data_types; 81 syncable::ModelTypeSet other_preferred_data_types;
87 GetClient(i)->service()->GetPreferredDataTypes( 82 GetClient(i)->service()->GetPreferredDataTypes(
88 &other_preferred_data_types); 83 &other_preferred_data_types);
89 EXPECT_EQ(preferred_data_types, other_preferred_data_types); 84 EXPECT_EQ(preferred_data_types, other_preferred_data_types);
90 } 85 }
91 return preferred_data_types; 86 return syncable::ModelTypeSetToEnumSet(preferred_data_types);
92 } 87 }
93 88
94 // Returns a MigrationList with every enabled data type in its own 89 // Returns a MigrationList with every enabled data type in its own
95 // set. 90 // set.
96 MigrationList GetPreferredDataTypesList() { 91 MigrationList GetPreferredDataTypesList() {
97 MigrationList migration_list; 92 MigrationList migration_list;
98 const syncable::ModelTypeSet& preferred_data_types = 93 const syncable::ModelEnumSet preferred_data_types =
99 GetPreferredDataTypes(); 94 GetPreferredDataTypes();
100 for (syncable::ModelTypeSet::const_iterator it = 95 for (syncable::ModelEnumSet::Iterator it =
101 preferred_data_types.begin(); 96 preferred_data_types.First(); it.Good(); it.Inc()) {
102 it != preferred_data_types.end(); ++it) { 97 migration_list.push_back(MakeSet(it.Get()));
103 migration_list.push_back(MakeSet(*it));
104 } 98 }
105 return migration_list; 99 return migration_list;
106 } 100 }
107 101
108 // Trigger a migration for the given types with the given method. 102 // Trigger a migration for the given types with the given method.
109 void TriggerMigration(const syncable::ModelTypeSet& model_types, 103 void TriggerMigration(syncable::ModelEnumSet model_types,
110 TriggerMethod trigger_method) { 104 TriggerMethod trigger_method) {
111 switch (trigger_method) { 105 switch (trigger_method) {
112 case MODIFY_PREF: 106 case MODIFY_PREF:
113 // Unlike MODIFY_BOOKMARK, MODIFY_PREF doesn't cause a 107 // Unlike MODIFY_BOOKMARK, MODIFY_PREF doesn't cause a
114 // notification to happen (since model association on a 108 // notification to happen (since model association on a
115 // boolean pref clobbers the local value), so it doesn't work 109 // boolean pref clobbers the local value), so it doesn't work
116 // for anything but single-client tests. 110 // for anything but single-client tests.
117 ASSERT_EQ(1, num_clients()); 111 ASSERT_EQ(1, num_clients());
118 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); 112 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
119 ChangeBooleanPref(0, prefs::kShowHomeButton); 113 ChangeBooleanPref(0, prefs::kShowHomeButton);
120 break; 114 break;
121 case MODIFY_BOOKMARK: 115 case MODIFY_BOOKMARK:
122 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0)))); 116 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))));
123 break; 117 break;
124 case TRIGGER_NOTIFICATION: 118 case TRIGGER_NOTIFICATION:
125 TriggerNotification(model_types); 119 TriggerNotification(model_types);
126 break; 120 break;
127 default: 121 default:
128 ADD_FAILURE(); 122 ADD_FAILURE();
129 } 123 }
130 } 124 }
131 125
132 // Block until all clients have completed migration for the given 126 // Block until all clients have completed migration for the given
133 // types. 127 // types.
134 void AwaitMigration(const syncable::ModelTypeSet& migrate_types) { 128 void AwaitMigration(syncable::ModelEnumSet migrate_types) {
129 const syncable::ModelTypeSet& migrate_types_set =
130 syncable::ModelEnumSetToSet(migrate_types);
135 for (int i = 0; i < num_clients(); ++i) { 131 for (int i = 0; i < num_clients(); ++i) {
136 ASSERT_TRUE(GetClient(i)->AwaitMigration(migrate_types)); 132 ASSERT_TRUE(GetClient(i)->AwaitMigration(migrate_types_set));
137 } 133 }
138 } 134 }
139 135
140 bool ShouldRunMigrationTest() const { 136 bool ShouldRunMigrationTest() const {
141 if (!ServerSupportsNotificationControl() || 137 if (!ServerSupportsNotificationControl() ||
142 !ServerSupportsErrorTriggering()) { 138 !ServerSupportsErrorTriggering()) {
143 LOG(WARNING) << "Test skipped in this server environment."; 139 LOG(WARNING) << "Test skipped in this server environment.";
144 return false; 140 return false;
145 } 141 }
146 return true; 142 return true;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, 289 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest,
294 AllTypesWithNigoriIndividually) { 290 AllTypesWithNigoriIndividually) {
295 ASSERT_TRUE(SetupClients()); 291 ASSERT_TRUE(SetupClients());
296 MigrationList migration_list = GetPreferredDataTypesList(); 292 MigrationList migration_list = GetPreferredDataTypesList();
297 migration_list.push_front(MakeSet(syncable::NIGORI)); 293 migration_list.push_front(MakeSet(syncable::NIGORI));
298 RunSingleClientMigrationTest(migration_list, MODIFY_BOOKMARK); 294 RunSingleClientMigrationTest(migration_list, MODIFY_BOOKMARK);
299 } 295 }
300 296
301 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, AllTypesWithNigoriAtOnce) { 297 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, AllTypesWithNigoriAtOnce) {
302 ASSERT_TRUE(SetupClients()); 298 ASSERT_TRUE(SetupClients());
303 syncable::ModelTypeSet all_types = GetPreferredDataTypes(); 299 syncable::ModelEnumSet all_types = GetPreferredDataTypes();
304 all_types.insert(syncable::NIGORI); 300 all_types.Put(syncable::NIGORI);
305 RunSingleClientMigrationTest(MakeList(all_types), MODIFY_PREF); 301 RunSingleClientMigrationTest(MakeList(all_types), MODIFY_PREF);
306 } 302 }
307 303
308 class MigrationTwoClientTest : public MigrationTest { 304 class MigrationTwoClientTest : public MigrationTest {
309 public: 305 public:
310 MigrationTwoClientTest() : MigrationTest(TWO_CLIENT) {} 306 MigrationTwoClientTest() : MigrationTest(TWO_CLIENT) {}
311 virtual ~MigrationTwoClientTest() {} 307 virtual ~MigrationTwoClientTest() {}
312 308
313 // Helper function that verifies that preferences sync still works. 309 // Helper function that verifies that preferences sync still works.
314 void VerifyPrefSync() { 310 void VerifyPrefSync() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 367
372 IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest, MigrationHellWithNigori) { 368 IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest, MigrationHellWithNigori) {
373 ASSERT_TRUE(SetupClients()); 369 ASSERT_TRUE(SetupClients());
374 MigrationList migration_list = GetPreferredDataTypesList(); 370 MigrationList migration_list = GetPreferredDataTypesList();
375 // Let the first nudge be a datatype that's neither prefs nor 371 // Let the first nudge be a datatype that's neither prefs nor
376 // bookmarks. 372 // bookmarks.
377 migration_list.push_front(MakeSet(syncable::THEMES)); 373 migration_list.push_front(MakeSet(syncable::THEMES));
378 // Pop off one so that we don't migrate all data types; the syncer 374 // Pop off one so that we don't migrate all data types; the syncer
379 // freaks out if we do that (see http://crbug.com/94882). 375 // freaks out if we do that (see http://crbug.com/94882).
380 ASSERT_GE(migration_list.size(), 2u); 376 ASSERT_GE(migration_list.size(), 2u);
381 ASSERT_NE(migration_list.back(), MakeSet(syncable::NIGORI)); 377 ASSERT_FALSE(migration_list.back().Equals(MakeSet(syncable::NIGORI)));
382 migration_list.back() = MakeSet(syncable::NIGORI); 378 migration_list.back() = MakeSet(syncable::NIGORI);
383 RunTwoClientMigrationTest(migration_list, MODIFY_BOOKMARK); 379 RunTwoClientMigrationTest(migration_list, MODIFY_BOOKMARK);
384 } 380 }
385 381
386 class MigrationReconfigureTest : public MigrationTwoClientTest { 382 class MigrationReconfigureTest : public MigrationTwoClientTest {
387 public: 383 public:
388 MigrationReconfigureTest() {} 384 MigrationReconfigureTest() {}
389 385
390 virtual void SetUpCommandLine(CommandLine* cl) OVERRIDE { 386 virtual void SetUpCommandLine(CommandLine* cl) OVERRIDE {
391 AddTestSwitches(cl); 387 AddTestSwitches(cl);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 444
449 // Phase 5: Verify that preferences can still be synchronized. 445 // Phase 5: Verify that preferences can still be synchronized.
450 VerifyPrefSync(); 446 VerifyPrefSync();
451 447
452 // Phase 6: Verify that sessions are registered and enabled. 448 // Phase 6: Verify that sessions are registered and enabled.
453 ASSERT_TRUE(GetClient(0)->IsTypeRunning(syncable::SESSIONS)); 449 ASSERT_TRUE(GetClient(0)->IsTypeRunning(syncable::SESSIONS));
454 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); 450 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncable::SESSIONS));
455 } 451 }
456 452
457 } // namespace 453 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/engine/test_directory_setter_upper.h ('k') | chrome/browser/sync/test/integration/sync_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698