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