OLD | NEW |
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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 InitiateDialog(); | 456 InitiateDialog(); |
457 | 457 |
458 ChromeAutofillClient* client = | 458 ChromeAutofillClient* client = |
459 ChromeAutofillClient::FromWebContents(contents); | 459 ChromeAutofillClient::FromWebContents(contents); |
460 AutofillDialogControllerImpl* controller = | 460 AutofillDialogControllerImpl* controller = |
461 static_cast<AutofillDialogControllerImpl*>( | 461 static_cast<AutofillDialogControllerImpl*>( |
462 client->GetDialogControllerForTesting()); | 462 client->GetDialogControllerForTesting()); |
463 return !!controller; | 463 return !!controller; |
464 } | 464 } |
465 | 465 |
| 466 void RunTestPageInIframe(const net::SpawnedTestServer& server) { |
| 467 InitializeDOMMessageQueue(); |
| 468 GURL iframe_url = server.GetURL( |
| 469 "files/request_autocomplete/test_page.html"); |
| 470 |
| 471 ui_test_utils::NavigateToURL( |
| 472 browser(), GURL(std::string("data:text/html,") + |
| 473 "<!doctype html>" |
| 474 "<html>" |
| 475 "<body>" |
| 476 "<iframe style='position: fixed;" |
| 477 "height: 100%;" |
| 478 "width: 100%;'" |
| 479 "id='racFrame'></iframe>" |
| 480 "<script>" |
| 481 "function send(msg) {" |
| 482 "domAutomationController.setAutomationId(0);" |
| 483 "domAutomationController.send(msg);" |
| 484 "}" |
| 485 "var racFrame = document.getElementById('racFrame');" |
| 486 "racFrame.onload = function() {" |
| 487 "send('iframe loaded');" |
| 488 "};" |
| 489 "racFrame.src = \"" + iframe_url.spec() + "\";" |
| 490 "function navigateFrame() {" |
| 491 "racFrame.src = 'about:blank';" |
| 492 "}" |
| 493 "</script>" |
| 494 "</body>" |
| 495 "</html>")); |
| 496 |
| 497 ChromeAutofillClient* client = |
| 498 ChromeAutofillClient::FromWebContents(GetActiveWebContents()); |
| 499 ExpectDomMessage("iframe loaded"); |
| 500 EXPECT_FALSE(client->GetDialogControllerForTesting()); |
| 501 InitiateDialog(); |
| 502 EXPECT_TRUE(client->GetDialogControllerForTesting()); |
| 503 } |
| 504 |
466 // Wait for a message from the DOM automation controller (from JS in the | 505 // Wait for a message from the DOM automation controller (from JS in the |
467 // page). Requires |SetUpHtmlAndInvoke()| be called first. | 506 // page). Requires |SetUpHtmlAndInvoke()| be called first. |
468 void ExpectDomMessage(const std::string& expected) { | 507 void ExpectDomMessage(const std::string& expected) { |
469 std::string message; | 508 std::string message; |
470 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message)); | 509 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message)); |
471 dom_message_queue_->ClearQueue(); | 510 dom_message_queue_->ClearQueue(); |
472 EXPECT_EQ("\"" + expected + "\"", message); | 511 EXPECT_EQ("\"" + expected + "\"", message); |
473 } | 512 } |
474 | 513 |
475 void InitiateDialog() { | 514 void InitiateDialog() { |
476 dom_message_queue_.reset(new content::DOMMessageQueue); | 515 InitializeDOMMessageQueue(); |
477 | |
478 // Triggers the onclick handler which invokes requestAutocomplete(). | 516 // Triggers the onclick handler which invokes requestAutocomplete(). |
479 content::WebContents* contents = GetActiveWebContents(); | 517 content::WebContents* contents = GetActiveWebContents(); |
480 content::SimulateMouseClick(contents, 0, blink::WebMouseEvent::ButtonLeft); | 518 content::SimulateMouseClick(contents, 0, blink::WebMouseEvent::ButtonLeft); |
481 ExpectDomMessage("clicked"); | 519 ExpectDomMessage("clicked"); |
482 } | 520 } |
483 | 521 |
| 522 void InitializeDOMMessageQueue() { |
| 523 dom_message_queue_.reset(new content::DOMMessageQueue); |
| 524 } |
| 525 |
484 // Returns the value filled into the first field with autocomplete attribute | 526 // Returns the value filled into the first field with autocomplete attribute |
485 // equal to |autocomplete_type|, or an empty string if there is no such field. | 527 // equal to |autocomplete_type|, or an empty string if there is no such field. |
486 std::string GetValueForHTMLFieldOfType(const std::string& autocomplete_type) { | 528 std::string GetValueForHTMLFieldOfType(const std::string& autocomplete_type) { |
487 std::string script = "getValueForFieldOfType('" + autocomplete_type + "');"; | 529 std::string script = "getValueForFieldOfType('" + autocomplete_type + "');"; |
488 std::string result; | 530 std::string result; |
489 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(), | 531 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(), |
490 script, | 532 script, |
491 &result)); | 533 &result)); |
492 return result; | 534 return result; |
493 } | 535 } |
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 " autocomplete='transaction-amount' value='24' readonly>" | 1796 " autocomplete='transaction-amount' value='24' readonly>" |
1755 "<input autocomplete='transaction-currency' value='USD' readonly>" | 1797 "<input autocomplete='transaction-currency' value='USD' readonly>" |
1756 "<input autocomplete='cc-csc'>"); | 1798 "<input autocomplete='cc-csc'>"); |
1757 AutofillDialogControllerImpl* controller = SetUpHtmlAndInvoke(html); | 1799 AutofillDialogControllerImpl* controller = SetUpHtmlAndInvoke(html); |
1758 ASSERT_TRUE(controller); | 1800 ASSERT_TRUE(controller); |
1759 | 1801 |
1760 EXPECT_EQ(ASCIIToUTF16("24"), controller->transaction_amount_); | 1802 EXPECT_EQ(ASCIIToUTF16("24"), controller->transaction_amount_); |
1761 EXPECT_EQ(ASCIIToUTF16("USD"), controller->transaction_currency_); | 1803 EXPECT_EQ(ASCIIToUTF16("USD"), controller->transaction_currency_); |
1762 } | 1804 } |
1763 | 1805 |
| 1806 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigate) { |
| 1807 base::WeakPtr<TestAutofillDialogController> weak_ptr = |
| 1808 controller()->AsWeakPtr(); |
| 1809 EXPECT_TRUE(weak_ptr.get()); |
| 1810 |
| 1811 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 1812 EXPECT_FALSE(weak_ptr.get()); |
| 1813 } |
| 1814 |
| 1815 // Tests that the rAc dialog hides when the main frame is navigated, even if |
| 1816 // it was invoked from a child frame. |
| 1817 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigateMainFrame) { |
| 1818 net::SpawnedTestServer http_server( |
| 1819 net::SpawnedTestServer::TYPE_HTTP, |
| 1820 net::SpawnedTestServer::kLocalhost, |
| 1821 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 1822 ASSERT_TRUE(http_server.Start()); |
| 1823 RunTestPageInIframe(http_server); |
| 1824 |
| 1825 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 1826 ChromeAutofillClient* client = |
| 1827 ChromeAutofillClient::FromWebContents(GetActiveWebContents()); |
| 1828 EXPECT_FALSE(client->GetDialogControllerForTesting()); |
| 1829 } |
| 1830 |
| 1831 // Tests that the rAc dialog hides when the iframe it's in is navigated. |
| 1832 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigateIframe) { |
| 1833 net::SpawnedTestServer http_server( |
| 1834 net::SpawnedTestServer::TYPE_HTTP, |
| 1835 net::SpawnedTestServer::kLocalhost, |
| 1836 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 1837 ASSERT_TRUE(http_server.Start()); |
| 1838 RunTestPageInIframe(http_server); |
| 1839 |
| 1840 std::string unused; |
| 1841 ASSERT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(), |
| 1842 "navigateFrame();", |
| 1843 &unused)); |
| 1844 ExpectDomMessage("iframe loaded"); |
| 1845 ChromeAutofillClient* client = |
| 1846 ChromeAutofillClient::FromWebContents(GetActiveWebContents()); |
| 1847 EXPECT_FALSE(client->GetDialogControllerForTesting()); |
| 1848 } |
| 1849 |
1764 } // namespace autofill | 1850 } // namespace autofill |
OLD | NEW |