OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "chrome/browser/autofill/autofill_common_test.h" | 12 #include "chrome/browser/autofill/autofill_common_test.h" |
13 #include "chrome/browser/autofill/autofill_profile.h" | 13 #include "chrome/browser/autofill/autofill_profile.h" |
14 #include "chrome/browser/autofill/personal_data_manager.h" | 14 #include "chrome/browser/autofill/personal_data_manager.h" |
15 #include "chrome/browser/net/predictor_api.h" | 15 #include "chrome/browser/net/predictor_api.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/renderer_host/mock_render_process_host.h" | 17 #include "chrome/browser/renderer_host/mock_render_process_host.h" |
18 #include "chrome/browser/renderer_host/render_view_host.h" | 18 #include "chrome/browser/renderer_host/render_view_host.h" |
19 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
20 #include "chrome/browser/translate/translate_infobar_delegate.h" | 20 #include "chrome/browser/translate/translate_infobar_delegate.h" |
21 #include "chrome/browser/translate/translate_manager.h" | 21 #include "chrome/browser/translate/translate_manager.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
24 #include "chrome/common/net/test_url_fetcher_factory.h" | 25 #include "chrome/common/net/test_url_fetcher_factory.h" |
25 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
26 #include "chrome/renderer/translate_helper.h" | 27 #include "chrome/renderer/translate_helper.h" |
27 #include "chrome/test/in_process_browser_test.h" | 28 #include "chrome/test/in_process_browser_test.h" |
28 #include "chrome/test/ui_test_utils.h" | 29 #include "chrome/test/ui_test_utils.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "ui/base/keycodes/keyboard_code_conversion.h" | 31 #include "ui/base/keycodes/keyboard_code_conversion.h" |
31 | 32 |
| 33 static const char* kDataURIPrefix = "data:text/html;charset=utf-8,"; |
32 static const char* kTestFormString = | 34 static const char* kTestFormString = |
33 "<form action=\"http://www.google.com/\" method=\"POST\">" | 35 "<form action=\"http://www.example.com/\" method=\"POST\">" |
34 "<label for=\"firstname\">First name:</label>" | 36 "<label for=\"firstname\">First name:</label>" |
35 " <input type=\"text\" id=\"firstname\"" | 37 " <input type=\"text\" id=\"firstname\"" |
36 " onFocus=\"domAutomationController.send(true)\"" | 38 " onFocus=\"domAutomationController.send(true)\"" |
37 " /><br />" | 39 " /><br />" |
38 "<label for=\"lastname\">Last name:</label>" | 40 "<label for=\"lastname\">Last name:</label>" |
39 " <input type=\"text\" id=\"lastname\" /><br />" | 41 " <input type=\"text\" id=\"lastname\" /><br />" |
40 "<label for=\"address1\">Address line 1:</label>" | 42 "<label for=\"address1\">Address line 1:</label>" |
41 " <input type=\"text\" id=\"address1\" /><br />" | 43 " <input type=\"text\" id=\"address1\" /><br />" |
42 "<label for=\"address2\">Address line 2:</label>" | 44 "<label for=\"address2\">Address line 2:</label>" |
43 " <input type=\"text\" id=\"address2\" /><br />" | 45 " <input type=\"text\" id=\"address2\" /><br />" |
(...skipping 17 matching lines...) Expand all Loading... |
61 " <input type=\"text\" id=\"phone\" /><br />" | 63 " <input type=\"text\" id=\"phone\" /><br />" |
62 "</form>"; | 64 "</form>"; |
63 | 65 |
64 class AutoFillTest : public InProcessBrowserTest { | 66 class AutoFillTest : public InProcessBrowserTest { |
65 protected: | 67 protected: |
66 AutoFillTest() { | 68 AutoFillTest() { |
67 set_show_window(true); | 69 set_show_window(true); |
68 EnableDOMAutomation(); | 70 EnableDOMAutomation(); |
69 } | 71 } |
70 | 72 |
71 void SetUpProfile() { | 73 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 74 URLFetcher::set_factory(&url_fetcher_factory_); |
| 75 } |
| 76 |
| 77 void CreateTestProfile() { |
72 autofill_test::DisableSystemServices(browser()->profile()); | 78 autofill_test::DisableSystemServices(browser()->profile()); |
73 | 79 |
74 AutoFillProfile profile; | 80 AutoFillProfile profile; |
75 autofill_test::SetProfileInfo( | 81 autofill_test::SetProfileInfo( |
76 &profile, "Office Space", "Milton", "C.", "Waddams", | 82 &profile, "Office Space", "Milton", "C.", "Waddams", |
77 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane", | 83 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane", |
78 "Basement", "Austin", "Texas", "78744", "United States", "5125551234", | 84 "Basement", "Austin", "Texas", "78744", "United States", "5125551234", |
79 "5125550000"); | 85 "5125550000"); |
80 | 86 |
81 PersonalDataManager* personal_data_manager = | 87 PersonalDataManager* personal_data_manager = |
82 browser()->profile()->GetPersonalDataManager(); | 88 browser()->profile()->GetPersonalDataManager(); |
83 ASSERT_TRUE(personal_data_manager); | 89 ASSERT_TRUE(personal_data_manager); |
84 | 90 |
85 std::vector<AutoFillProfile> profiles(1, profile); | 91 std::vector<AutoFillProfile> profiles(1, profile); |
86 personal_data_manager->SetProfiles(&profiles); | 92 personal_data_manager->SetProfiles(&profiles); |
87 } | 93 } |
88 | 94 |
89 void ExpectFieldValue(const std::wstring& field_name, | 95 void ExpectFieldValue(const std::wstring& field_name, |
90 const std::string& expected_value) { | 96 const std::string& expected_value) { |
91 std::string value; | 97 std::string value; |
92 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 98 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
93 browser()->GetSelectedTabContents()->render_view_host(), L"", | 99 browser()->GetSelectedTabContents()->render_view_host(), L"", |
94 L"window.domAutomationController.send(" | 100 L"window.domAutomationController.send(" |
95 L"document.getElementById('" + field_name + L"').value);", &value)); | 101 L"document.getElementById('" + field_name + L"').value);", &value)); |
96 EXPECT_EQ(expected_value, value); | 102 EXPECT_EQ(expected_value, value); |
97 } | 103 } |
98 | 104 |
99 RenderViewHost* rvh() { | 105 RenderViewHost* render_view_host() { |
100 return browser()->GetSelectedTabContents()->render_view_host(); | 106 return browser()->GetSelectedTabContents()->render_view_host(); |
101 } | 107 } |
102 | 108 |
103 virtual void SetUp() { | |
104 URLFetcher::set_factory(&url_fetcher_factory_); | |
105 InProcessBrowserTest::SetUp(); | |
106 } | |
107 | |
108 void SimulateURLFetch(bool success) { | 109 void SimulateURLFetch(bool success) { |
109 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 110 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
110 ASSERT_TRUE(fetcher); | 111 ASSERT_TRUE(fetcher); |
111 net::URLRequestStatus status; | 112 net::URLRequestStatus status; |
112 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 113 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
113 net::URLRequestStatus::FAILED); | 114 net::URLRequestStatus::FAILED); |
114 | 115 |
115 std::string script = " var google = {};" | 116 std::string script = " var google = {};" |
116 "google.translate = (function() {" | 117 "google.translate = (function() {" |
117 " return {" | 118 " return {" |
(...skipping 19 matching lines...) Expand all Loading... |
137 " }" | 138 " }" |
138 " };" | 139 " };" |
139 "})();"; | 140 "})();"; |
140 | 141 |
141 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), | 142 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), |
142 status, success ? 200 : 500, | 143 status, success ? 200 : 500, |
143 ResponseCookies(), | 144 ResponseCookies(), |
144 script); | 145 script); |
145 } | 146 } |
146 | 147 |
147 void TryBasicFormFillWithMKey() { | 148 void FocusFirstNameField() { |
148 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), | 149 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), |
149 VIEW_ID_TAB_CONTAINER)); | 150 VIEW_ID_TAB_CONTAINER)); |
150 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), | 151 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
151 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 152 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
152 | 153 |
153 bool result = false; | 154 bool result = false; |
154 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 155 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
155 rvh(), L"", L"document.getElementById('firstname').focus();", &result)); | 156 render_view_host(), L"", |
| 157 L"document.getElementById('firstname').focus();", &result)); |
156 ASSERT_TRUE(result); | 158 ASSERT_TRUE(result); |
| 159 } |
| 160 |
| 161 void ExpectFilledTestForm() { |
| 162 ExpectFieldValue(L"firstname", "Milton"); |
| 163 ExpectFieldValue(L"lastname", "Waddams"); |
| 164 ExpectFieldValue(L"address1", "4120 Freidrich Lane"); |
| 165 ExpectFieldValue(L"address2", "Basement"); |
| 166 ExpectFieldValue(L"city", "Austin"); |
| 167 ExpectFieldValue(L"state", "TX"); |
| 168 ExpectFieldValue(L"zip", "78744"); |
| 169 ExpectFieldValue(L"country", "US"); |
| 170 ExpectFieldValue(L"phone", "5125551234"); |
| 171 } |
| 172 |
| 173 void TryBasicFormFill() { |
| 174 FocusFirstNameField(); |
| 175 |
157 // Start filling the first name field with "M" and wait for the popup to be | 176 // Start filling the first name field with "M" and wait for the popup to be |
158 // shown. | 177 // shown. |
159 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 178 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
160 browser(), ui::VKEY_M, false, true, false, false, | 179 browser(), ui::VKEY_M, false, true, false, false, |
161 NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS, | 180 NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS, |
162 Source<RenderViewHost>(rvh()))); | 181 Source<RenderViewHost>(render_view_host()))); |
163 | 182 |
164 // Press the down arrow to select the suggestion and preview the autofilled | 183 // Press the down arrow to select the suggestion and preview the autofilled |
165 // form. | 184 // form. |
166 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 185 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
167 browser(), ui::VKEY_DOWN, false, false, false, false, | 186 browser(), ui::VKEY_DOWN, false, false, false, false, |
168 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, | 187 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, |
169 Source<RenderViewHost>(rvh()))); | 188 Source<RenderViewHost>(render_view_host()))); |
170 | 189 |
171 // The previewed values should not be accessible to JavaScript. | 190 // The previewed values should not be accessible to JavaScript. |
172 ExpectFieldValue(L"firstname", "M"); | 191 ExpectFieldValue(L"firstname", "M"); |
173 ExpectFieldValue(L"lastname", ""); | 192 ExpectFieldValue(L"lastname", ""); |
174 ExpectFieldValue(L"address1", ""); | 193 ExpectFieldValue(L"address1", ""); |
175 ExpectFieldValue(L"address2", ""); | 194 ExpectFieldValue(L"address2", ""); |
176 ExpectFieldValue(L"city", ""); | 195 ExpectFieldValue(L"city", ""); |
177 ExpectFieldValue(L"state", ""); | 196 ExpectFieldValue(L"state", ""); |
178 ExpectFieldValue(L"zip", ""); | 197 ExpectFieldValue(L"zip", ""); |
179 ExpectFieldValue(L"country", ""); | 198 ExpectFieldValue(L"country", ""); |
180 ExpectFieldValue(L"phone", ""); | 199 ExpectFieldValue(L"phone", ""); |
181 // TODO(isherman): It would be nice to test that the previewed values are | 200 // TODO(isherman): It would be nice to test that the previewed values are |
182 // displayed: http://crbug.com/57220 | 201 // displayed: http://crbug.com/57220 |
183 | 202 |
184 // Press Enter to accept the autofill suggestions. | 203 // Press Enter to accept the autofill suggestions. |
185 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 204 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
186 browser(), ui::VKEY_RETURN, false, false, false, false, | 205 browser(), ui::VKEY_RETURN, false, false, false, false, |
187 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, | 206 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, |
188 Source<RenderViewHost>(rvh()))); | 207 Source<RenderViewHost>(render_view_host()))); |
189 | 208 |
190 // The form should be filled. | 209 // The form should be filled. |
191 ExpectFieldValue(L"firstname", "Milton"); | 210 ExpectFilledTestForm(); |
192 ExpectFieldValue(L"lastname", "Waddams"); | |
193 ExpectFieldValue(L"address1", "4120 Freidrich Lane"); | |
194 ExpectFieldValue(L"address2", "Basement"); | |
195 ExpectFieldValue(L"city", "Austin"); | |
196 ExpectFieldValue(L"state", "TX"); | |
197 ExpectFieldValue(L"zip", "78744"); | |
198 ExpectFieldValue(L"country", "US"); | |
199 ExpectFieldValue(L"phone", "5125551234"); | |
200 } | 211 } |
201 | 212 |
202 private: | 213 private: |
203 TestURLFetcherFactory url_fetcher_factory_; | 214 TestURLFetcherFactory url_fetcher_factory_; |
204 }; | 215 }; |
205 | 216 |
206 // Test that basic form fill is working. | 217 // Test that basic form fill is working. |
207 IN_PROC_BROWSER_TEST_F(AutoFillTest, BasicFormFill) { | 218 IN_PROC_BROWSER_TEST_F(AutoFillTest, BasicFormFill) { |
208 SetUpProfile(); | 219 CreateTestProfile(); |
209 | 220 |
| 221 // Load the test page. |
210 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 222 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
211 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), | 223 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), |
212 GURL("data:text/html;charset=utf-8," + std::string(kTestFormString)))); | 224 GURL(std::string(kDataURIPrefix) + kTestFormString))); |
213 | 225 |
214 TryBasicFormFillWithMKey(); | 226 // Invoke AutoFill. |
| 227 TryBasicFormFill(); |
215 } | 228 } |
216 | 229 |
217 // Test that basic form fill is working. | 230 // Test that form filling can be initiated by pressing the down arrow. |
218 IN_PROC_BROWSER_TEST_F(AutoFillTest, TranslateAndFormFill) { | 231 IN_PROC_BROWSER_TEST_F(AutoFillTest, AutoFillViaDownArrow) { |
219 SetUpProfile(); | 232 CreateTestProfile(); |
220 | 233 |
221 GURL url("data:text/html;charset=utf-8," | 234 // Load the test page. |
222 "<form action=\"http://www.google.com/\" method=\"POST\">" | |
223 "<label for=\"firstname\">なまえ</label>" | |
224 " <input type=\"text\" id=\"firstname\"" | |
225 " onFocus=\"domAutomationController.send(true)\"" | |
226 " /><br />" | |
227 "<label for=\"lastname\">みょうじ</label>" | |
228 " <input type=\"text\" id=\"lastname\" /><br />" | |
229 "<label for=\"address1\">Address line 1:</label>" | |
230 " <input type=\"text\" id=\"address1\" /><br />" | |
231 "<label for=\"address2\">Address line 2:</label>" | |
232 " <input type=\"text\" id=\"address2\" /><br />" | |
233 "<label for=\"city\">City:</label>" | |
234 " <input type=\"text\" id=\"city\" /><br />" | |
235 "<label for=\"state\">State:</label>" | |
236 " <select id=\"state\">" | |
237 " <option value=\"\" selected=\"yes\">--</option>" | |
238 " <option value=\"CA\">California</option>" | |
239 " <option value=\"TX\">Texas</option>" | |
240 " </select><br />" | |
241 "<label for=\"zip\">ZIP code:</label>" | |
242 " <input type=\"text\" id=\"zip\" /><br />" | |
243 "<label for=\"country\">Country:</label>" | |
244 " <select id=\"country\">" | |
245 " <option value=\"\" selected=\"yes\">--</option>" | |
246 " <option value=\"CA\">Canada</option>" | |
247 " <option value=\"US\">United States</option>" | |
248 " </select><br />" | |
249 "<label for=\"phone\">Phone number:</label>" | |
250 " <input type=\"text\" id=\"phone\" /><br />" | |
251 "</form>"); | |
252 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 235 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
253 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | 236 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), |
254 browser(), url)); | 237 GURL(std::string(kDataURIPrefix) + kTestFormString))); |
| 238 |
| 239 // Focus a fillable field. |
| 240 FocusFirstNameField(); |
| 241 |
| 242 // Press the down arrow to initiate AutoFill and wait for the popup to be |
| 243 // shown. |
| 244 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 245 browser(), ui::VKEY_DOWN, false, false, false, false, |
| 246 NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS, |
| 247 Source<RenderViewHost>(render_view_host()))); |
| 248 |
| 249 // Press the down arrow to select the suggestion and preview the autofilled |
| 250 // form. |
| 251 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 252 browser(), ui::VKEY_DOWN, false, false, false, false, |
| 253 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, |
| 254 Source<RenderViewHost>(render_view_host()))); |
| 255 |
| 256 // Press Enter to accept the autofill suggestions. |
| 257 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 258 browser(), ui::VKEY_RETURN, false, false, false, false, |
| 259 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, |
| 260 Source<RenderViewHost>(render_view_host()))); |
| 261 |
| 262 // The form should be filled. |
| 263 ExpectFilledTestForm(); |
| 264 } |
| 265 |
| 266 // Test that form filling works after reloading the current page. |
| 267 // This test brought to you by http://crbug.com/69204 |
| 268 IN_PROC_BROWSER_TEST_F(AutoFillTest, AutoFillAfterReload) { |
| 269 CreateTestProfile(); |
| 270 |
| 271 // Load the test page. |
| 272 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 273 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), |
| 274 GURL(std::string(kDataURIPrefix) + kTestFormString))); |
| 275 |
| 276 // Reload the page. |
| 277 NavigationController* controller = |
| 278 &browser()->GetSelectedTabContentsWrapper()->tab_contents()->controller(); |
| 279 controller->Reload(false); |
| 280 ui_test_utils::WaitForLoadStop(controller); |
| 281 |
| 282 // Invoke AutoFill. |
| 283 TryBasicFormFill(); |
| 284 } |
| 285 |
| 286 // Test that autofill works after page translation. |
| 287 IN_PROC_BROWSER_TEST_F(AutoFillTest, AutoFillAfterTranslate) { |
| 288 CreateTestProfile(); |
| 289 |
| 290 GURL url(std::string(kDataURIPrefix) + |
| 291 "<form action=\"http://www.example.com/\" method=\"POST\">" |
| 292 "<label for=\"fn\">なまえ</label>" |
| 293 " <input type=\"text\" id=\"fn\"" |
| 294 " onFocus=\"domAutomationController.send(true)\"" |
| 295 " /><br />" |
| 296 "<label for=\"ln\">みょうじ</label>" |
| 297 " <input type=\"text\" id=\"ln\" /><br />" |
| 298 "<label for=\"a1\">Address line 1:</label>" |
| 299 " <input type=\"text\" id=\"a1\" /><br />" |
| 300 "<label for=\"a2\">Address line 2:</label>" |
| 301 " <input type=\"text\" id=\"a2\" /><br />" |
| 302 "<label for=\"ci\">City:</label>" |
| 303 " <input type=\"text\" id=\"ci\" /><br />" |
| 304 "<label for=\"st\">State:</label>" |
| 305 " <select id=\"st\">" |
| 306 " <option value=\"\" selected=\"yes\">--</option>" |
| 307 " <option value=\"CA\">California</option>" |
| 308 " <option value=\"TX\">Texas</option>" |
| 309 " </select><br />" |
| 310 "<label for=\"z\">ZIP code:</label>" |
| 311 " <input type=\"text\" id=\"z\" /><br />" |
| 312 "<label for=\"co\">Country:</label>" |
| 313 " <select id=\"co\">" |
| 314 " <option value=\"\" selected=\"yes\">--</option>" |
| 315 " <option value=\"CA\">Canada</option>" |
| 316 " <option value=\"US\">United States</option>" |
| 317 " </select><br />" |
| 318 "<label for=\"ph\">Phone number:</label>" |
| 319 " <input type=\"text\" id=\"ph\" /><br />" |
| 320 "</form>"); |
| 321 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 322 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), url)); |
255 | 323 |
256 // Get translation bar. | 324 // Get translation bar. |
257 int page_id = browser()->GetSelectedTabContents()->controller(). | 325 int page_id = browser()->GetSelectedTabContents()->controller(). |
258 GetLastCommittedEntry()->page_id(); | 326 GetLastCommittedEntry()->page_id(); |
259 rvh()->OnMessageReceived(ViewHostMsg_PageContents(0, url, page_id, | 327 render_view_host()->OnMessageReceived(ViewHostMsg_PageContents( |
260 UTF8ToUTF16("test"), "ja", true)); | 328 0, url, page_id, ASCIIToUTF16("test"), "ja", true)); |
261 TranslateInfoBarDelegate* infobar = browser()->GetSelectedTabContents()-> | 329 TranslateInfoBarDelegate* infobar = browser()->GetSelectedTabContents()-> |
262 GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); | 330 GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); |
263 | 331 |
264 ASSERT_TRUE(infobar != NULL); | 332 ASSERT_TRUE(infobar != NULL); |
265 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); | 333 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); |
266 | 334 |
267 // Simulate press translation button. | 335 // Simulate translation button press. |
268 infobar->Translate(); | 336 infobar->Translate(); |
269 | 337 |
270 // Simulate the translate script being retrieved. | 338 // Simulate the translate script being retrieved. |
271 // Pass fake google.translate lib as the translate script. | 339 // Pass fake google.translate lib as the translate script. |
272 SimulateURLFetch(true); | 340 SimulateURLFetch(true); |
273 | 341 |
274 // Simulate translation to kick onTranslateElementLoad. | 342 // Simulate translation to kick onTranslateElementLoad. |
275 // But right now, the call stucks here. | 343 // But right now, the call stucks here. |
276 // Once click the text field, it starts again. | 344 // Once click the text field, it starts again. |
277 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 345 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
278 rvh(), L"", L"cr.googleTranslate.onTranslateElementLoad();")); | 346 render_view_host(), L"", |
| 347 L"cr.googleTranslate.onTranslateElementLoad();")); |
279 | 348 |
280 // Simulate the render notifying the translation has been done. | 349 // Simulate the render notifying the translation has been done. |
281 ui_test_utils::WaitForNotification(NotificationType::PAGE_TRANSLATED); | 350 ui_test_utils::WaitForNotification(NotificationType::PAGE_TRANSLATED); |
282 | 351 |
283 TryBasicFormFillWithMKey(); | 352 TryBasicFormFill(); |
284 } | 353 } |
OLD | NEW |