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

Side by Side Diff: chrome/browser/password_manager/credential_manager_browsertest.cc

Issue 2605483002: Remove usages of raw new (Closed)
Patch Set: Created 3 years, 12 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/macros.h" 5 #include "base/macros.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/password_manager/password_manager_test_base.h" 8 #include "chrome/browser/password_manager/password_manager_test_base.h"
9 #include "chrome/browser/password_manager/password_store_factory.h" 9 #include "chrome/browser/password_manager/password_store_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 signin_form, 207 signin_form,
208 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); 208 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
209 209
210 NavigationObserver observer(WebContents()); 210 NavigationObserver observer(WebContents());
211 observer.SetPathToWaitFor("/password/done.html"); 211 observer.SetPathToWaitFor("/password/done.html");
212 observer.Wait(); 212 observer.Wait();
213 213
214 // Wait for the password store before checking the prompt because it pops up 214 // Wait for the password store before checking the prompt because it pops up
215 // after the store replies. 215 // after the store replies.
216 WaitForPasswordStore(); 216 WaitForPasswordStore();
217 std::unique_ptr<BubbleObserver> prompt_observer( 217 auto prompt_observer(base::MakeUnique<BubbleObserver>(WebContents()));
jdoerrie 2016/12/23 10:01:11 Thinking of it, all of these usages could be repla
vabr (Chromium) 2016/12/23 10:03:46 That would be great! I think these are smart point
jdoerrie 2016/12/23 10:22:51 Done. Thanks for the explanation :)
218 new BubbleObserver(WebContents()));
219 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 218 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
220 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); 219 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt());
221 220
222 // There should be an entry for both psl.example.com and www.example.com. 221 // There should be an entry for both psl.example.com and www.example.com.
223 password_manager::TestPasswordStore::PasswordMap passwords = 222 password_manager::TestPasswordStore::PasswordMap passwords =
224 password_store->stored_passwords(); 223 password_store->stored_passwords();
225 GURL www_url = https_test_server.GetURL("www.example.com", "/"); 224 GURL www_url = https_test_server.GetURL("www.example.com", "/");
226 EXPECT_EQ(2U, passwords.size()); 225 EXPECT_EQ(2U, passwords.size());
227 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec())); 226 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec()));
228 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec())); 227 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec()));
(...skipping 27 matching lines...) Expand all
256 // Call the API to trigger the notification to the client. 255 // Call the API to trigger the notification to the client.
257 ASSERT_TRUE(content::ExecuteScript( 256 ASSERT_TRUE(content::ExecuteScript(
258 RenderViewHost(), 257 RenderViewHost(),
259 "navigator.credentials.get({password: true})" 258 "navigator.credentials.get({password: true})"
260 ".then(cred => window.location = '/password/done.html');")); 259 ".then(cred => window.location = '/password/done.html');"));
261 260
262 NavigationObserver observer(WebContents()); 261 NavigationObserver observer(WebContents());
263 observer.SetPathToWaitFor("/password/done.html"); 262 observer.SetPathToWaitFor("/password/done.html");
264 observer.Wait(); 263 observer.Wait();
265 264
266 std::unique_ptr<BubbleObserver> prompt_observer( 265 auto prompt_observer(base::MakeUnique<BubbleObserver>(WebContents()));
267 new BubbleObserver(WebContents()));
268 // The autofill password manager shouldn't react to the successful login 266 // The autofill password manager shouldn't react to the successful login
269 // because it was suppressed when the site got the credential back. 267 // because it was suppressed when the site got the credential back.
270 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 268 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
271 } 269 }
272 270
273 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, SaveViaAPIAndAutofill) { 271 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, SaveViaAPIAndAutofill) {
274 NavigateToFile("/password/password_form.html"); 272 NavigateToFile("/password/password_form.html");
275 273
276 ASSERT_TRUE(content::ExecuteScript( 274 ASSERT_TRUE(content::ExecuteScript(
277 RenderViewHost(), 275 RenderViewHost(),
278 "document.getElementById('input_submit_button').addEventListener('click'," 276 "document.getElementById('input_submit_button').addEventListener('click',"
279 "function(event) {" 277 "function(event) {"
280 "var c = new PasswordCredential({ id: 'user', password: 'API' });" 278 "var c = new PasswordCredential({ id: 'user', password: 'API' });"
281 "navigator.credentials.store(c);" 279 "navigator.credentials.store(c);"
282 "});")); 280 "});"));
283 // Fill the password and click the button to submit the page. The API should 281 // Fill the password and click the button to submit the page. The API should
284 // suppress the autofill password manager. 282 // suppress the autofill password manager.
285 NavigationObserver form_submit_observer(WebContents()); 283 NavigationObserver form_submit_observer(WebContents());
286 ASSERT_TRUE(content::ExecuteScript( 284 ASSERT_TRUE(content::ExecuteScript(
287 RenderViewHost(), 285 RenderViewHost(),
288 "document.getElementById('username_field').value = 'user';" 286 "document.getElementById('username_field').value = 'user';"
289 "document.getElementById('password_field').value = 'autofill';" 287 "document.getElementById('password_field').value = 'autofill';"
290 "document.getElementById('input_submit_button').click();")); 288 "document.getElementById('input_submit_button').click();"));
291 form_submit_observer.Wait(); 289 form_submit_observer.Wait();
292 290
293 WaitForPasswordStore(); 291 WaitForPasswordStore();
294 std::unique_ptr<BubbleObserver> prompt_observer( 292 auto prompt_observer(base::MakeUnique<BubbleObserver>(WebContents()));
295 new BubbleObserver(WebContents()));
296 ASSERT_TRUE(prompt_observer->IsShowingSavePrompt()); 293 ASSERT_TRUE(prompt_observer->IsShowingSavePrompt());
297 prompt_observer->AcceptSavePrompt(); 294 prompt_observer->AcceptSavePrompt();
298 295
299 WaitForPasswordStore(); 296 WaitForPasswordStore();
300 password_manager::TestPasswordStore::PasswordMap stored = 297 password_manager::TestPasswordStore::PasswordMap stored =
301 static_cast<password_manager::TestPasswordStore*>( 298 static_cast<password_manager::TestPasswordStore*>(
302 PasswordStoreFactory::GetForProfile( 299 PasswordStoreFactory::GetForProfile(
303 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 300 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
304 .get())->stored_passwords(); 301 .get())->stored_passwords();
305 ASSERT_EQ(1u, stored.size()); 302 ASSERT_EQ(1u, stored.size());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 ASSERT_TRUE(content::ExecuteScript( 340 ASSERT_TRUE(content::ExecuteScript(
344 RenderViewHost(), 341 RenderViewHost(),
345 "document.getElementById('username_field').value = 'user';" 342 "document.getElementById('username_field').value = 'user';"
346 "document.getElementById('password_field').value = 'autofill';" 343 "document.getElementById('password_field').value = 'autofill';"
347 "document.getElementById('input_submit_button').click();")); 344 "document.getElementById('input_submit_button').click();"));
348 form_submit_observer.Wait(); 345 form_submit_observer.Wait();
349 346
350 // Wait for the password store before checking the prompt because it pops up 347 // Wait for the password store before checking the prompt because it pops up
351 // after the store replies. 348 // after the store replies.
352 WaitForPasswordStore(); 349 WaitForPasswordStore();
353 std::unique_ptr<BubbleObserver> prompt_observer( 350 auto prompt_observer(base::MakeUnique<BubbleObserver>(WebContents()));
354 new BubbleObserver(WebContents()));
355 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 351 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
356 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); 352 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt());
357 signin_form.skip_zero_click = false; 353 signin_form.skip_zero_click = false;
358 signin_form.times_used = 1; 354 signin_form.times_used = 1;
359 signin_form.password_value = base::ASCIIToUTF16("API"); 355 signin_form.password_value = base::ASCIIToUTF16("API");
360 password_manager::TestPasswordStore::PasswordMap stored = 356 password_manager::TestPasswordStore::PasswordMap stored =
361 password_store->stored_passwords(); 357 password_store->stored_passwords();
362 ASSERT_EQ(1u, stored.size()); 358 ASSERT_EQ(1u, stored.size());
363 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); 359 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]);
364 } 360 }
365 361
366 } // namespace 362 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698