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.
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/ui/login_display_host_impl.h"
17 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
18 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
19 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
20 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
21 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_utility.h"
22 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_utility_stub.h"
23 #include "chrome/browser/supervised_user/supervised_user_constants.h"
24 #include "chromeos/cryptohome/mock_async_method_caller.h"
25 #include "chromeos/cryptohome/mock_homedir_methods.h"
26 #include "content/public/browser/notification_service.h"
27 #include "content/public/test/browser_test_utils.h"
28 #include "content/public/test/test_utils.h"
29 #include "sync/api/fake_sync_change_processor.h"
30 #include "sync/api/sync_change.h"
31 #include "sync/api/sync_error_factory_mock.h"
32 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test.h"
33 #include "sync/protocol/sync.pb.h"
36 using chromeos::SupervisedUserTestBase
;
37 using chromeos::kTestSupervisedUserDisplayName
;
38 using chromeos::kTestManager
;
42 class SupervisedUserCreationTest
: public SupervisedUserTestBase
{
44 SupervisedUserCreationTest() : SupervisedUserTestBase() {}
47 DISALLOW_COPY_AND_ASSIGN(SupervisedUserCreationTest
);
50 class SupervisedUserTransactionCleanupTest
: public SupervisedUserTestBase
{
52 SupervisedUserTransactionCleanupTest() : SupervisedUserTestBase() {}
55 DISALLOW_COPY_AND_ASSIGN(SupervisedUserTransactionCleanupTest
);
58 class SupervisedUserOwnerCreationTest
: public SupervisedUserTestBase
{
60 SupervisedUserOwnerCreationTest() : SupervisedUserTestBase() {}
62 void SetUpInProcessBrowserTestFixture() override
{
63 SupervisedUserTestBase::SetUpInProcessBrowserTestFixture();
64 cros_settings_provider_
.reset(new StubCrosSettingsProvider());
65 cros_settings_provider_
->Set(kDeviceOwner
, base::StringValue(kTestManager
));
69 scoped_ptr
<StubCrosSettingsProvider
> cros_settings_provider_
;
70 DISALLOW_COPY_AND_ASSIGN(SupervisedUserOwnerCreationTest
);
73 class SupervisedUserTransactionCleanupTest2
74 : public SupervisedUserTransactionCleanupTest
{
76 SupervisedUserTransactionCleanupTest2()
77 : SupervisedUserTransactionCleanupTest() {}
79 void SetUpInProcessBrowserTestFixture() override
{
80 SupervisedUserTransactionCleanupTest::SetUpInProcessBrowserTestFixture();
81 EXPECT_CALL(*mock_async_method_caller_
, AsyncRemove(_
, _
)).Times(1);
85 DISALLOW_COPY_AND_ASSIGN(SupervisedUserTransactionCleanupTest2
);
88 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest
,
89 PRE_PRE_PRE_CreateAndRemoveSupervisedUser
) {
93 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest
,
94 PRE_PRE_CreateAndRemoveSupervisedUser
) {
95 StartFlowLoginAsManager();
96 FillNewUserData(kTestSupervisedUserDisplayName
);
97 StartUserCreation("supervised-user-creation-next-button",
98 kTestSupervisedUserDisplayName
);
101 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest
,
102 PRE_CreateAndRemoveSupervisedUser
) {
103 SigninAsSupervisedUser(true, 0, kTestSupervisedUserDisplayName
);
106 IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest
,
107 CreateAndRemoveSupervisedUser
) {
108 RemoveSupervisedUser(3, 0, kTestSupervisedUserDisplayName
);
111 IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest
,
112 PRE_PRE_PRE_CreateAndRemoveSupervisedUser
) {
116 IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest
,
117 PRE_PRE_CreateAndRemoveSupervisedUser
) {
118 StartFlowLoginAsManager();
119 FillNewUserData(kTestSupervisedUserDisplayName
);
120 StartUserCreation("supervised-user-creation-next-button",
121 kTestSupervisedUserDisplayName
);
124 IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest
,
125 PRE_CreateAndRemoveSupervisedUser
) {
126 SigninAsSupervisedUser(true, 0, kTestSupervisedUserDisplayName
);
129 IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest
,
130 CreateAndRemoveSupervisedUser
) {
131 RemoveSupervisedUser(3, 0, kTestSupervisedUserDisplayName
);
134 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest
,
135 PRE_PRE_CreateAndCancelSupervisedUser
) {
139 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest
,
140 PRE_CreateAndCancelSupervisedUser
) {
141 StartFlowLoginAsManager();
142 FillNewUserData(kTestSupervisedUserDisplayName
);
144 EXPECT_CALL(*mock_homedir_methods_
, MountEx(_
, _
, _
, _
)).Times(1);
145 EXPECT_CALL(*mock_homedir_methods_
, AddKeyEx(_
, _
, _
, _
, _
)).Times(1);
147 JSEval("$('supervised-user-creation-next-button').click()");
149 testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_
);
151 EXPECT_TRUE(registration_utility_stub_
->register_was_called());
152 EXPECT_EQ(registration_utility_stub_
->display_name(),
153 base::UTF8ToUTF16(kTestSupervisedUserDisplayName
));
155 std::string user_id
= registration_utility_stub_
->supervised_user_id();
157 // Make sure user is already in list.
158 ASSERT_EQ(3UL, user_manager::UserManager::Get()->GetUsers().size());
160 // We wait for token now. Press cancel button at this point.
161 JSEvalOrExitBrowser("$('cancel-add-user-button').click()");
164 IN_PROC_BROWSER_TEST_(
165 SupervisedUserTransactionCleanupTest
,
166 CreateAndCancelSupervisedUser
,
167 SupervisedUserTransactionCleanupTest2
,
168 testing::internal::GetTypeId
<SupervisedUserTransactionCleanupTest
>()) {
169 // Make sure there is no supervised user in list.
170 ASSERT_EQ(2UL, user_manager::UserManager::Get()->GetUsers().size());
173 } // namespace chromeos