| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 : ProfileSyncService( | 45 : ProfileSyncService( |
| 46 scoped_ptr<ProfileSyncComponentsFactory>( | 46 scoped_ptr<ProfileSyncComponentsFactory>( |
| 47 new ProfileSyncComponentsFactoryMock()), | 47 new ProfileSyncComponentsFactoryMock()), |
| 48 profile, | 48 profile, |
| 49 make_scoped_ptr<SupervisedUserSigninManagerWrapper>(NULL), | 49 make_scoped_ptr<SupervisedUserSigninManagerWrapper>(NULL), |
| 50 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 50 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| 51 browser_sync::MANUAL_START), | 51 browser_sync::MANUAL_START), |
| 52 sync_initialized_(true), | 52 sync_initialized_(true), |
| 53 initialized_state_violation_(false) {} | 53 initialized_state_violation_(false) {} |
| 54 | 54 |
| 55 virtual ~FakeProfileSyncService() {} | 55 ~FakeProfileSyncService() override {} |
| 56 | 56 |
| 57 static KeyedService* BuildFakeProfileSyncService( | 57 static KeyedService* BuildFakeProfileSyncService( |
| 58 content::BrowserContext* context) { | 58 content::BrowserContext* context) { |
| 59 return new FakeProfileSyncService(static_cast<Profile*>(context)); | 59 return new FakeProfileSyncService(static_cast<Profile*>(context)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void set_sync_initialized(bool sync_initialized) { | 62 void set_sync_initialized(bool sync_initialized) { |
| 63 sync_initialized_ = sync_initialized; | 63 sync_initialized_ = sync_initialized; |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool initialized_state_violation() { return initialized_state_violation_; } | 66 bool initialized_state_violation() { return initialized_state_violation_; } |
| 67 | 67 |
| 68 // ProfileSyncService: | 68 // ProfileSyncService: |
| 69 virtual bool SyncActive() const override { | 69 bool SyncActive() const override { return sync_initialized_; } |
| 70 return sync_initialized_; | |
| 71 } | |
| 72 | 70 |
| 73 virtual void AddObserver( | 71 void AddObserver(ProfileSyncServiceBase::Observer* observer) override { |
| 74 ProfileSyncServiceBase::Observer* observer) override { | |
| 75 if (sync_initialized_) | 72 if (sync_initialized_) |
| 76 initialized_state_violation_ = true; | 73 initialized_state_violation_ = true; |
| 77 // Set sync initialized state to true so the function will run after | 74 // Set sync initialized state to true so the function will run after |
| 78 // OnStateChanged is called. | 75 // OnStateChanged is called. |
| 79 sync_initialized_ = true; | 76 sync_initialized_ = true; |
| 80 base::MessageLoop::current()->PostTask( | 77 base::MessageLoop::current()->PostTask( |
| 81 FROM_HERE, | 78 FROM_HERE, |
| 82 base::Bind(&ProfileSyncServiceBase::Observer::OnStateChanged, | 79 base::Bind(&ProfileSyncServiceBase::Observer::OnStateChanged, |
| 83 base::Unretained(observer))); | 80 base::Unretained(observer))); |
| 84 } | 81 } |
| 85 | 82 |
| 86 virtual syncer::ModelTypeSet GetEncryptedDataTypes() const override { | 83 syncer::ModelTypeSet GetEncryptedDataTypes() const override { |
| 87 if (!sync_initialized_) | 84 if (!sync_initialized_) |
| 88 initialized_state_violation_ = true; | 85 initialized_state_violation_ = true; |
| 89 syncer::ModelTypeSet type_set; | 86 syncer::ModelTypeSet type_set; |
| 90 type_set.Put(syncer::AUTOFILL); | 87 type_set.Put(syncer::AUTOFILL); |
| 91 return type_set; | 88 return type_set; |
| 92 } | 89 } |
| 93 | 90 |
| 94 virtual syncer::ModelTypeSet GetPreferredDataTypes() const override { | 91 syncer::ModelTypeSet GetPreferredDataTypes() const override { |
| 95 if (!sync_initialized_) | 92 if (!sync_initialized_) |
| 96 initialized_state_violation_ = true; | 93 initialized_state_violation_ = true; |
| 97 syncer::ModelTypeSet preferred_types = | 94 syncer::ModelTypeSet preferred_types = |
| 98 syncer::UserSelectableTypes(); | 95 syncer::UserSelectableTypes(); |
| 99 preferred_types.Remove(syncer::TYPED_URLS); | 96 preferred_types.Remove(syncer::TYPED_URLS); |
| 100 return preferred_types; | 97 return preferred_types; |
| 101 } | 98 } |
| 102 | 99 |
| 103 private: | 100 private: |
| 104 bool sync_initialized_; | 101 bool sync_initialized_; |
| 105 // Set to true if a function is called when sync_initialized is in an | 102 // Set to true if a function is called when sync_initialized is in an |
| 106 // unexpected state. | 103 // unexpected state. |
| 107 mutable bool initialized_state_violation_; | 104 mutable bool initialized_state_violation_; |
| 108 | 105 |
| 109 DISALLOW_COPY_AND_ASSIGN(FakeProfileSyncService); | 106 DISALLOW_COPY_AND_ASSIGN(FakeProfileSyncService); |
| 110 }; | 107 }; |
| 111 | 108 |
| 112 class PreferencesPrivateApiTest : public ExtensionApiTest { | 109 class PreferencesPrivateApiTest : public ExtensionApiTest { |
| 113 public: | 110 public: |
| 114 PreferencesPrivateApiTest() : browser_(NULL), service_(NULL) {} | 111 PreferencesPrivateApiTest() : browser_(NULL), service_(NULL) {} |
| 115 virtual ~PreferencesPrivateApiTest() {} | 112 virtual ~PreferencesPrivateApiTest() {} |
| 116 | 113 |
| 117 virtual void SetUpCommandLine(CommandLine* command_line) override { | 114 void SetUpCommandLine(CommandLine* command_line) override { |
| 118 #if defined(OS_CHROMEOS) | 115 #if defined(OS_CHROMEOS) |
| 119 command_line->AppendSwitch( | 116 command_line->AppendSwitch( |
| 120 chromeos::switches::kIgnoreUserProfileMappingForTests); | 117 chromeos::switches::kIgnoreUserProfileMappingForTests); |
| 121 #endif | 118 #endif |
| 122 } | 119 } |
| 123 | 120 |
| 124 virtual void SetUpOnMainThread() override { | 121 void SetUpOnMainThread() override { |
| 125 ExtensionApiTest::SetUpOnMainThread(); | 122 ExtensionApiTest::SetUpOnMainThread(); |
| 126 | 123 |
| 127 base::FilePath path; | 124 base::FilePath path; |
| 128 PathService::Get(chrome::DIR_USER_DATA, &path); | 125 PathService::Get(chrome::DIR_USER_DATA, &path); |
| 129 path = path.AppendASCII("test_profile"); | 126 path = path.AppendASCII("test_profile"); |
| 130 if (!base::PathExists(path)) | 127 if (!base::PathExists(path)) |
| 131 CHECK(base::CreateDirectory(path)); | 128 CHECK(base::CreateDirectory(path)); |
| 132 | 129 |
| 133 Profile* profile = | 130 Profile* profile = |
| 134 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); | 131 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 188 |
| 192 // Verifies that we wait for the sync service to be ready before checking | 189 // Verifies that we wait for the sync service to be ready before checking |
| 193 // encryption status. | 190 // encryption status. |
| 194 IN_PROC_BROWSER_TEST_F(PreferencesPrivateApiTest, | 191 IN_PROC_BROWSER_TEST_F(PreferencesPrivateApiTest, |
| 195 GetSyncCategoriesWithoutPassphraseAsynchronous) { | 192 GetSyncCategoriesWithoutPassphraseAsynchronous) { |
| 196 service_->set_sync_initialized(false); | 193 service_->set_sync_initialized(false); |
| 197 TestGetSyncCategoriesWithoutPassphraseFunction(); | 194 TestGetSyncCategoriesWithoutPassphraseFunction(); |
| 198 } | 195 } |
| 199 | 196 |
| 200 } // namespace | 197 } // namespace |
| OLD | NEW |