OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/command_line.h" |
| 6 #include "base/win/metro.h" |
| 7 #include "content/public/browser/web_contents.h" |
| 8 #include "content/public/common/content_switches.h" |
| 9 #include "content/public/test/test_utils.h" |
| 10 #include "content/public/test/browser_test_utils.h" |
| 11 #include "content/shell/shell.h" |
| 12 #include "content/test/content_browser_test_utils.h" |
| 13 #include "content/test/content_browser_test.h" |
| 14 #include "ui/base/win/mock_tsf_bridge.h" |
| 15 #include "ui/base/win/tsf_bridge.h" |
| 16 |
| 17 namespace { |
| 18 class RenderWidgetHostViewWinTest : public content::ContentBrowserTest { |
| 19 public: |
| 20 RenderWidgetHostViewWinTest() {} |
| 21 |
| 22 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 23 command_line->AppendSwitch(switches::kEnableTextServiceFramework); |
| 24 } |
| 25 }; |
| 26 |
| 27 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewWinTest, SwichToPasswordField) { |
| 28 ui::MockTsfBridge mock_bridge; |
| 29 ui::TsfBridge* old_bridge = ui::TsfBridge::ReplaceForTesting(&mock_bridge); |
| 30 GURL test_url = content::GetTestUrl("textinput", |
| 31 "ime_enable_disable_test.html"); |
| 32 |
| 33 content::NavigateToURL(shell(), test_url); |
| 34 content::WaitForLoadStop(shell()->web_contents()); |
| 35 content::RunAllPendingInMessageLoop(); |
| 36 |
| 37 EXPECT_FALSE(mock_bridge.is_ime_enabled()); |
| 38 |
| 39 // Focus to the text field, the IME should be enabled. |
| 40 bool success = false; |
| 41 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
| 42 shell()->web_contents()->GetRenderViewHost(), L"", |
| 43 L"window.domAutomationController.send(text01_focus());", |
| 44 &success)); |
| 45 EXPECT_TRUE(success); |
| 46 content::WaitForLoadStop(shell()->web_contents()); |
| 47 content::RunAllPendingInMessageLoop(); |
| 48 EXPECT_TRUE(mock_bridge.is_ime_enabled()); |
| 49 |
| 50 // Focus to the password field, the IME should be disabled. |
| 51 success = false; |
| 52 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
| 53 shell()->web_contents()->GetRenderViewHost(), L"", |
| 54 L"window.domAutomationController.send(password02_focus());", |
| 55 &success)); |
| 56 EXPECT_TRUE(success); |
| 57 content::WaitForLoadStop(shell()->web_contents()); |
| 58 content::RunAllPendingInMessageLoop(); |
| 59 EXPECT_FALSE(mock_bridge.is_ime_enabled()); |
| 60 |
| 61 ui::TsfBridge::ReplaceForTesting(old_bridge); |
| 62 } |
| 63 |
| 64 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewWinTest, SwitchToSameField) { |
| 65 ui::MockTsfBridge mock_bridge; |
| 66 ui::TsfBridge* old_bridge = ui::TsfBridge::ReplaceForTesting(&mock_bridge); |
| 67 GURL test_url = content::GetTestUrl("textinput", |
| 68 "ime_enable_disable_test.html"); |
| 69 |
| 70 content::NavigateToURL(shell(), test_url); |
| 71 content::WaitForLoadStop(shell()->web_contents()); |
| 72 content::RunAllPendingInMessageLoop(); |
| 73 |
| 74 EXPECT_FALSE(mock_bridge.is_ime_enabled()); |
| 75 |
| 76 // Focus to the text field, the IME should be enabled. |
| 77 bool success = false; |
| 78 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
| 79 shell()->web_contents()->GetRenderViewHost(), L"", |
| 80 L"window.domAutomationController.send(text01_focus());", |
| 81 &success)); |
| 82 EXPECT_TRUE(success); |
| 83 content::WaitForLoadStop(shell()->web_contents()); |
| 84 content::RunAllPendingInMessageLoop(); |
| 85 EXPECT_TRUE(mock_bridge.is_ime_enabled()); |
| 86 |
| 87 // Focus to another text field, the IME should be enabled. |
| 88 success = false; |
| 89 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
| 90 shell()->web_contents()->GetRenderViewHost(), L"", |
| 91 L"window.domAutomationController.send(text02_focus());", |
| 92 &success)); |
| 93 EXPECT_TRUE(success); |
| 94 content::WaitForLoadStop(shell()->web_contents()); |
| 95 content::RunAllPendingInMessageLoop(); |
| 96 EXPECT_TRUE(mock_bridge.is_ime_enabled()); |
| 97 |
| 98 ui::TsfBridge::ReplaceForTesting(old_bridge); |
| 99 } |
| 100 |
| 101 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewWinTest, SwitchToSamePasswordField) { |
| 102 ui::MockTsfBridge mock_bridge; |
| 103 ui::TsfBridge* old_bridge = ui::TsfBridge::ReplaceForTesting(&mock_bridge); |
| 104 GURL test_url = content::GetTestUrl("textinput", |
| 105 "ime_enable_disable_test.html"); |
| 106 |
| 107 content::NavigateToURL(shell(), test_url); |
| 108 content::WaitForLoadStop(shell()->web_contents()); |
| 109 content::RunAllPendingInMessageLoop(); |
| 110 |
| 111 EXPECT_FALSE(mock_bridge.is_ime_enabled()); |
| 112 |
| 113 // Focus to the password field, the IME should be disabled. |
| 114 bool success = false; |
| 115 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
| 116 shell()->web_contents()->GetRenderViewHost(), L"", |
| 117 L"window.domAutomationController.send(password01_focus());", |
| 118 &success)); |
| 119 EXPECT_TRUE(success); |
| 120 content::WaitForLoadStop(shell()->web_contents()); |
| 121 content::RunAllPendingInMessageLoop(); |
| 122 EXPECT_FALSE(mock_bridge.is_ime_enabled()); |
| 123 |
| 124 // Focus to the another password field, the IME should be disabled. |
| 125 success = false; |
| 126 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
| 127 shell()->web_contents()->GetRenderViewHost(), L"", |
| 128 L"window.domAutomationController.send(password02_focus());", |
| 129 &success)); |
| 130 EXPECT_TRUE(success); |
| 131 content::WaitForLoadStop(shell()->web_contents()); |
| 132 content::RunAllPendingInMessageLoop(); |
| 133 EXPECT_FALSE(mock_bridge.is_ime_enabled()); |
| 134 |
| 135 ui::TsfBridge::ReplaceForTesting(old_bridge); |
| 136 } |
| 137 } // namespace |
OLD | NEW |