diff options
11 files changed, 177 insertions, 17 deletions
diff --git a/chrome/browser/chromeos/profiles/profile_helper.cc b/chrome/browser/chromeos/profiles/profile_helper.cc index bf64b12..71f751a 100644 --- a/chrome/browser/chromeos/profiles/profile_helper.cc +++ b/chrome/browser/chromeos/profiles/profile_helper.cc @@ -9,6 +9,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/browsing_data/browsing_data_helper.h" #include "chrome/browser/chromeos/login/oauth2_login_manager_factory.h" +#include "chrome/browser/chromeos/login/user.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" @@ -115,6 +116,13 @@ bool ProfileHelper::IsSigninProfile(Profile* profile) { return profile->GetPath().BaseName().value() == chrome::kInitialProfile; } +// static +bool ProfileHelper::IsOwnerProfile(Profile* profile) { + chromeos::UserManager* manager = chromeos::UserManager::Get(); + chromeos::User* user = manager->GetUserByProfile(profile); + return user->email() == manager->GetOwnerEmail(); +} + void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { // Initialize Chrome OS preferences like touch pad sensitivity. For the // preferences to work in the guest mode, the initialization has to be diff --git a/chrome/browser/chromeos/profiles/profile_helper.h b/chrome/browser/chromeos/profiles/profile_helper.h index e31cadd..73324bc 100644 --- a/chrome/browser/chromeos/profiles/profile_helper.h +++ b/chrome/browser/chromeos/profiles/profile_helper.h @@ -62,6 +62,9 @@ class ProfileHelper : public BrowsingDataRemover::Observer, // signin Profile. static bool IsSigninProfile(Profile* profile); + // Returns true when |profile| corresponds to owner's profile. + static bool IsOwnerProfile(Profile* profile); + // Initialize a bunch of services that are tied to a browser profile. // TODO(dzhioev): Investigate whether or not this method is needed. void ProfileStartup(Profile* profile, bool process_startup); diff --git a/chrome/browser/ui/webui/chromeos/proxy_settings_ui.cc b/chrome/browser/ui/webui/chromeos/proxy_settings_ui.cc index e6f37a0..56eb520 100644 --- a/chrome/browser/ui/webui/chromeos/proxy_settings_ui.cc +++ b/chrome/browser/ui/webui/chromeos/proxy_settings_ui.cc @@ -92,12 +92,12 @@ ProxySettingsUI::ProxySettingsUI(content::WebUI* web_ui) // |localized_strings| will be owned by ProxySettingsHTMLSource. base::DictionaryValue* localized_strings = new base::DictionaryValue(); + web_ui->AddMessageHandler(core_handler_); core_handler_->set_handlers_host(this); core_handler_->GetLocalizedValues(localized_strings); - web_ui->AddMessageHandler(core_handler_); - proxy_handler_->GetLocalizedValues(localized_strings); web_ui->AddMessageHandler(proxy_handler_); + proxy_handler_->GetLocalizedValues(localized_strings); bool keyboard_driven_oobe = system::keyboard_settings::ForceKeyboardDrivenUINavigation(); diff --git a/chrome/browser/ui/webui/chromeos/ui_account_tweaks.cc b/chrome/browser/ui/webui/chromeos/ui_account_tweaks.cc index f813cb5..03f2f7f 100644 --- a/chrome/browser/ui/webui/chromeos/ui_account_tweaks.cc +++ b/chrome/browser/ui/webui/chromeos/ui_account_tweaks.cc @@ -7,6 +7,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/chromeos/login/user_manager.h" +#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chromeos/settings/cros_settings_names.h" #include "content/public/browser/web_ui_data_source.h" @@ -14,7 +15,8 @@ namespace chromeos { void AddAccountUITweaksLocalizedValues( - base::DictionaryValue* localized_strings) { + base::DictionaryValue* localized_strings, + Profile* profile) { DCHECK(localized_strings); std::string owner_email; @@ -25,7 +27,7 @@ void AddAccountUITweaksLocalizedValues( localized_strings->SetString("ownerUserId", display_email); localized_strings->SetBoolean("currentUserIsOwner", - UserManager::Get()->IsCurrentUserOwner()); + ProfileHelper::IsOwnerProfile(profile)); localized_strings->SetBoolean("loggedInAsGuest", UserManager::Get()->IsLoggedInAsGuest()); @@ -35,10 +37,11 @@ void AddAccountUITweaksLocalizedValues( } void AddAccountUITweaksLocalizedValues( - content::WebUIDataSource* source) { + content::WebUIDataSource* source, + Profile* profile) { DCHECK(source); base::DictionaryValue dict; - AddAccountUITweaksLocalizedValues(&dict); + AddAccountUITweaksLocalizedValues(&dict, profile); source->AddLocalizedStrings(dict); } diff --git a/chrome/browser/ui/webui/chromeos/ui_account_tweaks.h b/chrome/browser/ui/webui/chromeos/ui_account_tweaks.h index 25a7f73..271085a 100644 --- a/chrome/browser/ui/webui/chromeos/ui_account_tweaks.h +++ b/chrome/browser/ui/webui/chromeos/ui_account_tweaks.h @@ -8,6 +8,8 @@ #include "base/values.h" #include "base/compiler_specific.h" +class Profile; + namespace content { class WebUIDataSource; } @@ -20,7 +22,7 @@ namespace chromeos { * @param localized_strings non-null dictionary that will be filled. */ void AddAccountUITweaksLocalizedValues( - base::DictionaryValue* localized_strings); + base::DictionaryValue* localized_strings, Profile* profile); /** * Fills given data source with account status data (whether current user is @@ -28,7 +30,8 @@ void AddAccountUITweaksLocalizedValues( * @param source non-null ui data source which localized values dictionary will * be filled. */ -void AddAccountUITweaksLocalizedValues(content::WebUIDataSource* source); +void AddAccountUITweaksLocalizedValues(content::WebUIDataSource* source, + Profile* profile); } // namespace chromeos diff --git a/chrome/browser/ui/webui/components_ui.cc b/chrome/browser/ui/webui/components_ui.cc index cbd4e2f..e5cce27 100644 --- a/chrome/browser/ui/webui/components_ui.cc +++ b/chrome/browser/ui/webui/components_ui.cc @@ -32,7 +32,7 @@ using content::WebUIMessageHandler; namespace { -content::WebUIDataSource* CreateComponentsUIHTMLSource() { +content::WebUIDataSource* CreateComponentsUIHTMLSource(Profile* profile) { content::WebUIDataSource* source = content::WebUIDataSource::Create(chrome::kChromeUIComponentsHost); source->SetUseJsonJSFormatV2(); @@ -48,7 +48,7 @@ content::WebUIDataSource* CreateComponentsUIHTMLSource() { source->AddResourcePath("components.js", IDR_COMPONENTS_JS); source->SetDefaultResource(IDR_COMPONENTS_HTML); #if defined(OS_CHROMEOS) - chromeos::AddAccountUITweaksLocalizedValues(source); + chromeos::AddAccountUITweaksLocalizedValues(source, profile); #endif return source; } @@ -156,7 +156,7 @@ ComponentsUI::ComponentsUI(content::WebUI* web_ui) : WebUIController(web_ui) { // Set up the chrome://components/ source. Profile* profile = Profile::FromWebUI(web_ui); - content::WebUIDataSource::Add(profile, CreateComponentsUIHTMLSource()); + content::WebUIDataSource::Add(profile, CreateComponentsUIHTMLSource(profile)); } // static diff --git a/chrome/browser/ui/webui/options/chromeos/accounts_options_browsertest.cc b/chrome/browser/ui/webui/options/chromeos/accounts_options_browsertest.cc new file mode 100644 index 0000000..33fbebf --- /dev/null +++ b/chrome/browser/ui/webui/options/chromeos/accounts_options_browsertest.cc @@ -0,0 +1,140 @@ +// Copyright 2014 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. + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/prefs/pref_service.h" +#include "chrome/browser/chromeos/login/login_manager_test.h" +#include "chrome/browser/chromeos/login/startup_utils.h" +#include "chrome/browser/chromeos/login/user_adding_screen.h" +#include "chrome/browser/chromeos/login/user_manager.h" +#include "chrome/browser/chromeos/settings/cros_settings.h" +#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" +#include "chrome/test/base/ui_test_utils.h" +#include "chromeos/chromeos_switches.h" +#include "chromeos/settings/cros_settings_names.h" +#include "content/public/browser/web_contents.h" +#include "content/public/test/browser_test_utils.h" +#include "content/public/test/test_utils.h" + +namespace chromeos { + +namespace { + +const char* kTestUsers[] = { "test-user1@gmail.com", "test-user2@gmail.com" }; + +} // namespace + +class AccountsOptionsTest : public LoginManagerTest { + public: + AccountsOptionsTest() + : LoginManagerTest(false), + device_settings_provider_(NULL) { + stub_settings_provider_.Set(kDeviceOwner, base::StringValue(kTestUsers[0])); + } + + virtual ~AccountsOptionsTest() { + } + + virtual void SetUpOnMainThread() OVERRIDE { + LoginManagerTest::SetUpOnMainThread(); + CrosSettings* settings = CrosSettings::Get(); + device_settings_provider_ = settings->GetProvider(kDeviceOwner); + settings->RemoveSettingsProvider(device_settings_provider_); + settings->AddSettingsProvider(&stub_settings_provider_); + } + + virtual void CleanUpOnMainThread() OVERRIDE { + CrosSettings* settings = CrosSettings::Get(); + settings->RemoveSettingsProvider(&stub_settings_provider_); + settings->AddSettingsProvider(device_settings_provider_); + LoginManagerTest::CleanUpOnMainThread(); + } + + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + LoginManagerTest::SetUpCommandLine(command_line); + command_line->AppendSwitch(::switches::kMultiProfiles); + command_line->AppendSwitch(switches::kForceMultiProfileInTests); + } + + protected: + void CheckAccountsUI(const User* user, bool is_owner) { + Profile* profile = UserManager::Get()->GetProfileByUser(user); + profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, + user->email()); + + ui_test_utils::BrowserAddedObserver observer; + Browser* browser = CreateBrowser(profile); + observer.WaitForSingleNewBrowser(); + + ui_test_utils::NavigateToURL(browser, + GURL("chrome://settings-frame/accounts")); + content::WebContents* contents = + browser->tab_strip_model()->GetActiveWebContents(); + + bool warning_visible; + ASSERT_TRUE(content::ExecuteScriptAndExtractBool( + contents, + "var e = document.getElementById('ownerOnlyWarning');" + "var visible = e.offsetWidth > 0 && e.offsetHeight > 0;" + "window.domAutomationController.send(visible);", + &warning_visible)); + EXPECT_EQ(is_owner, !warning_visible); + + bool guest_option_enabled; + ASSERT_TRUE(content::ExecuteScriptAndExtractBool( + contents, + "var e = document.getElementById('allowBwsiCheck');" + "window.domAutomationController.send(!e.disabled);", + &guest_option_enabled)); + ASSERT_EQ(is_owner, guest_option_enabled); + + bool user_pods_enabled; + ASSERT_TRUE(content::ExecuteScriptAndExtractBool( + contents, + "var e = document.getElementById('showUserNamesCheck');" + "window.domAutomationController.send(!e.disabled);", + &user_pods_enabled)); + ASSERT_EQ(is_owner, user_pods_enabled); + + bool whitelist_enabled; + ASSERT_TRUE(content::ExecuteScriptAndExtractBool( + contents, + "var e = document.getElementById('useWhitelistCheck');" + "window.domAutomationController.send(!e.disabled);", + &whitelist_enabled)); + ASSERT_EQ(is_owner, whitelist_enabled); + } + + StubCrosSettingsProvider stub_settings_provider_; + CrosSettingsProvider* device_settings_provider_; + + private: + DISALLOW_COPY_AND_ASSIGN(AccountsOptionsTest); +}; + +IN_PROC_BROWSER_TEST_F(AccountsOptionsTest, PRE_MultiProfilesAccountsOptions) { + RegisterUser(kTestUsers[0]); + RegisterUser(kTestUsers[1]); + StartupUtils::MarkOobeCompleted(); +} + +IN_PROC_BROWSER_TEST_F(AccountsOptionsTest, MultiProfilesAccountsOptions) { + LoginUser(kTestUsers[0]); + UserAddingScreen::Get()->Start(); + content::RunAllPendingInMessageLoop(); + AddUser(kTestUsers[1]); + + UserManager* manager = UserManager::Get(); + ASSERT_EQ(2u, manager->GetLoggedInUsers().size()); + + CheckAccountsUI(manager->FindUser(kTestUsers[0]), true /* is_owner */); + CheckAccountsUI(manager->FindUser(kTestUsers[1]), false /* is_owner */); +} + +} // namespace chromeos diff --git a/chrome/browser/ui/webui/options/chromeos/accounts_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/accounts_options_handler.cc index 353c098..42f13a4 100644 --- a/chrome/browser/ui/webui/options/chromeos/accounts_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/accounts_options_handler.cc @@ -88,7 +88,8 @@ void AccountsOptionsHandler::GetLocalizedValues( localized_strings->SetBoolean("whitelist_is_managed", connector->IsEnterpriseManaged()); - AddAccountUITweaksLocalizedValues(localized_strings); + AddAccountUITweaksLocalizedValues(localized_strings, + Profile::FromWebUI(web_ui())); } void AccountsOptionsHandler::HandleWhitelistUser(const base::ListValue* args) { diff --git a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc index 4535feb..0dc8c61 100644 --- a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc @@ -155,7 +155,7 @@ base::Value* CoreChromeOSOptionsHandler::FetchPref( if (connector->IsEnterpriseManaged()) dict->SetString("controlledBy", "policy"); bool disabled_by_owner = IsSettingOwnerOnly(pref_name) && - !UserManager::Get()->IsCurrentUserOwner(); + !ProfileHelper::IsOwnerProfile(Profile::FromWebUI(web_ui())); dict->SetBoolean("disabled", disabled_by_owner); if (disabled_by_owner) dict->SetString("controlledBy", "owner"); @@ -214,7 +214,8 @@ void CoreChromeOSOptionsHandler::GetLocalizedValues( DCHECK(localized_strings); CoreOptionsHandler::GetLocalizedValues(localized_strings); - AddAccountUITweaksLocalizedValues(localized_strings); + AddAccountUITweaksLocalizedValues(localized_strings, + Profile::FromWebUI(web_ui())); localized_strings->SetString("controlledSettingOwner", l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_OWNER)); } diff --git a/chrome/browser/ui/webui/plugins_ui.cc b/chrome/browser/ui/webui/plugins_ui.cc index 635ca3e..dd38da0 100644 --- a/chrome/browser/ui/webui/plugins_ui.cc +++ b/chrome/browser/ui/webui/plugins_ui.cc @@ -62,7 +62,7 @@ void AssertPluginEnabled(bool did_enable) { DCHECK(did_enable); } -content::WebUIDataSource* CreatePluginsUIHTMLSource() { +content::WebUIDataSource* CreatePluginsUIHTMLSource(Profile* profile) { content::WebUIDataSource* source = content::WebUIDataSource::Create(chrome::kChromeUIPluginsHost); source->SetUseJsonJSFormatV2(); @@ -101,7 +101,7 @@ content::WebUIDataSource* CreatePluginsUIHTMLSource() { source->AddResourcePath("plugins.js", IDR_PLUGINS_JS); source->SetDefaultResource(IDR_PLUGINS_HTML); #if defined(OS_CHROMEOS) - chromeos::AddAccountUITweaksLocalizedValues(source); + chromeos::AddAccountUITweaksLocalizedValues(source, profile); #endif return source; } @@ -485,7 +485,7 @@ PluginsUI::PluginsUI(content::WebUI* web_ui) : WebUIController(web_ui) { // Set up the chrome://plugins/ source. Profile* profile = Profile::FromWebUI(web_ui); - content::WebUIDataSource::Add(profile, CreatePluginsUIHTMLSource()); + content::WebUIDataSource::Add(profile, CreatePluginsUIHTMLSource(profile)); } // static diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index ec96b24..710dd1a 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1502,6 +1502,7 @@ 'browser/ui/webui/options/browser_options_browsertest.js', 'browser/ui/webui/options/certificate_manager_browsertest.cc', 'browser/ui/webui/options/certificate_manager_browsertest.js', + 'browser/ui/webui/options/chromeos/accounts_options_browsertest.cc', 'browser/ui/webui/options/chromeos/accounts_options_browsertest.js', 'browser/ui/webui/options/chromeos/bluetooth_options_browsertest.js', 'browser/ui/webui/options/chromeos/guest_mode_options_ui_browsertest.cc', |