| 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/legacy/supervised_user_shared_settings_
update.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 5 #include "base/bind.h" | 9 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | |
| 7 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_
service.h" | 10 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_
service.h" |
| 8 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_
update.h" | |
| 9 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "sync/api/sync_change.h" | 13 #include "sync/api/sync_change.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 class SupervisedUserSharedSettingsUpdateTest : public testing::Test { | 16 class SupervisedUserSharedSettingsUpdateTest : public testing::Test { |
| 15 public: | 17 public: |
| 16 SupervisedUserSharedSettingsUpdateTest() : service_(profile_.GetPrefs()) {} | 18 SupervisedUserSharedSettingsUpdateTest() : service_(profile_.GetPrefs()) {} |
| 17 ~SupervisedUserSharedSettingsUpdateTest() override {} | 19 ~SupervisedUserSharedSettingsUpdateTest() override {} |
| 18 | 20 |
| 19 void OnSettingUpdated(bool success) { | 21 void OnSettingUpdated(bool success) { |
| 20 result_.reset(new bool(success)); | 22 result_.reset(new bool(success)); |
| 21 } | 23 } |
| 22 | 24 |
| 23 protected: | 25 protected: |
| 24 content::TestBrowserThreadBundle thread_bundle_; | 26 content::TestBrowserThreadBundle thread_bundle_; |
| 25 TestingProfile profile_; | 27 TestingProfile profile_; |
| 26 SupervisedUserSharedSettingsService service_; | 28 SupervisedUserSharedSettingsService service_; |
| 27 scoped_ptr<bool> result_; | 29 std::unique_ptr<bool> result_; |
| 28 }; | 30 }; |
| 29 | 31 |
| 30 TEST_F(SupervisedUserSharedSettingsUpdateTest, Success) { | 32 TEST_F(SupervisedUserSharedSettingsUpdateTest, Success) { |
| 31 SupervisedUserSharedSettingsUpdate update( | 33 SupervisedUserSharedSettingsUpdate update( |
| 32 &service_, | 34 &service_, "abcdef", "name", |
| 33 "abcdef", | 35 std::unique_ptr<base::Value>(new base::StringValue("Hans Moleman")), |
| 34 "name", | |
| 35 scoped_ptr<base::Value>(new base::StringValue("Hans Moleman")), | |
| 36 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated, | 36 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated, |
| 37 base::Unretained(this))); | 37 base::Unretained(this))); |
| 38 syncer::SyncChangeList changes; | 38 syncer::SyncChangeList changes; |
| 39 changes.push_back(syncer::SyncChange( | 39 changes.push_back(syncer::SyncChange( |
| 40 FROM_HERE, | 40 FROM_HERE, |
| 41 syncer::SyncChange::ACTION_UPDATE, | 41 syncer::SyncChange::ACTION_UPDATE, |
| 42 SupervisedUserSharedSettingsService::CreateSyncDataForSetting( | 42 SupervisedUserSharedSettingsService::CreateSyncDataForSetting( |
| 43 "abcdef", "name", base::StringValue("Hans Moleman"), true))); | 43 "abcdef", "name", base::StringValue("Hans Moleman"), true))); |
| 44 syncer::SyncError error = service_.ProcessSyncChanges(FROM_HERE, changes); | 44 syncer::SyncError error = service_.ProcessSyncChanges(FROM_HERE, changes); |
| 45 EXPECT_FALSE(error.IsSet()) << error.ToString(); | 45 EXPECT_FALSE(error.IsSet()) << error.ToString(); |
| 46 ASSERT_TRUE(result_); | 46 ASSERT_TRUE(result_); |
| 47 EXPECT_TRUE(*result_); | 47 EXPECT_TRUE(*result_); |
| 48 } | 48 } |
| 49 | 49 |
| 50 TEST_F(SupervisedUserSharedSettingsUpdateTest, Failure) { | 50 TEST_F(SupervisedUserSharedSettingsUpdateTest, Failure) { |
| 51 SupervisedUserSharedSettingsUpdate update( | 51 SupervisedUserSharedSettingsUpdate update( |
| 52 &service_, | 52 &service_, "abcdef", "name", |
| 53 "abcdef", | 53 std::unique_ptr<base::Value>(new base::StringValue("Hans Moleman")), |
| 54 "name", | |
| 55 scoped_ptr<base::Value>(new base::StringValue("Hans Moleman")), | |
| 56 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated, | 54 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated, |
| 57 base::Unretained(this))); | 55 base::Unretained(this))); |
| 58 | 56 |
| 59 // Syncing down a different change will cause the update to fail. | 57 // Syncing down a different change will cause the update to fail. |
| 60 syncer::SyncChangeList changes; | 58 syncer::SyncChangeList changes; |
| 61 changes.push_back(syncer::SyncChange( | 59 changes.push_back(syncer::SyncChange( |
| 62 FROM_HERE, | 60 FROM_HERE, |
| 63 syncer::SyncChange::ACTION_UPDATE, | 61 syncer::SyncChange::ACTION_UPDATE, |
| 64 SupervisedUserSharedSettingsService::CreateSyncDataForSetting( | 62 SupervisedUserSharedSettingsService::CreateSyncDataForSetting( |
| 65 "abcdef", | 63 "abcdef", |
| 66 "name", | 64 "name", |
| 67 base::StringValue("Barney Gumble"), | 65 base::StringValue("Barney Gumble"), |
| 68 true))); | 66 true))); |
| 69 syncer::SyncError error = service_.ProcessSyncChanges(FROM_HERE, changes); | 67 syncer::SyncError error = service_.ProcessSyncChanges(FROM_HERE, changes); |
| 70 EXPECT_FALSE(error.IsSet()) << error.ToString(); | 68 EXPECT_FALSE(error.IsSet()) << error.ToString(); |
| 71 ASSERT_TRUE(result_); | 69 ASSERT_TRUE(result_); |
| 72 EXPECT_FALSE(*result_); | 70 EXPECT_FALSE(*result_); |
| 73 } | 71 } |
| 74 | 72 |
| 75 TEST_F(SupervisedUserSharedSettingsUpdateTest, Cancel) { | 73 TEST_F(SupervisedUserSharedSettingsUpdateTest, Cancel) { |
| 76 { | 74 { |
| 77 SupervisedUserSharedSettingsUpdate update( | 75 SupervisedUserSharedSettingsUpdate update( |
| 78 &service_, | 76 &service_, "abcdef", "name", |
| 79 "abcdef", | 77 std::unique_ptr<base::Value>(new base::StringValue("Hans Moleman")), |
| 80 "name", | |
| 81 scoped_ptr<base::Value>(new base::StringValue("Hans Moleman")), | |
| 82 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated, | 78 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated, |
| 83 base::Unretained(this))); | 79 base::Unretained(this))); |
| 84 ASSERT_FALSE(result_); | 80 ASSERT_FALSE(result_); |
| 85 } | 81 } |
| 86 ASSERT_FALSE(result_); | 82 ASSERT_FALSE(result_); |
| 87 } | 83 } |
| OLD | NEW |