| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "chrome/browser/sync/profile_sync_service_factory.h" | 7 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 8 #include "chrome/common/chrome_switches.h" | |
| 9 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "components/browser_sync/browser/profile_sync_service.h" |
| 10 #include "components/browser_sync/common/browser_sync_switches.h" | 10 #include "components/browser_sync/common/browser_sync_switches.h" |
| 11 #include "components/sync_driver/data_type_controller.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "sync/internal_api/public/base/model_type.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/app_list/app_list_switches.h" |
| 16 |
| 17 using sync_driver::DataTypeController; |
| 13 | 18 |
| 14 class ProfileSyncServiceFactoryTest : public testing::Test { | 19 class ProfileSyncServiceFactoryTest : public testing::Test { |
| 15 protected: | 20 protected: |
| 16 ProfileSyncServiceFactoryTest() {} | 21 ProfileSyncServiceFactoryTest() : profile_(new TestingProfile()) {} |
| 17 | 22 |
| 18 void SetUp() override { | 23 // Returns the collection of default datatypes. |
| 19 profile_.reset(new TestingProfile()); | 24 std::vector<syncer::ModelType> DefaultDatatypes() { |
| 25 std::vector<syncer::ModelType> datatypes; |
| 26 datatypes.push_back(syncer::APPS); |
| 27 #if defined(ENABLE_APP_LIST) |
| 28 if (app_list::switches::IsAppListSyncEnabled()) |
| 29 datatypes.push_back(syncer::APP_LIST); |
| 30 #endif |
| 31 datatypes.push_back(syncer::APP_SETTINGS); |
| 32 datatypes.push_back(syncer::AUTOFILL); |
| 33 datatypes.push_back(syncer::AUTOFILL_PROFILE); |
| 34 datatypes.push_back(syncer::AUTOFILL_WALLET_DATA); |
| 35 datatypes.push_back(syncer::BOOKMARKS); |
| 36 datatypes.push_back(syncer::DEVICE_INFO); |
| 37 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) |
| 38 datatypes.push_back(syncer::DICTIONARY); |
| 39 #endif |
| 40 datatypes.push_back(syncer::EXTENSIONS); |
| 41 datatypes.push_back(syncer::EXTENSION_SETTINGS); |
| 42 datatypes.push_back(syncer::HISTORY_DELETE_DIRECTIVES); |
| 43 datatypes.push_back(syncer::PASSWORDS); |
| 44 datatypes.push_back(syncer::PREFERENCES); |
| 45 datatypes.push_back(syncer::PRIORITY_PREFERENCES); |
| 46 datatypes.push_back(syncer::SEARCH_ENGINES); |
| 47 datatypes.push_back(syncer::SESSIONS); |
| 48 datatypes.push_back(syncer::PROXY_TABS); |
| 49 datatypes.push_back(syncer::THEMES); |
| 50 datatypes.push_back(syncer::TYPED_URLS); |
| 51 datatypes.push_back(syncer::FAVICON_TRACKING); |
| 52 datatypes.push_back(syncer::FAVICON_IMAGES); |
| 53 datatypes.push_back(syncer::SUPERVISED_USERS); |
| 54 datatypes.push_back(syncer::SUPERVISED_USER_SETTINGS); |
| 55 datatypes.push_back(syncer::SUPERVISED_USER_SHARED_SETTINGS); |
| 56 datatypes.push_back(syncer::SUPERVISED_USER_WHITELISTS); |
| 57 |
| 58 return datatypes; |
| 20 } | 59 } |
| 21 | 60 |
| 61 // Returns the number of default datatypes. |
| 62 size_t DefaultDatatypesCount() { return DefaultDatatypes().size(); } |
| 63 |
| 64 // Asserts that all the default datatypes are in |map|, except |
| 65 // for |exception_type|, which unless it is UNDEFINED, is asserted to |
| 66 // not be in |map|. |
| 67 void CheckDefaultDatatypesInMapExcept(DataTypeController::StateMap* map, |
| 68 syncer::ModelTypeSet exception_types) { |
| 69 std::vector<syncer::ModelType> defaults = DefaultDatatypes(); |
| 70 std::vector<syncer::ModelType>::iterator iter; |
| 71 for (iter = defaults.begin(); iter != defaults.end(); ++iter) { |
| 72 if (exception_types.Has(*iter)) |
| 73 EXPECT_EQ(0U, map->count(*iter)) |
| 74 << *iter << " found in dataypes map, shouldn't be there."; |
| 75 else |
| 76 EXPECT_EQ(1U, map->count(*iter)) << *iter |
| 77 << " not found in datatypes map"; |
| 78 } |
| 79 } |
| 80 |
| 81 void SetDisabledTypes(syncer::ModelTypeSet disabled_types) { |
| 82 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 83 switches::kDisableSyncTypes, |
| 84 syncer::ModelTypeSetToString(disabled_types)); |
| 85 } |
| 86 |
| 87 Profile* profile() { return profile_.get(); } |
| 88 |
| 89 private: |
| 22 content::TestBrowserThreadBundle thread_bundle_; | 90 content::TestBrowserThreadBundle thread_bundle_; |
| 23 scoped_ptr<Profile> profile_; | 91 scoped_ptr<Profile> profile_; |
| 24 }; | 92 }; |
| 25 | 93 |
| 26 // Verify that the disable sync flag disables creation of the sync service. | 94 // Verify that the disable sync flag disables creation of the sync service. |
| 27 TEST_F(ProfileSyncServiceFactoryTest, DisableSyncFlag) { | 95 TEST_F(ProfileSyncServiceFactoryTest, DisableSyncFlag) { |
| 28 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); | 96 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); |
| 29 EXPECT_EQ(nullptr, ProfileSyncServiceFactory::GetForProfile(profile_.get())); | 97 EXPECT_EQ(nullptr, ProfileSyncServiceFactory::GetForProfile(profile())); |
| 30 } | 98 } |
| 99 |
| 100 // Verify that a normal (no command line flags) PSS can be created and |
| 101 // properly initialized. |
| 102 TEST_F(ProfileSyncServiceFactoryTest, CreatePSSDefault) { |
| 103 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile()); |
| 104 DataTypeController::StateMap controller_states; |
| 105 pss->GetDataTypeControllerStates(&controller_states); |
| 106 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); |
| 107 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet()); |
| 108 } |
| 109 |
| 110 // Verify that a PSS with a disabled datatype can be created and properly |
| 111 // initialized. |
| 112 TEST_F(ProfileSyncServiceFactoryTest, CreatePSSDisableOne) { |
| 113 syncer::ModelTypeSet disabled_types(syncer::AUTOFILL); |
| 114 SetDisabledTypes(disabled_types); |
| 115 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile()); |
| 116 DataTypeController::StateMap controller_states; |
| 117 pss->GetDataTypeControllerStates(&controller_states); |
| 118 EXPECT_EQ(DefaultDatatypesCount() - disabled_types.Size(), |
| 119 controller_states.size()); |
| 120 CheckDefaultDatatypesInMapExcept(&controller_states, disabled_types); |
| 121 } |
| 122 |
| 123 // Verify that a PSS with multiple disabled datatypes can be created and |
| 124 // properly initialized. |
| 125 TEST_F(ProfileSyncServiceFactoryTest, CreatePSSDisableMultiple) { |
| 126 syncer::ModelTypeSet disabled_types(syncer::AUTOFILL_PROFILE, |
| 127 syncer::BOOKMARKS); |
| 128 SetDisabledTypes(disabled_types); |
| 129 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile()); |
| 130 DataTypeController::StateMap controller_states; |
| 131 pss->GetDataTypeControllerStates(&controller_states); |
| 132 EXPECT_EQ(DefaultDatatypesCount() - disabled_types.Size(), |
| 133 controller_states.size()); |
| 134 CheckDefaultDatatypesInMapExcept(&controller_states, disabled_types); |
| 135 } |
| OLD | NEW |