Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/test/scoped_feature_list.h" | |
| 10 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 12 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 12 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" | 13 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" |
| 14 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "components/autofill/core/browser/autofill_client.h" | |
| 21 #include "components/autofill/core/browser/test_autofill_client.h" | |
| 18 #include "components/guest_view/browser/guest_view_manager_delegate.h" | 22 #include "components/guest_view/browser/guest_view_manager_delegate.h" |
| 19 #include "components/guest_view/browser/test_guest_view_manager.h" | 23 #include "components/guest_view/browser/test_guest_view_manager.h" |
| 24 #include "components/security_state/core/security_state.h" | |
| 20 #include "content/public/browser/interstitial_page.h" | 25 #include "content/public/browser/interstitial_page.h" |
| 21 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
| 22 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
| 24 #include "content/public/browser/render_frame_host.h" | 29 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/browser/web_contents_observer.h" | 31 #include "content/public/browser/web_contents_observer.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 32 #include "content/public/test/browser_test_utils.h" |
| 28 #include "content/public/test/content_browser_test_utils.h" | 33 #include "content/public/test/content_browser_test_utils.h" |
| 29 #include "content/public/test/test_utils.h" | 34 #include "content/public/test/test_utils.h" |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n" | 498 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n" |
| 494 "var w = window.open('about:blank');\n" | 499 "var w = window.open('about:blank');\n" |
| 495 "window.domAutomationController.send(!!w);\n", | 500 "window.domAutomationController.send(!!w);\n", |
| 496 &popup_handle_is_valid)); | 501 &popup_handle_is_valid)); |
| 497 popup_observer.Wait(); | 502 popup_observer.Wait(); |
| 498 | 503 |
| 499 // The popup shouldn't be blocked. | 504 // The popup shouldn't be blocked. |
| 500 EXPECT_TRUE(popup_handle_is_valid); | 505 EXPECT_TRUE(popup_handle_is_valid); |
| 501 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 506 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 502 } | 507 } |
| 508 | |
| 509 namespace autofill { | |
|
EhsanK
2017/03/16 20:39:00
not sure if this is better on top.
Charlie Reis
2017/03/17 18:43:07
Yes, please move to the top.
EhsanK
2017/03/20 16:45:28
Done.
| |
| 510 class AutofillPopupDelegate; | |
| 511 struct Suggestion; | |
| 512 } | |
| 513 | |
| 514 class ChromeSitePerProcessAutofillTest : public ChromeSitePerProcessTest { | |
| 515 public: | |
| 516 ChromeSitePerProcessAutofillTest() : ChromeSitePerProcessTest() {} | |
| 517 ~ChromeSitePerProcessAutofillTest() override{}; | |
| 518 | |
| 519 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 520 ChromeSitePerProcessTest::SetUpCommandLine(command_line); | |
| 521 // We need to set the feature state before the render process is created, | |
| 522 // in order for it to inherit the feature state from the browser process. | |
| 523 // SetUp() runs too early, and SetUpOnMainThread() runs too late. | |
| 524 scoped_feature_list_.InitAndEnableFeature( | |
| 525 security_state::kHttpFormWarningFeature); | |
| 526 } | |
| 527 | |
| 528 void SetUpOnMainThread() override { | |
| 529 ChromeSitePerProcessTest::SetUpOnMainThread(); | |
| 530 } | |
| 531 | |
| 532 protected: | |
| 533 class TestAutofillClient : public autofill::TestAutofillClient { | |
| 534 public: | |
| 535 TestAutofillClient() : popup_shown_(false){}; | |
| 536 ~TestAutofillClient() override {} | |
| 537 | |
| 538 void WaitForNextPopup() { | |
| 539 if (popup_shown_) | |
| 540 return; | |
| 541 loop_runner_ = new content::MessageLoopRunner(); | |
| 542 loop_runner_->Run(); | |
| 543 } | |
| 544 | |
| 545 virtual void ShowAutofillPopup( | |
| 546 const gfx::RectF& element_bounds, | |
| 547 base::i18n::TextDirection text_direction, | |
| 548 const std::vector<autofill::Suggestion>& suggestions, | |
| 549 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) { | |
| 550 element_bounds_ = element_bounds; | |
| 551 popup_shown_ = true; | |
| 552 if (loop_runner_) | |
| 553 loop_runner_->Quit(); | |
| 554 } | |
| 555 | |
| 556 const gfx::RectF& last_element_bounds() const { return element_bounds_; } | |
| 557 | |
| 558 private: | |
| 559 gfx::RectF element_bounds_; | |
| 560 bool popup_shown_; | |
| 561 scoped_refptr<content::MessageLoopRunner> loop_runner_; | |
| 562 | |
| 563 DISALLOW_COPY_AND_ASSIGN(TestAutofillClient); | |
| 564 }; | |
| 565 | |
| 566 const int kIframeTopDisplacement = 150; | |
| 567 const int kIframeLeftDisplacement = 200; | |
| 568 | |
| 569 void SetupMainTab() { | |
| 570 // Add a fresh new WebContents for which we add our own version of the | |
| 571 // ChromePasswordManagerClient that uses a custom TestAutofillClient. | |
| 572 content::WebContents* new_contents = content::WebContents::Create( | |
| 573 content::WebContents::CreateParams(browser() | |
| 574 ->tab_strip_model() | |
| 575 ->GetActiveWebContents() | |
| 576 ->GetBrowserContext())); | |
| 577 ASSERT_TRUE(new_contents); | |
| 578 ASSERT_FALSE(ChromePasswordManagerClient::FromWebContents(new_contents)); | |
| 579 | |
| 580 // Create ChromePasswordManagerClient and verify it exists for the new | |
| 581 // WebContents. | |
| 582 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( | |
| 583 new_contents, &test_autofill_client_); | |
| 584 ASSERT_TRUE(ChromePasswordManagerClient::FromWebContents(new_contents)); | |
| 585 | |
| 586 browser()->tab_strip_model()->AppendWebContents(new_contents, true); | |
| 587 } | |
| 588 | |
| 589 TestAutofillClient& autofill_client() { return test_autofill_client_; } | |
| 590 | |
| 591 private: | |
| 592 base::test::ScopedFeatureList scoped_feature_list_; | |
| 593 TestAutofillClient test_autofill_client_; | |
| 594 | |
| 595 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessAutofillTest); | |
| 596 }; | |
| 597 | |
| 598 // This test verifies that displacements (margin, etc) in the position of an | |
| 599 // OOPIF is considered when showing an AutofillClient warning pop-up for | |
| 600 // unsecure web sites. | |
| 601 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessAutofillTest, | |
| 602 AutofillClientPoisitonWhenInsideOOPIF) { | |
|
Charlie Reis
2017/03/17 18:43:07
nit: typo in Position
EhsanK
2017/03/20 16:45:28
Done.
| |
| 603 SetupMainTab(); | |
| 604 ASSERT_TRUE( | |
| 605 base::FeatureList::IsEnabled(security_state::kHttpFormWarningFeature)); | |
| 606 | |
| 607 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); | |
| 608 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 609 content::WebContents* active_web_contents = | |
| 610 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 611 | |
| 612 // Add some displacement for <iframe>. | |
| 613 ASSERT_TRUE(content::ExecuteScript( | |
| 614 active_web_contents, | |
| 615 base::StringPrintf("var iframe = document.querySelector('iframe');" | |
| 616 "iframe.style.marginTop = '%dpx';" | |
| 617 "iframe.style.marginLeft = '%dpx';", | |
| 618 kIframeTopDisplacement, kIframeLeftDisplacement))); | |
| 619 | |
| 620 // Navigate the <iframe> to a page with <form> | |
|
Charlie Reis
2017/03/17 18:43:07
nit: End with period, as above.
EhsanK
2017/03/20 16:45:27
Done.
| |
| 621 GURL frame_url = embedded_test_server()->GetURL("b.com", "/title1.html"); | |
| 622 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url)); | |
| 623 | |
| 624 // Insert a password <input> inside the form. | |
|
Charlie Reis
2017/03/17 18:43:07
The comments are suggesting that there's an existi
EhsanK
2017/03/20 16:45:28
Yes I forgot to fix the comments after changing my
| |
| 625 content::RenderFrameHost* child_frame = content::FrameMatchingPredicate( | |
| 626 active_web_contents, base::Bind(&content::FrameIsChildOfMainFrame)); | |
| 627 | |
| 628 // Focus the child frame, add an <input> with type "password", and focus it. | |
| 629 ASSERT_TRUE(ExecuteScript(child_frame, | |
| 630 "window.focus();" | |
| 631 "var input = document.createElement('input');" | |
| 632 "input.type = 'password';" | |
| 633 "document.body.appendChild(input);" | |
| 634 "input.focus();")); | |
| 635 | |
| 636 // The user gesture should lead to a security warning. | |
| 637 content::SimulateKeyPress(active_web_contents, ui::DomKey::FromCharacter('A'), | |
| 638 ui::DomCode::US_A, ui::VKEY_A, false, false, false, | |
| 639 false); | |
| 640 autofill_client().WaitForNextPopup(); | |
| 641 | |
| 642 // Verify the whereabouts of the pop-up. | |
| 643 EXPECT_GT(autofill_client().last_element_bounds().origin().y() /* top */, | |
|
Charlie Reis
2017/03/17 18:43:07
This would miss cases that the popup is too low or
EhsanK
2017/03/20 16:45:28
I am now using the notification about focused node
| |
| 644 kIframeTopDisplacement); | |
| 645 EXPECT_GT(autofill_client().last_element_bounds().origin().x() /* left */, | |
| 646 kIframeLeftDisplacement); | |
| 647 } | |
| OLD | NEW |