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" |
11 #include "sync/api/fake_sync_change_processor.h" | 11 #include "sync/api/fake_sync_change_processor.h" |
12 #include "sync/api/sync_change.h" | 12 #include "sync/api/sync_change.h" |
13 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 13 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
14 #include "sync/api/sync_error_factory_mock.h" | 14 #include "sync/api/sync_error_factory_mock.h" |
15 #include "sync/protocol/sync.pb.h" | 15 #include "sync/protocol/sync.pb.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class MockSyncErrorFactory : public syncer::SyncErrorFactory { | 20 class MockSyncErrorFactory : public syncer::SyncErrorFactory { |
21 public: | 21 public: |
22 explicit MockSyncErrorFactory(syncer::ModelType type); | 22 explicit MockSyncErrorFactory(syncer::ModelType type); |
23 virtual ~MockSyncErrorFactory(); | 23 virtual ~MockSyncErrorFactory(); |
24 | 24 |
25 // SyncErrorFactory implementation: | 25 // SyncErrorFactory implementation: |
26 virtual syncer::SyncError CreateAndUploadError( | 26 virtual syncer::SyncError CreateAndUploadError( |
27 const tracked_objects::Location& location, | 27 const tracked_objects::Location& location, |
28 const std::string& message) OVERRIDE; | 28 const std::string& message) override; |
29 | 29 |
30 private: | 30 private: |
31 syncer::ModelType type_; | 31 syncer::ModelType type_; |
32 | 32 |
33 DISALLOW_COPY_AND_ASSIGN(MockSyncErrorFactory); | 33 DISALLOW_COPY_AND_ASSIGN(MockSyncErrorFactory); |
34 }; | 34 }; |
35 | 35 |
36 MockSyncErrorFactory::MockSyncErrorFactory(syncer::ModelType type) | 36 MockSyncErrorFactory::MockSyncErrorFactory(syncer::ModelType type) |
37 : type_(type) {} | 37 : type_(type) {} |
38 | 38 |
(...skipping 73 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 virtual 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 virtual void TearDown() override { |
135 settings_service_.Shutdown(); | 135 settings_service_.Shutdown(); |
136 } | 136 } |
137 | 137 |
138 base::DictionaryValue split_items_; | 138 base::DictionaryValue split_items_; |
139 scoped_ptr<base::Value> atomic_setting_value_; | 139 scoped_ptr<base::Value> atomic_setting_value_; |
140 SupervisedUserSettingsService settings_service_; | 140 SupervisedUserSettingsService settings_service_; |
141 scoped_ptr<base::DictionaryValue> settings_; | 141 scoped_ptr<base::DictionaryValue> settings_; |
142 | 142 |
143 scoped_ptr<syncer::FakeSyncChangeProcessor> sync_processor_; | 143 scoped_ptr<syncer::FakeSyncChangeProcessor> sync_processor_; |
144 }; | 144 }; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // The uploaded items should not show up as settings. | 282 // The uploaded items should not show up as settings. |
283 const base::Value* value = NULL; | 283 const base::Value* value = NULL; |
284 EXPECT_FALSE(settings_->GetWithoutPathExpansion(kAtomicItemName, &value)); | 284 EXPECT_FALSE(settings_->GetWithoutPathExpansion(kAtomicItemName, &value)); |
285 EXPECT_FALSE(settings_->GetWithoutPathExpansion(kSplitItemName, &value)); | 285 EXPECT_FALSE(settings_->GetWithoutPathExpansion(kSplitItemName, &value)); |
286 | 286 |
287 // Restarting sync should not create any new changes. | 287 // Restarting sync should not create any new changes. |
288 settings_service_.StopSyncing(syncer::SUPERVISED_USER_SETTINGS); | 288 settings_service_.StopSyncing(syncer::SUPERVISED_USER_SETTINGS); |
289 StartSyncing(sync_data); | 289 StartSyncing(sync_data); |
290 ASSERT_EQ(0u, sync_processor_->changes().size()); | 290 ASSERT_EQ(0u, sync_processor_->changes().size()); |
291 } | 291 } |
OLD | NEW |