Chromium Code Reviews| 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/test/base/testing_browser_process.h" | 9 #include "chrome/test/base/testing_browser_process.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
| 51 profile_ = profile_manager_.CreateTestingProfile("fake_id@gmail.com"); | 51 profile_ = profile_manager_.CreateTestingProfile("fake_id@gmail.com"); |
| 52 #else | 52 #else |
| 53 profile_ = profile_manager_.CreateTestingProfile("Profile 1"); | 53 profile_ = profile_manager_.CreateTestingProfile("Profile 1"); |
| 54 #endif | 54 #endif |
| 55 | 55 |
| 56 handler_.reset(new TestProfileInfoHandler(profile_)); | 56 handler_.reset(new TestProfileInfoHandler(profile_)); |
| 57 handler_->set_web_ui(&web_ui_); | 57 handler_->set_web_ui(&web_ui_); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void VerifyResponse(const base::Value* call_argument) { | 60 void VerifyProfileInfo(const base::Value* call_argument) { |
| 61 const base::DictionaryValue* response = nullptr; | 61 const base::DictionaryValue* response = nullptr; |
| 62 ASSERT_TRUE(call_argument->GetAsDictionary(&response)); | 62 ASSERT_TRUE(call_argument->GetAsDictionary(&response)); |
| 63 | 63 |
| 64 std::string name; | 64 std::string name; |
| 65 std::string icon_url; | 65 std::string icon_url; |
| 66 ASSERT_TRUE(response->GetString("name", &name)); | 66 ASSERT_TRUE(response->GetString("name", &name)); |
| 67 ASSERT_TRUE(response->GetString("iconUrl", &icon_url)); | 67 ASSERT_TRUE(response->GetString("iconUrl", &icon_url)); |
| 68 | 68 |
| 69 #if defined(OS_CHROMEOS) | 69 #if defined(OS_CHROMEOS) |
| 70 EXPECT_EQ("fake_id@gmail.com", name); | 70 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()); | 105 EXPECT_EQ("cr.webUIResponse", data.function_name()); |
| 106 | 106 |
| 107 std::string callback_id; | 107 std::string callback_id; |
| 108 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); | 108 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
| 109 EXPECT_EQ("get-profile-info-callback-id", callback_id); | 109 EXPECT_EQ("get-profile-info-callback-id", callback_id); |
| 110 | 110 |
| 111 bool success = false; | 111 bool success = false; |
| 112 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); | 112 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); |
| 113 EXPECT_TRUE(success); | 113 EXPECT_TRUE(success); |
| 114 | 114 |
| 115 VerifyResponse(data.arg3()); | 115 VerifyProfileInfo(data.arg3()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST_F(ProfileInfoHandlerTest, PushProfileInfo) { | 118 TEST_F(ProfileInfoHandlerTest, PushProfileInfo) { |
| 119 base::ListValue list_args; | 119 handler()->AllowJavascript(); |
| 120 list_args.AppendString("get-profile-info-callback-id"); | |
| 121 handler()->HandleGetProfileInfo(&list_args); | |
| 122 | 120 |
| 123 handler()->OnProfileAvatarChanged(base::FilePath()); | 121 handler()->OnProfileAvatarChanged(base::FilePath()); |
| 124 | 122 |
| 125 EXPECT_EQ(2U, web_ui()->call_data().size()); | 123 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 126 | 124 |
| 127 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); | 125 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); |
| 128 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); | 126 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); |
| 129 | 127 |
| 130 std::string event_id; | 128 std::string event_id; |
| 131 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); | 129 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); |
| 132 EXPECT_EQ(ProfileInfoHandler::kProfileInfoChangedEventName, event_id); | 130 EXPECT_EQ(ProfileInfoHandler::kProfileInfoChangedEventName, event_id); |
| 133 | 131 |
| 134 VerifyResponse(data.arg2()); | 132 VerifyProfileInfo(data.arg2()); |
| 133 } | |
| 134 | |
| 135 TEST_F(ProfileInfoHandlerTest, GetProfileManagesSupervisedUsers) { | |
| 136 base::ListValue list_args; | |
| 137 list_args.AppendString("get-profile-manages-supervised-users-callback-id"); | |
| 138 handler()->HandleGetProfileManagesSupervisedUsers(&list_args); | |
| 139 | |
| 140 EXPECT_EQ(1U, web_ui()->call_data().size()); | |
| 141 | |
| 142 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); | |
| 143 EXPECT_EQ("cr.webUIResponse", data.function_name()); | |
| 144 | |
| 145 std::string callback_id; | |
| 146 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); | |
| 147 EXPECT_EQ("get-profile-manages-supervised-users-callback-id", callback_id); | |
| 148 | |
| 149 bool success = false; | |
| 150 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); | |
| 151 EXPECT_TRUE(success); | |
| 152 | |
| 153 bool has_supervised_users = false; | |
| 154 ASSERT_TRUE(data.arg3()->GetAsBoolean(&has_supervised_users)); | |
| 155 EXPECT_FALSE(has_supervised_users); | |
| 156 } | |
| 157 | |
| 158 TEST_F(ProfileInfoHandlerTest, PushProfileManagesSupervisedUsers) { | |
| 159 handler()->AllowJavascript(); | |
| 160 | |
| 161 handler()->PushProfileManagesSupervisedUsersStatus(); | |
| 162 | |
| 163 EXPECT_EQ(1U, web_ui()->call_data().size()); | |
| 164 | |
| 165 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); | |
| 166 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); | |
| 167 | |
| 168 std::string event_id; | |
| 169 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); | |
| 170 EXPECT_EQ(ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName, | |
| 171 event_id); | |
| 172 | |
| 173 bool has_supervised_users = false; | |
| 174 ASSERT_TRUE(data.arg2()->GetAsBoolean(&has_supervised_users)); | |
| 175 EXPECT_FALSE(has_supervised_users); | |
|
hcarmona
2016/06/10 22:58:08
Is it possible to add a test where |has_supervised
tommycli
2016/06/10 23:28:45
Done. Yes, I was able to enhance the test using th
| |
| 135 } | 176 } |
| 136 | 177 |
| 137 } // namespace settings | 178 } // namespace settings |
| OLD | NEW |