| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 5 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" |
| 7 #include "base/task_runner.h" | 8 #include "base/task_runner.h" |
| 8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" | 9 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" |
| 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 10 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 11 #include "chrome/test/base/testing_profile.h" |
| 10 | 12 |
| 11 namespace { | 13 namespace { |
| 12 | 14 |
| 13 class FakeTaskRunner : public base::TaskRunner { | 15 class FakeTaskRunner : public base::TaskRunner { |
| 14 public: | 16 public: |
| 15 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | 17 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 16 const base::Closure& task, | 18 const base::Closure& task, |
| 17 base::TimeDelta delay) override { | 19 base::TimeDelta delay) override { |
| 18 task.Run(); | 20 task.Run(); |
| 19 return true; | 21 return true; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 UserFlow* MockUserManager::GetUserFlow(const std::string&) const { | 100 UserFlow* MockUserManager::GetUserFlow(const std::string&) const { |
| 99 return user_flow_.get(); | 101 return user_flow_.get(); |
| 100 } | 102 } |
| 101 | 103 |
| 102 user_manager::User* MockUserManager::CreatePublicAccountUser( | 104 user_manager::User* MockUserManager::CreatePublicAccountUser( |
| 103 const std::string& email) { | 105 const std::string& email) { |
| 104 ClearUserList(); | 106 ClearUserList(); |
| 105 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email); | 107 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email); |
| 106 user_list_.push_back(user); | 108 user_list_.push_back(user); |
| 107 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); | 109 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); |
| 110 |
| 111 TestingProfile* profile = new TestingProfile(); |
| 112 profile->set_profile_name(email); |
| 113 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, profile); |
| 114 profile_list_.push_back(profile); |
| 115 |
| 108 return user_list_.back(); | 116 return user_list_.back(); |
| 109 } | 117 } |
| 110 | 118 |
| 111 void MockUserManager::AddUser(const std::string& email) { | 119 void MockUserManager::AddUser(const std::string& email) { |
| 112 user_manager::User* user = user_manager::User::CreateRegularUser(email); | 120 user_manager::User* user = user_manager::User::CreateRegularUser(email); |
| 113 user_list_.push_back(user); | 121 user_list_.push_back(user); |
| 114 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); | 122 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); |
| 123 |
| 124 TestingProfile* profile = new TestingProfile(); |
| 125 profile->set_profile_name(email); |
| 126 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, profile); |
| 127 profile_list_.push_back(profile); |
| 115 } | 128 } |
| 116 | 129 |
| 117 void MockUserManager::ClearUserList() { | 130 void MockUserManager::ClearUserList() { |
| 118 // Can't use STLDeleteElements because of the protected destructor of User. | 131 // Can't use STLDeleteElements because of the protected destructor of User. |
| 119 user_manager::UserList::iterator user; | 132 user_manager::UserList::iterator user; |
| 120 for (user = user_list_.begin(); user != user_list_.end(); ++user) | 133 for (user = user_list_.begin(); user != user_list_.end(); ++user) |
| 121 delete *user; | 134 delete *user; |
| 122 user_list_.clear(); | 135 user_list_.clear(); |
| 136 |
| 137 STLDeleteElements(&profile_list_); |
| 123 } | 138 } |
| 124 | 139 |
| 125 } // namespace chromeos | 140 } // namespace chromeos |
| OLD | NEW |