#include <string>
#include <vector>
-#include "apps/app_window_registry.h"
-#include "apps/ui/native_app_window.h"
#include "ash/shell.h"
#include "ash/system/chromeos/session/logout_confirmation_controller.h"
#include "ash/system/chromeos/session/logout_confirmation_dialog.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/command_line.h"
-#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/location.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/screens/base_screen.h"
+#include "chrome/browser/chromeos/login/signin_specifics.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/ui/webui_login_view.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "crypto/rsa_private_key.h"
+#include "extensions/browser/app_window/app_window.h"
+#include "extensions/browser/app_window/app_window_registry.h"
+#include "extensions/browser/app_window/native_app_window.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/management_policy.h"
#include "extensions/browser/notification_types.h"
#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;
const char kAccountId2[] = "dla2@example.com";
const char kDisplayName1[] = "display name 1";
const char kDisplayName2[] = "display name 2";
-const char* kStartupURLs[] = {
+const char* const kStartupURLs[] = {
"chrome://policy",
"chrome://about",
};
const char kExternalData[] = "External data";
const char kExternalDataURL[] = "http://localhost/external_data";
-const char* kSingleRecommendedLocale[] = {
+const char* const kSingleRecommendedLocale[] = {
"el",
};
-const char* kRecommendedLocales1[] = {
+const char* const kRecommendedLocales1[] = {
"pl",
"et",
"en-US",
};
-const char* kRecommendedLocales2[] = {
+const char* const kRecommendedLocales2[] = {
"fr",
"nl",
};
+const char* const kInvalidRecommendedLocale[] = {
+ "xx",
+};
const char kPublicSessionLocale[] = "de";
const char kPublicSessionInputMethodIDTemplate[] = "_comp_ime_%sxkb:de:neo:ger";
http_response->set_code(net::HTTP_OK);
http_response->set_content(content);
http_response->set_content_type("text/xml");
- return http_response.PassAs<net::test_server::HttpResponse>();
+ return http_response.Pass();
}
DictionaryPrefValueWaiter::DictionaryPrefValueWaiter(
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,
public user_manager::UserManager::Observer,
public chrome::BrowserListObserver,
- public apps::AppWindowRegistry::Observer {
+ public extensions::AppWindowRegistry::Observer {
protected:
DeviceLocalAccountTest()
: user_id_1_(GenerateDeviceLocalAccountUserId(
virtual ~DeviceLocalAccountTest() {}
- virtual void SetUp() OVERRIDE {
+ virtual void SetUp() override {
// Configure and start the test server.
scoped_ptr<crypto::RSAPrivateKey> signing_key(
PolicyBuilder::CreateTestSigningKey());
DevicePolicyCrosBrowserTest::SetUp();
}
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ virtual void SetUpCommandLine(CommandLine* command_line) override {
DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(chromeos::switches::kLoginManager);
command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
test_server_.GetServiceURL().spec());
}
- virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
+ virtual void SetUpInProcessBrowserTestFixture() override {
DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
// Clear command-line arguments (but keep command-line switches) so the
InitializePolicy();
}
- virtual void SetUpOnMainThread() OVERRIDE {
+ 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();
wizard_controller->SkipToLoginForTesting(LoginScreenContext());
}
- virtual void TearDownOnMainThread() OVERRIDE {
+ virtual void TearDownOnMainThread() override {
BrowserList::RemoveObserver(this);
// This shuts down the login UI.
}
virtual void LocalStateChanged(
- user_manager::UserManager* user_manager) OVERRIDE {
+ user_manager::UserManager* user_manager) override {
if (run_loop_)
run_loop_->Quit();
}
- virtual void OnBrowserRemoved(Browser* browser) OVERRIDE {
+ virtual void OnBrowserRemoved(Browser* browser) override {
if (run_loop_)
run_loop_->Quit();
}
- virtual void OnAppWindowAdded(apps::AppWindow* app_window) OVERRIDE {
+ virtual void OnAppWindowAdded(extensions::AppWindow* app_window) override {
if (run_loop_)
run_loop_->Quit();
}
- virtual void OnAppWindowRemoved(apps::AppWindow* app_window) OVERRIDE {
+ virtual void OnAppWindowRemoved(extensions::AppWindow* app_window) override {
if (run_loop_)
run_loop_->Quit();
}
kAccountId1, device_local_account_policy_.GetBlob());
}
- void SetRecommendedLocales(const char* recommended_locales[],
+ void SetRecommendedLocales(const char* const recommended_locales[],
size_t array_size) {
em::StringListPolicyProto* session_locales_proto =
device_local_account_policy_.payload().mutable_sessionlocales();
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.
user_id_1_);
user_context.SetPublicSessionLocale(locale);
user_context.SetPublicSessionInputMethod(input_method);
- controller->LoginAsPublicSession(user_context);
+ controller->Login(user_context, chromeos::SigninSpecifics());
}
void WaitForSessionStart() {
&layouts_from_locale);
ASSERT_FALSE(layouts_from_locale.empty());
EXPECT_EQ(layouts_from_locale.front(),
- input_method_manager->GetCurrentInputMethod().id());
+ input_method_manager->GetActiveIMEState()
+ ->GetCurrentInputMethod()
+ .id());
}
const std::string user_id_1_;
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_;
Profile* profile = GetProfileForTest();
ASSERT_TRUE(profile);
- apps::AppWindowRegistry* app_window_registry =
- apps::AppWindowRegistry::Get(profile);
+ extensions::AppWindowRegistry* app_window_registry =
+ extensions::AppWindowRegistry::Get(profile);
app_window_registry->AddObserver(this);
// Verify that the logout confirmation dialog is not showing.
};
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(
// 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();
}
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(
// 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()->
- GetCurrentInputMethod().id());
+ chromeos::input_method::InputMethodManager::Get()
+ ->GetActiveIMEState()
+ ->GetCurrentInputMethod()
+ .id());
}
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(
// 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();
}
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.
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));
// 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()->
- GetCurrentInputMethod().id());
+ chromeos::input_method::InputMethodManager::Get()
+ ->GetActiveIMEState()
+ ->GetCurrentInputMethod()
+ .id());
+}
+
+IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, InvalidRecommendedLocale) {
+ // Specify an invalid recommended locale.
+ SetRecommendedLocales(kInvalidRecommendedLocale,
+ arraysize(kInvalidRecommendedLocale));
+ UploadAndInstallDeviceLocalAccountPolicy();
+ AddPublicSessionToDevicePolicy(kAccountId1);
+
+ 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);
+ EXPECT_EQ(l10n_util::GetLanguage(initial_locale_),
+ icu::Locale::getDefault().getLanguage());
+
+ // 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 since the recommended locale was invalid, 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(l10n_util::GetLanguage(initial_locale_),
+ icu::Locale::getDefault().getLanguage());
+ VerifyKeyboardLayoutMatchesLocale();
}
IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest,
AutoLoginWithoutRecommendedLocales) {
- const std::string initial_locale = g_browser_process->GetApplicationLocale();
-
UploadAndInstallDeviceLocalAccountPolicy();
AddPublicSessionToDevicePolicy(kAccountId1);
EnableAutoLogin();
// 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();
}
// 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();
}
// 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()->
- GetCurrentInputMethod().id());
+ chromeos::input_method::InputMethodManager::Get()
+ ->GetActiveIMEState()
+ ->GetCurrentInputMethod()
+ .id());
// Click the accept button.
ASSERT_TRUE(content::ExecuteScript(contents_,
// 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()->
- GetCurrentInputMethod().id());
+ chromeos::input_method::InputMethodManager::Get()
+ ->GetActiveIMEState()
+ ->GetCurrentInputMethod()
+ .id());
}
class TermsOfServiceDownloadTest : public DeviceLocalAccountTest,