Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / supervised_user / supervised_user_pref_mapping_service_unittest.cc
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.
4
5 #include <string>
6
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/supervised_user/supervised_user_constants.h"
9 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service.h"
10 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service_factory.h"
11 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service.h"
12 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service_factory.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 const char kFakeSupervisedUserId[] = "fakeID";
18
19 class SupervisedUserPrefMappingServiceTest : public ::testing::Test {
20  protected:
21   SupervisedUserPrefMappingServiceTest() {
22     profile_.GetPrefs()->SetString(prefs::kSupervisedUserId,
23                                    kFakeSupervisedUserId);
24     shared_settings_service_ =
25         SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
26             &profile_);
27     mapping_service_ =
28         SupervisedUserPrefMappingServiceFactory::GetForBrowserContext(
29             &profile_);
30   }
31   ~SupervisedUserPrefMappingServiceTest() override {}
32
33   // testing::Test overrides:
34   void SetUp() override { mapping_service_->Init(); }
35
36   void TearDown() override {
37     mapping_service_->Shutdown();
38     shared_settings_service_->Shutdown();
39   }
40
41   TestingProfile profile_;
42   SupervisedUserSharedSettingsService* shared_settings_service_;
43   SupervisedUserPrefMappingService* mapping_service_;
44 };
45
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);
53   int avatar_index;
54   value->GetAsInteger(&avatar_index);
55   EXPECT_EQ(avatar_index, 4);
56 }
57
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);
67 }