| 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/test/base/testing_browser_process.h" | 10 #include "chrome/test/base/testing_browser_process.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 11 #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" |
| 12 #include "content/public/browser/web_ui_data_source.h" | 14 #include "content/public/browser/web_ui_data_source.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "content/public/test/test_web_ui.h" | 16 #include "content/public/test/test_web_ui.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
| 18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 19 #include "components/user_manager/fake_user_manager.h" | 21 #include "components/user_manager/fake_user_manager.h" |
| 20 #endif | 22 #endif |
| 21 | 23 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 50 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
| 51 profile_ = profile_manager_.CreateTestingProfile("fake_id@gmail.com"); | 53 profile_ = profile_manager_.CreateTestingProfile("fake_id@gmail.com"); |
| 52 #else | 54 #else |
| 53 profile_ = profile_manager_.CreateTestingProfile("Profile 1"); | 55 profile_ = profile_manager_.CreateTestingProfile("Profile 1"); |
| 54 #endif | 56 #endif |
| 55 | 57 |
| 56 handler_.reset(new TestProfileInfoHandler(profile_)); | 58 handler_.reset(new TestProfileInfoHandler(profile_)); |
| 57 handler_->set_web_ui(&web_ui_); | 59 handler_->set_web_ui(&web_ui_); |
| 58 } | 60 } |
| 59 | 61 |
| 60 void VerifyResponse(const base::Value* call_argument) { | 62 void VerifyProfileInfo(const base::Value* call_argument) { |
| 61 const base::DictionaryValue* response = nullptr; | 63 const base::DictionaryValue* response = nullptr; |
| 62 ASSERT_TRUE(call_argument->GetAsDictionary(&response)); | 64 ASSERT_TRUE(call_argument->GetAsDictionary(&response)); |
| 63 | 65 |
| 64 std::string name; | 66 std::string name; |
| 65 std::string icon_url; | 67 std::string icon_url; |
| 66 ASSERT_TRUE(response->GetString("name", &name)); | 68 ASSERT_TRUE(response->GetString("name", &name)); |
| 67 ASSERT_TRUE(response->GetString("iconUrl", &icon_url)); | 69 ASSERT_TRUE(response->GetString("iconUrl", &icon_url)); |
| 68 | 70 |
| 69 #if defined(OS_CHROMEOS) | 71 #if defined(OS_CHROMEOS) |
| 70 EXPECT_EQ("fake_id@gmail.com", name); | 72 EXPECT_EQ("fake_id@gmail.com", name); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 EXPECT_EQ("cr.webUIResponse", data.function_name()); | 107 EXPECT_EQ("cr.webUIResponse", data.function_name()); |
| 106 | 108 |
| 107 std::string callback_id; | 109 std::string callback_id; |
| 108 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); | 110 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
| 109 EXPECT_EQ("get-profile-info-callback-id", callback_id); | 111 EXPECT_EQ("get-profile-info-callback-id", callback_id); |
| 110 | 112 |
| 111 bool success = false; | 113 bool success = false; |
| 112 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); | 114 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); |
| 113 EXPECT_TRUE(success); | 115 EXPECT_TRUE(success); |
| 114 | 116 |
| 115 VerifyResponse(data.arg3()); | 117 VerifyProfileInfo(data.arg3()); |
| 116 } | 118 } |
| 117 | 119 |
| 118 TEST_F(ProfileInfoHandlerTest, PushProfileInfo) { | 120 TEST_F(ProfileInfoHandlerTest, PushProfileInfo) { |
| 119 base::ListValue list_args; | 121 handler()->AllowJavascript(); |
| 120 list_args.AppendString("get-profile-info-callback-id"); | |
| 121 handler()->HandleGetProfileInfo(&list_args); | |
| 122 | 122 |
| 123 handler()->OnProfileAvatarChanged(base::FilePath()); | 123 handler()->OnProfileAvatarChanged(base::FilePath()); |
| 124 | 124 |
| 125 EXPECT_EQ(2U, web_ui()->call_data().size()); | 125 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 126 | 126 |
| 127 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); | 127 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); |
| 128 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); | 128 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); |
| 129 | 129 |
| 130 std::string event_id; | 130 std::string event_id; |
| 131 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); | 131 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); |
| 132 EXPECT_EQ(ProfileInfoHandler::kProfileInfoChangedEventName, event_id); | 132 EXPECT_EQ(ProfileInfoHandler::kProfileInfoChangedEventName, event_id); |
| 133 | 133 |
| 134 VerifyResponse(data.arg2()); | 134 VerifyProfileInfo(data.arg2()); |
| 135 } |
| 136 |
| 137 TEST_F(ProfileInfoHandlerTest, GetProfileManagesSupervisedUsers) { |
| 138 base::ListValue list_args; |
| 139 list_args.AppendString("get-profile-manages-supervised-users-callback-id"); |
| 140 handler()->HandleGetProfileManagesSupervisedUsers(&list_args); |
| 141 |
| 142 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 143 |
| 144 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); |
| 145 EXPECT_EQ("cr.webUIResponse", data.function_name()); |
| 146 |
| 147 std::string callback_id; |
| 148 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
| 149 EXPECT_EQ("get-profile-manages-supervised-users-callback-id", callback_id); |
| 150 |
| 151 bool success = false; |
| 152 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); |
| 153 EXPECT_TRUE(success); |
| 154 |
| 155 bool has_supervised_users = false; |
| 156 ASSERT_TRUE(data.arg3()->GetAsBoolean(&has_supervised_users)); |
| 157 EXPECT_FALSE(has_supervised_users); |
| 158 } |
| 159 |
| 160 TEST_F(ProfileInfoHandlerTest, PushProfileManagesSupervisedUsers) { |
| 161 handler()->AllowJavascript(); |
| 162 |
| 163 // The handler is notified of the change after |update| is destroyed. |
| 164 std::unique_ptr<DictionaryPrefUpdate> update( |
| 165 new DictionaryPrefUpdate(profile()->GetPrefs(), prefs::kSupervisedUsers)); |
| 166 base::DictionaryValue* dict = update->Get(); |
| 167 dict->SetWithoutPathExpansion("supervised-user-id", |
| 168 new base::DictionaryValue); |
| 169 update.reset(); |
| 170 |
| 171 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 172 |
| 173 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); |
| 174 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); |
| 175 |
| 176 std::string event_id; |
| 177 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); |
| 178 EXPECT_EQ(ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName, |
| 179 event_id); |
| 180 |
| 181 bool has_supervised_users = false; |
| 182 ASSERT_TRUE(data.arg2()->GetAsBoolean(&has_supervised_users)); |
| 183 EXPECT_TRUE(has_supervised_users); |
| 135 } | 184 } |
| 136 | 185 |
| 137 } // namespace settings | 186 } // namespace settings |
| OLD | NEW |