Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1300)

Side by Side Diff: chrome/browser/managed_mode/managed_user_service_browsertest.cc

Issue 23868042: Mark supervised profiles as such immediately when they're created. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/command_line.h"
5 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
6 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/managed_mode/managed_user_constants.h" 9 #include "chrome/browser/managed_mode/managed_user_constants.h"
9 #include "chrome/browser/managed_mode/managed_user_service.h" 10 #include "chrome/browser/managed_mode/managed_user_service.h"
10 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 11 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
11 #include "chrome/browser/managed_mode/managed_user_settings_service.h" 12 #include "chrome/browser/managed_mode/managed_user_settings_service.h"
12 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" 13 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_info_cache.h" 15 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
19 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
20 22
21 typedef InProcessBrowserTest ManagedUserServiceTest; 23 typedef InProcessBrowserTest ManagedUserServiceTest;
22 24
25 class ManagedUserServiceTestManaged : public InProcessBrowserTest {
26 public:
27 // content::BrowserTestBase:
28 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
29 command_line->AppendSwitch(switches::kNewProfileIsSupervised);
30 }
31 };
32
23 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, LocalPolicies) { 33 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, LocalPolicies) {
24 Profile* profile = browser()->profile(); 34 Profile* profile = browser()->profile();
25 PrefService* prefs = profile->GetPrefs(); 35 PrefService* prefs = profile->GetPrefs();
26 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); 36 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch));
27 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); 37 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch));
28
29 ManagedUserService* managed_user_service =
30 ManagedUserServiceFactory::GetForProfile(profile);
31 managed_user_service->InitForTesting();
32
33 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch));
34 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch));
35 } 38 }
36 39
37 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) { 40 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) {
38 Profile* profile = browser()->profile(); 41 Profile* profile = browser()->profile();
39 PrefService* prefs = profile->GetPrefs(); 42 PrefService* prefs = profile->GetPrefs();
40 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kProfileName)); 43 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kProfileName));
41 44
42 std::string original_name = prefs->GetString(prefs::kProfileName); 45 std::string original_name = prefs->GetString(prefs::kProfileName);
43 ProfileManager* profile_manager = g_browser_process->profile_manager(); 46 ProfileManager* profile_manager = g_browser_process->profile_manager();
44 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 47 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
45 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 48 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
46 EXPECT_EQ(original_name, 49 EXPECT_EQ(original_name,
47 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); 50 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
51 }
48 52
49 // Change the profile to a managed user. 53 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTestManaged, LocalPolicies) {
50 ManagedUserService* managed_user_service = 54 Profile* profile = browser()->profile();
51 ManagedUserServiceFactory::GetForProfile(profile); 55 PrefService* prefs = profile->GetPrefs();
52 managed_user_service->InitForTesting(); 56 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch));
57 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch));
58 }
59
60 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTestManaged, ProfileName) {
61 Profile* profile = browser()->profile();
62 PrefService* prefs = profile->GetPrefs();
63 std::string original_name = prefs->GetString(prefs::kProfileName);
64 ProfileManager* profile_manager = g_browser_process->profile_manager();
65 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
66
53 ManagedUserSettingsService* settings = 67 ManagedUserSettingsService* settings =
54 ManagedUserSettingsServiceFactory::GetForProfile(profile); 68 ManagedUserSettingsServiceFactory::GetForProfile(profile);
55 69
56 std::string name = "Managed User Test Name"; 70 std::string name = "Managed User Test Name";
57 settings->SetLocalSettingForTesting( 71 settings->SetLocalSettingForTesting(
58 managed_users::kUserName, 72 managed_users::kUserName,
59 scoped_ptr<base::Value>(new base::StringValue(name))); 73 scoped_ptr<base::Value>(new base::StringValue(name)));
60 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kProfileName)); 74 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kProfileName));
61 EXPECT_EQ(name, prefs->GetString(prefs::kProfileName)); 75 EXPECT_EQ(name, prefs->GetString(prefs::kProfileName));
62 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 76 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
63 EXPECT_EQ(name, UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); 77 EXPECT_EQ(name, UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
64 78
65 // Change the name once more. 79 // Change the name once more.
66 std::string new_name = "New Managed User Test Name"; 80 std::string new_name = "New Managed User Test Name";
67 settings->SetLocalSettingForTesting( 81 settings->SetLocalSettingForTesting(
68 managed_users::kUserName, 82 managed_users::kUserName,
69 scoped_ptr<base::Value>(new base::StringValue(new_name))); 83 scoped_ptr<base::Value>(new base::StringValue(new_name)));
70 EXPECT_EQ(new_name, prefs->GetString(prefs::kProfileName)); 84 EXPECT_EQ(new_name, prefs->GetString(prefs::kProfileName));
71 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 85 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
72 EXPECT_EQ(new_name, 86 EXPECT_EQ(new_name,
73 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); 87 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
74 88
75 // Remove the setting. 89 // Remove the setting.
76 settings->SetLocalSettingForTesting(managed_users::kUserName, 90 settings->SetLocalSettingForTesting(managed_users::kUserName,
77 scoped_ptr<base::Value>()); 91 scoped_ptr<base::Value>());
78 EXPECT_EQ(original_name, prefs->GetString(prefs::kProfileName)); 92 EXPECT_EQ(original_name, prefs->GetString(prefs::kProfileName));
79 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 93 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
80 EXPECT_EQ(original_name, 94 EXPECT_EQ(original_name,
81 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); 95 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
82 } 96 }
OLDNEW
« no previous file with comments | « chrome/browser/managed_mode/managed_user_service.cc ('k') | chrome/browser/managed_mode/managed_user_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698