| 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/files/file_path.h" | 8 #include "base/files/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" |
| 11 #include "chrome/browser/sync/glue/data_type_controller.h" | 11 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using browser_sync::DataTypeController; | 19 using browser_sync::DataTypeController; |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 using syncer::FullModelTypeSet; |
| 21 | 22 |
| 22 class ProfileSyncComponentsFactoryImplTest : public testing::Test { | 23 class ProfileSyncComponentsFactoryImplTest : public testing::Test { |
| 23 protected: | 24 protected: |
| 24 ProfileSyncComponentsFactoryImplTest() | 25 ProfileSyncComponentsFactoryImplTest() |
| 25 : ui_thread_(BrowserThread::UI, &message_loop_) {} | 26 : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 26 | 27 |
| 27 virtual void SetUp() { | 28 virtual void SetUp() { |
| 28 profile_.reset(new TestingProfile()); | 29 profile_.reset(new TestingProfile()); |
| 29 base::FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); | 30 base::FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); |
| 30 command_line_.reset(new CommandLine(program_path)); | 31 command_line_.reset(new CommandLine(program_path)); |
| 31 } | 32 } |
| 32 | 33 |
| 33 // Returns the collection of default datatypes. | 34 // Returns the collection of default datatypes. |
| 34 static std::vector<syncer::ModelType> DefaultDatatypes() { | 35 static std::vector<syncer::ModelType> DefaultDatatypes() { |
| 35 std::vector<syncer::ModelType> datatypes; | 36 std::vector<syncer::ModelType> datatypes; |
| 36 datatypes.push_back(syncer::APPS); | 37 datatypes.push_back(syncer::APPS); |
| 37 datatypes.push_back(syncer::APP_SETTINGS); | 38 datatypes.push_back(syncer::APP_SETTINGS); |
| 38 datatypes.push_back(syncer::AUTOFILL); | 39 datatypes.push_back(syncer::AUTOFILL); |
| 39 datatypes.push_back(syncer::AUTOFILL_PROFILE); | 40 datatypes.push_back(syncer::AUTOFILL_PROFILE); |
| 40 datatypes.push_back(syncer::BOOKMARKS); | 41 datatypes.push_back(syncer::BOOKMARKS); |
| 41 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) | 42 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) |
| 42 datatypes.push_back(syncer::DICTIONARY); | 43 datatypes.push_back(syncer::DICTIONARY); |
| 43 #endif | 44 #endif |
| 44 datatypes.push_back(syncer::EXTENSIONS); | 45 datatypes.push_back(syncer::EXTENSIONS); |
| 45 datatypes.push_back(syncer::EXTENSION_SETTINGS); | 46 datatypes.push_back(syncer::EXTENSION_SETTINGS); |
| 46 datatypes.push_back(syncer::PASSWORDS); | 47 datatypes.push_back(syncer::PASSWORDS); |
| 47 datatypes.push_back(syncer::PREFERENCES); | 48 datatypes.push_back(syncer::PREFERENCES); |
| 49 datatypes.push_back(syncer::PRIORITY_PREFERENCES); |
| 48 datatypes.push_back(syncer::SEARCH_ENGINES); | 50 datatypes.push_back(syncer::SEARCH_ENGINES); |
| 49 datatypes.push_back(syncer::SESSIONS); | 51 datatypes.push_back(syncer::SESSIONS); |
| 50 datatypes.push_back(syncer::PROXY_TABS); | 52 datatypes.push_back(syncer::PROXY_TABS); |
| 51 datatypes.push_back(syncer::THEMES); | 53 datatypes.push_back(syncer::THEMES); |
| 52 datatypes.push_back(syncer::TYPED_URLS); | 54 datatypes.push_back(syncer::TYPED_URLS); |
| 53 return datatypes; | 55 return datatypes; |
| 54 } | 56 } |
| 55 | 57 |
| 56 // Returns the number of default datatypes. | 58 // Returns the number of default datatypes. |
| 57 static size_t DefaultDatatypesCount() { | 59 static size_t DefaultDatatypesCount() { |
| 58 return DefaultDatatypes().size(); | 60 return DefaultDatatypes().size(); |
| 59 } | 61 } |
| 60 | 62 |
| 61 // Asserts that all the default datatypes are in |map|, except | 63 // Asserts that all the default datatypes are in |map|, except |
| 62 // for |exception_type|, which unless it is UNDEFINED, is asserted to | 64 // for |exception_types|, which unless are UNDEFINED, are asserted to |
| 63 // not be in |map|. | 65 // not be in |map|. |
| 64 static void CheckDefaultDatatypesInMapExcept( | 66 static void CheckDefaultDatatypesInMapExcept( |
| 65 DataTypeController::StateMap* map, | 67 DataTypeController::StateMap* map, |
| 66 syncer::ModelType exception_type) { | 68 FullModelTypeSet exception_types) { |
| 69 DCHECK(exception_types.Size() == 1 || |
| 70 !exception_types.Has(syncer::UNSPECIFIED)); |
| 71 |
| 67 std::vector<syncer::ModelType> defaults = DefaultDatatypes(); | 72 std::vector<syncer::ModelType> defaults = DefaultDatatypes(); |
| 68 std::vector<syncer::ModelType>::iterator iter; | 73 std::vector<syncer::ModelType>::iterator iter; |
| 69 for (iter = defaults.begin(); iter != defaults.end(); ++iter) { | 74 for (iter = defaults.begin(); iter != defaults.end(); ++iter) { |
| 70 if (exception_type != syncer::UNSPECIFIED && exception_type == *iter) | 75 if (!exception_types.Has(syncer::UNSPECIFIED) && |
| 76 exception_types.Has(*iter)) |
| 71 EXPECT_EQ(0U, map->count(*iter)) | 77 EXPECT_EQ(0U, map->count(*iter)) |
| 72 << *iter << " found in dataypes map, shouldn't be there."; | 78 << *iter << " found in dataypes map, shouldn't be there."; |
| 73 else | 79 else |
| 74 EXPECT_EQ(1U, map->count(*iter)) | 80 EXPECT_EQ(1U, map->count(*iter)) |
| 75 << *iter << " not found in datatypes map"; | 81 << *iter << " not found in datatypes map"; |
| 76 } | 82 } |
| 77 } | 83 } |
| 78 | 84 |
| 79 // Asserts that if you apply the command line switch |cmd_switch|, | 85 // Asserts that if you apply the command line switch |cmd_switch|, |
| 80 // all types are enabled except for |type|, which is disabled. | 86 // all types are enabled except for |type|, which is disabled. |
| 81 void TestSwitchDisablesType(const char* cmd_switch, | 87 void TestSwitchDisablesType(const char* cmd_switch, |
| 82 syncer::ModelType type) { | 88 syncer::ModelType type) { |
| 89 TestSwitchDisablesType(cmd_switch, FullModelTypeSet(type)); |
| 90 } |
| 91 |
| 92 void TestSwitchDisablesType(const char* cmd_switch, |
| 93 FullModelTypeSet types) { |
| 83 command_line_->AppendSwitch(cmd_switch); | 94 command_line_->AppendSwitch(cmd_switch); |
| 84 scoped_ptr<ProfileSyncService> pss( | 95 scoped_ptr<ProfileSyncService> pss( |
| 85 new ProfileSyncService( | 96 new ProfileSyncService( |
| 86 new ProfileSyncComponentsFactoryImpl(profile_.get(), | 97 new ProfileSyncComponentsFactoryImpl(profile_.get(), |
| 87 command_line_.get()), | 98 command_line_.get()), |
| 88 profile_.get(), | 99 profile_.get(), |
| 89 NULL, | 100 NULL, |
| 90 ProfileSyncService::MANUAL_START)); | 101 ProfileSyncService::MANUAL_START)); |
| 91 pss->factory()->RegisterDataTypes(pss.get()); | 102 pss->factory()->RegisterDataTypes(pss.get()); |
| 92 DataTypeController::StateMap controller_states; | 103 DataTypeController::StateMap controller_states; |
| 93 pss->GetDataTypeControllerStates(&controller_states); | 104 pss->GetDataTypeControllerStates(&controller_states); |
| 94 EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size()); | 105 EXPECT_EQ(DefaultDatatypesCount() - types.Size(), controller_states.size()); |
| 95 CheckDefaultDatatypesInMapExcept(&controller_states, type); | 106 CheckDefaultDatatypesInMapExcept(&controller_states, types); |
| 96 } | 107 } |
| 97 | 108 |
| 98 MessageLoop message_loop_; | 109 MessageLoop message_loop_; |
| 99 content::TestBrowserThread ui_thread_; | 110 content::TestBrowserThread ui_thread_; |
| 100 scoped_ptr<Profile> profile_; | 111 scoped_ptr<Profile> profile_; |
| 101 scoped_ptr<CommandLine> command_line_; | 112 scoped_ptr<CommandLine> command_line_; |
| 102 }; | 113 }; |
| 103 | 114 |
| 104 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { | 115 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { |
| 105 scoped_ptr<ProfileSyncService> pss( | 116 scoped_ptr<ProfileSyncService> pss( |
| 106 new ProfileSyncService( | 117 new ProfileSyncService( |
| 107 new ProfileSyncComponentsFactoryImpl(profile_.get(), | 118 new ProfileSyncComponentsFactoryImpl(profile_.get(), |
| 108 command_line_.get()), | 119 command_line_.get()), |
| 109 profile_.get(), | 120 profile_.get(), |
| 110 NULL, | 121 NULL, |
| 111 ProfileSyncService::MANUAL_START)); | 122 ProfileSyncService::MANUAL_START)); |
| 112 pss->factory()->RegisterDataTypes(pss.get()); | 123 pss->factory()->RegisterDataTypes(pss.get()); |
| 113 DataTypeController::StateMap controller_states; | 124 DataTypeController::StateMap controller_states; |
| 114 pss->GetDataTypeControllerStates(&controller_states); | 125 pss->GetDataTypeControllerStates(&controller_states); |
| 115 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); | 126 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); |
| 116 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::UNSPECIFIED); | 127 CheckDefaultDatatypesInMapExcept( |
| 128 &controller_states, |
| 129 FullModelTypeSet(syncer::UNSPECIFIED)); |
| 117 } | 130 } |
| 118 | 131 |
| 119 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofill) { | 132 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofill) { |
| 120 TestSwitchDisablesType(switches::kDisableSyncAutofill, | 133 TestSwitchDisablesType(switches::kDisableSyncAutofill, |
| 121 syncer::AUTOFILL); | 134 syncer::AUTOFILL); |
| 122 } | 135 } |
| 123 | 136 |
| 124 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableBookmarks) { | 137 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableBookmarks) { |
| 125 TestSwitchDisablesType(switches::kDisableSyncBookmarks, | 138 TestSwitchDisablesType(switches::kDisableSyncBookmarks, |
| 126 syncer::BOOKMARKS); | 139 syncer::BOOKMARKS); |
| 127 } | 140 } |
| 128 | 141 |
| 129 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePreferences) { | 142 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePreferences) { |
| 130 TestSwitchDisablesType(switches::kDisableSyncPreferences, | 143 TestSwitchDisablesType(switches::kDisableSyncPreferences, |
| 131 syncer::PREFERENCES); | 144 FullModelTypeSet(syncer::PREFERENCES, |
| 145 syncer::PRIORITY_PREFERENCES)); |
| 132 } | 146 } |
| 133 | 147 |
| 134 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableThemes) { | 148 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableThemes) { |
| 135 TestSwitchDisablesType(switches::kDisableSyncThemes, | 149 TestSwitchDisablesType(switches::kDisableSyncThemes, |
| 136 syncer::THEMES); | 150 syncer::THEMES); |
| 137 } | 151 } |
| 138 | 152 |
| 139 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableExtensions) { | 153 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableExtensions) { |
| 140 TestSwitchDisablesType(switches::kDisableSyncExtensions, | 154 TestSwitchDisablesType(switches::kDisableSyncExtensions, |
| 141 syncer::EXTENSIONS); | 155 syncer::EXTENSIONS); |
| 142 } | 156 } |
| 143 | 157 |
| 144 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableApps) { | 158 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableApps) { |
| 145 TestSwitchDisablesType(switches::kDisableSyncApps, | 159 TestSwitchDisablesType(switches::kDisableSyncApps, |
| 146 syncer::APPS); | 160 syncer::APPS); |
| 147 } | 161 } |
| 148 | 162 |
| 149 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) { | 163 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) { |
| 150 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, | 164 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, |
| 151 syncer::AUTOFILL_PROFILE); | 165 syncer::AUTOFILL_PROFILE); |
| 152 } | 166 } |
| 153 | 167 |
| 154 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) { | 168 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) { |
| 155 TestSwitchDisablesType(switches::kDisableSyncPasswords, | 169 TestSwitchDisablesType(switches::kDisableSyncPasswords, |
| 156 syncer::PASSWORDS); | 170 syncer::PASSWORDS); |
| 157 } | 171 } |
| OLD | NEW |