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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 // Wait for a message from the DOM automation controller (from JS in the | 466 // Wait for a message from the DOM automation controller (from JS in the |
467 // page). Requires |SetUpHtmlAndInvoke()| be called first. | 467 // page). Requires |SetUpHtmlAndInvoke()| be called first. |
468 void ExpectDomMessage(const std::string& expected) { | 468 void ExpectDomMessage(const std::string& expected) { |
469 std::string message; | 469 std::string message; |
470 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message)); | 470 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message)); |
471 dom_message_queue_->ClearQueue(); | 471 dom_message_queue_->ClearQueue(); |
472 EXPECT_EQ("\"" + expected + "\"", message); | 472 EXPECT_EQ("\"" + expected + "\"", message); |
473 } | 473 } |
474 | 474 |
475 void InitiateDialog() { | 475 void InitiateDialog() { |
476 dom_message_queue_.reset(new content::DOMMessageQueue); | 476 InitializeDOMMessageQueue(); |
Dan Beam
2014/12/19 01:59:34
nit: InitializeDomMessageQueue() (I'm pretty sure
| |
477 | |
478 // Triggers the onclick handler which invokes requestAutocomplete(). | 477 // Triggers the onclick handler which invokes requestAutocomplete(). |
479 content::WebContents* contents = GetActiveWebContents(); | 478 content::WebContents* contents = GetActiveWebContents(); |
480 content::SimulateMouseClick(contents, 0, blink::WebMouseEvent::ButtonLeft); | 479 content::SimulateMouseClick(contents, 0, blink::WebMouseEvent::ButtonLeft); |
481 ExpectDomMessage("clicked"); | 480 ExpectDomMessage("clicked"); |
482 } | 481 } |
483 | 482 |
483 void InitializeDOMMessageQueue() { | |
484 dom_message_queue_.reset(new content::DOMMessageQueue); | |
485 } | |
486 | |
484 // Returns the value filled into the first field with autocomplete attribute | 487 // 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. | 488 // equal to |autocomplete_type|, or an empty string if there is no such field. |
486 std::string GetValueForHTMLFieldOfType(const std::string& autocomplete_type) { | 489 std::string GetValueForHTMLFieldOfType(const std::string& autocomplete_type) { |
487 std::string script = "getValueForFieldOfType('" + autocomplete_type + "');"; | 490 std::string script = "getValueForFieldOfType('" + autocomplete_type + "');"; |
488 std::string result; | 491 std::string result; |
489 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(), | 492 EXPECT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(), |
490 script, | 493 script, |
491 &result)); | 494 &result)); |
492 return result; | 495 return result; |
493 } | 496 } |
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1754 " autocomplete='transaction-amount' value='24' readonly>" | 1757 " autocomplete='transaction-amount' value='24' readonly>" |
1755 "<input autocomplete='transaction-currency' value='USD' readonly>" | 1758 "<input autocomplete='transaction-currency' value='USD' readonly>" |
1756 "<input autocomplete='cc-csc'>"); | 1759 "<input autocomplete='cc-csc'>"); |
1757 AutofillDialogControllerImpl* controller = SetUpHtmlAndInvoke(html); | 1760 AutofillDialogControllerImpl* controller = SetUpHtmlAndInvoke(html); |
1758 ASSERT_TRUE(controller); | 1761 ASSERT_TRUE(controller); |
1759 | 1762 |
1760 EXPECT_EQ(ASCIIToUTF16("24"), controller->transaction_amount_); | 1763 EXPECT_EQ(ASCIIToUTF16("24"), controller->transaction_amount_); |
1761 EXPECT_EQ(ASCIIToUTF16("USD"), controller->transaction_currency_); | 1764 EXPECT_EQ(ASCIIToUTF16("USD"), controller->transaction_currency_); |
1762 } | 1765 } |
1763 | 1766 |
1767 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigate) { | |
1768 base::WeakPtr<TestAutofillDialogController> weak_ptr = | |
1769 controller()->AsWeakPtr(); | |
1770 EXPECT_TRUE(weak_ptr.get()); | |
1771 | |
1772 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
1773 EXPECT_FALSE(weak_ptr.get()); | |
1774 } | |
1775 | |
1776 // Tests that the rAc dialog hides when the main frame is navigated, even if | |
1777 // it was invoked from a child frame. | |
1778 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigateMainFrame) { | |
1779 | |
Dan Beam
2014/12/19 01:59:34
nit: ^H
Evan Stade
2014/12/19 21:21:12
Done.
| |
1780 net::SpawnedTestServer http_server( | |
1781 net::SpawnedTestServer::TYPE_HTTP, | |
1782 net::SpawnedTestServer::kLocalhost, | |
1783 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
1784 ASSERT_TRUE(http_server.Start()); | |
1785 | |
1786 InitializeDOMMessageQueue(); | |
1787 GURL iframe_url = http_server.GetURL( | |
1788 "files/request_autocomplete/test_page.html"); | |
1789 | |
1790 ui_test_utils::NavigateToURL( | |
1791 browser(), GURL(std::string("data:text/html,") + | |
1792 "<!doctype html>" | |
1793 "<html>" | |
1794 "<body>" | |
1795 "<iframe style='position: fixed;" | |
1796 "height: 100%;" | |
1797 "width: 100%;'" | |
1798 "id='racFrame'></iframe>" | |
1799 "<script>" | |
1800 "function send(msg) {" | |
1801 "domAutomationController.setAutomationId(0);" | |
1802 "domAutomationController.send(msg);" | |
1803 "}" | |
1804 "var racFrame = document.getElementById('racFrame');" | |
1805 "racFrame.onload = function() {" | |
1806 "send('iframe loaded');" | |
1807 "};" | |
1808 "racFrame.src = \"" + iframe_url.spec() + "\";" | |
1809 "</script>" | |
1810 "</body>" | |
1811 "</html>")); | |
1812 | |
1813 ChromeAutofillClient* client = | |
1814 ChromeAutofillClient::FromWebContents(GetActiveWebContents()); | |
1815 ExpectDomMessage("iframe loaded"); | |
1816 EXPECT_FALSE(client->GetDialogControllerForTesting()); | |
1817 InitiateDialog(); | |
1818 | |
1819 EXPECT_TRUE(client->GetDialogControllerForTesting()); | |
1820 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
1821 EXPECT_FALSE(client->GetDialogControllerForTesting()); | |
1822 } | |
1823 | |
1764 } // namespace autofill | 1824 } // namespace autofill |
OLD | NEW |