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

Unified Diff: chrome/browser/chromeos/policy/device_local_account_browsertest.cc

Issue 426063005: Allow recommended locales to be set for public sessions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/device_local_account_browsertest.cc
diff --git a/chrome/browser/chromeos/policy/device_local_account_browsertest.cc b/chrome/browser/chromeos/policy/device_local_account_browsertest.cc
index 8d79f63f40a2ec56ee3f87b147139cd535cd3315..8fffa2cfa8b8ca5f102b406f4916198eaf918bbf 100644
--- a/chrome/browser/chromeos/policy/device_local_account_browsertest.cc
+++ b/chrome/browser/chromeos/policy/device_local_account_browsertest.cc
@@ -4,6 +4,7 @@
#include <map>
#include <string>
+#include <vector>
#include "apps/app_window_registry.h"
#include "apps/ui/native_app_window.h"
@@ -39,6 +40,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.h"
#include "chrome/browser/chromeos/extensions/external_cache.h"
+#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/screens/wizard_screen.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
@@ -99,6 +101,7 @@
#include "components/signin/core/common/signin_pref_names.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_type.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
@@ -172,6 +175,15 @@ const char kPackagedAppCRXPath[] = "extensions/platform_apps/app_window_2.crx";
const char kExternalData[] = "External data";
const char kExternalDataURL[] = "http://localhost/external_data";
+const char* kRecommendedLocales1[] = {
+ "pl",
+ "et",
+ "en-US",
+};
+const char* kRecommendedLocales2[] = {
+ "fr",
+ "nl",
+};
const char kPublicSessionLocale[] = "de";
const char kPublicSessionInputMethodIDTemplate[] = "_comp_ime_%sxkb:de:neo:ger";
@@ -491,6 +503,17 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
std::string(), proto.SerializeAsString());
}
+ void EnableAutoLogin() {
+ em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
+ em::DeviceLocalAccountsProto* device_local_accounts =
+ proto.mutable_device_local_accounts();
+ device_local_accounts->set_auto_login_id(kAccountId1);
+ device_local_accounts->set_auto_login_delay(0);
+ RefreshDevicePolicy();
+ test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType,
+ std::string(), proto.SerializeAsString());
+ }
+
void CheckPublicSessionPresent(const std::string& id) {
const user_manager::User* user = chromeos::UserManager::Get()->FindUser(id);
ASSERT_TRUE(user);
@@ -522,6 +545,21 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
return ProfileManager::GetActiveUserProfile();
}
+ content::WebContents* GetWebContents() {
+ chromeos::LoginDisplayHostImpl* host =
+ reinterpret_cast<chromeos::LoginDisplayHostImpl*>(
+ chromeos::LoginDisplayHostImpl::default_host());
+ if (!host)
+ return NULL;
+ chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
+ if (!web_ui_login_view)
+ return NULL;
+ content::WebUI* web_ui = web_ui_login_view->GetWebUI();
+ if (!web_ui)
+ return NULL;
+ return web_ui->GetWebContents();
+ }
+
void WaitForDisplayName(const std::string& user_id,
const std::string& expected_display_name) {
DictionaryPrefValueWaiter("UserDisplayName",
@@ -576,6 +614,30 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
base::Bind(IsSessionStarted)).Wait();
}
+ void SkipToLoginScreen() {
+ chromeos::WizardController* wizard_controller =
+ chromeos::WizardController::default_controller();
+ ASSERT_TRUE(wizard_controller);
pneubeck (no reviews) 2014/07/30 15:23:19 just FYI: ASSERTs in functions only skip the rest
bartfab (slow) 2014/08/05 17:16:23 That's why I use ASSERT_NO_FATAL_FAILURE().
+ wizard_controller->SkipToLoginForTesting(LoginScreenContext());
+ content::WindowedNotificationObserver(
+ chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
+ content::NotificationService::AllSources()).Wait();
+ }
+
+ void VerifyKeyboardLayoutMatchesLocale() {
+ chromeos::input_method::InputMethodManager* input_method_manager =
+ chromeos::input_method::InputMethodManager::Get();
+ std::vector<std::string> layouts_from_locale;
+ input_method_manager->GetInputMethodUtil()->
pneubeck (no reviews) 2014/07/30 17:55:44 I don't know how the logic for selecting the keybo
bartfab (slow) 2014/08/05 17:16:24 This is exactly the production function that the U
+ GetInputMethodIdsFromLanguageCode(
+ g_browser_process->GetApplicationLocale(),
+ chromeos::input_method::kKeyboardLayoutsOnly,
+ &layouts_from_locale);
+ ASSERT_FALSE(layouts_from_locale.empty());
+ EXPECT_EQ(layouts_from_locale.front(),
+ input_method_manager->GetCurrentInputMethod().id());
+ }
+
const std::string user_id_1_;
const std::string user_id_2_;
const std::string public_session_input_method_id_;
@@ -611,26 +673,10 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DisplayName) {
AddPublicSessionToDevicePolicy(kAccountId1);
WaitForPolicy();
-
- // Skip to the login screen.
- chromeos::WizardController* wizard_controller =
- chromeos::WizardController::default_controller();
- ASSERT_TRUE(wizard_controller);
- wizard_controller->SkipToLoginForTesting(LoginScreenContext());
- content::WindowedNotificationObserver(
- chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
- content::NotificationService::AllSources()).Wait();
+ ASSERT_NO_FATAL_FAILURE(SkipToLoginScreen());
// Verify that the display name is shown in the UI.
- chromeos::LoginDisplayHostImpl* host =
- reinterpret_cast<chromeos::LoginDisplayHostImpl*>(
- chromeos::LoginDisplayHostImpl::default_host());
- ASSERT_TRUE(host);
- chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
- ASSERT_TRUE(web_ui_login_view);
- content::WebUI* web_ui = web_ui_login_view->GetWebUI();
- ASSERT_TRUE(web_ui);
- content::WebContents* contents = web_ui->GetWebContents();
+ content::WebContents* contents = GetWebContents();
ASSERT_TRUE(contents);
const std::string get_compact_pod_display_name = base::StringPrintf(
"domAutomationController.send(document.getElementById('pod-row')"
@@ -1295,43 +1341,258 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LastWindowClosedLogoutReminder) {
app_window_registry->RemoveObserver(this);
};
-IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DoNotSelectLanguageAndKeyboard) {
- chromeos::input_method::InputMethodManager* input_method_manager =
- chromeos::input_method::InputMethodManager::Get();
+IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, NoRecommendedLocale) {
pneubeck (no reviews) 2014/07/30 15:39:23 is this case different from no locale policy being
bartfab (slow) 2014/08/05 17:16:24 There was no test verifying that scenario. I added
const std::string initial_locale = g_browser_process->GetApplicationLocale();
- const std::string initial_input_method =
- input_method_manager->GetCurrentInputMethod().id();
UploadAndInstallDeviceLocalAccountPolicy();
AddPublicSessionToDevicePolicy(kAccountId1);
WaitForPolicy();
- ASSERT_NO_FATAL_FAILURE(WaitForLoginUI());
- ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string()));
+ ASSERT_NO_FATAL_FAILURE(SkipToLoginScreen());
+
+ // Click on the pod to expand it. Verify that the pod expands to its basic
+ // form as there are no recommended locales.
+ content::WebContents* contents = GetWebContents();
+ ASSERT_TRUE(contents);
+ bool advanced = false;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents,
+ base::StringPrintf(
+ "var pod ="
+ " document.getElementById('pod-row').getPodWithUsername_('%s');"
+ "pod.click();"
+ "domAutomationController.send(pod.classList.contains('advanced'));",
+ user_id_1_.c_str()),
+ &advanced));
+ EXPECT_FALSE(advanced);
+
+ // Click the enter button to start the session.
+ ASSERT_TRUE(content::ExecuteScript(
+ contents,
+ base::StringPrintf(
+ "document.getElementById('pod-row').getPodWithUsername_('%s')"
+ " .querySelector('.enter-button').click();",
+ user_id_1_.c_str())));
+
WaitForSessionStart();
+ // Verify that the locale has not changed and the first keyboard layout
+ // applicable to the locale was chosen.
EXPECT_EQ(initial_locale, g_browser_process->GetApplicationLocale());
- EXPECT_EQ(initial_input_method,
- input_method_manager->GetCurrentInputMethod().id());
+ VerifyKeyboardLayoutMatchesLocale();
}
-IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, SelectLanguageAndKeyboard) {
- // Specify startup pages.
- device_local_account_policy_.payload().mutable_restoreonstartup()->set_value(
- SessionStartupPref::kPrefValueURLs);
- em::StringListPolicyProto* startup_urls_proto =
- device_local_account_policy_.payload().mutable_restoreonstartupurls();
- for (size_t i = 0; i < arraysize(kStartupURLs); ++i)
- startup_urls_proto->mutable_value()->add_entries(kStartupURLs[i]);
+IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, OneRecommendedLocale) {
+ // Specify a recommended locale.
+ em::StringListPolicyProto* session_locales_proto =
+ device_local_account_policy_.payload().mutable_sessionlocales();
+ session_locales_proto->mutable_policy_options()->set_mode(
+ em::PolicyOptions_PolicyMode_RECOMMENDED);
+ session_locales_proto->mutable_value()->add_entries(kRecommendedLocales1[0]);
pneubeck (no reviews) 2014/07/30 17:55:44 instead of using the unrelated kRecommendedLocales
bartfab (slow) 2014/08/05 17:16:24 Done.
UploadAndInstallDeviceLocalAccountPolicy();
AddPublicSessionToDevicePolicy(kAccountId1);
- // Log in to the device-local account with a specific locale and keyboard
- // layout.
WaitForPolicy();
- ASSERT_NO_FATAL_FAILURE(WaitForLoginUI());
- ASSERT_NO_FATAL_FAILURE(
- StartLogin(kPublicSessionLocale, public_session_input_method_id_));
+ ASSERT_NO_FATAL_FAILURE(SkipToLoginScreen());
+
+ // Click on the pod to expand it. Verify that the pod expands to its basic
+ // form as there is only one recommended locale.
+ content::WebContents* contents = GetWebContents();
+ ASSERT_TRUE(contents);
+ bool advanced = false;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents,
+ base::StringPrintf(
+ "var pod ="
+ " document.getElementById('pod-row').getPodWithUsername_('%s');"
+ "pod.click();"
+ "domAutomationController.send(pod.classList.contains('advanced'));",
+ user_id_1_.c_str()),
+ &advanced));
+ EXPECT_FALSE(advanced);
+
+ // Click the enter button to start the session.
+ ASSERT_TRUE(content::ExecuteScript(
+ contents,
+ base::StringPrintf(
+ "document.getElementById('pod-row').getPodWithUsername_('%s')"
+ " .querySelector('.enter-button').click();",
+ user_id_1_.c_str())));
+
+ WaitForSessionStart();
+
+ // Verify that the recommended locale has been applied and the first keyboard
+ // layout applicable to the locale was chosen.
+ EXPECT_EQ(kRecommendedLocales1[0], g_browser_process->GetApplicationLocale());
+ VerifyKeyboardLayoutMatchesLocale();
+}
+
+IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, MultipleRecommendedLocales) {
pneubeck (no reviews) 2014/07/30 17:55:44 can the user also minify the pod after expanding?
bartfab (slow) 2014/08/05 17:16:23 Yes, the pod will contract if it loses focus. The
+ // Specify recommended locales.
+ em::StringListPolicyProto* session_locales_proto =
pneubeck (no reviews) 2014/07/30 17:55:44 the setting of the locales could be in helper func
bartfab (slow) 2014/08/05 17:16:24 Done.
+ device_local_account_policy_.payload().mutable_sessionlocales();
+ session_locales_proto->mutable_policy_options()->set_mode(
+ em::PolicyOptions_PolicyMode_RECOMMENDED);
+ for (size_t i = 0; i < arraysize(kRecommendedLocales1); ++i) {
+ session_locales_proto->mutable_value()->add_entries(
+ kRecommendedLocales1[i]);
+ }
+ UploadAndInstallDeviceLocalAccountPolicy();
+ AddPublicSessionToDevicePolicy(kAccountId1);
+
+ WaitForPolicy();
+ ASSERT_NO_FATAL_FAILURE(SkipToLoginScreen());
+
+ // Verify that the pod shows a list of locales beginning with the recommended
+ // ones, followed by others.
+ content::WebContents* contents = GetWebContents();
+ ASSERT_TRUE(contents);
+ const std::string get_locale_list = base::StringPrintf(
+ "var languageSelect = document.getElementById('pod-row')"
+ " .getPodWithUsername_('%s').querySelector('.language-select');"
+ "var locales = [];"
+ "for (var i = 0; i < languageSelect.length; ++i)"
+ " locales.push(languageSelect.options[i].value);"
+ "domAutomationController.send(JSON.stringify(locales));",
+ user_id_1_.c_str());
+ std::string json;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents,
+ get_locale_list,
+ &json));
+ scoped_ptr<base::Value> value_ptr(base::JSONReader::Read(json));
+ const base::ListValue* locales = NULL;
+ ASSERT_TRUE(value_ptr);
+ ASSERT_TRUE(value_ptr->GetAsList(&locales));
+ EXPECT_LT(arraysize(kRecommendedLocales1), locales->GetSize());
+ for (size_t i = 0; i < arraysize(kRecommendedLocales1); ++i) {
+ std::string locale;
+ EXPECT_TRUE(locales->GetString(i, &locale));
+ EXPECT_EQ(kRecommendedLocales1[i], locale);
+ }
+
+ // Verify that the first recommended locale is selected.
pneubeck (no reviews) 2014/07/30 15:39:23 It's irritating that you're testing this before th
bartfab (slow) 2014/08/05 17:16:23 Done.
+ const std::string get_selected_locale =
+ base::StringPrintf(
pneubeck (no reviews) 2014/07/30 15:39:23 This block and the next together should test: - f
bartfab (slow) 2014/08/05 17:16:23 My test verifies this but the focus is slightly di
+ "domAutomationController.send(document.getElementById('pod-row')"
+ " .getPodWithUsername_('%s').querySelector('.language-select')"
+ " .value);",
+ user_id_1_.c_str());
+ std::string selected_locale;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents,
+ get_selected_locale,
+ &selected_locale));
+ EXPECT_EQ(kRecommendedLocales1[0], selected_locale);
+
+ // Click on the pod to expand it. Verify that the pod expands to its advanced
+ // form directly as there are two or more recommended locales.
pneubeck (no reviews) 2014/07/30 15:39:23 nit: "as there are more than two"
bartfab (slow) 2014/08/05 17:16:24 No, "two or more" is correct. The advanced pod is
+ bool advanced = false;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents,
+ base::StringPrintf(
+ "var pod ="
+ " document.getElementById('pod-row').getPodWithUsername_('%s');"
+ "pod.click();"
+ "domAutomationController.send(pod.classList.contains('advanced'));",
+ user_id_1_.c_str()),
+ &advanced));
+ EXPECT_TRUE(advanced);
+
+ // Change the list of recommended locales.
+ session_locales_proto->mutable_value()->Clear();
+ for (size_t i = 0; i < arraysize(kRecommendedLocales2); ++i) {
+ session_locales_proto->mutable_value()->add_entries(
+ kRecommendedLocales2[i]);
+ }
pneubeck (no reviews) 2014/07/30 15:39:23 nit: empty line after this one.
bartfab (slow) 2014/08/05 17:16:23 Done.
+ // Also change the display name as it is easy to ensure that policy has been
+ // updated by waiting for a display name change.
+ device_local_account_policy_.payload().mutable_userdisplayname()->set_value(
+ kDisplayName2);
+ UploadAndInstallDeviceLocalAccountPolicy();
+ policy::BrowserPolicyConnectorChromeOS* connector =
+ g_browser_process->platform_part()->browser_policy_connector_chromeos();
+ DeviceLocalAccountPolicyBroker* broker =
+ connector->GetDeviceLocalAccountPolicyService()->GetBrokerForUser(
+ user_id_1_);
+ ASSERT_TRUE(broker);
+ broker->core()->store()->Load();
+ WaitForDisplayName(user_id_1_, kDisplayName2);
+
+ // Verify that the new list of locales is shown in the UI.
+ ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents,
+ get_locale_list,
+ &json));
+ value_ptr.reset(base::JSONReader::Read(json));
pneubeck (no reviews) 2014/07/30 17:55:44 if this code part (JSONReader -> cast to concrete
bartfab (slow) 2014/08/05 17:16:23 I do such a conversion three times in this file. I
+ locales = NULL;
+ ASSERT_TRUE(value_ptr);
+ ASSERT_TRUE(value_ptr->GetAsList(&locales));
+ EXPECT_LT(arraysize(kRecommendedLocales2), locales->GetSize());
+ for (size_t i = 0; i < arraysize(kRecommendedLocales2); ++i) {
+ std::string locale;
+ EXPECT_TRUE(locales->GetString(i, &locale));
+ EXPECT_EQ(kRecommendedLocales2[i], locale);
+ }
+
+ // Verify that the first new recommended locale is selected.
+ ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents,
+ get_selected_locale,
+ &selected_locale));
+ EXPECT_EQ(kRecommendedLocales2[0], selected_locale);
+
+ // Manually select a different locale.
+ ASSERT_TRUE(content::ExecuteScript(
+ contents,
+ base::StringPrintf(
+ "var languageSelect = document.getElementById('pod-row')"
+ " .getPodWithUsername_('%s').querySelector('.language-select');"
+ "languageSelect.value = '%s';"
+ "var event = document.createEvent('HTMLEvents');"
+ "event.initEvent('change', false, true);"
+ "languageSelect.dispatchEvent(event);",
+ user_id_1_.c_str(),
+ kPublicSessionLocale)));
+
+ // Change the list of recommended locales.
+ session_locales_proto->mutable_value()->Clear();
+ for (size_t i = 0; i < arraysize(kRecommendedLocales1); ++i) {
+ session_locales_proto->mutable_value()->add_entries(
+ kRecommendedLocales1[i]);
+ }
+ device_local_account_policy_.payload().mutable_userdisplayname()->set_value(
+ kDisplayName1);
+ UploadAndInstallDeviceLocalAccountPolicy();
+ broker->core()->store()->Load();
+ WaitForDisplayName(user_id_1_, kDisplayName1);
+
+ // Verify that the first manually selected locale is still selected.
pneubeck (no reviews) 2014/07/30 17:55:44 what means 'the first manually selected' ? Can the
bartfab (slow) 2014/08/05 17:16:24 Oops, typo. Removed the "first".
+ ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents,
+ get_selected_locale,
+ &selected_locale));
+ EXPECT_EQ(kPublicSessionLocale, selected_locale);
+
+ // The UI will have requested an updated list of keyboard layouts at this
pneubeck (no reviews) 2014/07/30 17:55:44 nit: move to a helper "FlushFileThread"
bartfab (slow) 2014/08/05 17:16:23 Done.
+ // point. Flush the FILE and UI thread loops to allow the process that
+ // constructs this list to complete.
+ base::RunLoop run_loop;
+ content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&base::DoNothing),
+ run_loop.QuitClosure());
+ run_loop.Run();
+ base::RunLoop().RunUntilIdle();
+
+ // Manually select a different keyboard layout and click the enter button to
+ // start the session.
+ ASSERT_TRUE(content::ExecuteScript(
+ contents,
+ base::StringPrintf(
+ "var pod ="
+ " document.getElementById('pod-row').getPodWithUsername_('%s');"
+ "pod.querySelector('.keyboard-select').value = '%s';"
+ "pod.querySelector('.enter-button').click();",
+ user_id_1_.c_str(),
+ public_session_input_method_id_.c_str())));
+
WaitForSessionStart();
// Verify that the locale and keyboard layout have been applied.
pneubeck (no reviews) 2014/07/30 17:55:44 'Verify that the manually selected ...' Hm. Is th
bartfab (slow) 2014/08/05 17:16:24 There are several places where you can pick the lo
@@ -1342,7 +1603,51 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, SelectLanguageAndKeyboard) {
}
pneubeck (no reviews) 2014/07/30 15:39:23 will continue review after this part later.
bartfab (slow) 2014/08/05 17:16:24 Acknowledged.
IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest,
- SelectLanguageAndKeyboardWithTermsOfService) {
+ AutoLoginWithoutRecommendedLocales) {
pneubeck (no reviews) 2014/07/30 17:55:44 can you compare this to whatever other test maybe
bartfab (slow) 2014/08/05 17:16:23 The only other auto-login tests I am aware of are
+ const std::string initial_locale = g_browser_process->GetApplicationLocale();
+
+ UploadAndInstallDeviceLocalAccountPolicy();
+ AddPublicSessionToDevicePolicy(kAccountId1);
+ EnableAutoLogin();
+
+ WaitForPolicy();
+ ASSERT_NO_FATAL_FAILURE(SkipToLoginScreen());
+
+ WaitForSessionStart();
+
+ // Verify that the locale has not changed and the first keyboard layout
+ // applicable to the locale was chosen.
+ EXPECT_EQ(initial_locale, g_browser_process->GetApplicationLocale());
+ VerifyKeyboardLayoutMatchesLocale();
+}
+
+IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest,
+ AutoLoginWithRecommendedLocales) {
+ // Specify recommended locales.
+ em::StringListPolicyProto* session_locales_proto =
+ device_local_account_policy_.payload().mutable_sessionlocales();
+ session_locales_proto->mutable_policy_options()->set_mode(
+ em::PolicyOptions_PolicyMode_RECOMMENDED);
+ for (size_t i = 0; i < arraysize(kRecommendedLocales1); ++i) {
+ session_locales_proto->mutable_value()->add_entries(
+ kRecommendedLocales1[i]);
+ }
+ UploadAndInstallDeviceLocalAccountPolicy();
+ AddPublicSessionToDevicePolicy(kAccountId1);
+ EnableAutoLogin();
+
+ WaitForPolicy();
+ ASSERT_NO_FATAL_FAILURE(SkipToLoginScreen());
+
+ WaitForSessionStart();
+
+ // Verify that the first recommended locale has been applied and the first
+ // keyboard layout applicable to the locale was chosen.
+ EXPECT_EQ(kRecommendedLocales1[0], g_browser_process->GetApplicationLocale());
+ VerifyKeyboardLayoutMatchesLocale();
+}
+
+IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, TermsOfServiceWithLocaleSwitch) {
// Specify Terms of Service URL.
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
device_local_account_policy_.payload().mutable_termsofserviceurl()->set_value(
@@ -1351,12 +1656,35 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest,
UploadAndInstallDeviceLocalAccountPolicy();
AddPublicSessionToDevicePolicy(kAccountId1);
- // Log in to the device-local account with a specific locale and keyboard
- // layout.
WaitForPolicy();
- ASSERT_NO_FATAL_FAILURE(WaitForLoginUI());
- ASSERT_NO_FATAL_FAILURE(
- StartLogin(kPublicSessionLocale, public_session_input_method_id_));
+ ASSERT_NO_FATAL_FAILURE(SkipToLoginScreen());
+
+ // Select a different locale.
+ content::WebContents* contents = GetWebContents();
+ ASSERT_TRUE(contents);
+ ASSERT_TRUE(content::ExecuteScript(
+ contents,
+ base::StringPrintf(
+ "var languageSelect = document.getElementById('pod-row')"
+ " .getPodWithUsername_('%s').querySelector('.language-select');"
+ "languageSelect.value = '%s';"
+ "var event = document.createEvent('HTMLEvents');"
+ "event.initEvent('change', false, true);"
+ "languageSelect.dispatchEvent(event);",
+ user_id_1_.c_str(),
+ kPublicSessionLocale)));
+
+ // The UI will have requested an updated list of keyboard layouts at this
+ // point. Flush the FILE and UI thread loops to allow the process that
+ // constructs this list to complete.
+ base::RunLoop run_loop;
+ content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&base::DoNothing),
+ run_loop.QuitClosure());
+ run_loop.Run();
+ base::RunLoop().RunUntilIdle();
// Set up an observer that will quit the message loop when login has succeeded
// and the first wizard screen, if any, is being shown.
@@ -1364,12 +1692,25 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest,
chromeos::MockAuthStatusConsumer login_status_consumer;
EXPECT_CALL(login_status_consumer, OnAuthSuccess(_)).Times(1).WillOnce(
InvokeWithoutArgs(&login_wait_run_loop, &base::RunLoop::Quit));
-
- // Spin the loop until the observer fires. Then, unregister the observer.
chromeos::ExistingUserController* controller =
chromeos::ExistingUserController::current_controller();
ASSERT_TRUE(controller);
controller->set_login_status_consumer(&login_status_consumer);
+
+ // Manually select a different keyboard layout and click the enter button to
+ // start the session.
+ ASSERT_TRUE(content::ExecuteScript(
+ contents,
+ base::StringPrintf(
+ "var pod ="
+ " document.getElementById('pod-row').getPodWithUsername_('%s');"
+ "pod.querySelector('.keyboard-select').value = '%s';"
+ "pod.querySelector('.enter-button').click();",
+ user_id_1_.c_str(),
+ public_session_input_method_id_.c_str())));
+
+ // Spin the loop until the login observer fires. Then, unregister the
+ // observer.
login_wait_run_loop.Run();
controller->set_login_status_consumer(NULL);
@@ -1382,16 +1723,6 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest,
wizard_controller->current_screen()->GetName());
// Wait for the Terms of Service to finish downloading.
- chromeos::LoginDisplayHostImpl* host =
- reinterpret_cast<chromeos::LoginDisplayHostImpl*>(
- chromeos::LoginDisplayHostImpl::default_host());
- ASSERT_TRUE(host);
- chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
- ASSERT_TRUE(web_ui_login_view);
- content::WebUI* web_ui = web_ui_login_view->GetWebUI();
- ASSERT_TRUE(web_ui);
- content::WebContents* contents = web_ui->GetWebContents();
- ASSERT_TRUE(contents);
bool done = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(contents,
"var screenElement = document.getElementById('terms-of-service');"
@@ -1472,15 +1803,7 @@ IN_PROC_BROWSER_TEST_P(TermsOfServiceDownloadTest, TermsOfServiceScreen) {
// Wait for the Terms of Service to finish downloading, then get the status of
// the screen's UI elements.
- chromeos::LoginDisplayHostImpl* host =
- reinterpret_cast<chromeos::LoginDisplayHostImpl*>(
- chromeos::LoginDisplayHostImpl::default_host());
- ASSERT_TRUE(host);
- chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
- ASSERT_TRUE(web_ui_login_view);
- content::WebUI* web_ui = web_ui_login_view->GetWebUI();
- ASSERT_TRUE(web_ui);
- content::WebContents* contents = web_ui->GetWebContents();
+ content::WebContents* contents = GetWebContents();
ASSERT_TRUE(contents);
std::string json;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents,

Powered by Google App Engine
This is Rietveld 408576698