| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/keyboard_code_conversion.h" | |
| 9 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 10 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 11 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 12 #include "base/string16.h" | 11 #include "base/string16.h" |
| 13 #include "chrome/browser/autofill/autofill_common_test.h" | 12 #include "chrome/browser/autofill/autofill_common_test.h" |
| 14 #include "chrome/browser/autofill/autofill_profile.h" | 13 #include "chrome/browser/autofill/autofill_profile.h" |
| 15 #include "chrome/browser/autofill/personal_data_manager.h" | 14 #include "chrome/browser/autofill/personal_data_manager.h" |
| 16 #include "chrome/browser/net/predictor_api.h" | 15 #include "chrome/browser/net/predictor_api.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/renderer_host/mock_render_process_host.h" | 17 #include "chrome/browser/renderer_host/mock_render_process_host.h" |
| 19 #include "chrome/browser/renderer_host/render_view_host.h" | 18 #include "chrome/browser/renderer_host/render_view_host.h" |
| 20 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 21 #include "chrome/browser/translate/translate_infobar_delegate.h" | 20 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 22 #include "chrome/browser/translate/translate_manager.h" | 21 #include "chrome/browser/translate/translate_manager.h" |
| 23 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 25 #include "chrome/common/net/test_url_fetcher_factory.h" | 24 #include "chrome/common/net/test_url_fetcher_factory.h" |
| 26 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
| 28 #include "chrome/renderer/translate_helper.h" | 27 #include "chrome/renderer/translate_helper.h" |
| 29 #include "chrome/test/in_process_browser_test.h" | 28 #include "chrome/test/in_process_browser_test.h" |
| 30 #include "chrome/test/ui_test_utils.h" | 29 #include "chrome/test/ui_test_utils.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "ui/base/keycodes/keyboard_code_conversion.h" |
| 32 | 32 |
| 33 static const char* kTestFormString = | 33 static const char* kTestFormString = |
| 34 "<form action=\"http://www.google.com/\" method=\"POST\">" | 34 "<form action=\"http://www.google.com/\" method=\"POST\">" |
| 35 "<label for=\"firstname\">First name:</label>" | 35 "<label for=\"firstname\">First name:</label>" |
| 36 " <input type=\"text\" id=\"firstname\"" | 36 " <input type=\"text\" id=\"firstname\"" |
| 37 " onFocus=\"domAutomationController.send(true)\"" | 37 " onFocus=\"domAutomationController.send(true)\"" |
| 38 " /><br />" | 38 " /><br />" |
| 39 "<label for=\"lastname\">Last name:</label>" | 39 "<label for=\"lastname\">Last name:</label>" |
| 40 " <input type=\"text\" id=\"lastname\" /><br />" | 40 " <input type=\"text\" id=\"lastname\" /><br />" |
| 41 "<label for=\"address1\">Address line 1:</label>" | 41 "<label for=\"address1\">Address line 1:</label>" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), | 151 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 152 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 152 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 153 | 153 |
| 154 bool result = false; | 154 bool result = false; |
| 155 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 155 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 156 rvh(), L"", L"document.getElementById('firstname').focus();", &result)); | 156 rvh(), L"", L"document.getElementById('firstname').focus();", &result)); |
| 157 ASSERT_TRUE(result); | 157 ASSERT_TRUE(result); |
| 158 // Start filling the first name field with "M" and wait for the popup to be | 158 // Start filling the first name field with "M" and wait for the popup to be |
| 159 // shown. | 159 // shown. |
| 160 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 160 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 161 browser(), app::VKEY_M, false, true, false, false, | 161 browser(), ui::VKEY_M, false, true, false, false, |
| 162 NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS, | 162 NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS, |
| 163 Source<RenderViewHost>(rvh()))); | 163 Source<RenderViewHost>(rvh()))); |
| 164 | 164 |
| 165 // Press the down arrow to select the suggestion and preview the autofilled | 165 // Press the down arrow to select the suggestion and preview the autofilled |
| 166 // form. | 166 // form. |
| 167 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 167 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 168 browser(), app::VKEY_DOWN, false, false, false, false, | 168 browser(), ui::VKEY_DOWN, false, false, false, false, |
| 169 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, | 169 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, |
| 170 Source<RenderViewHost>(rvh()))); | 170 Source<RenderViewHost>(rvh()))); |
| 171 | 171 |
| 172 // The previewed values should not be accessible to JavaScript. | 172 // The previewed values should not be accessible to JavaScript. |
| 173 ExpectFieldValue(L"firstname", "M"); | 173 ExpectFieldValue(L"firstname", "M"); |
| 174 ExpectFieldValue(L"lastname", ""); | 174 ExpectFieldValue(L"lastname", ""); |
| 175 ExpectFieldValue(L"address1", ""); | 175 ExpectFieldValue(L"address1", ""); |
| 176 ExpectFieldValue(L"address2", ""); | 176 ExpectFieldValue(L"address2", ""); |
| 177 ExpectFieldValue(L"city", ""); | 177 ExpectFieldValue(L"city", ""); |
| 178 ExpectFieldValue(L"state", ""); | 178 ExpectFieldValue(L"state", ""); |
| 179 ExpectFieldValue(L"zip", ""); | 179 ExpectFieldValue(L"zip", ""); |
| 180 ExpectFieldValue(L"country", ""); | 180 ExpectFieldValue(L"country", ""); |
| 181 ExpectFieldValue(L"phone", ""); | 181 ExpectFieldValue(L"phone", ""); |
| 182 // TODO(isherman): It would be nice to test that the previewed values are | 182 // TODO(isherman): It would be nice to test that the previewed values are |
| 183 // displayed: http://crbug.com/57220 | 183 // displayed: http://crbug.com/57220 |
| 184 | 184 |
| 185 // Press Enter to accept the autofill suggestions. | 185 // Press Enter to accept the autofill suggestions. |
| 186 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 186 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 187 browser(), app::VKEY_RETURN, false, false, false, false, | 187 browser(), ui::VKEY_RETURN, false, false, false, false, |
| 188 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, | 188 NotificationType::AUTOFILL_DID_FILL_FORM_DATA, |
| 189 Source<RenderViewHost>(rvh()))); | 189 Source<RenderViewHost>(rvh()))); |
| 190 | 190 |
| 191 // The form should be filled. | 191 // The form should be filled. |
| 192 ExpectFieldValue(L"firstname", "Milton"); | 192 ExpectFieldValue(L"firstname", "Milton"); |
| 193 ExpectFieldValue(L"lastname", "Waddams"); | 193 ExpectFieldValue(L"lastname", "Waddams"); |
| 194 ExpectFieldValue(L"address1", "4120 Freidrich Lane"); | 194 ExpectFieldValue(L"address1", "4120 Freidrich Lane"); |
| 195 ExpectFieldValue(L"address2", "Basement"); | 195 ExpectFieldValue(L"address2", "Basement"); |
| 196 ExpectFieldValue(L"city", "Austin"); | 196 ExpectFieldValue(L"city", "Austin"); |
| 197 ExpectFieldValue(L"state", "TX"); | 197 ExpectFieldValue(L"state", "TX"); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // But right now, the call stucks here. | 277 // But right now, the call stucks here. |
| 278 // Once click the text field, it starts again. | 278 // Once click the text field, it starts again. |
| 279 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 279 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 280 rvh(), L"", L"cr.googleTranslate.onTranslateElementLoad();")); | 280 rvh(), L"", L"cr.googleTranslate.onTranslateElementLoad();")); |
| 281 | 281 |
| 282 // Simulate the render notifying the translation has been done. | 282 // Simulate the render notifying the translation has been done. |
| 283 ui_test_utils::WaitForNotification(NotificationType::PAGE_TRANSLATED); | 283 ui_test_utils::WaitForNotification(NotificationType::PAGE_TRANSLATED); |
| 284 | 284 |
| 285 TryBasicFormFillWithMKey(); | 285 TryBasicFormFillWithMKey(); |
| 286 } | 286 } |
| OLD | NEW |