Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / managed_mode / managed_user_service_browsertest.cc
blobcecbde8a07a40540826e34b6fcd914ad36d4806d
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
3 // found in the LICENSE file.
5 #include "base/callback.h"
6 #include "base/command_line.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/managed_mode/managed_user_constants.h"
11 #include "chrome/browser/managed_mode/managed_user_service.h"
12 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
13 #include "chrome/browser/managed_mode/managed_user_settings_service.h"
14 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_info_cache.h"
17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "content/public/test/test_utils.h"
23 #include "google_apis/gaia/google_service_auth_error.h"
25 namespace {
27 void TestAuthErrorCallback(const GoogleServiceAuthError& error) {}
29 class ManagedUserServiceTestManaged : public InProcessBrowserTest {
30 public:
31 // content::BrowserTestBase:
32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
33 command_line->AppendSwitchASCII(switches::kManagedUserId, "asdf");
37 } // namespace
39 typedef InProcessBrowserTest ManagedUserServiceTest;
41 // Crashes on Mac.
42 // http://crbug.com/339501
43 #if defined(OS_MACOSX)
44 #define MAYBE_ClearOmitOnRegistration DISABLED_ClearOmitOnRegistration
45 #else
46 #define MAYBE_ClearOmitOnRegistration ClearOmitOnRegistration
47 #endif
48 // Ensure that a profile that has completed registration is included in the
49 // list shown in the avatar menu.
50 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, MAYBE_ClearOmitOnRegistration) {
51 // Artificially mark the profile as omitted.
52 ProfileManager* profile_manager = g_browser_process->profile_manager();
53 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
54 Profile* profile = browser()->profile();
55 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
56 cache.SetIsOmittedProfileAtIndex(index, true);
57 ASSERT_TRUE(cache.IsOmittedProfileAtIndex(index));
59 ManagedUserService* managed_user_service =
60 ManagedUserServiceFactory::GetForProfile(profile);
62 // A registration error does not clear the flag (the profile should be deleted
63 // anyway).
64 managed_user_service->OnManagedUserRegistered(
65 base::Bind(&TestAuthErrorCallback),
66 profile,
67 GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED),
68 std::string());
69 ASSERT_TRUE(cache.IsOmittedProfileAtIndex(index));
71 // Successfully completing registration clears the flag.
72 managed_user_service->OnManagedUserRegistered(
73 base::Bind(&TestAuthErrorCallback),
74 profile,
75 GoogleServiceAuthError(GoogleServiceAuthError::NONE),
76 std::string("abcdef"));
77 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(index));
80 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, LocalPolicies) {
81 Profile* profile = browser()->profile();
82 PrefService* prefs = profile->GetPrefs();
83 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch));
84 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch));
87 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) {
88 Profile* profile = browser()->profile();
89 PrefService* prefs = profile->GetPrefs();
90 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kProfileName));
92 std::string original_name = prefs->GetString(prefs::kProfileName);
93 ProfileManager* profile_manager = g_browser_process->profile_manager();
94 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
95 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
96 EXPECT_EQ(original_name,
97 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
100 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTestManaged, LocalPolicies) {
101 Profile* profile = browser()->profile();
102 PrefService* prefs = profile->GetPrefs();
103 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch));
104 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch));
107 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTestManaged, ProfileName) {
108 Profile* profile = browser()->profile();
109 PrefService* prefs = profile->GetPrefs();
110 std::string original_name = prefs->GetString(prefs::kProfileName);
111 ProfileManager* profile_manager = g_browser_process->profile_manager();
112 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
114 ManagedUserSettingsService* settings =
115 ManagedUserSettingsServiceFactory::GetForProfile(profile);
117 std::string name = "Managed User Test Name";
118 settings->SetLocalSettingForTesting(
119 managed_users::kUserName,
120 scoped_ptr<base::Value>(new base::StringValue(name)));
121 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kProfileName));
122 EXPECT_EQ(name, prefs->GetString(prefs::kProfileName));
123 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
124 EXPECT_EQ(name,
125 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
127 // Change the name once more.
128 std::string new_name = "New Managed User Test Name";
129 settings->SetLocalSettingForTesting(
130 managed_users::kUserName,
131 scoped_ptr<base::Value>(new base::StringValue(new_name)));
132 EXPECT_EQ(new_name, prefs->GetString(prefs::kProfileName));
133 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
134 EXPECT_EQ(new_name,
135 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
137 // Remove the setting.
138 settings->SetLocalSettingForTesting(managed_users::kUserName,
139 scoped_ptr<base::Value>());
140 EXPECT_EQ(original_name, prefs->GetString(prefs::kProfileName));
141 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
142 EXPECT_EQ(original_name,
143 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));