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

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

Issue 2900983002: Ignore form action URL when determine if a credential should be autofilled. (Closed)
Patch Set: comments and tests Created 3 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 22 matching lines...) Expand all
33 #include "chrome/common/chrome_paths.h" 33 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/chrome_switches.h" 34 #include "chrome/common/chrome_switches.h"
35 #include "chrome/test/base/ui_test_utils.h" 35 #include "chrome/test/base/ui_test_utils.h"
36 #include "components/autofill/core/browser/autofill_test_utils.h" 36 #include "components/autofill/core/browser/autofill_test_utils.h"
37 #include "components/autofill/core/browser/test_autofill_client.h" 37 #include "components/autofill/core/browser/test_autofill_client.h"
38 #include "components/autofill/core/common/password_form.h" 38 #include "components/autofill/core/common/password_form.h"
39 #include "components/password_manager/content/browser/content_password_manager_d river.h" 39 #include "components/password_manager/content/browser/content_password_manager_d river.h"
40 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" 40 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h"
41 #include "components/password_manager/core/browser/login_model.h" 41 #include "components/password_manager/core/browser/login_model.h"
42 #include "components/password_manager/core/browser/test_password_store.h" 42 #include "components/password_manager/core/browser/test_password_store.h"
43 #include "components/password_manager/core/common/password_manager_features.h"
43 #include "components/version_info/version_info.h" 44 #include "components/version_info/version_info.h"
44 #include "content/public/browser/navigation_controller.h" 45 #include "content/public/browser/navigation_controller.h"
45 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
46 #include "content/public/browser/render_frame_host.h" 47 #include "content/public/browser/render_frame_host.h"
47 #include "content/public/browser/render_process_host.h" 48 #include "content/public/browser/render_process_host.h"
48 #include "content/public/browser/render_view_host.h" 49 #include "content/public/browser/render_view_host.h"
49 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
50 #include "content/public/browser/web_contents_observer.h" 51 #include "content/public/browser/web_contents_observer.h"
51 #include "content/public/common/content_switches.h" 52 #include "content/public/common/content_switches.h"
52 #include "content/public/test/browser_test_utils.h" 53 #include "content/public/test/browser_test_utils.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 std::string fill_and_submit = 365 std::string fill_and_submit =
365 "document.getElementById('username_field').value = 'temp';" 366 "document.getElementById('username_field').value = 'temp';"
366 "document.getElementById('password_field').value = 'random';" 367 "document.getElementById('password_field').value = 'random';"
367 "document.getElementById('submit_button').click()"; 368 "document.getElementById('submit_button').click()";
368 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 369 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
369 observer.Wait(); 370 observer.Wait();
370 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 371 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt());
371 } 372 }
372 373
373 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForDynamicForm) { 374 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForDynamicForm) {
374 // Adding a form is a workaround explained later. 375 // Adding a PSL matching form is a workaround explained later.
375 scoped_refptr<password_manager::TestPasswordStore> password_store = 376 scoped_refptr<password_manager::TestPasswordStore> password_store =
376 static_cast<password_manager::TestPasswordStore*>( 377 static_cast<password_manager::TestPasswordStore*>(
377 PasswordStoreFactory::GetForProfile( 378 PasswordStoreFactory::GetForProfile(
378 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 379 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
379 .get()); 380 .get());
380 autofill::PasswordForm signin_form; 381 autofill::PasswordForm signin_form;
381 signin_form.signon_realm = embedded_test_server()->base_url().spec(); 382 GURL psl_orogin = embedded_test_server()->GetURL("psl.example.com", "/");
382 signin_form.origin = embedded_test_server()->base_url(); 383 signin_form.signon_realm = psl_orogin.spec();
384 signin_form.origin = psl_orogin;
383 signin_form.username_value = base::ASCIIToUTF16("unused_username"); 385 signin_form.username_value = base::ASCIIToUTF16("unused_username");
384 signin_form.password_value = base::ASCIIToUTF16("unused_password"); 386 signin_form.password_value = base::ASCIIToUTF16("unused_password");
385 password_store->AddLogin(signin_form); 387 password_store->AddLogin(signin_form);
386 388
387 // Show the dynamic form. 389 // Show the dynamic form.
388 NavigateToFile("/password/dynamic_password_form.html"); 390 ui_test_utils::NavigateToURL(
391 browser(), embedded_test_server()->GetURL(
392 "example.com", "/password/dynamic_password_form.html"));
389 ASSERT_TRUE(content::ExecuteScript( 393 ASSERT_TRUE(content::ExecuteScript(
390 RenderViewHost(), 394 RenderViewHost(),
391 "document.getElementById('create_form_button').click();")); 395 "document.getElementById('create_form_button').click();"));
392 396
393 // Blink has a timer for 0.3 seconds before it updates the browser with the 397 // Blink has a timer for 0.3 seconds before it updates the browser with the
394 // new dynamic form. We wait for the form being detected by observing the UI 398 // new dynamic form. We wait for the form being detected by observing the UI
395 // state. The state changes due to the matching credential saved above. Later 399 // state. The state changes due to the matching credential saved above. Later
396 // the form submission is definitely noticed by the browser. 400 // the form submission is definitely noticed by the browser.
397 BubbleObserver(WebContents()).WaitForManagementState(); 401 BubbleObserver(WebContents()).WaitForManagementState();
398 402
(...skipping 1963 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 static_cast<password_manager::TestPasswordStore*>( 2366 static_cast<password_manager::TestPasswordStore*>(
2363 PasswordStoreFactory::GetForProfile( 2367 PasswordStoreFactory::GetForProfile(
2364 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 2368 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
2365 .get()); 2369 .get());
2366 autofill::PasswordForm signin_form; 2370 autofill::PasswordForm signin_form;
2367 signin_form.signon_realm = embedded_test_server()->base_url().spec(); 2371 signin_form.signon_realm = embedded_test_server()->base_url().spec();
2368 signin_form.username_value = base::ASCIIToUTF16("temp"); 2372 signin_form.username_value = base::ASCIIToUTF16("temp");
2369 signin_form.password_value = base::ASCIIToUTF16("pw"); 2373 signin_form.password_value = base::ASCIIToUTF16("pw");
2370 password_store->AddLogin(signin_form); 2374 password_store->AddLogin(signin_form);
2371 2375
2376 // Disable autofill. If a password is autofilled then all the Javacript
2377 // changes are discarded. The test would not be able to feed the new password
2378 // below.
2379 base::test::ScopedFeatureList scoped_feature_list;
2380 scoped_feature_list.InitAndEnableFeature(features::kFillOnAccountSelect);
dvadym 2017/05/24 13:19:59 Cool solution for preventing filling.
vasilii 2017/05/24 14:31:50 I'm not proud of myself because strictly speaking
2381
2372 // Check that password update bubble is shown. 2382 // Check that password update bubble is shown.
2373 NavigateToFile("/password/password_form.html"); 2383 NavigateToFile("/password/password_form.html");
2374 NavigationObserver observer(WebContents()); 2384 NavigationObserver observer(WebContents());
2375 std::unique_ptr<BubbleObserver> prompt_observer( 2385 std::unique_ptr<BubbleObserver> prompt_observer(
2376 new BubbleObserver(WebContents())); 2386 new BubbleObserver(WebContents()));
2377 std::string fill_and_submit = 2387 std::string fill_and_submit =
2378 "document.getElementById('username_field').value = 'temp';" 2388 "document.getElementById('username_field').value = 'temp';"
2379 "document.getElementById('password_field').value = 'new_pw';" 2389 "document.getElementById('password_field').value = 'new_pw';"
2380 "document.getElementById('input_submit_button').click()"; 2390 "document.getElementById('input_submit_button').click()";
2381 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2391 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2382 observer.Wait(); 2392 observer.Wait();
2383 // The stored password "pw" was overriden with "new_pw", so update prompt is 2393 // The stored password "pw" was overriden with "new_pw", so update prompt is
2384 // expected. 2394 // expected.
2385 EXPECT_TRUE(prompt_observer->IsShowingUpdatePrompt()); 2395 EXPECT_TRUE(prompt_observer->IsShowingUpdatePrompt());
2386 2396
2387 const autofill::PasswordForm stored_form = 2397 const autofill::PasswordForm stored_form =
2388 password_store->stored_passwords().begin()->second[0]; 2398 password_store->stored_passwords().begin()->second[0];
2389 prompt_observer->AcceptUpdatePrompt(stored_form); 2399 prompt_observer->AcceptUpdatePrompt(stored_form);
2390 // Spin the message loop to make sure the password store had a chance to 2400 WaitForPasswordStore();
2391 // update the password.
2392 base::RunLoop run_loop;
2393 run_loop.RunUntilIdle();
2394 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), 2401 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"),
2395 base::ASCIIToUTF16("new_pw")); 2402 base::ASCIIToUTF16("new_pw"));
2396 } 2403 }
2397 2404
2398 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 2405 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2399 PasswordNotOverridenUpdateBubbleNotShown) { 2406 PasswordNotOverridenUpdateBubbleNotShown) {
2400 // At first let us save credentials to the PasswordManager. 2407 // At first let us save credentials to the PasswordManager.
2401 scoped_refptr<password_manager::TestPasswordStore> password_store = 2408 scoped_refptr<password_manager::TestPasswordStore> password_store =
2402 static_cast<password_manager::TestPasswordStore*>( 2409 static_cast<password_manager::TestPasswordStore*>(
2403 PasswordStoreFactory::GetForProfile( 2410 PasswordStoreFactory::GetForProfile(
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
3365 // Force a round-trip. 3372 // Force a round-trip.
3366 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture(RenderFrameHost(), 3373 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture(RenderFrameHost(),
3367 "var noop = 'noop';")); 3374 "var noop = 'noop';"));
3368 // Ensure the warning was not triggered. 3375 // Ensure the warning was not triggered.
3369 ASSERT_FALSE(observing_autofill_client->DidPopupAppear()); 3376 ASSERT_FALSE(observing_autofill_client->DidPopupAppear());
3370 // Ensure the histogram remains empty. 3377 // Ensure the histogram remains empty.
3371 histograms.ExpectTotalCount(kHistogram, 0); 3378 histograms.ExpectTotalCount(kHistogram, 0);
3372 } 3379 }
3373 3380
3374 } // namespace password_manager 3381 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698