Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/ui/webui/signin/signin_supervised_user_import_handler_unittest.cc

Issue 2030013003: Remove ListValue::Append(new {Fundamental,String}Value(...)) pattern in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/signin/signin_supervised_user_import_handler.h " 5 #include "chrome/browser/ui/webui/signin/signin_supervised_user_import_handler.h "
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "chrome/browser/signin/fake_signin_manager_builder.h" 9 #include "chrome/browser/signin/fake_signin_manager_builder.h"
10 #include "chrome/browser/signin/signin_error_controller_factory.h" 10 #include "chrome/browser/signin/signin_error_controller_factory.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Stop Sync before signing out. 168 // Stop Sync before signing out.
169 SupervisedUserSyncService* sync_service_ = 169 SupervisedUserSyncService* sync_service_ =
170 SupervisedUserSyncServiceFactory::GetForProfile(profile()); 170 SupervisedUserSyncServiceFactory::GetForProfile(profile());
171 sync_service_->StopSyncing(syncer::SUPERVISED_USERS); 171 sync_service_->StopSyncing(syncer::SUPERVISED_USERS);
172 172
173 // Sign out the user. 173 // Sign out the user.
174 signin_manager()->ForceSignOut(); 174 signin_manager()->ForceSignOut();
175 175
176 // Test the JS -> C++ -> JS callback path. 176 // Test the JS -> C++ -> JS callback path.
177 base::ListValue list_args; 177 base::ListValue list_args;
178 list_args.Append(new base::StringValue(kTestCallbackId)); 178 list_args.AppendString(kTestCallbackId);
179 list_args.Append(new base::StringValue(profile()->GetPath().AsUTF16Unsafe())); 179 list_args.AppendString(profile()->GetPath().AsUTF16Unsafe());
180 handler()->GetExistingSupervisedUsers(&list_args); 180 handler()->GetExistingSupervisedUsers(&list_args);
181 181
182 // Expect an error response. 182 // Expect an error response.
183 VerifyResponse(1U, kTestCallbackId, false); 183 VerifyResponse(1U, kTestCallbackId, false);
184 184
185 base::string16 expected_error_message = l10n_util::GetStringUTF16( 185 base::string16 expected_error_message = l10n_util::GetStringUTF16(
186 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR); 186 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR);
187 base::string16 error_message; 187 base::string16 error_message;
188 ASSERT_TRUE(web_ui()->call_data()[0]->arg3()->GetAsString(&error_message)); 188 ASSERT_TRUE(web_ui()->call_data()[0]->arg3()->GetAsString(&error_message));
189 EXPECT_EQ(expected_error_message, error_message); 189 EXPECT_EQ(expected_error_message, error_message);
190 } 190 }
191 191
192 TEST_F(SigninSupervisedUserImportHandlerTest, AuthError) { 192 TEST_F(SigninSupervisedUserImportHandlerTest, AuthError) {
193 // Set Auth Error. 193 // Set Auth Error.
194 const GoogleServiceAuthError error( 194 const GoogleServiceAuthError error(
195 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 195 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
196 FakeAuthStatusProvider provider( 196 FakeAuthStatusProvider provider(
197 SigninErrorControllerFactory::GetForProfile(profile())); 197 SigninErrorControllerFactory::GetForProfile(profile()));
198 provider.SetAuthError(kTestGaiaId, error); 198 provider.SetAuthError(kTestGaiaId, error);
199 199
200 // Test the JS -> C++ -> JS callback path. 200 // Test the JS -> C++ -> JS callback path.
201 base::ListValue list_args; 201 base::ListValue list_args;
202 list_args.Append(new base::StringValue(kTestCallbackId)); 202 list_args.AppendString(kTestCallbackId);
203 list_args.Append(new base::StringValue(profile()->GetPath().AsUTF16Unsafe())); 203 list_args.AppendString(profile()->GetPath().AsUTF16Unsafe());
204 handler()->GetExistingSupervisedUsers(&list_args); 204 handler()->GetExistingSupervisedUsers(&list_args);
205 205
206 // Expect an error response. 206 // Expect an error response.
207 VerifyResponse(1U, kTestCallbackId, false); 207 VerifyResponse(1U, kTestCallbackId, false);
208 208
209 base::string16 expected_error_message = l10n_util::GetStringUTF16( 209 base::string16 expected_error_message = l10n_util::GetStringUTF16(
210 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR); 210 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR);
211 base::string16 error_message; 211 base::string16 error_message;
212 ASSERT_TRUE(web_ui()->call_data()[0]->arg3()->GetAsString(&error_message)); 212 ASSERT_TRUE(web_ui()->call_data()[0]->arg3()->GetAsString(&error_message));
213 EXPECT_EQ(expected_error_message, error_message); 213 EXPECT_EQ(expected_error_message, error_message);
214 } 214 }
215 215
216 TEST_F(SigninSupervisedUserImportHandlerTest, CustodianIsSupervised) { 216 TEST_F(SigninSupervisedUserImportHandlerTest, CustodianIsSupervised) {
217 // Build a supervised test profile. 217 // Build a supervised test profile.
218 TestingProfile* profile_ = profile_manager()->CreateTestingProfile( 218 TestingProfile* profile_ = profile_manager()->CreateTestingProfile(
219 "supervised-test-profile", 219 "supervised-test-profile",
220 std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), 220 std::unique_ptr<syncable_prefs::PrefServiceSyncable>(),
221 base::UTF8ToUTF16("supervised-test-profile"), 221 base::UTF8ToUTF16("supervised-test-profile"),
222 0, 222 0,
223 "12345", // supervised_user_id 223 "12345", // supervised_user_id
224 TestingProfile::TestingFactories()); 224 TestingProfile::TestingFactories());
225 225
226 // Test the JS -> C++ -> JS callback path. 226 // Test the JS -> C++ -> JS callback path.
227 base::ListValue list_args; 227 base::ListValue list_args;
228 list_args.Append(new base::StringValue(kTestCallbackId)); 228 list_args.AppendString(kTestCallbackId);
229 list_args.Append(new base::StringValue(profile_->GetPath().AsUTF16Unsafe())); 229 list_args.AppendString(profile_->GetPath().AsUTF16Unsafe());
230 handler()->GetExistingSupervisedUsers(&list_args); 230 handler()->GetExistingSupervisedUsers(&list_args);
231 231
232 // Expect to do nothing. 232 // Expect to do nothing.
233 EXPECT_EQ(0U, web_ui()->call_data().size()); 233 EXPECT_EQ(0U, web_ui()->call_data().size());
234 } 234 }
235 235
236 TEST_F(SigninSupervisedUserImportHandlerTest, SendExistingSupervisedUsers) { 236 TEST_F(SigninSupervisedUserImportHandlerTest, SendExistingSupervisedUsers) {
237 // Test the JS -> C++ -> JS callback path. 237 // Test the JS -> C++ -> JS callback path.
238 base::ListValue list_args; 238 base::ListValue list_args;
239 list_args.Append(new base::StringValue(kTestCallbackId)); 239 list_args.AppendString(kTestCallbackId);
240 list_args.Append(new base::StringValue(profile()->GetPath().AsUTF16Unsafe())); 240 list_args.AppendString(profile()->GetPath().AsUTF16Unsafe());
241 handler()->GetExistingSupervisedUsers(&list_args); 241 handler()->GetExistingSupervisedUsers(&list_args);
242 242
243 // Expect a success response. 243 // Expect a success response.
244 VerifyResponse(1U, kTestCallbackId, true); 244 VerifyResponse(1U, kTestCallbackId, true);
245 245
246 const base::ListValue* supervised_users; 246 const base::ListValue* supervised_users;
247 ASSERT_TRUE(web_ui()->call_data()[0]->arg3()->GetAsList(&supervised_users)); 247 ASSERT_TRUE(web_ui()->call_data()[0]->arg3()->GetAsList(&supervised_users));
248 EXPECT_EQ(1U, supervised_users->GetSize()); 248 EXPECT_EQ(1U, supervised_users->GetSize());
249 249
250 const base::DictionaryValue* supervised_user; 250 const base::DictionaryValue* supervised_user;
251 ASSERT_TRUE(supervised_users->GetDictionary(0, &supervised_user)); 251 ASSERT_TRUE(supervised_users->GetDictionary(0, &supervised_user));
252 std::string id; 252 std::string id;
253 ASSERT_TRUE(supervised_user->GetString("id", &id)); 253 ASSERT_TRUE(supervised_user->GetString("id", &id));
254 EXPECT_EQ(kSupervisedUserId, id); 254 EXPECT_EQ(kSupervisedUserId, id);
255 std::string name; 255 std::string name;
256 ASSERT_TRUE(supervised_user->GetString("name", &name)); 256 ASSERT_TRUE(supervised_user->GetString("name", &name));
257 EXPECT_EQ(kSupervisedUsername, name); 257 EXPECT_EQ(kSupervisedUsername, name);
258 std::string iconURL; 258 std::string iconURL;
259 ASSERT_TRUE(supervised_user->GetString("iconURL", &iconURL)); 259 ASSERT_TRUE(supervised_user->GetString("iconURL", &iconURL));
260 EXPECT_EQ(kSupervisedUserAvatarUrl, iconURL); 260 EXPECT_EQ(kSupervisedUserAvatarUrl, iconURL);
261 bool onCurrentDevice; 261 bool onCurrentDevice;
262 ASSERT_TRUE(supervised_user->GetBoolean("onCurrentDevice", &onCurrentDevice)); 262 ASSERT_TRUE(supervised_user->GetBoolean("onCurrentDevice", &onCurrentDevice));
263 ASSERT_FALSE(onCurrentDevice); 263 ASSERT_FALSE(onCurrentDevice);
264 } 264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698