| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/webui/settings/profile_info_handler.h" | 5 #include "chrome/browser/ui/webui/settings/profile_info_handler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/test/base/testing_browser_process.h" | 10 #include "chrome/test/base/testing_browser_process.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "chrome/test/base/testing_profile_manager.h" | 12 #include "chrome/test/base/testing_profile_manager.h" |
| 13 #include "components/prefs/scoped_user_pref_update.h" | 13 #include "components/prefs/scoped_user_pref_update.h" |
| 14 #include "content/public/browser/web_ui_data_source.h" | 14 #include "content/public/browser/web_ui_data_source.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "content/public/test/test_web_ui.h" | 16 #include "content/public/test/test_web_ui.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
| 20 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 21 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 21 #include "components/user_manager/fake_user_manager.h" | |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace settings { | 24 namespace settings { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class TestProfileInfoHandler : public ProfileInfoHandler { | 28 class TestProfileInfoHandler : public ProfileInfoHandler { |
| 29 public: | 29 public: |
| 30 explicit TestProfileInfoHandler(Profile* profile) | 30 explicit TestProfileInfoHandler(Profile* profile) |
| 31 : ProfileInfoHandler(profile) {} | 31 : ProfileInfoHandler(profile) {} |
| 32 | 32 |
| 33 using ProfileInfoHandler::set_web_ui; | 33 using ProfileInfoHandler::set_web_ui; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 class ProfileInfoHandlerTest : public testing::Test { | 38 class ProfileInfoHandlerTest : public testing::Test { |
| 39 public: | 39 public: |
| 40 ProfileInfoHandlerTest() | 40 ProfileInfoHandlerTest() |
| 41 : profile_manager_(TestingBrowserProcess::GetGlobal()), | 41 : profile_manager_(TestingBrowserProcess::GetGlobal()), |
| 42 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
| 43 user_manager_(new user_manager::FakeUserManager), | 43 user_manager_enabler_(new chromeos::FakeChromeUserManager), |
| 44 user_manager_enabler_(user_manager_), | |
| 45 #endif | 44 #endif |
| 46 profile_(nullptr) { | 45 profile_(nullptr) { |
| 47 } | 46 } |
| 48 | 47 |
| 49 void SetUp() override { | 48 void SetUp() override { |
| 50 ASSERT_TRUE(profile_manager_.SetUp()); | 49 ASSERT_TRUE(profile_manager_.SetUp()); |
| 51 | 50 |
| 52 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 53 profile_ = profile_manager_.CreateTestingProfile("fake_id@gmail.com"); | 52 profile_ = profile_manager_.CreateTestingProfile("fake_id@gmail.com"); |
| 54 #else | 53 #else |
| (...skipping 25 matching lines...) Expand all Loading... |
| 80 content::TestWebUI* web_ui() { return &web_ui_; } | 79 content::TestWebUI* web_ui() { return &web_ui_; } |
| 81 Profile* profile() const { return profile_; } | 80 Profile* profile() const { return profile_; } |
| 82 TestProfileInfoHandler* handler() const { return handler_.get(); } | 81 TestProfileInfoHandler* handler() const { return handler_.get(); } |
| 83 | 82 |
| 84 private: | 83 private: |
| 85 content::TestBrowserThreadBundle thread_bundle_; | 84 content::TestBrowserThreadBundle thread_bundle_; |
| 86 TestingProfileManager profile_manager_; | 85 TestingProfileManager profile_manager_; |
| 87 content::TestWebUI web_ui_; | 86 content::TestWebUI web_ui_; |
| 88 | 87 |
| 89 #if defined(OS_CHROMEOS) | 88 #if defined(OS_CHROMEOS) |
| 90 // |user_manager_| is destroyed by |user_manager_enabler_|. | |
| 91 user_manager::FakeUserManager* user_manager_; | |
| 92 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 89 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 93 #endif | 90 #endif |
| 94 | 91 |
| 95 Profile* profile_; | 92 Profile* profile_; |
| 96 std::unique_ptr<TestProfileInfoHandler> handler_; | 93 std::unique_ptr<TestProfileInfoHandler> handler_; |
| 97 }; | 94 }; |
| 98 | 95 |
| 99 TEST_F(ProfileInfoHandlerTest, GetProfileInfo) { | 96 TEST_F(ProfileInfoHandlerTest, GetProfileInfo) { |
| 100 base::ListValue list_args; | 97 base::ListValue list_args; |
| 101 list_args.AppendString("get-profile-info-callback-id"); | 98 list_args.AppendString("get-profile-info-callback-id"); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); | 174 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); |
| 178 EXPECT_EQ(ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName, | 175 EXPECT_EQ(ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName, |
| 179 event_id); | 176 event_id); |
| 180 | 177 |
| 181 bool has_supervised_users = false; | 178 bool has_supervised_users = false; |
| 182 ASSERT_TRUE(data.arg2()->GetAsBoolean(&has_supervised_users)); | 179 ASSERT_TRUE(data.arg2()->GetAsBoolean(&has_supervised_users)); |
| 183 EXPECT_TRUE(has_supervised_users); | 180 EXPECT_TRUE(has_supervised_users); |
| 184 } | 181 } |
| 185 | 182 |
| 186 } // namespace settings | 183 } // namespace settings |
| OLD | NEW |