| 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 "chrome/browser/supervised_user/supervised_user_whitelist_service.h" |
| 6 |
| 5 #include <map> | 7 #include <map> |
| 8 #include <memory> |
| 6 #include <set> | 9 #include <set> |
| 7 #include <string> | 10 #include <string> |
| 8 | 11 |
| 9 #include "base/bind.h" | 12 #include "base/bind.h" |
| 10 #include "base/callback.h" | 13 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 13 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 14 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 15 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 17 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 18 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" | 20 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" |
| 19 #include "chrome/browser/supervised_user/supervised_user_site_list.h" | 21 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
| 20 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" | |
| 21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
| 24 #include "components/prefs/scoped_user_pref_update.h" | 25 #include "components/prefs/scoped_user_pref_update.h" |
| 25 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
| 26 #include "sync/api/sync_change.h" | 27 #include "sync/api/sync_change.h" |
| 27 #include "sync/api/sync_error_factory.h" | 28 #include "sync/api/sync_error_factory.h" |
| 28 #include "sync/protocol/sync.pb.h" | 29 #include "sync/protocol/sync.pb.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 31 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 base::Unretained(this))); | 100 base::Unretained(this))); |
| 100 } | 101 } |
| 101 | 102 |
| 102 protected: | 103 protected: |
| 103 void PrepareInitialStateAndPreferences() { | 104 void PrepareInitialStateAndPreferences() { |
| 104 // Create two whitelists. | 105 // Create two whitelists. |
| 105 DictionaryPrefUpdate update(profile_.GetPrefs(), | 106 DictionaryPrefUpdate update(profile_.GetPrefs(), |
| 106 prefs::kSupervisedUserWhitelists); | 107 prefs::kSupervisedUserWhitelists); |
| 107 base::DictionaryValue* dict = update.Get(); | 108 base::DictionaryValue* dict = update.Get(); |
| 108 | 109 |
| 109 scoped_ptr<base::DictionaryValue> whitelist_dict(new base::DictionaryValue); | 110 std::unique_ptr<base::DictionaryValue> whitelist_dict( |
| 111 new base::DictionaryValue); |
| 110 whitelist_dict->SetString("name", "Whitelist A"); | 112 whitelist_dict->SetString("name", "Whitelist A"); |
| 111 dict->Set("aaaa", whitelist_dict.release()); | 113 dict->Set("aaaa", whitelist_dict.release()); |
| 112 | 114 |
| 113 whitelist_dict.reset(new base::DictionaryValue); | 115 whitelist_dict.reset(new base::DictionaryValue); |
| 114 whitelist_dict->SetString("name", "Whitelist B"); | 116 whitelist_dict->SetString("name", "Whitelist B"); |
| 115 dict->Set("bbbb", whitelist_dict.release()); | 117 dict->Set("bbbb", whitelist_dict.release()); |
| 116 | 118 |
| 117 installer_->RegisterWhitelist(kClientId, "aaaa", "Whitelist A"); | 119 installer_->RegisterWhitelist(kClientId, "aaaa", "Whitelist A"); |
| 118 installer_->RegisterWhitelist(kClientId, "bbbb", "Whitelist B"); | 120 installer_->RegisterWhitelist(kClientId, "bbbb", "Whitelist B"); |
| 119 } | 121 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 site_lists_changed_callback_.Run(); | 157 site_lists_changed_callback_.Run(); |
| 156 } | 158 } |
| 157 | 159 |
| 158 content::TestBrowserThreadBundle thread_bundle_; | 160 content::TestBrowserThreadBundle thread_bundle_; |
| 159 TestingProfile profile_; | 161 TestingProfile profile_; |
| 160 | 162 |
| 161 #if !defined(OS_ANDROID) | 163 #if !defined(OS_ANDROID) |
| 162 safe_json::TestingJsonParser::ScopedFactoryOverride factory_override_; | 164 safe_json::TestingJsonParser::ScopedFactoryOverride factory_override_; |
| 163 #endif | 165 #endif |
| 164 | 166 |
| 165 scoped_ptr<MockSupervisedUserWhitelistInstaller> installer_; | 167 std::unique_ptr<MockSupervisedUserWhitelistInstaller> installer_; |
| 166 scoped_ptr<SupervisedUserWhitelistService> service_; | 168 std::unique_ptr<SupervisedUserWhitelistService> service_; |
| 167 | 169 |
| 168 std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists_; | 170 std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists_; |
| 169 base::Closure site_lists_changed_callback_; | 171 base::Closure site_lists_changed_callback_; |
| 170 }; | 172 }; |
| 171 | 173 |
| 172 TEST_F(SupervisedUserWhitelistServiceTest, MergeEmpty) { | 174 TEST_F(SupervisedUserWhitelistServiceTest, MergeEmpty) { |
| 173 service_->Init(); | 175 service_->Init(); |
| 174 | 176 |
| 175 syncer::SyncMergeResult result = service_->MergeDataAndStartSyncing( | 177 syncer::SyncMergeResult result = service_->MergeDataAndStartSyncing( |
| 176 syncer::SUPERVISED_USER_WHITELISTS, syncer::SyncDataList(), | 178 syncer::SUPERVISED_USER_WHITELISTS, syncer::SyncDataList(), |
| 177 scoped_ptr<syncer::SyncChangeProcessor>(), | 179 std::unique_ptr<syncer::SyncChangeProcessor>(), |
| 178 scoped_ptr<syncer::SyncErrorFactory>()); | 180 std::unique_ptr<syncer::SyncErrorFactory>()); |
| 179 EXPECT_FALSE(result.error().IsSet()); | 181 EXPECT_FALSE(result.error().IsSet()); |
| 180 EXPECT_EQ(0, result.num_items_added()); | 182 EXPECT_EQ(0, result.num_items_added()); |
| 181 EXPECT_EQ(0, result.num_items_modified()); | 183 EXPECT_EQ(0, result.num_items_modified()); |
| 182 EXPECT_EQ(0, result.num_items_deleted()); | 184 EXPECT_EQ(0, result.num_items_deleted()); |
| 183 EXPECT_EQ(0, result.num_items_before_association()); | 185 EXPECT_EQ(0, result.num_items_before_association()); |
| 184 EXPECT_EQ(0, result.num_items_after_association()); | 186 EXPECT_EQ(0, result.num_items_after_association()); |
| 185 | 187 |
| 186 EXPECT_EQ(0u, installer_->registered_whitelists().size()); | 188 EXPECT_EQ(0u, installer_->registered_whitelists().size()); |
| 187 } | 189 } |
| 188 | 190 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 212 // modified (whitelist B), and one item should be removed (whitelist A). | 214 // modified (whitelist B), and one item should be removed (whitelist A). |
| 213 syncer::SyncDataList initial_data; | 215 syncer::SyncDataList initial_data; |
| 214 initial_data.push_back( | 216 initial_data.push_back( |
| 215 SupervisedUserWhitelistService::CreateWhitelistSyncData( | 217 SupervisedUserWhitelistService::CreateWhitelistSyncData( |
| 216 "bbbb", "Whitelist B New")); | 218 "bbbb", "Whitelist B New")); |
| 217 initial_data.push_back( | 219 initial_data.push_back( |
| 218 SupervisedUserWhitelistService::CreateWhitelistSyncData( | 220 SupervisedUserWhitelistService::CreateWhitelistSyncData( |
| 219 "cccc", "Whitelist C")); | 221 "cccc", "Whitelist C")); |
| 220 syncer::SyncMergeResult result = service_->MergeDataAndStartSyncing( | 222 syncer::SyncMergeResult result = service_->MergeDataAndStartSyncing( |
| 221 syncer::SUPERVISED_USER_WHITELISTS, initial_data, | 223 syncer::SUPERVISED_USER_WHITELISTS, initial_data, |
| 222 scoped_ptr<syncer::SyncChangeProcessor>(), | 224 std::unique_ptr<syncer::SyncChangeProcessor>(), |
| 223 scoped_ptr<syncer::SyncErrorFactory>()); | 225 std::unique_ptr<syncer::SyncErrorFactory>()); |
| 224 EXPECT_FALSE(result.error().IsSet()); | 226 EXPECT_FALSE(result.error().IsSet()); |
| 225 EXPECT_EQ(1, result.num_items_added()); | 227 EXPECT_EQ(1, result.num_items_added()); |
| 226 EXPECT_EQ(1, result.num_items_modified()); | 228 EXPECT_EQ(1, result.num_items_modified()); |
| 227 EXPECT_EQ(1, result.num_items_deleted()); | 229 EXPECT_EQ(1, result.num_items_deleted()); |
| 228 EXPECT_EQ(2, result.num_items_before_association()); | 230 EXPECT_EQ(2, result.num_items_before_association()); |
| 229 EXPECT_EQ(2, result.num_items_after_association()); | 231 EXPECT_EQ(2, result.num_items_after_association()); |
| 230 | 232 |
| 231 // Whitelist A (which was previously ready) should be removed now, and | 233 // Whitelist A (which was previously ready) should be removed now, and |
| 232 // whitelist B was never ready. | 234 // whitelist B was never ready. |
| 233 EXPECT_EQ(0u, site_lists_.size()); | 235 EXPECT_EQ(0u, site_lists_.size()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 service_->GetAllSyncData(syncer::SUPERVISED_USER_WHITELISTS); | 277 service_->GetAllSyncData(syncer::SUPERVISED_USER_WHITELISTS); |
| 276 ASSERT_EQ(2u, sync_data.size()); | 278 ASSERT_EQ(2u, sync_data.size()); |
| 277 const sync_pb::ManagedUserWhitelistSpecifics* whitelist = | 279 const sync_pb::ManagedUserWhitelistSpecifics* whitelist = |
| 278 FindWhitelist(sync_data, "aaaa"); | 280 FindWhitelist(sync_data, "aaaa"); |
| 279 ASSERT_TRUE(whitelist); | 281 ASSERT_TRUE(whitelist); |
| 280 EXPECT_EQ("Whitelist A", whitelist->name()); | 282 EXPECT_EQ("Whitelist A", whitelist->name()); |
| 281 whitelist = FindWhitelist(sync_data, "bbbb"); | 283 whitelist = FindWhitelist(sync_data, "bbbb"); |
| 282 ASSERT_TRUE(whitelist); | 284 ASSERT_TRUE(whitelist); |
| 283 EXPECT_EQ("Whitelist B", whitelist->name()); | 285 EXPECT_EQ("Whitelist B", whitelist->name()); |
| 284 } | 286 } |
| OLD | NEW |