Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / supervised / supervised_user_creation_browsertest.cc
blobd9e8394023e00f4a27ab5ee49d56adb28f6ee562
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 <string>
7 #include "base/compiler_specific.h"
8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/sequenced_worker_pool.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/chromeos/login/login_manager_test.h"
13 #include "chrome/browser/chromeos/login/startup_utils.h"
14 #include "chrome/browser/chromeos/login/supervised/supervised_user_authentication.h"
15 #include "chrome/browser/chromeos/login/supervised/supervised_user_test_base.h"
16 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
17 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
18 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
19 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
20 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
21 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
22 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_utility.h"
23 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_utility_stub.h"
24 #include "chrome/browser/supervised_user/supervised_user_constants.h"
25 #include "chromeos/cryptohome/mock_async_method_caller.h"
26 #include "chromeos/cryptohome/mock_homedir_methods.h"
27 #include "content/public/browser/notification_service.h"
28 #include "content/public/test/browser_test_utils.h"
29 #include "content/public/test/test_utils.h"
30 #include "sync/api/fake_sync_change_processor.h"
31 #include "sync/api/sync_change.h"
32 #include "sync/api/sync_error_factory_mock.h"
33 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test.h"
34 #include "sync/protocol/sync.pb.h"
36 using testing::_;
37 using chromeos::SupervisedUserTestBase;
38 using chromeos::kTestSupervisedUserDisplayName;
39 using chromeos::kTestManager;
41 namespace chromeos {
43 class SupervisedUserCreationTest : public SupervisedUserTestBase {
44 public:
45 SupervisedUserCreationTest() : SupervisedUserTestBase() {}
47 private:
48 DISALLOW_COPY_AND_ASSIGN(SupervisedUserCreationTest);
51 class SupervisedUserTransactionCleanupTest : public SupervisedUserTestBase {
52 public:
53 SupervisedUserTransactionCleanupTest() : SupervisedUserTestBase() {}
55 private:
56 DISALLOW_COPY_AND_ASSIGN(SupervisedUserTransactionCleanupTest);
59 class SupervisedUserOwnerCreationTest : public SupervisedUserTestBase {
60 public:
61 SupervisedUserOwnerCreationTest() : SupervisedUserTestBase() {}
63 void SetUpInProcessBrowserTestFixture() override {
64 SupervisedUserTestBase::SetUpInProcessBrowserTestFixture();
65 cros_settings_provider_.reset(new StubCrosSettingsProvider());
66 cros_settings_provider_->Set(kDeviceOwner, base::StringValue(kTestManager));
69 private:
70 scoped_ptr<StubCrosSettingsProvider> cros_settings_provider_;
71 DISALLOW_COPY_AND_ASSIGN(SupervisedUserOwnerCreationTest);
74 class SupervisedUserTransactionCleanupTest2
75 : public SupervisedUserTransactionCleanupTest {
76 public:
77 SupervisedUserTransactionCleanupTest2()
78 : SupervisedUserTransactionCleanupTest() {}
80 void SetUpInProcessBrowserTestFixture() override {
81 SupervisedUserTransactionCleanupTest::SetUpInProcessBrowserTestFixture();
82 EXPECT_CALL(*mock_async_method_caller_, AsyncRemove(_, _)).Times(1);
85 private:
86 DISALLOW_COPY_AND_ASSIGN(SupervisedUserTransactionCleanupTest2);
89 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
90 PRE_PRE_PRE_CreateAndRemoveSupervisedUser) {
91 PrepareUsers();
94 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
95 PRE_PRE_CreateAndRemoveSupervisedUser) {
96 StartFlowLoginAsManager();
97 FillNewUserData(kTestSupervisedUserDisplayName);
98 StartUserCreation("supervised-user-creation-next-button",
99 kTestSupervisedUserDisplayName);
102 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
103 PRE_CreateAndRemoveSupervisedUser) {
104 SigninAsSupervisedUser(true, 0, kTestSupervisedUserDisplayName);
107 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
108 CreateAndRemoveSupervisedUser) {
109 RemoveSupervisedUser(3, 0, kTestSupervisedUserDisplayName);
112 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
113 PRE_PRE_CheckPodForSupervisedUser) {
114 PrepareUsers();
117 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
118 PRE_CheckPodForSupervisedUser) {
119 StartFlowLoginAsManager();
120 FillNewUserData(kTestSupervisedUserDisplayName);
121 StartUserCreation("supervised-user-creation-next-button",
122 kTestSupervisedUserDisplayName);
125 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest, CheckPodForSupervisedUser) {
126 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait();
128 // Open pod menu
129 JSEval("$('pod-row').pods[0].querySelector('.action-box-button').click()");
130 JSExpect("$('pod-row').pods[0].actionBoxMenuTitleEmailElement.hidden");
133 IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
134 PRE_PRE_PRE_CreateAndRemoveSupervisedUser) {
135 PrepareUsers();
138 IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
139 PRE_PRE_CreateAndRemoveSupervisedUser) {
140 StartFlowLoginAsManager();
141 FillNewUserData(kTestSupervisedUserDisplayName);
142 StartUserCreation("supervised-user-creation-next-button",
143 kTestSupervisedUserDisplayName);
146 IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
147 PRE_CreateAndRemoveSupervisedUser) {
148 SigninAsSupervisedUser(true, 0, kTestSupervisedUserDisplayName);
151 IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
152 CreateAndRemoveSupervisedUser) {
153 RemoveSupervisedUser(3, 0, kTestSupervisedUserDisplayName);
156 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest,
157 PRE_PRE_CreateAndCancelSupervisedUser) {
158 PrepareUsers();
161 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest,
162 PRE_CreateAndCancelSupervisedUser) {
163 StartFlowLoginAsManager();
164 FillNewUserData(kTestSupervisedUserDisplayName);
166 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
167 EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1);
169 JSEval("$('supervised-user-creation-next-button').click()");
171 testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
173 EXPECT_TRUE(registration_utility_stub_->register_was_called());
174 EXPECT_EQ(registration_utility_stub_->display_name(),
175 base::UTF8ToUTF16(kTestSupervisedUserDisplayName));
177 std::string user_id = registration_utility_stub_->supervised_user_id();
179 // Make sure user is already in list.
180 ASSERT_EQ(3UL, user_manager::UserManager::Get()->GetUsers().size());
182 // We wait for token now. Press cancel button at this point.
183 JSEvalOrExitBrowser("$('cancel-add-user-button').click()");
186 IN_PROC_BROWSER_TEST_(
187 SupervisedUserTransactionCleanupTest,
188 CreateAndCancelSupervisedUser,
189 SupervisedUserTransactionCleanupTest2,
190 testing::internal::GetTypeId<SupervisedUserTransactionCleanupTest>()) {
191 // Make sure there is no supervised user in list.
192 ASSERT_EQ(2UL, user_manager::UserManager::Get()->GetUsers().size());
195 } // namespace chromeos