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.
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/supervised_user/legacy/supervised_user_pref_mapping_service.h"
9 #include "chrome/browser/supervised_user/legacy/supervised_user_pref_mapping_service_factory.h"
10 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service.h"
11 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service_factory.h"
12 #include "chrome/browser/supervised_user/supervised_user_constants.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 const char kFakeSupervisedUserId
[] = "fakeID";
19 class SupervisedUserPrefMappingServiceTest
: public ::testing::Test
{
21 SupervisedUserPrefMappingServiceTest() {
22 profile_
.GetPrefs()->SetString(prefs::kSupervisedUserId
,
23 kFakeSupervisedUserId
);
24 shared_settings_service_
=
25 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
28 SupervisedUserPrefMappingServiceFactory::GetForBrowserContext(
31 ~SupervisedUserPrefMappingServiceTest() override
{}
33 // testing::Test overrides:
34 void SetUp() override
{ mapping_service_
->Init(); }
36 void TearDown() override
{
37 mapping_service_
->Shutdown();
38 shared_settings_service_
->Shutdown();
41 TestingProfile profile_
;
42 SupervisedUserSharedSettingsService
* shared_settings_service_
;
43 SupervisedUserPrefMappingService
* mapping_service_
;
46 TEST_F(SupervisedUserPrefMappingServiceTest
, CheckPrefUpdate
) {
47 EXPECT_TRUE(shared_settings_service_
->GetValue(
48 kFakeSupervisedUserId
,
49 supervised_users::kChromeAvatarIndex
) == NULL
);
50 profile_
.GetPrefs()->SetInteger(prefs::kProfileAvatarIndex
, 4);
51 const base::Value
* value
= shared_settings_service_
->GetValue(
52 kFakeSupervisedUserId
, supervised_users::kChromeAvatarIndex
);
54 value
->GetAsInteger(&avatar_index
);
55 EXPECT_EQ(avatar_index
, 4);
58 TEST_F(SupervisedUserPrefMappingServiceTest
, CheckSharedSettingUpdate
) {
59 EXPECT_EQ(profile_
.GetPrefs()->GetInteger(prefs::kProfileAvatarIndex
), -1);
60 shared_settings_service_
->SetValue(kFakeSupervisedUserId
,
61 supervised_users::kChromeAvatarIndex
,
62 base::FundamentalValue(1));
63 mapping_service_
->OnSharedSettingChanged(
64 kFakeSupervisedUserId
,
65 supervised_users::kChromeAvatarIndex
);
66 EXPECT_EQ(profile_
.GetPrefs()->GetInteger(prefs::kProfileAvatarIndex
), 1);