QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / chrome / browser / supervised_user / legacy / supervised_user_pref_mapping_service_unittest.cc
blob67224b57c1773fb97e15dd78e4c8b2ac17aa3ad9
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.
5 #include <string>
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 "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 const char kFakeSupervisedUserId[] = "fakeID";
20 class SupervisedUserPrefMappingServiceTest : public ::testing::Test {
21 protected:
22 SupervisedUserPrefMappingServiceTest() {
23 profile_.GetPrefs()->SetString(prefs::kSupervisedUserId,
24 kFakeSupervisedUserId);
25 shared_settings_service_ =
26 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
27 &profile_);
28 mapping_service_ =
29 SupervisedUserPrefMappingServiceFactory::GetForBrowserContext(
30 &profile_);
32 ~SupervisedUserPrefMappingServiceTest() override {}
34 // testing::Test overrides:
35 void SetUp() override { mapping_service_->Init(); }
37 void TearDown() override {
38 mapping_service_->Shutdown();
39 shared_settings_service_->Shutdown();
42 content::TestBrowserThreadBundle thread_bundle_;
43 TestingProfile profile_;
44 SupervisedUserSharedSettingsService* shared_settings_service_;
45 SupervisedUserPrefMappingService* mapping_service_;
48 TEST_F(SupervisedUserPrefMappingServiceTest, CheckPrefUpdate) {
49 EXPECT_TRUE(shared_settings_service_->GetValue(
50 kFakeSupervisedUserId,
51 supervised_users::kChromeAvatarIndex) == NULL);
52 profile_.GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, 4);
53 const base::Value* value = shared_settings_service_->GetValue(
54 kFakeSupervisedUserId, supervised_users::kChromeAvatarIndex);
55 int avatar_index;
56 value->GetAsInteger(&avatar_index);
57 EXPECT_EQ(avatar_index, 4);
60 TEST_F(SupervisedUserPrefMappingServiceTest, CheckSharedSettingUpdate) {
61 EXPECT_EQ(profile_.GetPrefs()->GetInteger(prefs::kProfileAvatarIndex), -1);
62 shared_settings_service_->SetValue(kFakeSupervisedUserId,
63 supervised_users::kChromeAvatarIndex,
64 base::FundamentalValue(1));
65 mapping_service_->OnSharedSettingChanged(
66 kFakeSupervisedUserId,
67 supervised_users::kChromeAvatarIndex);
68 EXPECT_EQ(profile_.GetPrefs()->GetInteger(prefs::kProfileAvatarIndex), 1);