Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / signin_userlist_unittest.cc
blobed1d6f39f4627d511a416a400afaa12ec22507d4
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/compiler_specific.h"
6 #include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
7 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
8 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
9 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller_delegate.h"
10 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
11 #include "chrome/test/base/testing_browser_process.h"
12 #include "chrome/test/base/testing_profile_manager.h"
13 #include "components/proximity_auth/screenlock_bridge.h"
14 #include "components/user_manager/user.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace {
19 const size_t kMaxUsers = 18; // same as in user_selection_screen.cc
20 const char* kOwner = "owner@gmail.com";
21 const char* kUsersPublic[] = {"public0@gmail.com", "public1@gmail.com"};
22 const char* kUsers[] = {
23 "a0@gmail.com", "a1@gmail.com", "a2@gmail.com", "a3@gmail.com",
24 "a4@gmail.com", "a5@gmail.com", "a6@gmail.com", "a7@gmail.com",
25 "a8@gmail.com", "a9@gmail.com", "a10@gmail.com", "a11@gmail.com",
26 "a12@gmail.com", "a13@gmail.com", "a14@gmail.com", "a15@gmail.com",
27 "a16@gmail.com", "a17@gmail.com", kOwner, "a18@gmail.com"};
29 } // namespace
31 namespace chromeos {
33 class SigninPrepareUserListTest
34 : public testing::Test,
35 public MultiProfileUserControllerDelegate {
36 public:
37 SigninPrepareUserListTest()
38 : fake_user_manager_(new FakeChromeUserManager()),
39 user_manager_enabler_(fake_user_manager_) {}
41 ~SigninPrepareUserListTest() override {}
43 void SetUp() override {
44 profile_manager_.reset(
45 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
46 ASSERT_TRUE(profile_manager_->SetUp());
47 controller_.reset(new MultiProfileUserController(
48 this, TestingBrowserProcess::GetGlobal()->local_state()));
49 fake_user_manager_->set_multi_profile_user_controller(controller_.get());
51 for (size_t i = 0; i < arraysize(kUsersPublic); ++i)
52 fake_user_manager_->AddPublicAccountUser(kUsersPublic[i]);
54 for (size_t i = 0; i < arraysize(kUsers); ++i)
55 fake_user_manager_->AddUser(kUsers[i]);
57 fake_user_manager_->set_owner_email(kOwner);
60 void TearDown() override {
61 controller_.reset();
62 profile_manager_.reset();
65 // MultiProfileUserControllerDelegate overrides:
66 void OnUserNotAllowed(const std::string& user_email) override {}
68 FakeChromeUserManager* fake_user_manager_;
69 ScopedUserManagerEnabler user_manager_enabler_;
70 scoped_ptr<TestingProfileManager> profile_manager_;
71 std::map<std::string, proximity_auth::ScreenlockBridge::LockHandler::AuthType>
72 user_auth_type_map;
73 scoped_ptr<MultiProfileUserController> controller_;
75 DISALLOW_COPY_AND_ASSIGN(SigninPrepareUserListTest);
78 TEST_F(SigninPrepareUserListTest, AlwaysKeepOwnerInList) {
79 EXPECT_LT(kMaxUsers, fake_user_manager_->GetUsers().size());
80 user_manager::UserList users_to_send =
81 UserSelectionScreen::PrepareUserListForSending(
82 fake_user_manager_->GetUsers(), kOwner, true /* is signin to add */);
84 EXPECT_EQ(kMaxUsers, users_to_send.size());
85 EXPECT_EQ(kOwner, users_to_send.back()->email());
87 fake_user_manager_->RemoveUserFromList("a16@gmail.com");
88 fake_user_manager_->RemoveUserFromList("a17@gmail.com");
89 users_to_send = UserSelectionScreen::PrepareUserListForSending(
90 fake_user_manager_->GetUsers(),
91 kOwner,
92 true /* is signin to add */);
94 EXPECT_EQ(kMaxUsers, users_to_send.size());
95 EXPECT_EQ("a18@gmail.com", users_to_send.back()->email());
96 EXPECT_EQ(kOwner, users_to_send[kMaxUsers-2]->email());
99 TEST_F(SigninPrepareUserListTest, PublicAccounts) {
100 user_manager::UserList users_to_send =
101 UserSelectionScreen::PrepareUserListForSending(
102 fake_user_manager_->GetUsers(), kOwner, true /* is signin to add */);
104 EXPECT_EQ(kMaxUsers, users_to_send.size());
105 EXPECT_EQ("a0@gmail.com", users_to_send.front()->email());
107 users_to_send = UserSelectionScreen::PrepareUserListForSending(
108 fake_user_manager_->GetUsers(),
109 kOwner,
110 false /* is signin to add */);
112 EXPECT_EQ(kMaxUsers, users_to_send.size());
113 EXPECT_EQ("public0@gmail.com", users_to_send.front()->email());
116 } // namespace chromeos