Commit d84bb42a authored by Jochen Eisinger's avatar Jochen Eisinger Committed by Commit Bot

Stop opening legacy supervised users profiles

Omit them from the profile info cache, and show a profile picker if
the default profile is supervised.

BUG=866578
R=bauerb@chromium.org,tschumann@chromium.org,msarda@chromium.org

Change-Id: Ice583daee39eb1efc987af6a16de256d5bb1fc65
Reviewed-on: https://chromium-review.googlesource.com/1145271
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarCarlos IL <carlosil@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577307}
parent ea0ed30f
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/prefs/pref_service_syncable_util.h" #include "chrome/browser/prefs/pref_service_syncable_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
...@@ -651,7 +652,15 @@ class AccessibilityManagerUserTypeTest : public AccessibilityManagerTest, ...@@ -651,7 +652,15 @@ class AccessibilityManagerUserTypeTest : public AccessibilityManagerTest,
user_manager::GuestAccountId().GetUserEmail()); user_manager::GuestAccountId().GetUserEmail());
} else if (GetParam() == } else if (GetParam() ==
AccountId::FromUserEmail(kTestSupervisedUserName)) { AccountId::FromUserEmail(kTestSupervisedUserName)) {
command_line->AppendSwitchASCII(::switches::kSupervisedUserId, "asdf"); command_line->AppendSwitchASCII(::switches::kSupervisedUserId,
supervised_users::kChildAccountSUID);
#if defined(OS_CHROMEOS)
command_line->AppendSwitchASCII(
chromeos::switches::kLoginUser,
"supervised_user@locally-managed.localhost");
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
"hash");
#endif
} }
AccessibilityManager::SetBrailleControllerForTest(&braille_controller_); AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
} }
......
...@@ -351,24 +351,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, EmptyCrx) { ...@@ -351,24 +351,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, EmptyCrx) {
} }
#if BUILDFLAG(ENABLE_SUPERVISED_USERS) #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
class ExtensionWebstorePrivateApiTestSupervised
: public ExtensionWebstorePrivateApiTest {
public:
void SetUpCommandLine(base::CommandLine* command_line) override {
ExtensionWebstorePrivateApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(switches::kSupervisedUserId, "not_empty");
}
};
// Tests that extension installation is blocked for supervised users.
// Note: This will have to be updated if we enable SU-initiated installs.
IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTestSupervised,
InstallBlocked) {
ASSERT_TRUE(
RunInstallTest("begin_install_fail_supervised.html", "extension.crx"));
}
class ExtensionWebstorePrivateApiTestChild class ExtensionWebstorePrivateApiTestChild
: public ExtensionWebstorePrivateApiTest { : public ExtensionWebstorePrivateApiTest {
public: public:
......
...@@ -28,6 +28,14 @@ ...@@ -28,6 +28,14 @@
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "url/gurl.h" #include "url/gurl.h"
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#endif
#if defined(OS_CHROMEOS)
#include "chromeos/chromeos_switches.h"
#endif
using content::WebContents; using content::WebContents;
using extensions::DictionaryBuilder; using extensions::DictionaryBuilder;
using extensions::Extension; using extensions::Extension;
...@@ -174,13 +182,21 @@ IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) { ...@@ -174,13 +182,21 @@ IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) {
EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId));
} }
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
class WebstoreStartupInstallerSupervisedUsersTest class WebstoreStartupInstallerSupervisedUsersTest
: public WebstoreStartupInstallerTest { : public WebstoreStartupInstallerTest {
public: public:
// InProcessBrowserTest overrides: // InProcessBrowserTest overrides:
void SetUpCommandLine(base::CommandLine* command_line) override { void SetUpCommandLine(base::CommandLine* command_line) override {
WebstoreStartupInstallerTest::SetUpCommandLine(command_line); WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); command_line->AppendSwitchASCII(switches::kSupervisedUserId,
supervised_users::kChildAccountSUID);
#if defined(OS_CHROMEOS)
command_line->AppendSwitchASCII(
chromeos::switches::kLoginUser,
"supervised_user@locally-managed.localhost");
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash");
#endif
} }
}; };
...@@ -198,6 +214,7 @@ IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerSupervisedUsersTest, ...@@ -198,6 +214,7 @@ IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerSupervisedUsersTest,
InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
EXPECT_EQ(0u, infobar_service->infobar_count()); EXPECT_EQ(0u, infobar_service->infobar_count());
} }
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
// The unpack failure test needs to use a different install .crx, which is // The unpack failure test needs to use a different install .crx, which is
// specified via a command-line flag, so it needs its own test subclass. // specified via a command-line flag, so it needs its own test subclass.
......
...@@ -339,7 +339,14 @@ Profile* Profile::CreateProfile(const base::FilePath& path, ...@@ -339,7 +339,14 @@ Profile* Profile::CreateProfile(const base::FilePath& path,
NOTREACHED(); NOTREACHED();
} }
return new ProfileImpl(path, delegate, create_mode, io_task_runner); auto profile = base::WrapUnique(
new ProfileImpl(path, delegate, create_mode, io_task_runner));
#if BUILDFLAG(ENABLE_SUPERVISED_USERS) && !defined(OS_ANDROID) && \
!defined(OS_CHROMEOS)
if (create_mode == CREATE_MODE_SYNCHRONOUS && profile->IsLegacySupervised())
return nullptr;
#endif
return profile.release();
} }
// static // static
......
...@@ -76,6 +76,16 @@ ProfileInfoCache::ProfileInfoCache(PrefService* prefs, ...@@ -76,6 +76,16 @@ ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
!it.IsAtEnd(); it.Advance()) { !it.IsAtEnd(); it.Advance()) {
base::DictionaryValue* info = NULL; base::DictionaryValue* info = NULL;
cache->GetDictionaryWithoutPathExpansion(it.key(), &info); cache->GetDictionaryWithoutPathExpansion(it.key(), &info);
#if BUILDFLAG(ENABLE_SUPERVISED_USERS) && !defined(OS_ANDROID) && \
!defined(OS_CHROMEOS)
std::string supervised_user_id;
info->GetString(kSupervisedUserId, &supervised_user_id);
// Silently ignore legacy supervised user profiles.
if (!supervised_user_id.empty() &&
supervised_user_id != supervised_users::kChildAccountSUID) {
continue;
}
#endif
base::string16 name; base::string16 name;
info->GetString(kNameKey, &name); info->GetString(kNameKey, &name);
sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key()); sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key());
...@@ -115,6 +125,14 @@ void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path, ...@@ -115,6 +125,14 @@ void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path,
size_t icon_index, size_t icon_index,
const std::string& supervised_user_id, const std::string& supervised_user_id,
const AccountId& account_id) { const AccountId& account_id) {
#if BUILDFLAG(ENABLE_SUPERVISED_USERS) && !defined(OS_ANDROID) && \
!defined(OS_CHROMEOS)
// Silently ignore legacy supervised user profiles.
if (!supervised_user_id.empty() &&
supervised_user_id != supervised_users::kChildAccountSUID) {
return;
}
#endif
std::string key = CacheKeyFromProfilePath(profile_path); std::string key = CacheKeyFromProfilePath(profile_path);
DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
base::DictionaryValue* cache = update.Get(); base::DictionaryValue* cache = update.Get();
......
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_unittest_util.h" #include "ui/gfx/image/image_unittest_util.h"
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#endif
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
using base::UTF8ToUTF16; using base::UTF8ToUTF16;
using content::BrowserThread; using content::BrowserThread;
...@@ -137,7 +141,11 @@ TEST_F(ProfileInfoCacheTest, AddProfiles) { ...@@ -137,7 +141,11 @@ TEST_F(ProfileInfoCacheTest, AddProfiles) {
const SkBitmap* icon = rb.GetImageNamed( const SkBitmap* icon = rb.GetImageNamed(
profiles::GetDefaultAvatarIconResourceIDAtIndex( profiles::GetDefaultAvatarIconResourceIDAtIndex(
i)).ToSkBitmap(); i)).ToSkBitmap();
std::string supervised_user_id = i == 3 ? "TEST_ID" : ""; std::string supervised_user_id = "";
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
if (i == 3)
supervised_user_id = supervised_users::kChildAccountSUID;
#endif
GetCache()->AddProfileToCache(profile_path, profile_name, std::string(), GetCache()->AddProfileToCache(profile_path, profile_name, std::string(),
base::string16(), i, supervised_user_id, base::string16(), i, supervised_user_id,
...@@ -438,15 +446,18 @@ TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { ...@@ -438,15 +446,18 @@ TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) {
gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0)));
} }
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) {
GetCache()->AddProfileToCache(GetProfilePath("test"), ASCIIToUTF16("Test"), GetCache()->AddProfileToCache(GetProfilePath("test"), ASCIIToUTF16("Test"),
std::string(), base::string16(), 0, std::string(), base::string16(), 0,
std::string(), EmptyAccountId()); std::string(), EmptyAccountId());
EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0));
GetCache()->SetSupervisedUserIdOfProfileAtIndex(0, "TEST_ID"); GetCache()->SetSupervisedUserIdOfProfileAtIndex(
0, supervised_users::kChildAccountSUID);
EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0));
EXPECT_EQ("TEST_ID", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); EXPECT_EQ(supervised_users::kChildAccountSUID,
GetCache()->GetSupervisedUserIdOfProfileAtIndex(0));
ResetCache(); ResetCache();
EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0));
...@@ -455,6 +466,7 @@ TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { ...@@ -455,6 +466,7 @@ TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) {
EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0));
EXPECT_EQ("", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); EXPECT_EQ("", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0));
} }
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) {
base::string16 profile_name = ASCIIToUTF16("name_1"); base::string16 profile_name = ASCIIToUTF16("name_1");
...@@ -477,17 +489,20 @@ TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { ...@@ -477,17 +489,20 @@ TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) {
profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0)));
} }
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
TEST_F(ProfileInfoCacheTest, CreateSupervisedTestingProfile) { TEST_F(ProfileInfoCacheTest, CreateSupervisedTestingProfile) {
testing_profile_manager_.CreateTestingProfile("default"); testing_profile_manager_.CreateTestingProfile("default");
base::string16 supervised_user_name = ASCIIToUTF16("Supervised User"); base::string16 supervised_user_name = ASCIIToUTF16("Supervised User");
testing_profile_manager_.CreateTestingProfile( testing_profile_manager_.CreateTestingProfile(
"test1", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), "test1", std::unique_ptr<sync_preferences::PrefServiceSyncable>(),
supervised_user_name, 0, "TEST_ID", TestingProfile::TestingFactories()); supervised_user_name, 0, supervised_users::kChildAccountSUID,
TestingProfile::TestingFactories());
for (size_t i = 0; i < GetCache()->GetNumberOfProfiles(); i++) { for (size_t i = 0; i < GetCache()->GetNumberOfProfiles(); i++) {
bool is_supervised = bool is_supervised =
GetCache()->GetNameOfProfileAtIndex(i) == supervised_user_name; GetCache()->GetNameOfProfileAtIndex(i) == supervised_user_name;
EXPECT_EQ(is_supervised, GetCache()->ProfileIsSupervisedAtIndex(i)); EXPECT_EQ(is_supervised, GetCache()->ProfileIsSupervisedAtIndex(i));
std::string supervised_user_id = is_supervised ? "TEST_ID" : ""; std::string supervised_user_id =
is_supervised ? supervised_users::kChildAccountSUID : "";
EXPECT_EQ(supervised_user_id, EXPECT_EQ(supervised_user_id,
GetCache()->GetSupervisedUserIdOfProfileAtIndex(i)); GetCache()->GetSupervisedUserIdOfProfileAtIndex(i));
} }
...@@ -497,6 +512,7 @@ TEST_F(ProfileInfoCacheTest, CreateSupervisedTestingProfile) { ...@@ -497,6 +512,7 @@ TEST_F(ProfileInfoCacheTest, CreateSupervisedTestingProfile) {
// we still have a FILE thread. // we still have a FILE thread.
TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
} }
#endif
TEST_F(ProfileInfoCacheTest, AddStubProfile) { TEST_F(ProfileInfoCacheTest, AddStubProfile) {
EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
......
...@@ -262,36 +262,4 @@ TEST_F(ProfileListDesktopTest, ChangeOnNotify) { ...@@ -262,36 +262,4 @@ TEST_F(ProfileListDesktopTest, ChangeOnNotify) {
EXPECT_EQ(ASCIIToUTF16("Test 3"), item3.name); EXPECT_EQ(ASCIIToUTF16("Test 3"), item3.name);
} }
TEST_F(ProfileListDesktopTest, SyncState) {
// If multiprofile mode is not enabled then the menu is never shown.
if (!profiles::IsMultipleProfilesEnabled())
return;
manager()->CreateTestingProfile("Test 1");
// Add a managed user profile.
ProfileAttributesStorage* storage = manager()->profile_attributes_storage();
base::FilePath path = manager()->profiles_dir().AppendASCII("p2");
storage->AddProfile(path, ASCIIToUTF16("Test 2"), std::string(),
base::string16(), 0u, "TEST_ID", EmptyAccountId());
ProfileAttributesEntry* entry;
ASSERT_TRUE(storage->GetProfileAttributesWithPath(path, &entry));
entry->SetIsOmitted(false);
AvatarMenu* menu = GetAvatarMenu();
menu->RebuildMenu();
EXPECT_EQ(2u, menu->GetNumberOfItems());
// Now check that the username of a supervised user shows the supervised
// user avatar label instead.
base::string16 supervised_user_label =
l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_AVATAR_LABEL);
const AvatarMenu::Item& item1 = menu->GetItemAt(0u);
EXPECT_NE(item1.username, supervised_user_label);
const AvatarMenu::Item& item2 = menu->GetItemAt(1u);
EXPECT_EQ(item2.username, supervised_user_label);
}
} // namespace } // namespace
...@@ -66,6 +66,10 @@ ...@@ -66,6 +66,10 @@
#include "extensions/common/features/feature_session_type.h" #include "extensions/common/features/feature_session_type.h"
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#endif
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
namespace { namespace {
...@@ -173,12 +177,19 @@ class ProfileManagerTest : public testing::Test { ...@@ -173,12 +177,19 @@ class ProfileManagerTest : public testing::Test {
const std::string& name, const std::string& name,
bool is_supervised, bool is_supervised,
MockObserver* mock_observer) { MockObserver* mock_observer) {
std::string supervised_user_id;
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
if (is_supervised)
supervised_user_id = supervised_users::kChildAccountSUID;
#else
DCHECK(!is_supervised);
#endif
manager->CreateProfileAsync(temp_dir_.GetPath().AppendASCII(name), manager->CreateProfileAsync(temp_dir_.GetPath().AppendASCII(name),
base::Bind(&MockObserver::OnProfileCreated, base::Bind(&MockObserver::OnProfileCreated,
base::Unretained(mock_observer)), base::Unretained(mock_observer)),
base::UTF8ToUTF16(name), base::UTF8ToUTF16(name),
profiles::GetDefaultAvatarIconUrl(0), profiles::GetDefaultAvatarIconUrl(0),
is_supervised ? "Dummy ID" : std::string()); supervised_user_id);
} }
// Helper function to add a profile with |profile_name| to |profile_manager|'s // Helper function to add a profile with |profile_name| to |profile_manager|'s
...@@ -510,31 +521,37 @@ TEST_F(ProfileManagerTest, CreateProfilesAsync) { ...@@ -510,31 +521,37 @@ TEST_F(ProfileManagerTest, CreateProfilesAsync) {
} }
TEST_F(ProfileManagerTest, CreateProfileAsyncCheckOmitted) { TEST_F(ProfileManagerTest, CreateProfileAsyncCheckOmitted) {
std::string name = "0 Supervised Profile";
MockObserver mock_observer; MockObserver mock_observer;
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
EXPECT_CALL(mock_observer, OnProfileCreated( EXPECT_CALL(mock_observer, OnProfileCreated(
testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); testing::NotNull(), NotFail())).Times(testing::AtLeast(2));
#else
EXPECT_CALL(mock_observer, OnProfileCreated(testing::NotNull(), NotFail()))
.Times(testing::AtLeast(1));
#endif
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
ProfileAttributesStorage& storage = ProfileAttributesStorage& storage =
profile_manager->GetProfileAttributesStorage(); profile_manager->GetProfileAttributesStorage();
EXPECT_EQ(0u, storage.GetNumberOfProfiles()); EXPECT_EQ(0u, storage.GetNumberOfProfiles());
CreateProfileAsync(profile_manager, name, true, &mock_observer); std::string name = "0 Regular Profile";
CreateProfileAsync(profile_manager, name, false, &mock_observer);
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
ASSERT_EQ(1u, storage.GetNumberOfProfiles()); ASSERT_EQ(1u, storage.GetNumberOfProfiles());
// Supervised profiles should start out omitted from the profile list. // Non-supervised profiles should be included in the profile list.
EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0]->IsOmitted()); EXPECT_FALSE(storage.GetAllProfilesAttributesSortedByName()[0]->IsOmitted());
name = "1 Regular Profile"; #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
CreateProfileAsync(profile_manager, name, false, &mock_observer); name = "1 Supervised Profile";
CreateProfileAsync(profile_manager, name, true, &mock_observer);
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
ASSERT_EQ(2u, storage.GetNumberOfProfiles()); ASSERT_EQ(2u, storage.GetNumberOfProfiles());
// Non-supervised profiles should be included in the profile list. // Supervised profiles should start out omitted from the profile list.
EXPECT_FALSE(storage.GetAllProfilesAttributesSortedByName()[1]->IsOmitted()); EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[1]->IsOmitted());
#endif
} }
TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) { TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) {
...@@ -543,16 +560,19 @@ TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) { ...@@ -543,16 +560,19 @@ TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) {
profile_manager->GetProfileAttributesStorage(); profile_manager->GetProfileAttributesStorage();
EXPECT_EQ(0u, storage.GetNumberOfProfiles()); EXPECT_EQ(0u, storage.GetNumberOfProfiles());
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
const base::FilePath supervised_path = const base::FilePath supervised_path =
temp_dir_.GetPath().AppendASCII("Supervised"); temp_dir_.GetPath().AppendASCII("Supervised");
TestingProfile* supervised_profile = TestingProfile* supervised_profile =
new TestingProfile(supervised_path, nullptr); new TestingProfile(supervised_path, nullptr);
supervised_profile->GetPrefs()->SetString(prefs::kSupervisedUserId, "An ID"); supervised_profile->GetPrefs()->SetString(
prefs::kSupervisedUserId, supervised_users::kChildAccountSUID);
// RegisterTestingProfile adds the profile to the cache and takes ownership. // RegisterTestingProfile adds the profile to the cache and takes ownership.
profile_manager->RegisterTestingProfile(supervised_profile, true, false); profile_manager->RegisterTestingProfile(supervised_profile, true, false);
ASSERT_EQ(1u, storage.GetNumberOfProfiles()); ASSERT_EQ(1u, storage.GetNumberOfProfiles());
EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0]->IsOmitted()); EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0]->IsOmitted());
#endif
const base::FilePath nonsupervised_path = const base::FilePath nonsupervised_path =
temp_dir_.GetPath().AppendASCII("Non-Supervised"); temp_dir_.GetPath().AppendASCII("Non-Supervised");
...@@ -560,10 +580,16 @@ TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) { ...@@ -560,10 +580,16 @@ TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) {
new TestingProfile(nonsupervised_path, nullptr); new TestingProfile(nonsupervised_path, nullptr);
profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false); profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false);
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
EXPECT_EQ(2u, storage.GetNumberOfProfiles()); EXPECT_EQ(2u, storage.GetNumberOfProfiles());
#else
EXPECT_EQ(1u, storage.GetNumberOfProfiles());
#endif
ProfileAttributesEntry* entry; ProfileAttributesEntry* entry;
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
ASSERT_TRUE(storage.GetProfileAttributesWithPath(supervised_path, &entry)); ASSERT_TRUE(storage.GetProfileAttributesWithPath(supervised_path, &entry));
EXPECT_TRUE(entry->IsOmitted()); EXPECT_TRUE(entry->IsOmitted());
#endif
ASSERT_TRUE(storage.GetProfileAttributesWithPath(nonsupervised_path, &entry)); ASSERT_TRUE(storage.GetProfileAttributesWithPath(nonsupervised_path, &entry));
EXPECT_FALSE(entry->IsOmitted()); EXPECT_FALSE(entry->IsOmitted());
......
...@@ -47,6 +47,10 @@ ...@@ -47,6 +47,10 @@
#include "services/network/public/cpp/network_switches.h" #include "services/network/public/cpp/network_switches.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#if defined(OS_CHROMEOS)
#include "chromeos/chromeos_switches.h"
#endif
using content::InterstitialPage; using content::InterstitialPage;
using content::NavigationController; using content::NavigationController;
using content::NavigationEntry; using content::NavigationEntry;
...@@ -186,7 +190,14 @@ class SupervisedUserTest : public InProcessBrowserTest, ...@@ -186,7 +190,14 @@ class SupervisedUserTest : public InProcessBrowserTest,
"MAP *.new-example.com " + host_port + "MAP *.new-example.com " + host_port +
"," + "MAP *.a.com " + host_port); "," + "MAP *.a.com " + host_port);
command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); command_line->AppendSwitchASCII(switches::kSupervisedUserId,
supervised_users::kChildAccountSUID);
#if defined(OS_CHROMEOS)
command_line->AppendSwitchASCII(
chromeos::switches::kLoginUser,
"supervised_user@locally-managed.localhost");
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash");
#endif
} }
// Acts like a synchronous call to history's QueryHistory. Modified from // Acts like a synchronous call to history's QueryHistory. Modified from
......
...@@ -352,8 +352,10 @@ void SupervisedUserInterstitial::OnAccessRequestAdded(bool success) { ...@@ -352,8 +352,10 @@ void SupervisedUserInterstitial::OnAccessRequestAdded(bool success) {
<< (success ? " successfully" : " unsuccessfully"); << (success ? " successfully" : " unsuccessfully");
std::string jsFunc = std::string jsFunc =
base::StringPrintf("setRequestStatus(%s);", success ? "true" : "false"); base::StringPrintf("setRequestStatus(%s);", success ? "true" : "false");
interstitial_page_->GetMainFrame()->ExecuteJavaScript( if (interstitial_page_->GetMainFrame()) {
base::ASCIIToUTF16(jsFunc)); interstitial_page_->GetMainFrame()->ExecuteJavaScript(
base::ASCIIToUTF16(jsFunc));
}
} }
bool SupervisedUserInterstitial::ShouldProceed() { bool SupervisedUserInterstitial::ShouldProceed() {
......
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#if defined(OS_CHROMEOS)
#include "chromeos/chromeos_switches.h"
#endif
using content::NavigationController; using content::NavigationController;
using content::WebContents; using content::WebContents;
...@@ -107,7 +111,13 @@ void SupervisedUserNavigationThrottleTest::SetUpOnMainThread() { ...@@ -107,7 +111,13 @@ void SupervisedUserNavigationThrottleTest::SetUpOnMainThread() {
void SupervisedUserNavigationThrottleTest::SetUpCommandLine( void SupervisedUserNavigationThrottleTest::SetUpCommandLine(
base::CommandLine* command_line) { base::CommandLine* command_line) {
command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); command_line->AppendSwitchASCII(switches::kSupervisedUserId,
supervised_users::kChildAccountSUID);
#if defined(OS_CHROMEOS)
command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
"supervised_user@locally-managed.localhost");
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash");
#endif
} }
INSTANTIATE_TEST_CASE_P(, INSTANTIATE_TEST_CASE_P(,
......
...@@ -27,13 +27,24 @@ ...@@ -27,13 +27,24 @@
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/google_service_auth_error.h"
#if defined(OS_CHROMEOS)
#include "chromeos/chromeos_switches.h"
#endif
namespace { namespace {
class SupervisedUserServiceTestSupervised : public InProcessBrowserTest { class SupervisedUserServiceTestSupervised : public InProcessBrowserTest {
public: public:
// content::BrowserTestBase: // content::BrowserTestBase:
void SetUpCommandLine(base::CommandLine* command_line) override { void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); command_line->AppendSwitchASCII(switches::kSupervisedUserId,
supervised_users::kChildAccountSUID);
#if defined(OS_CHROMEOS)
command_line->AppendSwitchASCII(
chromeos::switches::kLoginUser,
"supervised_user@locally-managed.localhost");
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash");
#endif
} }
}; };
...@@ -67,9 +78,9 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTest, ProfileName) { ...@@ -67,9 +78,9 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTest, ProfileName) {
IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTestSupervised, LocalPolicies) { IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTestSupervised, LocalPolicies) {
Profile* profile = browser()->profile(); Profile* profile = browser()->profile();
PrefService* prefs = profile->GetPrefs(); PrefService* prefs = profile->GetPrefs();
EXPECT_TRUE(prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); EXPECT_FALSE(prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict), EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict),
safe_search_util::YOUTUBE_RESTRICT_MODERATE); safe_search_util::YOUTUBE_RESTRICT_OFF);
EXPECT_FALSE( EXPECT_FALSE(
prefs->IsUserModifiablePreference(prefs::kForceGoogleSafeSearch)); prefs->IsUserModifiablePreference(prefs::kForceGoogleSafeSearch));
EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceYouTubeRestrict)); EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceYouTubeRestrict));
......
...@@ -247,55 +247,3 @@ TEST_F(ProfileMenuControllerTest, DeleteActiveProfile) { ...@@ -247,55 +247,3 @@ TEST_F(ProfileMenuControllerTest, DeleteActiveProfile) {
[controller() activeBrowserChangedTo:NULL]; [controller() activeBrowserChangedTo:NULL];
base::ThreadRestrictions::SetIOAllowed(io_was_allowed); base::ThreadRestrictions::SetIOAllowed(io_was_allowed);
} }
TEST_F(ProfileMenuControllerTest, SupervisedProfile) {
TestingProfileManager* manager = testing_profile_manager();
TestingProfile* supervised_profile = manager->CreateTestingProfile(
"test1", std::unique_ptr<sync_preferences::PrefServiceSyncable>(),
base::ASCIIToUTF16("Supervised User"), 0, "TEST_ID",
TestingProfile::TestingFactories());
// The supervised profile is initially marked as omitted from the avatar menu
// (in non-test code, until we have confirmation that it has actually been
// created on the server). For the test, just tell the profile attribute
// storage to un-hide it.
ProfileAttributesEntry* entry;
ASSERT_TRUE(manager->profile_attributes_storage()->
GetProfileAttributesWithPath(supervised_profile->GetPath(), &entry));
entry->SetIsOmitted(false);
BrowserList::SetLastActive(browser());
NSMenu* menu = [controller() menu];
// Person 1, Supervised User, <sep>, Edit, <sep>, New.
ASSERT_EQ(6, [menu numberOfItems]);
NSMenuItem* item = [menu itemAtIndex:0];
ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]);
EXPECT_TRUE([controller() validateMenuItem:item]);
item = [menu itemAtIndex:1];
ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]);
EXPECT_TRUE([controller() validateMenuItem:item]);
item = [menu itemAtIndex:5];
ASSERT_EQ(@selector(newProfile:), [item action]);
EXPECT_TRUE([controller() validateMenuItem:item]);
// Open a new browser for the supervised user and switch to it.
Browser::CreateParams supervised_profile_params(supervised_profile, true);
std::unique_ptr<Browser> supervised_browser(
CreateBrowserWithTestWindowForParams(&supervised_profile_params));
BrowserList::SetLastActive(supervised_browser.get());
item = [menu itemAtIndex:0];
ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]);
EXPECT_FALSE([controller() validateMenuItem:item]);
item = [menu itemAtIndex:1];
ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]);
EXPECT_TRUE([controller() validateMenuItem:item]);
item = [menu itemAtIndex:5];
ASSERT_EQ(@selector(newProfile:), [item action]);
EXPECT_FALSE([controller() validateMenuItem:item]);
}
...@@ -82,6 +82,7 @@ using testing::Return; ...@@ -82,6 +82,7 @@ using testing::Return;
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
#if BUILDFLAG(ENABLE_SUPERVISED_USERS) #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "chrome/browser/supervised_user/supervised_user_navigation_observer.h" #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
#include "chrome/browser/supervised_user/supervised_user_service.h" #include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h" #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
...@@ -1025,7 +1026,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ...@@ -1025,7 +1026,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
class SupervisedUserBrowserCreatorTest : public InProcessBrowserTest { class SupervisedUserBrowserCreatorTest : public InProcessBrowserTest {
protected: protected:
void SetUpCommandLine(base::CommandLine* command_line) override { void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); command_line->AppendSwitchASCII(switches::kSupervisedUserId,
supervised_users::kChildAccountSUID);
} }
}; };
......
<!--
* Copyright 2016 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<script src="common.js"></script>
<script>
runTests([
function beginInstall() {
var manifest = getManifest();
var expectedError =
"Apps and extensions can only be modified by the manager ()."
chrome.webstorePrivate.beginInstallWithManifest3(
{id: extensionId, manifest: manifest},
callbackFail(expectedError, function(result) {
assertEq("blocked_by_policy", result);
}));
},
]);
</script>
...@@ -750,6 +750,8 @@ RenderWidgetHostView* InterstitialPageImpl::GetView() { ...@@ -750,6 +750,8 @@ RenderWidgetHostView* InterstitialPageImpl::GetView() {
} }
RenderFrameHost* InterstitialPageImpl::GetMainFrame() const { RenderFrameHost* InterstitialPageImpl::GetMainFrame() const {
if (!render_view_host_)
return nullptr;
return render_view_host_->GetMainFrame(); return render_view_host_->GetMainFrame();
} }
......
...@@ -94,8 +94,8 @@ class InterstitialPage { ...@@ -94,8 +94,8 @@ class InterstitialPage {
// DidAttachInterstitialPage or DidDetachInterstitialPage notifications. // DidAttachInterstitialPage or DidDetachInterstitialPage notifications.
virtual WebContents* GetWebContents() const = 0; virtual WebContents* GetWebContents() const = 0;
// Gets the RenderFrameHost associated with // Gets the RenderFrameHost associated with the interstitial page's main
// the interstitial page's main frame. // frame. May return nullptr if the interstitial is already hidden.
virtual RenderFrameHost* GetMainFrame() const = 0; virtual RenderFrameHost* GetMainFrame() const = 0;
virtual InterstitialPageDelegate* GetDelegateForTesting() = 0; virtual InterstitialPageDelegate* GetDelegateForTesting() = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment