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/managed_mode/managed_user_shared_settings_service.h"
8 #include "chrome/browser/managed_mode/managed_user_shared_settings_update.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "sync/api/sync_change.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 class ManagedUserSharedSettingsUpdateTest
: public testing::Test
{
15 ManagedUserSharedSettingsUpdateTest() : service_(profile_
.GetPrefs()) {}
16 virtual ~ManagedUserSharedSettingsUpdateTest() {}
18 void OnSettingUpdated(bool success
) {
19 result_
.reset(new bool(success
));
23 TestingProfile profile_
;
24 ManagedUserSharedSettingsService service_
;
25 scoped_ptr
<bool> result_
;
28 TEST_F(ManagedUserSharedSettingsUpdateTest
, Success
) {
29 ManagedUserSharedSettingsUpdate
update(
33 scoped_ptr
<base::Value
>(new base::StringValue("Hans Moleman")),
34 base::Bind(&ManagedUserSharedSettingsUpdateTest::OnSettingUpdated
,
35 base::Unretained(this)));
36 syncer::SyncChangeList changes
;
37 changes
.push_back(syncer::SyncChange(
39 syncer::SyncChange::ACTION_UPDATE
,
40 ManagedUserSharedSettingsService::CreateSyncDataForSetting(
41 "abcdef", "name", base::StringValue("Hans Moleman"), true)));
42 syncer::SyncError error
= service_
.ProcessSyncChanges(FROM_HERE
, changes
);
43 EXPECT_FALSE(error
.IsSet()) << error
.ToString();
45 EXPECT_TRUE(*result_
);
48 TEST_F(ManagedUserSharedSettingsUpdateTest
, Failure
) {
49 ManagedUserSharedSettingsUpdate
update(
53 scoped_ptr
<base::Value
>(new base::StringValue("Hans Moleman")),
54 base::Bind(&ManagedUserSharedSettingsUpdateTest::OnSettingUpdated
,
55 base::Unretained(this)));
57 // Syncing down a different change will cause the update to fail.
58 syncer::SyncChangeList changes
;
59 changes
.push_back(syncer::SyncChange(
61 syncer::SyncChange::ACTION_UPDATE
,
62 ManagedUserSharedSettingsService::CreateSyncDataForSetting(
65 base::StringValue("Barney Gumble"),
67 syncer::SyncError error
= service_
.ProcessSyncChanges(FROM_HERE
, changes
);
68 EXPECT_FALSE(error
.IsSet()) << error
.ToString();
70 EXPECT_FALSE(*result_
);
73 TEST_F(ManagedUserSharedSettingsUpdateTest
, Cancel
) {
75 ManagedUserSharedSettingsUpdate
update(
79 scoped_ptr
<base::Value
>(new base::StringValue("Hans Moleman")),
80 base::Bind(&ManagedUserSharedSettingsUpdateTest::OnSettingUpdated
,
81 base::Unretained(this)));
82 ASSERT_FALSE(result_
);
84 ASSERT_FALSE(result_
);