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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc

Issue 796493004: Remove FrameDetached and FrameWillClose listeners from AutofillAgent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix init order Created 5 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 InitiateDialog(); 455 InitiateDialog();
456 456
457 ChromeAutofillClient* client = 457 ChromeAutofillClient* client =
458 ChromeAutofillClient::FromWebContents(contents); 458 ChromeAutofillClient::FromWebContents(contents);
459 AutofillDialogControllerImpl* controller = 459 AutofillDialogControllerImpl* controller =
460 static_cast<AutofillDialogControllerImpl*>( 460 static_cast<AutofillDialogControllerImpl*>(
461 client->GetDialogControllerForTesting()); 461 client->GetDialogControllerForTesting());
462 return !!controller; 462 return !!controller;
463 } 463 }
464 464
465 void RunTestPageInIframe(const net::SpawnedTestServer& server) {
466 InitializeDOMMessageQueue();
467 GURL iframe_url = server.GetURL(
468 "files/request_autocomplete/test_page.html");
469
470 ui_test_utils::NavigateToURL(
471 browser(), GURL(std::string("data:text/html,") +
472 "<!doctype html>"
473 "<html>"
474 "<body>"
475 "<iframe style='position: fixed;"
476 "height: 100%;"
477 "width: 100%;'"
478 "id='racFrame'></iframe>"
479 "<script>"
480 "function send(msg) {"
481 "domAutomationController.setAutomationId(0);"
482 "domAutomationController.send(msg);"
483 "}"
484 "var racFrame = document.getElementById('racFrame');"
485 "racFrame.onload = function() {"
486 "send('iframe loaded');"
487 "};"
488 "racFrame.src = \"" + iframe_url.spec() + "\";"
489 "function navigateFrame() {"
490 "racFrame.src = 'about:blank';"
491 "}"
492 "</script>"
493 "</body>"
494 "</html>"));
495
496 ChromeAutofillClient* client =
497 ChromeAutofillClient::FromWebContents(GetActiveWebContents());
498 ExpectDomMessage("iframe loaded");
499 EXPECT_FALSE(client->GetDialogControllerForTesting());
500 InitiateDialog();
501 EXPECT_TRUE(client->GetDialogControllerForTesting());
502 }
503
465 // Wait for a message from the DOM automation controller (from JS in the 504 // Wait for a message from the DOM automation controller (from JS in the
466 // page). Requires |SetUpHtmlAndInvoke()| be called first. 505 // page). Requires |SetUpHtmlAndInvoke()| be called first.
467 void ExpectDomMessage(const std::string& expected) { 506 void ExpectDomMessage(const std::string& expected) {
468 std::string message; 507 std::string message;
469 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message)); 508 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message));
470 dom_message_queue_->ClearQueue(); 509 dom_message_queue_->ClearQueue();
471 EXPECT_EQ("\"" + expected + "\"", message); 510 EXPECT_EQ("\"" + expected + "\"", message);
472 } 511 }
473 512
474 void InitiateDialog() { 513 void InitiateDialog() {
475 dom_message_queue_.reset(new content::DOMMessageQueue); 514 InitializeDOMMessageQueue();
476
477 // Triggers the onclick handler which invokes requestAutocomplete(). 515 // Triggers the onclick handler which invokes requestAutocomplete().
478 content::WebContents* contents = GetActiveWebContents(); 516 content::WebContents* contents = GetActiveWebContents();
479 content::SimulateMouseClick(contents, 0, blink::WebMouseEvent::ButtonLeft); 517 content::SimulateMouseClick(contents, 0, blink::WebMouseEvent::ButtonLeft);
480 ExpectDomMessage("clicked"); 518 ExpectDomMessage("clicked");
481 } 519 }
482 520
521 void InitializeDOMMessageQueue() {
522 dom_message_queue_.reset(new content::DOMMessageQueue);
523 }
524
483 // Returns the value filled into the first field with autocomplete attribute 525 // Returns the value filled into the first field with autocomplete attribute
484 // equal to |autocomplete_type|, or an empty string if there is no such field. 526 // equal to |autocomplete_type|, or an empty string if there is no such field.
485 std::string GetValueForHTMLFieldOfType(const std::string& autocomplete_type) { 527 std::string GetValueForHTMLFieldOfType(const std::string& autocomplete_type) {
486 std::string script = "getValueForFieldOfType('" + autocomplete_type + "');"; 528 std::string script = "getValueForFieldOfType('" + autocomplete_type + "');";
487 std::string result; 529 std::string result;
488 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(), 530 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(),
489 script, 531 script,
490 &result)); 532 &result));
491 return result; 533 return result;
492 } 534 }
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 " autocomplete='transaction-amount' value='24' readonly>" 1808 " autocomplete='transaction-amount' value='24' readonly>"
1767 "<input autocomplete='transaction-currency' value='USD' readonly>" 1809 "<input autocomplete='transaction-currency' value='USD' readonly>"
1768 "<input autocomplete='cc-csc'>"); 1810 "<input autocomplete='cc-csc'>");
1769 AutofillDialogControllerImpl* controller = SetUpHtmlAndInvoke(html); 1811 AutofillDialogControllerImpl* controller = SetUpHtmlAndInvoke(html);
1770 ASSERT_TRUE(controller); 1812 ASSERT_TRUE(controller);
1771 1813
1772 EXPECT_EQ(ASCIIToUTF16("24"), controller->transaction_amount_); 1814 EXPECT_EQ(ASCIIToUTF16("24"), controller->transaction_amount_);
1773 EXPECT_EQ(ASCIIToUTF16("USD"), controller->transaction_currency_); 1815 EXPECT_EQ(ASCIIToUTF16("USD"), controller->transaction_currency_);
1774 } 1816 }
1775 1817
1818 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigate) {
1819 base::WeakPtr<TestAutofillDialogController> weak_ptr =
1820 controller()->AsWeakPtr();
1821 EXPECT_TRUE(weak_ptr.get());
1822
1823 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
1824 EXPECT_FALSE(weak_ptr.get());
1825 }
1826
1827 // Tests that the rAc dialog hides when the main frame is navigated, even if
1828 // it was invoked from a child frame.
1829 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigateMainFrame) {
1830 net::SpawnedTestServer http_server(
1831 net::SpawnedTestServer::TYPE_HTTP,
1832 net::SpawnedTestServer::kLocalhost,
1833 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1834 ASSERT_TRUE(http_server.Start());
1835 RunTestPageInIframe(http_server);
1836
1837 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
1838 ChromeAutofillClient* client =
1839 ChromeAutofillClient::FromWebContents(GetActiveWebContents());
1840 EXPECT_FALSE(client->GetDialogControllerForTesting());
1841 }
1842
1843 // Tests that the rAc dialog hides when the iframe it's in is navigated.
1844 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigateIframe) {
1845 net::SpawnedTestServer http_server(
1846 net::SpawnedTestServer::TYPE_HTTP,
1847 net::SpawnedTestServer::kLocalhost,
1848 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1849 ASSERT_TRUE(http_server.Start());
1850 RunTestPageInIframe(http_server);
1851
1852 std::string unused;
1853 ASSERT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(),
1854 "navigateFrame();",
1855 &unused));
1856 ExpectDomMessage("iframe loaded");
1857 ChromeAutofillClient* client =
1858 ChromeAutofillClient::FromWebContents(GetActiveWebContents());
1859 EXPECT_FALSE(client->GetDialogControllerForTesting());
1860 }
1861
1776 } // namespace autofill 1862 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller.h ('k') | chrome/browser/ui/autofill/chrome_autofill_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698