1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/chromeos/login/login_manager_test.h"
9 #include "chrome/browser/chromeos/login/startup_utils.h"
10 #include "chrome/browser/chromeos/login/user_adding_screen.h"
11 #include "chrome/browser/chromeos/login/user_manager.h"
12 #include "chrome/browser/chromeos/settings/cros_settings.h"
13 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "chromeos/settings/cros_settings_names.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/browser_test_utils.h"
22 #include "content/public/test/test_utils.h"
28 const char* kTestUsers
[] = { "test-user1@gmail.com", "test-user2@gmail.com" };
32 class AccountsOptionsTest
: public LoginManagerTest
{
35 : LoginManagerTest(false),
36 device_settings_provider_(NULL
) {
37 stub_settings_provider_
.Set(kDeviceOwner
, base::StringValue(kTestUsers
[0]));
40 virtual ~AccountsOptionsTest() {
43 virtual void SetUpOnMainThread() OVERRIDE
{
44 LoginManagerTest::SetUpOnMainThread();
45 CrosSettings
* settings
= CrosSettings::Get();
46 device_settings_provider_
= settings
->GetProvider(kDeviceOwner
);
47 settings
->RemoveSettingsProvider(device_settings_provider_
);
48 settings
->AddSettingsProvider(&stub_settings_provider_
);
51 virtual void CleanUpOnMainThread() OVERRIDE
{
52 CrosSettings
* settings
= CrosSettings::Get();
53 settings
->RemoveSettingsProvider(&stub_settings_provider_
);
54 settings
->AddSettingsProvider(device_settings_provider_
);
55 LoginManagerTest::CleanUpOnMainThread();
58 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
59 LoginManagerTest::SetUpCommandLine(command_line
);
63 void CheckAccountsUI(const User
* user
, bool is_owner
) {
64 Profile
* profile
= UserManager::Get()->GetProfileByUser(user
);
65 profile
->GetPrefs()->SetString(prefs::kGoogleServicesUsername
,
68 ui_test_utils::BrowserAddedObserver observer
;
69 Browser
* browser
= CreateBrowser(profile
);
70 observer
.WaitForSingleNewBrowser();
72 ui_test_utils::NavigateToURL(browser
,
73 GURL("chrome://settings-frame/accounts"));
74 content::WebContents
* contents
=
75 browser
->tab_strip_model()->GetActiveWebContents();
78 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
80 "var e = document.getElementById('ownerOnlyWarning');"
81 "var visible = e.offsetWidth > 0 && e.offsetHeight > 0;"
82 "window.domAutomationController.send(visible);",
84 EXPECT_EQ(is_owner
, !warning_visible
);
86 bool guest_option_enabled
;
87 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
89 "var e = document.getElementById('allowBwsiCheck');"
90 "window.domAutomationController.send(!e.disabled);",
91 &guest_option_enabled
));
92 EXPECT_EQ(is_owner
, guest_option_enabled
);
94 bool user_pods_enabled
;
95 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
97 "var e = document.getElementById('showUserNamesCheck');"
98 "window.domAutomationController.send(!e.disabled);",
100 EXPECT_EQ(is_owner
, user_pods_enabled
);
102 bool whitelist_enabled
;
103 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
105 "var e = document.getElementById('useWhitelistCheck');"
106 "window.domAutomationController.send(!e.disabled);",
107 &whitelist_enabled
));
108 EXPECT_EQ(is_owner
, whitelist_enabled
);
111 StubCrosSettingsProvider stub_settings_provider_
;
112 CrosSettingsProvider
* device_settings_provider_
;
115 DISALLOW_COPY_AND_ASSIGN(AccountsOptionsTest
);
118 IN_PROC_BROWSER_TEST_F(AccountsOptionsTest
, PRE_MultiProfilesAccountsOptions
) {
119 RegisterUser(kTestUsers
[0]);
120 RegisterUser(kTestUsers
[1]);
121 StartupUtils::MarkOobeCompleted();
124 // TODO(pastarmovj): Enable this test once https://crbug.com/362430 is fixed.
125 IN_PROC_BROWSER_TEST_F(AccountsOptionsTest
,
126 DISABLED_MultiProfilesAccountsOptions
) {
127 LoginUser(kTestUsers
[0]);
128 UserAddingScreen::Get()->Start();
129 content::RunAllPendingInMessageLoop();
130 AddUser(kTestUsers
[1]);
132 UserManager
* manager
= UserManager::Get();
133 ASSERT_EQ(2u, manager
->GetLoggedInUsers().size());
135 CheckAccountsUI(manager
->FindUser(kTestUsers
[0]), true /* is_owner */);
136 CheckAccountsUI(manager
->FindUser(kTestUsers
[1]), false /* is_owner */);
139 } // namespace chromeos