Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / chromeos / accounts_options_browsertest.cc
blob33c6c55c3ee838816036ce5a6b2d094e5c539bae
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/command_line.h"
7 #include "base/compiler_specific.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/chromeos/login/login_manager_test.h"
10 #include "chrome/browser/chromeos/login/startup_utils.h"
11 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
12 #include "chrome/browser/chromeos/profiles/profile_helper.h"
13 #include "chrome/browser/chromeos/settings/cros_settings.h"
14 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/ui_test_utils.h"
20 #include "chromeos/settings/cros_settings_names.h"
21 #include "components/user_manager/user_manager.h"
22 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/test_utils.h"
26 namespace chromeos {
28 namespace {
30 const char* kTestUsers[] = { "test-user1@gmail.com", "test-user2@gmail.com" };
32 } // namespace
34 class AccountsOptionsTest : public LoginManagerTest {
35 public:
36 AccountsOptionsTest()
37 : LoginManagerTest(false),
38 device_settings_provider_(NULL) {
39 stub_settings_provider_.Set(kDeviceOwner, base::StringValue(kTestUsers[0]));
42 ~AccountsOptionsTest() override {}
44 void SetUpOnMainThread() override {
45 LoginManagerTest::SetUpOnMainThread();
46 CrosSettings* settings = CrosSettings::Get();
47 device_settings_provider_ = settings->GetProvider(kDeviceOwner);
48 settings->RemoveSettingsProvider(device_settings_provider_);
49 settings->AddSettingsProvider(&stub_settings_provider_);
52 void TearDownOnMainThread() override {
53 CrosSettings* settings = CrosSettings::Get();
54 settings->RemoveSettingsProvider(&stub_settings_provider_);
55 settings->AddSettingsProvider(device_settings_provider_);
56 LoginManagerTest::TearDownOnMainThread();
59 void SetUpCommandLine(base::CommandLine* command_line) override {
60 LoginManagerTest::SetUpCommandLine(command_line);
63 protected:
64 void CheckAccountsUI(const user_manager::User* user, bool is_owner) {
65 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user);
67 ui_test_utils::BrowserAddedObserver observer;
68 Browser* browser = CreateBrowser(profile);
69 observer.WaitForSingleNewBrowser();
71 ui_test_utils::NavigateToURL(browser,
72 GURL("chrome://settings-frame/accounts"));
73 content::WebContents* contents =
74 browser->tab_strip_model()->GetActiveWebContents();
76 bool warning_visible;
77 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
78 contents,
79 "var e = document.getElementById('ownerOnlyWarning');"
80 "var visible = e.offsetWidth > 0 && e.offsetHeight > 0;"
81 "window.domAutomationController.send(visible);",
82 &warning_visible));
83 EXPECT_EQ(is_owner, !warning_visible);
85 bool guest_option_enabled;
86 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
87 contents,
88 "var e = document.getElementById('allowBwsiCheck');"
89 "window.domAutomationController.send(!e.disabled);",
90 &guest_option_enabled));
91 EXPECT_EQ(is_owner, guest_option_enabled);
93 bool supervised_users_enabled;
94 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
95 contents,
96 "var e = document.getElementById('allowSupervisedCheck');"
97 "window.domAutomationController.send(!e.disabled);",
98 &supervised_users_enabled));
99 ASSERT_EQ(is_owner, supervised_users_enabled);
101 bool user_pods_enabled;
102 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
103 contents,
104 "var e = document.getElementById('showUserNamesCheck');"
105 "window.domAutomationController.send(!e.disabled);",
106 &user_pods_enabled));
107 EXPECT_EQ(is_owner, user_pods_enabled);
109 bool whitelist_enabled;
110 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
111 contents,
112 "var e = document.getElementById('useWhitelistCheck');"
113 "window.domAutomationController.send(!e.disabled);",
114 &whitelist_enabled));
115 EXPECT_EQ(is_owner, whitelist_enabled);
118 StubCrosSettingsProvider stub_settings_provider_;
119 CrosSettingsProvider* device_settings_provider_;
121 private:
122 DISALLOW_COPY_AND_ASSIGN(AccountsOptionsTest);
125 IN_PROC_BROWSER_TEST_F(AccountsOptionsTest, PRE_MultiProfilesAccountsOptions) {
126 RegisterUser(kTestUsers[0]);
127 RegisterUser(kTestUsers[1]);
128 StartupUtils::MarkOobeCompleted();
131 IN_PROC_BROWSER_TEST_F(AccountsOptionsTest, MultiProfilesAccountsOptions) {
132 LoginUser(kTestUsers[0]);
133 UserAddingScreen::Get()->Start();
134 content::RunAllPendingInMessageLoop();
135 AddUser(kTestUsers[1]);
137 user_manager::UserManager* manager = user_manager::UserManager::Get();
138 ASSERT_EQ(2u, manager->GetLoggedInUsers().size());
140 CheckAccountsUI(manager->FindUser(kTestUsers[0]), true /* is_owner */);
141 CheckAccountsUI(manager->FindUser(kTestUsers[1]), false /* is_owner */);
144 } // namespace chromeos