| 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/fake_chrome_user_manager.h" |
| 21 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 21 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace settings { | 24 namespace settings { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 #if defined(OS_CHROMEOS) |
| 29 constexpr char fake_id[] = "fake_id"; |
| 30 constexpr char fake_email[] = "fake_id@gmail.com"; |
| 31 #endif |
| 32 |
| 28 class TestProfileInfoHandler : public ProfileInfoHandler { | 33 class TestProfileInfoHandler : public ProfileInfoHandler { |
| 29 public: | 34 public: |
| 30 explicit TestProfileInfoHandler(Profile* profile) | 35 explicit TestProfileInfoHandler(Profile* profile) |
| 31 : ProfileInfoHandler(profile) {} | 36 : ProfileInfoHandler(profile) {} |
| 32 | 37 |
| 33 using ProfileInfoHandler::set_web_ui; | 38 using ProfileInfoHandler::set_web_ui; |
| 34 }; | 39 }; |
| 35 | 40 |
| 36 } // namespace | 41 } // namespace |
| 37 | 42 |
| 38 class ProfileInfoHandlerTest : public testing::Test { | 43 class ProfileInfoHandlerTest : public testing::Test { |
| 39 public: | 44 public: |
| 40 ProfileInfoHandlerTest() | 45 ProfileInfoHandlerTest() |
| 41 : profile_manager_(TestingBrowserProcess::GetGlobal()), | 46 : profile_manager_(TestingBrowserProcess::GetGlobal()), |
| 42 #if defined(OS_CHROMEOS) | 47 profile_(nullptr) {} |
| 43 user_manager_enabler_(new chromeos::FakeChromeUserManager), | |
| 44 #endif | |
| 45 profile_(nullptr) { | |
| 46 } | |
| 47 | 48 |
| 48 void SetUp() override { | 49 void SetUp() override { |
| 49 ASSERT_TRUE(profile_manager_.SetUp()); | 50 ASSERT_TRUE(profile_manager_.SetUp()); |
| 50 | 51 |
| 51 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
| 52 profile_ = profile_manager_.CreateTestingProfile("fake_id@gmail.com"); | 53 chromeos::FakeChromeUserManager* fake_user_manager = |
| 54 new chromeos::FakeChromeUserManager; |
| 55 user_manager_enabler_.reset( |
| 56 new chromeos::ScopedUserManagerEnabler(fake_user_manager)); |
| 57 profile_ = profile_manager_.CreateTestingProfile(fake_email); |
| 58 fake_user_manager->AddUser(AccountId::FromUserEmail(fake_email)); |
| 53 #else | 59 #else |
| 54 profile_ = profile_manager_.CreateTestingProfile("Profile 1"); | 60 profile_ = profile_manager_.CreateTestingProfile("Profile 1"); |
| 55 #endif | 61 #endif |
| 56 | 62 |
| 57 handler_.reset(new TestProfileInfoHandler(profile_)); | 63 handler_.reset(new TestProfileInfoHandler(profile_)); |
| 58 handler_->set_web_ui(&web_ui_); | 64 handler_->set_web_ui(&web_ui_); |
| 59 } | 65 } |
| 60 | 66 |
| 61 void VerifyProfileInfo(const base::Value* call_argument) { | 67 void VerifyProfileInfo(const base::Value* call_argument) { |
| 62 const base::DictionaryValue* response = nullptr; | 68 const base::DictionaryValue* response = nullptr; |
| 63 ASSERT_TRUE(call_argument->GetAsDictionary(&response)); | 69 ASSERT_TRUE(call_argument->GetAsDictionary(&response)); |
| 64 | 70 |
| 65 std::string name; | 71 std::string name; |
| 66 std::string icon_url; | 72 std::string icon_url; |
| 67 ASSERT_TRUE(response->GetString("name", &name)); | 73 ASSERT_TRUE(response->GetString("name", &name)); |
| 68 ASSERT_TRUE(response->GetString("iconUrl", &icon_url)); | 74 ASSERT_TRUE(response->GetString("iconUrl", &icon_url)); |
| 69 | 75 |
| 70 #if defined(OS_CHROMEOS) | 76 #if defined(OS_CHROMEOS) |
| 71 EXPECT_EQ("fake_id@gmail.com", name); | 77 EXPECT_EQ(fake_id, name); |
| 72 EXPECT_FALSE(icon_url.empty()); | 78 EXPECT_FALSE(icon_url.empty()); |
| 73 #else | 79 #else |
| 74 EXPECT_EQ("Profile 1", name); | 80 EXPECT_EQ("Profile 1", name); |
| 75 EXPECT_EQ("chrome://theme/IDR_PROFILE_AVATAR_0", icon_url); | 81 EXPECT_EQ("chrome://theme/IDR_PROFILE_AVATAR_0", icon_url); |
| 76 #endif | 82 #endif |
| 77 } | 83 } |
| 78 | 84 |
| 79 content::TestWebUI* web_ui() { return &web_ui_; } | 85 content::TestWebUI* web_ui() { return &web_ui_; } |
| 80 Profile* profile() const { return profile_; } | 86 Profile* profile() const { return profile_; } |
| 81 TestProfileInfoHandler* handler() const { return handler_.get(); } | 87 TestProfileInfoHandler* handler() const { return handler_.get(); } |
| 82 | 88 |
| 83 private: | 89 private: |
| 84 content::TestBrowserThreadBundle thread_bundle_; | 90 content::TestBrowserThreadBundle thread_bundle_; |
| 85 TestingProfileManager profile_manager_; | 91 TestingProfileManager profile_manager_; |
| 86 content::TestWebUI web_ui_; | 92 content::TestWebUI web_ui_; |
| 87 | 93 |
| 88 #if defined(OS_CHROMEOS) | 94 #if defined(OS_CHROMEOS) |
| 89 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 95 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 90 #endif | 96 #endif |
| 91 | 97 |
| 92 Profile* profile_; | 98 Profile* profile_; |
| 93 std::unique_ptr<TestProfileInfoHandler> handler_; | 99 std::unique_ptr<TestProfileInfoHandler> handler_; |
| 94 }; | 100 }; |
| 95 | 101 |
| 96 TEST_F(ProfileInfoHandlerTest, GetProfileInfo) { | 102 TEST_F(ProfileInfoHandlerTest, GetProfileInfo) { |
| 97 base::ListValue list_args; | 103 base::ListValue list_args; |
| 98 list_args.AppendString("get-profile-info-callback-id"); | 104 list_args.AppendString("get-profile-info-callback-id"); |
| 99 handler()->HandleGetProfileInfo(&list_args); | 105 handler()->HandleGetProfileInfo(&list_args); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); | 180 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); |
| 175 EXPECT_EQ(ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName, | 181 EXPECT_EQ(ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName, |
| 176 event_id); | 182 event_id); |
| 177 | 183 |
| 178 bool has_supervised_users = false; | 184 bool has_supervised_users = false; |
| 179 ASSERT_TRUE(data.arg2()->GetAsBoolean(&has_supervised_users)); | 185 ASSERT_TRUE(data.arg2()->GetAsBoolean(&has_supervised_users)); |
| 180 EXPECT_TRUE(has_supervised_users); | 186 EXPECT_TRUE(has_supervised_users); |
| 181 } | 187 } |
| 182 | 188 |
| 183 } // namespace settings | 189 } // namespace settings |
| OLD | NEW |