| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
| 26 #include "chrome/renderer/translate_helper.h" | 26 #include "chrome/renderer/translate_helper.h" |
| 27 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
| 28 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/test/mock_render_process_host.h" | 33 #include "content/test/mock_render_process_host.h" |
| 34 #include "content/test/test_renderer_host.h" |
| 34 #include "content/test/test_url_fetcher_factory.h" | 35 #include "content/test/test_url_fetcher_factory.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "ui/base/keycodes/keyboard_codes.h" | 37 #include "ui/base/keycodes/keyboard_codes.h" |
| 37 | 38 |
| 38 using content::RenderViewHost; | 39 using content::RenderViewHost; |
| 40 using content::RenderViewHostTester; |
| 39 using content::WebContents; | 41 using content::WebContents; |
| 40 | 42 |
| 41 static const char* kDataURIPrefix = "data:text/html;charset=utf-8,"; | 43 static const char* kDataURIPrefix = "data:text/html;charset=utf-8,"; |
| 42 static const char* kTestFormString = | 44 static const char* kTestFormString = |
| 43 "<form action=\"http://www.example.com/\" method=\"POST\">" | 45 "<form action=\"http://www.example.com/\" method=\"POST\">" |
| 44 "<label for=\"firstname\">First name:</label>" | 46 "<label for=\"firstname\">First name:</label>" |
| 45 " <input type=\"text\" id=\"firstname\"" | 47 " <input type=\"text\" id=\"firstname\"" |
| 46 " onFocus=\"domAutomationController.send(true)\"><br>" | 48 " onFocus=\"domAutomationController.send(true)\"><br>" |
| 47 "<label for=\"lastname\">Last name:</label>" | 49 "<label for=\"lastname\">Last name:</label>" |
| 48 " <input type=\"text\" id=\"lastname\"><br>" | 50 " <input type=\"text\" id=\"lastname\"><br>" |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 " <option value=\"CA\">Canada</option>" | 686 " <option value=\"CA\">Canada</option>" |
| 685 " <option value=\"US\">United States</option>" | 687 " <option value=\"US\">United States</option>" |
| 686 " </select><br>" | 688 " </select><br>" |
| 687 "<label for=\"ph\">Phone number:</label>" | 689 "<label for=\"ph\">Phone number:</label>" |
| 688 " <input type=\"text\" id=\"ph\"><br>" | 690 " <input type=\"text\" id=\"ph\"><br>" |
| 689 "</form>"); | 691 "</form>"); |
| 690 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 692 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 691 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), url)); | 693 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), url)); |
| 692 | 694 |
| 693 // Get translation bar. | 695 // Get translation bar. |
| 694 render_view_host()->OnMessageReceivedForTesting( | 696 RenderViewHostTester::TestOnMessageReceived( |
| 697 render_view_host(), |
| 695 ChromeViewHostMsg_TranslateLanguageDetermined(0, "ja", true)); | 698 ChromeViewHostMsg_TranslateLanguageDetermined(0, "ja", true)); |
| 696 TranslateInfoBarDelegate* infobar = | 699 TranslateInfoBarDelegate* infobar = |
| 697 browser()->GetSelectedTabContentsWrapper()->infobar_tab_helper()-> | 700 browser()->GetSelectedTabContentsWrapper()->infobar_tab_helper()-> |
| 698 GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); | 701 GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); |
| 699 | 702 |
| 700 ASSERT_TRUE(infobar != NULL); | 703 ASSERT_TRUE(infobar != NULL); |
| 701 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); | 704 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); |
| 702 | 705 |
| 703 // Simulate translation button press. | 706 // Simulate translation button press. |
| 704 infobar->Translate(); | 707 infobar->Translate(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 716 // Once click the text field, it starts again. | 719 // Once click the text field, it starts again. |
| 717 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 720 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 718 render_view_host(), L"", | 721 render_view_host(), L"", |
| 719 L"cr.googleTranslate.onTranslateElementLoad();")); | 722 L"cr.googleTranslate.onTranslateElementLoad();")); |
| 720 | 723 |
| 721 // Simulate the render notifying the translation has been done. | 724 // Simulate the render notifying the translation has been done. |
| 722 translation_observer.Wait(); | 725 translation_observer.Wait(); |
| 723 | 726 |
| 724 TryBasicFormFill(); | 727 TryBasicFormFill(); |
| 725 } | 728 } |
| OLD | NEW |