| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/prefs/testing_pref_store.h" | 8 #include "base/prefs/testing_pref_store.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 10 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 const char kAtomicItemName[] = "X-Wombat"; | 52 const char kAtomicItemName[] = "X-Wombat"; |
| 53 const char kSettingsName[] = "TestingSetting"; | 53 const char kSettingsName[] = "TestingSetting"; |
| 54 const char kSettingsValue[] = "SettingsValue"; | 54 const char kSettingsValue[] = "SettingsValue"; |
| 55 const char kSplitItemName[] = "X-SuperMoosePowers"; | 55 const char kSplitItemName[] = "X-SuperMoosePowers"; |
| 56 | 56 |
| 57 class SupervisedUserSettingsServiceTest : public ::testing::Test { | 57 class SupervisedUserSettingsServiceTest : public ::testing::Test { |
| 58 protected: | 58 protected: |
| 59 SupervisedUserSettingsServiceTest() {} | 59 SupervisedUserSettingsServiceTest() {} |
| 60 virtual ~SupervisedUserSettingsServiceTest() {} | 60 ~SupervisedUserSettingsServiceTest() override {} |
| 61 | 61 |
| 62 scoped_ptr<syncer::SyncChangeProcessor> CreateSyncProcessor() { | 62 scoped_ptr<syncer::SyncChangeProcessor> CreateSyncProcessor() { |
| 63 sync_processor_.reset(new syncer::FakeSyncChangeProcessor); | 63 sync_processor_.reset(new syncer::FakeSyncChangeProcessor); |
| 64 return scoped_ptr<syncer::SyncChangeProcessor>( | 64 return scoped_ptr<syncer::SyncChangeProcessor>( |
| 65 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); | 65 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void StartSyncing(const syncer::SyncDataList& initial_sync_data) { | 68 void StartSyncing(const syncer::SyncDataList& initial_sync_data) { |
| 69 scoped_ptr<syncer::SyncErrorFactory> error_handler( | 69 scoped_ptr<syncer::SyncErrorFactory> error_handler( |
| 70 new MockSyncErrorFactory(syncer::SUPERVISED_USER_SETTINGS)); | 70 new MockSyncErrorFactory(syncer::SUPERVISED_USER_SETTINGS)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 void OnNewSettingsAvailable(const base::DictionaryValue* settings) { | 114 void OnNewSettingsAvailable(const base::DictionaryValue* settings) { |
| 115 if (!settings) | 115 if (!settings) |
| 116 settings_.reset(); | 116 settings_.reset(); |
| 117 else | 117 else |
| 118 settings_.reset(settings->DeepCopy()); | 118 settings_.reset(settings->DeepCopy()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // testing::Test overrides: | 121 // testing::Test overrides: |
| 122 virtual void SetUp() override { | 122 void SetUp() override { |
| 123 TestingPrefStore* pref_store = new TestingPrefStore; | 123 TestingPrefStore* pref_store = new TestingPrefStore; |
| 124 settings_service_.Init(pref_store); | 124 settings_service_.Init(pref_store); |
| 125 settings_service_.Subscribe( | 125 settings_service_.Subscribe( |
| 126 base::Bind(&SupervisedUserSettingsServiceTest::OnNewSettingsAvailable, | 126 base::Bind(&SupervisedUserSettingsServiceTest::OnNewSettingsAvailable, |
| 127 base::Unretained(this))); | 127 base::Unretained(this))); |
| 128 pref_store->SetInitializationCompleted(); | 128 pref_store->SetInitializationCompleted(); |
| 129 ASSERT_FALSE(settings_); | 129 ASSERT_FALSE(settings_); |
| 130 settings_service_.SetActive(true); | 130 settings_service_.SetActive(true); |
| 131 ASSERT_TRUE(settings_); | 131 ASSERT_TRUE(settings_); |
| 132 } | 132 } |
| 133 | 133 |
| 134 virtual void TearDown() override { | 134 void TearDown() override { settings_service_.Shutdown(); } |
| 135 settings_service_.Shutdown(); | |
| 136 } | |
| 137 | 135 |
| 138 base::DictionaryValue split_items_; | 136 base::DictionaryValue split_items_; |
| 139 scoped_ptr<base::Value> atomic_setting_value_; | 137 scoped_ptr<base::Value> atomic_setting_value_; |
| 140 SupervisedUserSettingsService settings_service_; | 138 SupervisedUserSettingsService settings_service_; |
| 141 scoped_ptr<base::DictionaryValue> settings_; | 139 scoped_ptr<base::DictionaryValue> settings_; |
| 142 | 140 |
| 143 scoped_ptr<syncer::FakeSyncChangeProcessor> sync_processor_; | 141 scoped_ptr<syncer::FakeSyncChangeProcessor> sync_processor_; |
| 144 }; | 142 }; |
| 145 | 143 |
| 146 TEST_F(SupervisedUserSettingsServiceTest, ProcessAtomicSetting) { | 144 TEST_F(SupervisedUserSettingsServiceTest, ProcessAtomicSetting) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // The uploaded items should not show up as settings. | 280 // The uploaded items should not show up as settings. |
| 283 const base::Value* value = NULL; | 281 const base::Value* value = NULL; |
| 284 EXPECT_FALSE(settings_->GetWithoutPathExpansion(kAtomicItemName, &value)); | 282 EXPECT_FALSE(settings_->GetWithoutPathExpansion(kAtomicItemName, &value)); |
| 285 EXPECT_FALSE(settings_->GetWithoutPathExpansion(kSplitItemName, &value)); | 283 EXPECT_FALSE(settings_->GetWithoutPathExpansion(kSplitItemName, &value)); |
| 286 | 284 |
| 287 // Restarting sync should not create any new changes. | 285 // Restarting sync should not create any new changes. |
| 288 settings_service_.StopSyncing(syncer::SUPERVISED_USER_SETTINGS); | 286 settings_service_.StopSyncing(syncer::SUPERVISED_USER_SETTINGS); |
| 289 StartSyncing(sync_data); | 287 StartSyncing(sync_data); |
| 290 ASSERT_EQ(0u, sync_processor_->changes().size()); | 288 ASSERT_EQ(0u, sync_processor_->changes().size()); |
| 291 } | 289 } |
| OLD | NEW |