| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.h" | 7 #include "chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 11 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "extensions/test/extension_test_message_listener.h" | 13 #include "extensions/test/extension_test_message_listener.h" |
| 15 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
| 17 #include "ui/base/ime/composition_text.h" | 16 #include "ui/base/ime/composition_text.h" |
| 18 #include "ui/base/ime/dummy_text_input_client.h" | 17 #include "ui/base/ime/dummy_text_input_client.h" |
| 19 #include "ui/base/ime/input_method.h" | 18 #include "ui/base/ime/input_method.h" |
| 20 #include "url/origin.h" | |
| 21 | 19 |
| 22 namespace extensions { | 20 namespace extensions { |
| 23 | 21 |
| 24 class InputImeApiTest : public ExtensionApiTest { | 22 class InputImeApiTest : public ExtensionApiTest { |
| 25 public: | 23 public: |
| 26 InputImeApiTest() {} | 24 InputImeApiTest() {} |
| 27 | 25 |
| 28 protected: | 26 protected: |
| 29 void SetUpCommandLine(base::CommandLine* command_line) override { | 27 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 30 ExtensionApiTest::SetUpCommandLine(command_line); | 28 ExtensionApiTest::SetUpCommandLine(command_line); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 std::unique_ptr<ui::DummyTextInputClient> client2( | 100 std::unique_ptr<ui::DummyTextInputClient> client2( |
| 103 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | 101 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); |
| 104 input_method->SetFocusedTextInputClient(client2.get()); | 102 input_method->SetFocusedTextInputClient(client2.get()); |
| 105 ASSERT_TRUE(blur_listener.WaitUntilSatisfied()) << message_; | 103 ASSERT_TRUE(blur_listener.WaitUntilSatisfied()) << message_; |
| 106 | 104 |
| 107 input_method->DetachTextInputClient(client2.get()); | 105 input_method->DetachTextInputClient(client2.get()); |
| 108 } | 106 } |
| 109 | 107 |
| 110 IN_PROC_BROWSER_TEST_F(InputImeApiTest, SendKeyEventsOnNormalPage) { | 108 IN_PROC_BROWSER_TEST_F(InputImeApiTest, SendKeyEventsOnNormalPage) { |
| 111 // Navigates to special page that sendKeyEvents API has limition with. | 109 // Navigates to special page that sendKeyEvents API has limition with. |
| 112 GURL test_url(chrome::kChromeUINewTabURL); | 110 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
| 113 ui_test_utils::NavigateToURL(browser(), test_url); | |
| 114 // Manipulates the focused text input client because the follow cursor | 111 // Manipulates the focused text input client because the follow cursor |
| 115 // window requires the text input focus. | 112 // window requires the text input focus. |
| 116 ui::InputMethod* input_method = | 113 ui::InputMethod* input_method = |
| 117 browser()->window()->GetNativeWindow()->GetHost()->GetInputMethod(); | 114 browser()->window()->GetNativeWindow()->GetHost()->GetInputMethod(); |
| 118 std::unique_ptr<ui::DummyTextInputClient> client( | 115 std::unique_ptr<ui::DummyTextInputClient> client( |
| 119 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | 116 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); |
| 120 input_method->SetFocusedTextInputClient(client.get()); | 117 input_method->SetFocusedTextInputClient(client.get()); |
| 121 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; | 118 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; |
| 122 base::AutoReset<bool> auto_reset_disable_bubble( | 119 base::AutoReset<bool> auto_reset_disable_bubble( |
| 123 &InputImeActivateFunction::disable_bubble_for_testing_, true); | 120 &InputImeActivateFunction::disable_bubble_for_testing_, true); |
| 124 SetTrackKeyEvents(input_method, true); | 121 SetTrackKeyEvents(input_method, true); |
| 125 | 122 |
| 126 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | 123 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; |
| 127 | 124 |
| 128 content::WebContents* web_contents = | 125 std::vector<std::unique_ptr<ui::KeyEvent>> key_events; |
| 129 browser()->tab_strip_model()->GetActiveWebContents(); | 126 key_events.push_back(std::unique_ptr<ui::KeyEvent>( |
| 130 url::Origin origin(web_contents->GetLastCommittedURL()); | 127 new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE))); |
| 128 key_events.push_back(std::unique_ptr<ui::KeyEvent>( |
| 129 new ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE))); |
| 130 key_events.push_back(std::unique_ptr<ui::KeyEvent>( |
| 131 new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_CONTROL_DOWN))); |
| 132 key_events.push_back(std::unique_ptr<ui::KeyEvent>( |
| 133 new ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_CONTROL_DOWN))); |
| 134 key_events.push_back(std::unique_ptr<ui::KeyEvent>( |
| 135 new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_TAB, ui::EF_NONE))); |
| 131 | 136 |
| 132 // Don't check events if the url has not been correctly set. | 137 EXPECT_TRUE(CompareKeyEvents(key_events, input_method)); |
| 133 if (url::Origin(test_url).IsSameOriginWith(origin)) { | |
| 134 std::vector<std::unique_ptr<ui::KeyEvent>> key_events; | |
| 135 key_events.push_back(std::unique_ptr<ui::KeyEvent>( | |
| 136 new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE))); | |
| 137 key_events.push_back(std::unique_ptr<ui::KeyEvent>( | |
| 138 new ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE))); | |
| 139 key_events.push_back(std::unique_ptr<ui::KeyEvent>( | |
| 140 new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_CONTROL_DOWN))); | |
| 141 key_events.push_back(std::unique_ptr<ui::KeyEvent>(new ui::KeyEvent( | |
| 142 ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_CONTROL_DOWN))); | |
| 143 key_events.push_back(std::unique_ptr<ui::KeyEvent>( | |
| 144 new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_TAB, ui::EF_NONE))); | |
| 145 | |
| 146 EXPECT_TRUE(CompareKeyEvents(key_events, input_method)); | |
| 147 } | |
| 148 | 138 |
| 149 input_method->DetachTextInputClient(client.get()); | 139 input_method->DetachTextInputClient(client.get()); |
| 150 } | 140 } |
| 151 | 141 |
| 152 IN_PROC_BROWSER_TEST_F(InputImeApiTest, SendKeyEventsOnSpecialPage) { | 142 IN_PROC_BROWSER_TEST_F(InputImeApiTest, SendKeyEventsOnSpecialPage) { |
| 153 // Navigates to special page that sendKeyEvents API has limition with. | 143 // Navigates to special page that sendKeyEvents API has limition with. |
| 154 GURL test_url("chrome://flags"); | 144 ui_test_utils::NavigateToURL(browser(), GURL("chrome://flags")); |
| 155 ui_test_utils::NavigateToURL(browser(), test_url); | |
| 156 | 145 |
| 157 ui::InputMethod* input_method = | 146 ui::InputMethod* input_method = |
| 158 browser()->window()->GetNativeWindow()->GetHost()->GetInputMethod(); | 147 browser()->window()->GetNativeWindow()->GetHost()->GetInputMethod(); |
| 159 std::unique_ptr<ui::DummyTextInputClient> client( | 148 std::unique_ptr<ui::DummyTextInputClient> client( |
| 160 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | 149 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); |
| 161 input_method->SetFocusedTextInputClient(client.get()); | 150 input_method->SetFocusedTextInputClient(client.get()); |
| 162 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; | 151 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; |
| 163 base::AutoReset<bool> auto_reset_disable_bubble( | 152 base::AutoReset<bool> auto_reset_disable_bubble( |
| 164 &InputImeActivateFunction::disable_bubble_for_testing_, true); | 153 &InputImeActivateFunction::disable_bubble_for_testing_, true); |
| 165 SetTrackKeyEvents(input_method, true); | 154 SetTrackKeyEvents(input_method, true); |
| 166 | 155 |
| 167 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | 156 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; |
| 168 | 157 |
| 169 content::WebContents* web_contents = | 158 std::vector<std::unique_ptr<ui::KeyEvent>> key_events; |
| 170 browser()->tab_strip_model()->GetActiveWebContents(); | 159 key_events.push_back(std::unique_ptr<ui::KeyEvent>( |
| 171 url::Origin origin(web_contents->GetLastCommittedURL()); | 160 new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE))); |
| 161 key_events.push_back(std::unique_ptr<ui::KeyEvent>( |
| 162 new ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE))); |
| 172 | 163 |
| 173 // Don't check events if the url has not been correctly set. | 164 EXPECT_TRUE(CompareKeyEvents(key_events, input_method)); |
| 174 if (url::Origin(test_url).IsSameOriginWith(origin)) { | |
| 175 std::vector<std::unique_ptr<ui::KeyEvent>> key_events; | |
| 176 key_events.push_back(std::unique_ptr<ui::KeyEvent>( | |
| 177 new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE))); | |
| 178 key_events.push_back(std::unique_ptr<ui::KeyEvent>( | |
| 179 new ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE))); | |
| 180 | |
| 181 EXPECT_TRUE(CompareKeyEvents(key_events, input_method)); | |
| 182 } | |
| 183 input_method->DetachTextInputClient(client.get()); | 165 input_method->DetachTextInputClient(client.get()); |
| 184 } | 166 } |
| 185 | 167 |
| 186 } // namespace extensions | 168 } // namespace extensions |
| OLD | NEW |