| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 ProfileSyncComponentsFactoryImplTest() | 24 ProfileSyncComponentsFactoryImplTest() |
| 25 : ui_thread_(BrowserThread::UI, &message_loop_) {} | 25 : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 26 | 26 |
| 27 virtual void SetUp() { | 27 virtual void SetUp() { |
| 28 profile_.reset(new TestingProfile()); | 28 profile_.reset(new TestingProfile()); |
| 29 FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); | 29 FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); |
| 30 command_line_.reset(new CommandLine(program_path)); | 30 command_line_.reset(new CommandLine(program_path)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Returns the collection of default datatypes. | 33 // Returns the collection of default datatypes. |
| 34 static std::vector<syncable::ModelType> DefaultDatatypes() { | 34 static std::vector<syncer::ModelType> DefaultDatatypes() { |
| 35 std::vector<syncable::ModelType> datatypes; | 35 std::vector<syncer::ModelType> datatypes; |
| 36 datatypes.push_back(syncable::APPS); | 36 datatypes.push_back(syncer::APPS); |
| 37 datatypes.push_back(syncable::APP_NOTIFICATIONS); | 37 datatypes.push_back(syncer::APP_NOTIFICATIONS); |
| 38 datatypes.push_back(syncable::APP_SETTINGS); | 38 datatypes.push_back(syncer::APP_SETTINGS); |
| 39 datatypes.push_back(syncable::AUTOFILL); | 39 datatypes.push_back(syncer::AUTOFILL); |
| 40 datatypes.push_back(syncable::AUTOFILL_PROFILE); | 40 datatypes.push_back(syncer::AUTOFILL_PROFILE); |
| 41 datatypes.push_back(syncable::BOOKMARKS); | 41 datatypes.push_back(syncer::BOOKMARKS); |
| 42 datatypes.push_back(syncable::EXTENSIONS); | 42 datatypes.push_back(syncer::EXTENSIONS); |
| 43 datatypes.push_back(syncable::EXTENSION_SETTINGS); | 43 datatypes.push_back(syncer::EXTENSION_SETTINGS); |
| 44 datatypes.push_back(syncable::PASSWORDS); | 44 datatypes.push_back(syncer::PASSWORDS); |
| 45 datatypes.push_back(syncable::PREFERENCES); | 45 datatypes.push_back(syncer::PREFERENCES); |
| 46 datatypes.push_back(syncable::SEARCH_ENGINES); | 46 datatypes.push_back(syncer::SEARCH_ENGINES); |
| 47 datatypes.push_back(syncable::SESSIONS); | 47 datatypes.push_back(syncer::SESSIONS); |
| 48 datatypes.push_back(syncable::THEMES); | 48 datatypes.push_back(syncer::THEMES); |
| 49 datatypes.push_back(syncable::TYPED_URLS); | 49 datatypes.push_back(syncer::TYPED_URLS); |
| 50 return datatypes; | 50 return datatypes; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Returns the number of default datatypes. | 53 // Returns the number of default datatypes. |
| 54 static size_t DefaultDatatypesCount() { | 54 static size_t DefaultDatatypesCount() { |
| 55 return DefaultDatatypes().size(); | 55 return DefaultDatatypes().size(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Asserts that all the default datatypes are in |map|, except | 58 // Asserts that all the default datatypes are in |map|, except |
| 59 // for |exception_type|, which unless it is UNDEFINED, is asserted to | 59 // for |exception_type|, which unless it is UNDEFINED, is asserted to |
| 60 // not be in |map|. | 60 // not be in |map|. |
| 61 static void CheckDefaultDatatypesInMapExcept( | 61 static void CheckDefaultDatatypesInMapExcept( |
| 62 DataTypeController::StateMap* map, | 62 DataTypeController::StateMap* map, |
| 63 syncable::ModelType exception_type) { | 63 syncer::ModelType exception_type) { |
| 64 std::vector<syncable::ModelType> defaults = DefaultDatatypes(); | 64 std::vector<syncer::ModelType> defaults = DefaultDatatypes(); |
| 65 std::vector<syncable::ModelType>::iterator iter; | 65 std::vector<syncer::ModelType>::iterator iter; |
| 66 for (iter = defaults.begin(); iter != defaults.end(); ++iter) { | 66 for (iter = defaults.begin(); iter != defaults.end(); ++iter) { |
| 67 if (exception_type != syncable::UNSPECIFIED && exception_type == *iter) | 67 if (exception_type != syncer::UNSPECIFIED && exception_type == *iter) |
| 68 EXPECT_EQ(0U, map->count(*iter)) | 68 EXPECT_EQ(0U, map->count(*iter)) |
| 69 << *iter << " found in dataypes map, shouldn't be there."; | 69 << *iter << " found in dataypes map, shouldn't be there."; |
| 70 else | 70 else |
| 71 EXPECT_EQ(1U, map->count(*iter)) | 71 EXPECT_EQ(1U, map->count(*iter)) |
| 72 << *iter << " not found in datatypes map"; | 72 << *iter << " not found in datatypes map"; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Asserts that if you apply the command line switch |cmd_switch|, | 76 // Asserts that if you apply the command line switch |cmd_switch|, |
| 77 // all types are enabled except for |type|, which is disabled. | 77 // all types are enabled except for |type|, which is disabled. |
| 78 void TestSwitchDisablesType(const char* cmd_switch, | 78 void TestSwitchDisablesType(const char* cmd_switch, |
| 79 syncable::ModelType type) { | 79 syncer::ModelType type) { |
| 80 command_line_->AppendSwitch(cmd_switch); | 80 command_line_->AppendSwitch(cmd_switch); |
| 81 scoped_ptr<ProfileSyncService> pss( | 81 scoped_ptr<ProfileSyncService> pss( |
| 82 new ProfileSyncService( | 82 new ProfileSyncService( |
| 83 new ProfileSyncComponentsFactoryImpl(profile_.get(), | 83 new ProfileSyncComponentsFactoryImpl(profile_.get(), |
| 84 command_line_.get()), | 84 command_line_.get()), |
| 85 profile_.get(), | 85 profile_.get(), |
| 86 NULL, | 86 NULL, |
| 87 ProfileSyncService::MANUAL_START)); | 87 ProfileSyncService::MANUAL_START)); |
| 88 pss->factory()->RegisterDataTypes(pss.get()); | 88 pss->factory()->RegisterDataTypes(pss.get()); |
| 89 DataTypeController::StateMap controller_states; | 89 DataTypeController::StateMap controller_states; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 103 new ProfileSyncService( | 103 new ProfileSyncService( |
| 104 new ProfileSyncComponentsFactoryImpl(profile_.get(), | 104 new ProfileSyncComponentsFactoryImpl(profile_.get(), |
| 105 command_line_.get()), | 105 command_line_.get()), |
| 106 profile_.get(), | 106 profile_.get(), |
| 107 NULL, | 107 NULL, |
| 108 ProfileSyncService::MANUAL_START)); | 108 ProfileSyncService::MANUAL_START)); |
| 109 pss->factory()->RegisterDataTypes(pss.get()); | 109 pss->factory()->RegisterDataTypes(pss.get()); |
| 110 DataTypeController::StateMap controller_states; | 110 DataTypeController::StateMap controller_states; |
| 111 pss->GetDataTypeControllerStates(&controller_states); | 111 pss->GetDataTypeControllerStates(&controller_states); |
| 112 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); | 112 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); |
| 113 CheckDefaultDatatypesInMapExcept(&controller_states, syncable::UNSPECIFIED); | 113 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::UNSPECIFIED); |
| 114 } | 114 } |
| 115 | 115 |
| 116 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofill) { | 116 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofill) { |
| 117 TestSwitchDisablesType(switches::kDisableSyncAutofill, | 117 TestSwitchDisablesType(switches::kDisableSyncAutofill, |
| 118 syncable::AUTOFILL); | 118 syncer::AUTOFILL); |
| 119 } | 119 } |
| 120 | 120 |
| 121 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableBookmarks) { | 121 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableBookmarks) { |
| 122 TestSwitchDisablesType(switches::kDisableSyncBookmarks, | 122 TestSwitchDisablesType(switches::kDisableSyncBookmarks, |
| 123 syncable::BOOKMARKS); | 123 syncer::BOOKMARKS); |
| 124 } | 124 } |
| 125 | 125 |
| 126 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePreferences) { | 126 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePreferences) { |
| 127 TestSwitchDisablesType(switches::kDisableSyncPreferences, | 127 TestSwitchDisablesType(switches::kDisableSyncPreferences, |
| 128 syncable::PREFERENCES); | 128 syncer::PREFERENCES); |
| 129 } | 129 } |
| 130 | 130 |
| 131 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableThemes) { | 131 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableThemes) { |
| 132 TestSwitchDisablesType(switches::kDisableSyncThemes, | 132 TestSwitchDisablesType(switches::kDisableSyncThemes, |
| 133 syncable::THEMES); | 133 syncer::THEMES); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableExtensions) { | 136 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableExtensions) { |
| 137 TestSwitchDisablesType(switches::kDisableSyncExtensions, | 137 TestSwitchDisablesType(switches::kDisableSyncExtensions, |
| 138 syncable::EXTENSIONS); | 138 syncer::EXTENSIONS); |
| 139 } | 139 } |
| 140 | 140 |
| 141 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableApps) { | 141 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableApps) { |
| 142 TestSwitchDisablesType(switches::kDisableSyncApps, | 142 TestSwitchDisablesType(switches::kDisableSyncApps, |
| 143 syncable::APPS); | 143 syncer::APPS); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) { | 146 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) { |
| 147 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, | 147 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, |
| 148 syncable::AUTOFILL_PROFILE); | 148 syncer::AUTOFILL_PROFILE); |
| 149 } | 149 } |
| 150 | 150 |
| 151 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) { | 151 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) { |
| 152 TestSwitchDisablesType(switches::kDisableSyncPasswords, | 152 TestSwitchDisablesType(switches::kDisableSyncPasswords, |
| 153 syncable::PASSWORDS); | 153 syncer::PASSWORDS); |
| 154 } | 154 } |
| OLD | NEW |