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 b9991a721c167b282c4483ad8030119b3f4c4994..23c1675331bdd432b756b5ee65893738859f23b4 100644 |
--- a/chrome/browser/chromeos/policy/device_local_account_browsertest.cc |
+++ b/chrome/browser/chromeos/policy/device_local_account_browsertest.cc |
@@ -129,12 +129,12 @@ |
#include "net/url_request/url_request_status.h" |
#include "policy/policy_constants.h" |
#include "testing/gmock/include/gmock/gmock.h" |
+#include "third_party/icu/source/common/unicode/locid.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/window_open_disposition.h" |
#include "ui/gfx/image/image_skia.h" |
#include "ui/views/widget/widget.h" |
#include "url/gurl.h" |
-//#include "third_party/cros_system_api/dbus/service_constants.h" |
namespace em = enterprise_management; |
@@ -378,23 +378,6 @@ bool IsSessionStarted() { |
return user_manager::UserManager::Get()->IsSessionStarted(); |
} |
-// GetKeyboardLayoutsForLocale() posts a task to a background task runner. This |
-// method flushes that task runner and the current thread's message loop to |
-// ensure that GetKeyboardLayoutsForLocale() is finished. |
-void WaitForGetKeyboardLayoutsForLocaleToFinish() { |
- base::SequencedWorkerPool* worker_pool = |
- content::BrowserThread::GetBlockingPool(); |
- scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
- worker_pool->GetSequencedTaskRunner( |
- worker_pool->GetNamedSequenceToken(kSequenceToken)); |
- base::RunLoop run_loop; |
- background_task_runner->PostTaskAndReply(FROM_HERE, |
- base::Bind(&base::DoNothing), |
- run_loop.QuitClosure()); |
- run_loop.Run(); |
- base::RunLoop().RunUntilIdle(); |
-} |
- |
} // namespace |
class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest, |
@@ -461,6 +444,9 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest, |
virtual void SetUpOnMainThread() OVERRIDE { |
DevicePolicyCrosBrowserTest::SetUpOnMainThread(); |
+ initial_locale_ = g_browser_process->GetApplicationLocale(); |
+ initial_language_ = l10n_util::GetLanguage(initial_locale_); |
+ |
content::WindowedNotificationObserver( |
chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
content::NotificationService::AllSources()).Wait(); |
@@ -656,6 +642,47 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest, |
WaitForDisplayName(user_id_1_, kDisplayName1); |
} |
+ void ExpandPublicSessionPod(bool expect_advanced) { |
+ bool advanced = false; |
+ // Click on the pod to expand it. |
+ 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)); |
+ // Verify that the pod expanded to its basic/advanced form, as expected. |
+ EXPECT_EQ(expect_advanced, advanced); |
+ |
+ // Verify that the construction of the pod's language list did not affect |
+ // the current ICU locale. |
+ EXPECT_EQ(initial_language_, icu::Locale::getDefault().getLanguage()); |
+ } |
+ |
+ // GetKeyboardLayoutsForLocale() posts a task to a background task runner. |
+ // This method flushes that task runner and the current thread's message loop |
+ // to ensure that GetKeyboardLayoutsForLocale() is finished. |
+ void WaitForGetKeyboardLayoutsForLocaleToFinish() { |
+ base::SequencedWorkerPool* worker_pool = |
+ content::BrowserThread::GetBlockingPool(); |
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
+ worker_pool->GetSequencedTaskRunner( |
+ worker_pool->GetNamedSequenceToken(kSequenceToken)); |
+ base::RunLoop run_loop; |
+ background_task_runner->PostTaskAndReply(FROM_HERE, |
+ base::Bind(&base::DoNothing), |
+ run_loop.QuitClosure()); |
+ run_loop.Run(); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ // Verify that the construction of the keyboard layout list did not affect |
+ // the current ICU locale. |
+ EXPECT_EQ(initial_language_, icu::Locale::getDefault().getLanguage()); |
+ } |
+ |
void StartLogin(const std::string& locale, |
const std::string& input_method) { |
// Start login into the device-local account. |
@@ -702,6 +729,9 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest, |
const std::string user_id_2_; |
const std::string public_session_input_method_id_; |
+ std::string initial_locale_; |
+ std::string initial_language_; |
+ |
scoped_ptr<base::RunLoop> run_loop_; |
UserPolicyBuilder device_local_account_policy_; |
@@ -1398,26 +1428,12 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LastWindowClosedLogoutReminder) { |
}; |
IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, NoRecommendedLocaleNoSwitch) { |
- const std::string initial_locale = g_browser_process->GetApplicationLocale(); |
- |
UploadAndInstallDeviceLocalAccountPolicy(); |
AddPublicSessionToDevicePolicy(kAccountId1); |
WaitForPolicy(); |
- // Click on the pod to expand it. Verify that the pod expands to its basic |
- // form as there are no recommended locales. |
- 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); |
+ ExpandPublicSessionPod(false); |
// Click the enter button to start the session. |
ASSERT_TRUE(content::ExecuteScript( |
@@ -1431,7 +1447,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, NoRecommendedLocaleNoSwitch) { |
// 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_locale_, g_browser_process->GetApplicationLocale()); |
+ EXPECT_EQ(initial_language_, icu::Locale::getDefault().getLanguage()); |
VerifyKeyboardLayoutMatchesLocale(); |
} |
@@ -1441,22 +1458,11 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, NoRecommendedLocaleSwitch) { |
WaitForPolicy(); |
- // Click on the pod to expand it. Verify that the pod expands to its basic |
- // form as there are no recommended locales. |
- 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); |
+ ExpandPublicSessionPod(false); |
// Click the link that switches the pod to its advanced form. Verify that the |
// pod switches from basic to advanced. |
+ bool advanced = false; |
ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
contents_, |
base::StringPrintf( |
@@ -1501,6 +1507,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, NoRecommendedLocaleSwitch) { |
// Verify that the locale and keyboard layout have been applied. |
EXPECT_EQ(kPublicSessionLocale, g_browser_process->GetApplicationLocale()); |
+ EXPECT_EQ(l10n_util::GetLanguage(kPublicSessionLocale), |
+ icu::Locale::getDefault().getLanguage()); |
EXPECT_EQ(public_session_input_method_id_, |
chromeos::input_method::InputMethodManager::Get() |
->GetActiveIMEState() |
@@ -1517,19 +1525,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, OneRecommendedLocale) { |
WaitForPolicy(); |
- // Click on the pod to expand it. Verify that the pod expands to its basic |
- // form as there is only one recommended locale. |
- 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); |
+ ExpandPublicSessionPod(false); |
// Click the enter button to start the session. |
ASSERT_TRUE(content::ExecuteScript( |
@@ -1545,6 +1541,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, OneRecommendedLocale) { |
// layout applicable to the locale was chosen. |
EXPECT_EQ(kSingleRecommendedLocale[0], |
g_browser_process->GetApplicationLocale()); |
+ EXPECT_EQ(l10n_util::GetLanguage(kSingleRecommendedLocale[0]), |
+ icu::Locale::getDefault().getLanguage()); |
VerifyKeyboardLayoutMatchesLocale(); |
} |
@@ -1557,19 +1555,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, MultipleRecommendedLocales) { |
WaitForPolicy(); |
- // 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. |
- 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); |
+ ExpandPublicSessionPod(true); |
// Verify that the pod shows a list of locales beginning with the recommended |
// ones, followed by others. |
@@ -1732,6 +1718,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, MultipleRecommendedLocales) { |
const base::DictionaryValue* state = NULL; |
ASSERT_TRUE(value_ptr); |
ASSERT_TRUE(value_ptr->GetAsDictionary(&state)); |
+ bool advanced = false; |
EXPECT_TRUE(state->GetBoolean("advanced", &advanced)); |
EXPECT_TRUE(advanced); |
EXPECT_TRUE(state->GetString("locale", &selected_locale)); |
@@ -1752,6 +1739,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, MultipleRecommendedLocales) { |
// Verify that the locale and keyboard layout have been applied. |
EXPECT_EQ(kPublicSessionLocale, g_browser_process->GetApplicationLocale()); |
+ EXPECT_EQ(l10n_util::GetLanguage(kPublicSessionLocale), |
+ icu::Locale::getDefault().getLanguage()); |
EXPECT_EQ(public_session_input_method_id_, |
chromeos::input_method::InputMethodManager::Get() |
->GetActiveIMEState() |
@@ -1761,8 +1750,6 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, MultipleRecommendedLocales) { |
IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, |
AutoLoginWithoutRecommendedLocales) { |
- const std::string initial_locale = g_browser_process->GetApplicationLocale(); |
- |
UploadAndInstallDeviceLocalAccountPolicy(); |
AddPublicSessionToDevicePolicy(kAccountId1); |
EnableAutoLogin(); |
@@ -1773,7 +1760,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, |
// 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_locale_, g_browser_process->GetApplicationLocale()); |
+ EXPECT_EQ(initial_language_, icu::Locale::getDefault().getLanguage()); |
VerifyKeyboardLayoutMatchesLocale(); |
} |
@@ -1792,6 +1780,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, |
// 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()); |
+ EXPECT_EQ(l10n_util::GetLanguage(kRecommendedLocales1[0]), |
+ icu::Locale::getDefault().getLanguage()); |
VerifyKeyboardLayoutMatchesLocale(); |
} |
@@ -1879,6 +1869,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, TermsOfServiceWithLocaleSwitch) { |
// Verify that the locale and keyboard layout have been applied. |
EXPECT_EQ(kPublicSessionLocale, g_browser_process->GetApplicationLocale()); |
+ EXPECT_EQ(l10n_util::GetLanguage(kPublicSessionLocale), |
+ icu::Locale::getDefault().getLanguage()); |
EXPECT_EQ(public_session_input_method_id_, |
chromeos::input_method::InputMethodManager::Get() |
->GetActiveIMEState() |
@@ -1893,6 +1885,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, TermsOfServiceWithLocaleSwitch) { |
// Verify that the locale and keyboard layout are still in force. |
EXPECT_EQ(kPublicSessionLocale, g_browser_process->GetApplicationLocale()); |
+ EXPECT_EQ(l10n_util::GetLanguage(kPublicSessionLocale), |
+ icu::Locale::getDefault().getLanguage()); |
EXPECT_EQ(public_session_input_method_id_, |
chromeos::input_method::InputMethodManager::Get() |
->GetActiveIMEState() |