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
3 // found in the LICENSE file.
6 #include "base/memory/scoped_ptr.h"
7 #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"
10 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "sync/api/sync_change.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 class SupervisedUserSharedSettingsUpdateTest
: public testing::Test
{
16 SupervisedUserSharedSettingsUpdateTest() : service_(profile_
.GetPrefs()) {}
17 ~SupervisedUserSharedSettingsUpdateTest() override
{}
19 void OnSettingUpdated(bool success
) {
20 result_
.reset(new bool(success
));
24 content::TestBrowserThreadBundle thread_bundle_
;
25 TestingProfile profile_
;
26 SupervisedUserSharedSettingsService service_
;
27 scoped_ptr
<bool> result_
;
30 TEST_F(SupervisedUserSharedSettingsUpdateTest
, Success
) {
31 SupervisedUserSharedSettingsUpdate
update(
35 scoped_ptr
<base::Value
>(new base::StringValue("Hans Moleman")),
36 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated
,
37 base::Unretained(this)));
38 syncer::SyncChangeList changes
;
39 changes
.push_back(syncer::SyncChange(
41 syncer::SyncChange::ACTION_UPDATE
,
42 SupervisedUserSharedSettingsService::CreateSyncDataForSetting(
43 "abcdef", "name", base::StringValue("Hans Moleman"), true)));
44 syncer::SyncError error
= service_
.ProcessSyncChanges(FROM_HERE
, changes
);
45 EXPECT_FALSE(error
.IsSet()) << error
.ToString();
47 EXPECT_TRUE(*result_
);
50 TEST_F(SupervisedUserSharedSettingsUpdateTest
, Failure
) {
51 SupervisedUserSharedSettingsUpdate
update(
55 scoped_ptr
<base::Value
>(new base::StringValue("Hans Moleman")),
56 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated
,
57 base::Unretained(this)));
59 // Syncing down a different change will cause the update to fail.
60 syncer::SyncChangeList changes
;
61 changes
.push_back(syncer::SyncChange(
63 syncer::SyncChange::ACTION_UPDATE
,
64 SupervisedUserSharedSettingsService::CreateSyncDataForSetting(
67 base::StringValue("Barney Gumble"),
69 syncer::SyncError error
= service_
.ProcessSyncChanges(FROM_HERE
, changes
);
70 EXPECT_FALSE(error
.IsSet()) << error
.ToString();
72 EXPECT_FALSE(*result_
);
75 TEST_F(SupervisedUserSharedSettingsUpdateTest
, Cancel
) {
77 SupervisedUserSharedSettingsUpdate
update(
81 scoped_ptr
<base::Value
>(new base::StringValue("Hans Moleman")),
82 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated
,
83 base::Unretained(this)));
84 ASSERT_FALSE(result_
);
86 ASSERT_FALSE(result_
);