OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/managed_mode/managed_user_constants.h" | 8 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
9 #include "chrome/browser/managed_mode/managed_user_shared_settings_service.h" | 9 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service.h" |
10 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto
ry.h" | 10 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service_fa
ctory.h" |
11 #include "chrome/browser/managed_mode/supervised_user_pref_mapping_service.h" | 11 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
.h" |
12 #include "chrome/browser/managed_mode/supervised_user_pref_mapping_service_facto
ry.h" | 12 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 const char kFakeSupervisedUserId[] = "fakeID"; | 17 const char kFakeSupervisedUserId[] = "fakeID"; |
18 | 18 |
19 class SupervisedUserPrefMappingServiceTest : public ::testing::Test { | 19 class SupervisedUserPrefMappingServiceTest : public ::testing::Test { |
20 protected: | 20 protected: |
21 SupervisedUserPrefMappingServiceTest() { | 21 SupervisedUserPrefMappingServiceTest() { |
22 profile_.GetPrefs()->SetString(prefs::kSupervisedUserId, | 22 profile_.GetPrefs()->SetString(prefs::kSupervisedUserId, |
23 kFakeSupervisedUserId); | 23 kFakeSupervisedUserId); |
24 shared_settings_service_ = | 24 shared_settings_service_ = |
25 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext( | 25 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( |
26 &profile_); | 26 &profile_); |
27 mapping_service_ = | 27 mapping_service_ = |
28 SupervisedUserPrefMappingServiceFactory::GetForBrowserContext( | 28 SupervisedUserPrefMappingServiceFactory::GetForBrowserContext( |
29 &profile_); | 29 &profile_); |
30 } | 30 } |
31 virtual ~SupervisedUserPrefMappingServiceTest() {} | 31 virtual ~SupervisedUserPrefMappingServiceTest() {} |
32 | 32 |
33 // testing::Test overrides: | 33 // testing::Test overrides: |
34 virtual void SetUp() OVERRIDE { | 34 virtual void SetUp() OVERRIDE { |
35 mapping_service_->Init(); | 35 mapping_service_->Init(); |
36 } | 36 } |
37 | 37 |
38 virtual void TearDown() OVERRIDE { | 38 virtual void TearDown() OVERRIDE { |
39 mapping_service_->Shutdown(); | 39 mapping_service_->Shutdown(); |
40 shared_settings_service_->Shutdown(); | 40 shared_settings_service_->Shutdown(); |
41 } | 41 } |
42 | 42 |
43 TestingProfile profile_; | 43 TestingProfile profile_; |
44 ManagedUserSharedSettingsService* shared_settings_service_; | 44 SupervisedUserSharedSettingsService* shared_settings_service_; |
45 SupervisedUserPrefMappingService* mapping_service_; | 45 SupervisedUserPrefMappingService* mapping_service_; |
46 }; | 46 }; |
47 | 47 |
48 TEST_F(SupervisedUserPrefMappingServiceTest, CheckPrefUpdate) { | 48 TEST_F(SupervisedUserPrefMappingServiceTest, CheckPrefUpdate) { |
49 EXPECT_TRUE(shared_settings_service_->GetValue( | 49 EXPECT_TRUE(shared_settings_service_->GetValue( |
50 kFakeSupervisedUserId, managed_users::kChromeAvatarIndex) == | 50 kFakeSupervisedUserId, |
51 NULL); | 51 supervised_users::kChromeAvatarIndex) == NULL); |
52 profile_.GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, 4); | 52 profile_.GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, 4); |
53 const base::Value* value = shared_settings_service_->GetValue( | 53 const base::Value* value = shared_settings_service_->GetValue( |
54 kFakeSupervisedUserId, managed_users::kChromeAvatarIndex); | 54 kFakeSupervisedUserId, supervised_users::kChromeAvatarIndex); |
55 int avatar_index; | 55 int avatar_index; |
56 value->GetAsInteger(&avatar_index); | 56 value->GetAsInteger(&avatar_index); |
57 EXPECT_EQ(avatar_index, 4); | 57 EXPECT_EQ(avatar_index, 4); |
58 } | 58 } |
59 | 59 |
60 TEST_F(SupervisedUserPrefMappingServiceTest, CheckSharedSettingUpdate) { | 60 TEST_F(SupervisedUserPrefMappingServiceTest, CheckSharedSettingUpdate) { |
61 EXPECT_EQ(profile_.GetPrefs()->GetInteger(prefs::kProfileAvatarIndex), -1); | 61 EXPECT_EQ(profile_.GetPrefs()->GetInteger(prefs::kProfileAvatarIndex), -1); |
62 shared_settings_service_->SetValue(kFakeSupervisedUserId, | 62 shared_settings_service_->SetValue(kFakeSupervisedUserId, |
63 managed_users::kChromeAvatarIndex, | 63 supervised_users::kChromeAvatarIndex, |
64 base::FundamentalValue(1)); | 64 base::FundamentalValue(1)); |
65 mapping_service_->OnSharedSettingChanged(kFakeSupervisedUserId, | 65 mapping_service_->OnSharedSettingChanged( |
66 managed_users::kChromeAvatarIndex); | 66 kFakeSupervisedUserId, |
| 67 supervised_users::kChromeAvatarIndex); |
67 EXPECT_EQ(profile_.GetPrefs()->GetInteger(prefs::kProfileAvatarIndex), 1); | 68 EXPECT_EQ(profile_.GetPrefs()->GetInteger(prefs::kProfileAvatarIndex), 1); |
68 } | 69 } |
OLD | NEW |