OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "chrome/browser/autofill/autofill_uitest_util.h" | 19 #include "chrome/browser/autofill/autofill_uitest_util.h" |
19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/translate/chrome_translate_client.h" | 22 #include "chrome/browser/translate/chrome_translate_client.h" |
22 #include "chrome/browser/translate/translate_service.h" | 23 #include "chrome/browser/translate/translate_service.h" |
23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 using base::ASCIIToUTF16; | 63 using base::ASCIIToUTF16; |
63 | 64 |
64 namespace autofill { | 65 namespace autofill { |
65 | 66 |
66 namespace { | 67 namespace { |
67 | 68 |
68 static const char kDataURIPrefix[] = "data:text/html;charset=utf-8,"; | 69 static const char kDataURIPrefix[] = "data:text/html;charset=utf-8,"; |
69 static const char kTestFormString[] = | 70 static const char kTestFormString[] = |
70 "<form action=\"http://www.example.com/\" method=\"POST\">" | 71 "<form action=\"http://www.example.com/\" method=\"POST\">" |
71 "<label for=\"firstname\">First name:</label>" | 72 "<label for=\"firstname\">First name:</label>" |
72 " <input type=\"text\" id=\"firstname\"" | 73 " <input type=\"text\" id=\"firstname\"><br>" |
73 " onfocus=\"domAutomationController.send(true)\"><br>" | |
74 "<label for=\"lastname\">Last name:</label>" | 74 "<label for=\"lastname\">Last name:</label>" |
75 " <input type=\"text\" id=\"lastname\"><br>" | 75 " <input type=\"text\" id=\"lastname\"><br>" |
76 "<label for=\"address1\">Address line 1:</label>" | 76 "<label for=\"address1\">Address line 1:</label>" |
77 " <input type=\"text\" id=\"address1\"><br>" | 77 " <input type=\"text\" id=\"address1\"><br>" |
78 "<label for=\"address2\">Address line 2:</label>" | 78 "<label for=\"address2\">Address line 2:</label>" |
79 " <input type=\"text\" id=\"address2\"><br>" | 79 " <input type=\"text\" id=\"address2\"><br>" |
80 "<label for=\"city\">City:</label>" | 80 "<label for=\"city\">City:</label>" |
81 " <input type=\"text\" id=\"city\"><br>" | 81 " <input type=\"text\" id=\"city\"><br>" |
82 "<label for=\"state\">State:</label>" | 82 "<label for=\"state\">State:</label>" |
83 " <select id=\"state\">" | 83 " <select id=\"state\">" |
(...skipping 29 matching lines...) Expand all Loading... |
113 "var textchange = false;" | 113 "var textchange = false;" |
114 "var textkeyup = false;" | 114 "var textkeyup = false;" |
115 "var textblur = false;" | 115 "var textblur = false;" |
116 "var selectfocus = false;" | 116 "var selectfocus = false;" |
117 "var selectinput = false;" | 117 "var selectinput = false;" |
118 "var selectchange = false;" | 118 "var selectchange = false;" |
119 "var selectblur = false;" | 119 "var selectblur = false;" |
120 "</script>" | 120 "</script>" |
121 "<form action=\"http://www.example.com/\" method=\"POST\">" | 121 "<form action=\"http://www.example.com/\" method=\"POST\">" |
122 "<label for=\"firstname\">First name:</label>" | 122 "<label for=\"firstname\">First name:</label>" |
123 " <input type=\"text\" id=\"firstname\"" | 123 " <input type=\"text\" id=\"firstname\"><br>" |
124 " onfocus=\"domAutomationController.send(true)\"><br>" | |
125 "<label for=\"lastname\">Last name:</label>" | 124 "<label for=\"lastname\">Last name:</label>" |
126 " <input type=\"text\" id=\"lastname\"" | 125 " <input type=\"text\" id=\"lastname\"" |
127 " onfocus=\"inputfocus = true\" onkeydown=\"inputkeydown = true\"" | 126 " onfocus=\"inputfocus = true\" onkeydown=\"inputkeydown = true\"" |
128 " oninput=\"inputinput = true\" onchange=\"inputchange = true\"" | 127 " oninput=\"inputinput = true\" onchange=\"inputchange = true\"" |
129 " onkeyup=\"inputkeyup = true\" onblur=\"inputblur = true\" ><br>" | 128 " onkeyup=\"inputkeyup = true\" onblur=\"inputblur = true\" ><br>" |
130 "<label for=\"address1\">Address line 1:</label>" | 129 "<label for=\"address1\">Address line 1:</label>" |
131 " <input type=\"text\" id=\"address1\"><br>" | 130 " <input type=\"text\" id=\"address1\"><br>" |
132 "<label for=\"address2\">Address line 2:</label>" | 131 "<label for=\"address2\">Address line 2:</label>" |
133 " <input type=\"text\" id=\"address2\"><br>" | 132 " <input type=\"text\" id=\"address2\"><br>" |
134 "<label for=\"city\">City:</label>" | 133 "<label for=\"city\">City:</label>" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 351 |
353 fetcher->set_url(fetcher->GetOriginalURL()); | 352 fetcher->set_url(fetcher->GetOriginalURL()); |
354 fetcher->set_status(net::URLRequestStatus::FromError(error)); | 353 fetcher->set_status(net::URLRequestStatus::FromError(error)); |
355 fetcher->set_response_code(success ? 200 : 500); | 354 fetcher->set_response_code(success ? 200 : 500); |
356 fetcher->SetResponseString(script); | 355 fetcher->SetResponseString(script); |
357 fetcher->delegate()->OnURLFetchComplete(fetcher); | 356 fetcher->delegate()->OnURLFetchComplete(fetcher); |
358 } | 357 } |
359 | 358 |
360 void FocusFieldByName(const std::string& name) { | 359 void FocusFieldByName(const std::string& name) { |
361 bool result = false; | 360 bool result = false; |
362 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 361 std::string script = base::StringPrintf( |
363 GetRenderViewHost(), | 362 R"( function onFocusHandler(e) { |
364 "if (document.readyState === 'complete')" | 363 e.target.removeEventListener(e.type, arguments.callee); |
365 " document.getElementById('" + name + "').focus();" | 364 domAutomationController.send(true); |
366 "else" | 365 } |
367 " domAutomationController.send(false);", | 366 if (document.readyState === 'complete') { |
368 &result)); | 367 var target = document.getElementById('%s'); |
| 368 target.addEventListener('focus', onFocusHandler); |
| 369 target.focus(); |
| 370 } else { |
| 371 domAutomationController.send(false); |
| 372 })", |
| 373 name.c_str()); |
| 374 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(GetRenderViewHost(), |
| 375 script, &result)); |
369 ASSERT_TRUE(result); | 376 ASSERT_TRUE(result); |
370 } | 377 } |
371 | 378 |
372 void FocusFirstNameField() { | 379 void FocusFirstNameField() { FocusFieldByName("firstname"); } |
373 bool result = false; | |
374 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
375 GetRenderViewHost(), | |
376 "if (document.readyState === 'complete')" | |
377 " document.getElementById('firstname').focus();" | |
378 "else" | |
379 " domAutomationController.send(false);", | |
380 &result)); | |
381 ASSERT_TRUE(result); | |
382 } | |
383 | 380 |
384 // Simulates a click on the middle of the DOM element with the given |id|. | 381 // Simulates a click on the middle of the DOM element with the given |id|. |
385 void ClickElementWithId(const std::string& id) { | 382 void ClickElementWithId(const std::string& id) { |
386 int x; | 383 int x; |
387 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 384 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
388 GetRenderViewHost(), | 385 GetRenderViewHost(), |
389 "var bounds = document.getElementById('" + | 386 "var bounds = document.getElementById('" + |
390 id + | 387 id + |
391 "').getBoundingClientRect();" | 388 "').getBoundingClientRect();" |
392 "domAutomationController.send(" | 389 "domAutomationController.send(" |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 #else | 785 #else |
789 #define MAYBE_OnSelectOptionFromDatalist OnSelectOptionFromDatalist | 786 #define MAYBE_OnSelectOptionFromDatalist OnSelectOptionFromDatalist |
790 #endif | 787 #endif |
791 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, | 788 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, |
792 MAYBE_OnSelectOptionFromDatalist) { | 789 MAYBE_OnSelectOptionFromDatalist) { |
793 // Load the test page. | 790 // Load the test page. |
794 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | 791 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
795 browser(), | 792 browser(), |
796 GURL(std::string(kDataURIPrefix) + | 793 GURL(std::string(kDataURIPrefix) + |
797 "<form action=\"http://www.example.com/\" method=\"POST\">" | 794 "<form action=\"http://www.example.com/\" method=\"POST\">" |
798 " <input list=\"dl\" type=\"search\" id=\"firstname\"" | 795 " <input list=\"dl\" type=\"search\" id=\"firstname\"><br>" |
799 " onfocus=\"domAutomationController.send(true)\"><br>" | |
800 " <datalist id=\"dl\">" | 796 " <datalist id=\"dl\">" |
801 " <option value=\"Adam\"></option>" | 797 " <option value=\"Adam\"></option>" |
802 " <option value=\"Bob\"></option>" | 798 " <option value=\"Bob\"></option>" |
803 " <option value=\"Carl\"></option>" | 799 " <option value=\"Carl\"></option>" |
804 " </datalist>" | 800 " </datalist>" |
805 "</form>"))); | 801 "</form>"))); |
806 std::string orginalcolor; | 802 std::string orginalcolor; |
807 GetFieldBackgroundColor("firstname", &orginalcolor); | 803 GetFieldBackgroundColor("firstname", &orginalcolor); |
808 | 804 |
809 FocusFirstNameField(); | 805 FocusFirstNameField(); |
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1891 std::string script_focus( | 1887 std::string script_focus( |
1892 "window.focus();" | 1888 "window.focus();" |
1893 "document.getElementById('CREDIT_CARD_NUMBER').focus();"); | 1889 "document.getElementById('CREDIT_CARD_NUMBER').focus();"); |
1894 ASSERT_TRUE(content::ExecuteScript(cross_frame, script_focus)); | 1890 ASSERT_TRUE(content::ExecuteScript(cross_frame, script_focus)); |
1895 | 1891 |
1896 // Send an arrow dow keypress in order to trigger the autofill popup. | 1892 // Send an arrow dow keypress in order to trigger the autofill popup. |
1897 SendKeyToPageAndWait(ui::DomKey::ARROW_DOWN); | 1893 SendKeyToPageAndWait(ui::DomKey::ARROW_DOWN); |
1898 } | 1894 } |
1899 | 1895 |
1900 } // namespace autofill | 1896 } // namespace autofill |
OLD | NEW |