Chromium Code Reviews| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" | 9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/interactive_test_utils.h" | 12 #include "chrome/test/base/interactive_test_utils.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 18 #include "content/public/test/content_browser_test_utils.h" | 18 #include "content/public/test/content_browser_test_utils.h" |
| 19 #include "content/public/test/test_navigation_observer.h" | 19 #include "content/public/test/test_navigation_observer.h" |
| 20 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
| 21 #include "net/dns/mock_host_resolver.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/test/embedded_test_server/embedded_test_server.h" | 22 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 23 #include "ui/base/ime/text_edit_commands.h" | |
| 23 #include "ui/display/display.h" | 24 #include "ui/display/display.h" |
| 24 #include "ui/display/screen.h" | 25 #include "ui/display/screen.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 28 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 29 #include "ui/base/ime/linux/text_edit_command_auralinux.h" | |
| 30 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | |
| 31 #endif | |
| 32 | |
| 27 class SitePerProcessInteractiveBrowserTest : public InProcessBrowserTest { | 33 class SitePerProcessInteractiveBrowserTest : public InProcessBrowserTest { |
| 28 public: | 34 public: |
| 29 SitePerProcessInteractiveBrowserTest() {} | 35 SitePerProcessInteractiveBrowserTest() {} |
| 30 ~SitePerProcessInteractiveBrowserTest() override {} | 36 ~SitePerProcessInteractiveBrowserTest() override {} |
| 31 | 37 |
| 32 void SetUpCommandLine(base::CommandLine* command_line) override { | 38 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 33 content::IsolateAllSitesForTesting(command_line); | 39 content::IsolateAllSitesForTesting(command_line); |
| 34 } | 40 } |
| 35 | 41 |
| 36 void SetUpOnMainThread() override { | 42 void SetUpOnMainThread() override { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('O'), | 170 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('O'), |
| 165 ui::DomCode::US_O, ui::VKEY_O, false, false, false, false); | 171 ui::DomCode::US_O, ui::VKEY_O, false, false, false, false); |
| 166 | 172 |
| 167 // Verify that the input field in the subframe received the keystrokes. | 173 // Verify that the input field in the subframe received the keystrokes. |
| 168 EXPECT_TRUE(ExecuteScriptAndExtractString( | 174 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 169 child, | 175 child, |
| 170 "window.domAutomationController.send(getInputFieldText());", &result)); | 176 "window.domAutomationController.send(getInputFieldText());", &result)); |
| 171 EXPECT_EQ("FOO", result); | 177 EXPECT_EQ("FOO", result); |
| 172 } | 178 } |
| 173 | 179 |
| 180 // Ensure that a cross-process subframe can utilize keyboard edit commands. | |
| 181 // See https://crbug.com/640706. This test is Linux-specific, as it relies on | |
| 182 // overriding TextEditKeyBindingsDelegateAuraLinux, which only exists on Linux. | |
| 183 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 184 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, | |
| 185 SubframeKeyboardEditCommands) { | |
|
Charlie Reis
2016/09/07 20:41:42
I think this might belong more in site_per_process
alexmos
2016/09/08 21:00:07
Done. It was straightforward to move. :)
| |
| 186 GURL main_url(embedded_test_server()->GetURL( | |
| 187 "a.com", "/frame_tree/page_with_one_frame.html")); | |
| 188 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 189 content::WebContents* web_contents = | |
| 190 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 191 | |
| 192 GURL frame_url( | |
| 193 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); | |
| 194 EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); | |
| 195 | |
| 196 // Focus the subframe and then its input field. The return value | |
| 197 // "input-focus" will be sent once the input field's focus event fires. | |
| 198 content::RenderFrameHost* child = | |
| 199 ChildFrameAt(web_contents->GetMainFrame(), 0); | |
| 200 std::string result; | |
| 201 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 202 child, "window.focus(); focusInputField();", &result)); | |
| 203 EXPECT_EQ("input-focus", result); | |
| 204 EXPECT_EQ(child, web_contents->GetFocusedFrame()); | |
| 205 | |
| 206 // Generate a couple of keystrokes, which will be routed to the subframe. | |
| 207 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('1'), | |
| 208 ui::DomCode::DIGIT1, ui::VKEY_1, false, false, false, false); | |
| 209 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('2'), | |
| 210 ui::DomCode::DIGIT2, ui::VKEY_2, false, false, false, false); | |
| 211 | |
| 212 // Verify that the input field in the subframe received the keystrokes. | |
| 213 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 214 child, "window.domAutomationController.send(getInputFieldText());", | |
| 215 &result)); | |
| 216 EXPECT_EQ("12", result); | |
| 217 | |
| 218 // Define and install a test delegate that translates any keystroke to a | |
| 219 // command to delete all text from current cursor position to the beginning | |
| 220 // of the line. | |
| 221 class TextDeleteDelegate : public ui::TextEditKeyBindingsDelegateAuraLinux { | |
| 222 public: | |
| 223 TextDeleteDelegate() {} | |
| 224 ~TextDeleteDelegate() override {} | |
| 225 | |
| 226 bool MatchEvent( | |
| 227 const ui::Event& event, | |
| 228 std::vector<ui::TextEditCommandAuraLinux>* commands) override { | |
| 229 if (commands) { | |
| 230 commands->emplace_back(ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE, | |
| 231 ""); | |
| 232 } | |
| 233 return true; | |
| 234 } | |
| 235 | |
| 236 private: | |
| 237 DISALLOW_COPY_AND_ASSIGN(TextDeleteDelegate); | |
| 238 }; | |
| 239 | |
| 240 TextDeleteDelegate delegate; | |
| 241 ui::TextEditKeyBindingsDelegateAuraLinux* old_delegate = | |
| 242 ui::GetTextEditKeyBindingsDelegate(); | |
| 243 ui::SetTextEditKeyBindingsDelegate(&delegate); | |
| 244 | |
| 245 // Press ctrl-alt-shift-D. The test's delegate will pretend that this | |
| 246 // corresponds to the command to delete everyting to the beginning of the | |
| 247 // line. Note the use of SendKeyPressSync instead of SimulateKeyPress, as | |
| 248 // the latter doesn't go through | |
| 249 // RenderWidgetHostViewAura::ForwardKeyboardEvent, which contains the edit | |
| 250 // commands logic that's's tested here. | |
|
Charlie Reis
2016/09/07 20:41:42
nit: that's
alexmos
2016/09/08 21:00:07
Done.
| |
| 251 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_D, | |
| 252 true, true, true, false)); | |
| 253 ui::SetTextEditKeyBindingsDelegate(old_delegate); | |
| 254 | |
| 255 // Verify that the input field in the subframe is erased. | |
| 256 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 257 child, "window.domAutomationController.send(getInputFieldText());", | |
| 258 &result)); | |
| 259 EXPECT_EQ("", result); | |
| 260 } | |
| 261 #endif | |
| 262 | |
| 174 // Ensure that sequential focus navigation (advancing focused elements with | 263 // Ensure that sequential focus navigation (advancing focused elements with |
| 175 // <tab> and <shift-tab>) works across cross-process subframes. | 264 // <tab> and <shift-tab>) works across cross-process subframes. |
| 176 // The test sets up six inputs fields in a page with two cross-process | 265 // The test sets up six inputs fields in a page with two cross-process |
| 177 // subframes: | 266 // subframes: |
| 178 // child1 child2 | 267 // child1 child2 |
| 179 // /------------\ /------------\. | 268 // /------------\ /------------\. |
| 180 // | 2. <input> | | 4. <input> | | 269 // | 2. <input> | | 4. <input> | |
| 181 // 1. <input> | 3. <input> | | 5. <input> | 6. <input> | 270 // 1. <input> | 3. <input> | | 5. <input> | 6. <input> |
| 182 // \------------/ \------------/. | 271 // \------------/ \------------/. |
| 183 // | 272 // |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 "document.pointerLockElement)", | 852 "document.pointerLockElement)", |
| 764 &mouse_locked)); | 853 &mouse_locked)); |
| 765 EXPECT_TRUE(mouse_locked); | 854 EXPECT_TRUE(mouse_locked); |
| 766 EXPECT_TRUE(main_frame->GetView()->IsMouseLocked()); | 855 EXPECT_TRUE(main_frame->GetView()->IsMouseLocked()); |
| 767 | 856 |
| 768 EXPECT_TRUE(ExecuteScript(main_frame, | 857 EXPECT_TRUE(ExecuteScript(main_frame, |
| 769 "document.querySelector('iframe').parentNode." | 858 "document.querySelector('iframe').parentNode." |
| 770 "removeChild(document.querySelector('iframe'))")); | 859 "removeChild(document.querySelector('iframe'))")); |
| 771 EXPECT_FALSE(main_frame->GetView()->IsMouseLocked()); | 860 EXPECT_FALSE(main_frame->GetView()->IsMouseLocked()); |
| 772 } | 861 } |
| OLD | NEW |