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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 4051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4062 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); | 4062 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); |
4063 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); | 4063 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); |
4064 | 4064 |
4065 // Verify that the input field in the subframe received the keystrokes. | 4065 // Verify that the input field in the subframe received the keystrokes. |
4066 EXPECT_TRUE(ExecuteScriptAndExtractString( | 4066 EXPECT_TRUE(ExecuteScriptAndExtractString( |
4067 root->child_at(0)->current_frame_host(), | 4067 root->child_at(0)->current_frame_host(), |
4068 "window.domAutomationController.send(getInputFieldText());", &result)); | 4068 "window.domAutomationController.send(getInputFieldText());", &result)); |
4069 EXPECT_EQ("FOO", result); | 4069 EXPECT_EQ("FOO", result); |
4070 } | 4070 } |
4071 | 4071 |
4072 // Ensure that sequential focus navigation (advancing focused elements with | |
4073 // <tab> and <shift-tab>) works across cross-process subframes. | |
4074 // The test sets up six inputs fields in a page with two cross-process | |
4075 // subframes: | |
4076 // child1 child2 | |
4077 // /------------\ /------------\. | |
4078 // | 2. <input> | | 4. <input> | | |
4079 // 1. <input> | 3. <input> | | 5. <input> | 6. <input> | |
4080 // \------------/ \------------/. | |
4081 // | |
4082 // The test then presses <tab> six times to cycle through focused elements 1-6. | |
4083 // The test then repeats this with <shift-tab> to cycle in reverse order. | |
4084 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SequentialFocusNavigation) { | |
4085 GURL main_url(embedded_test_server()->GetURL( | |
4086 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); | |
4087 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
4088 | |
4089 WebContents* contents = shell()->web_contents(); | |
4090 FrameTreeNode* root = | |
4091 static_cast<WebContentsImpl*>(contents)->GetFrameTree()->root(); | |
4092 | |
4093 // Assign a name to each frame. This will be sent along in messages from | |
Charlie Reis
2015/12/04 21:44:50
nit: s/messages/test messages/
(To be clear that t
alexmos
2015/12/04 22:21:17
Done.
| |
4094 // focus events. | |
4095 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), | |
4096 "window.name = 'root';")); | |
4097 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), | |
4098 "window.name = 'child1';")); | |
4099 EXPECT_TRUE(ExecuteScript(root->child_at(1)->current_frame_host(), | |
4100 "window.name = 'child2';")); | |
4101 | |
4102 // This script will insert two <input> fields in the document, one at the | |
4103 // beginning and one at the end. For root frame, this means that we will | |
4104 // have an <input>, then two <iframe> elements, then another <input>. | |
Charlie Reis
2015/12/04 21:44:50
Heh, clever.
| |
4105 std::string script = | |
4106 "function onFocus(e) {" | |
4107 " domAutomationController.setAutomationId(0);" | |
4108 " domAutomationController.send(window.name + '-focused-' + e.target.id);" | |
4109 "}" | |
4110 "var input1 = document.createElement('input');" | |
4111 "input1.id = 'input1';" | |
4112 "var input2 = document.createElement('input');" | |
4113 "input2.id = 'input2';" | |
4114 "document.body.insertBefore(input1, document.body.firstChild);" | |
4115 "document.body.appendChild(input2);" | |
4116 "input1.addEventListener('focus', onFocus, false);" | |
4117 "input2.addEventListener('focus', onFocus, false);"; | |
4118 | |
4119 // Add two input fields to each of the three frames. | |
4120 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script)); | |
4121 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script)); | |
4122 EXPECT_TRUE(ExecuteScript(root->child_at(1)->current_frame_host(), script)); | |
4123 | |
4124 // Helper to simulate a tab press and wait for a focus message. | |
4125 auto press_tab_and_wait_for_message = [contents](bool reverse) { | |
4126 DOMMessageQueue msg_queue; | |
4127 std::string status; | |
Charlie Reis
2015/12/04 21:44:50
nit: s/status/reply/?
alexmos
2015/12/04 22:21:17
Done.
| |
4128 SimulateKeyPress(contents, ui::VKEY_TAB, false, reverse /* shift */, false, | |
4129 false); | |
4130 EXPECT_TRUE(msg_queue.WaitForMessage(&status)); | |
4131 return status; | |
4132 }; | |
4133 | |
4134 // Press <tab> six times to focus each of the <input> elements in turn. | |
4135 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(false)); | |
4136 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | |
4137 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(false)); | |
4138 EXPECT_EQ(root->child_at(0), root->frame_tree()->GetFocusedFrame()); | |
4139 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(false)); | |
4140 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(false)); | |
4141 EXPECT_EQ(root->child_at(1), root->frame_tree()->GetFocusedFrame()); | |
4142 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(false)); | |
4143 EXPECT_EQ("\"root-focused-input2\"", press_tab_and_wait_for_message(false)); | |
4144 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | |
4145 | |
4146 // Now, press <shift-tab> to navigate focus in the reverse direction. | |
4147 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(true)); | |
4148 EXPECT_EQ(root->child_at(1), root->frame_tree()->GetFocusedFrame()); | |
4149 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(true)); | |
4150 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); | |
4151 EXPECT_EQ(root->child_at(0), root->frame_tree()->GetFocusedFrame()); | |
4152 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(true)); | |
4153 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); | |
4154 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | |
4155 } | |
4156 | |
4072 // A WebContentsDelegate to capture ContextMenu creation events. | 4157 // A WebContentsDelegate to capture ContextMenu creation events. |
4073 class ContextMenuObserverDelegate : public WebContentsDelegate { | 4158 class ContextMenuObserverDelegate : public WebContentsDelegate { |
4074 public: | 4159 public: |
4075 ContextMenuObserverDelegate() | 4160 ContextMenuObserverDelegate() |
4076 : context_menu_created_(false), | 4161 : context_menu_created_(false), |
4077 message_loop_runner_(new MessageLoopRunner) {} | 4162 message_loop_runner_(new MessageLoopRunner) {} |
4078 | 4163 |
4079 ~ContextMenuObserverDelegate() override {} | 4164 ~ContextMenuObserverDelegate() override {} |
4080 | 4165 |
4081 bool HandleContextMenu(const content::ContextMenuParams& params) override { | 4166 bool HandleContextMenu(const content::ContextMenuParams& params) override { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4175 | 4260 |
4176 context_menu_delegate.Wait(); | 4261 context_menu_delegate.Wait(); |
4177 | 4262 |
4178 ContextMenuParams params = context_menu_delegate.getParams(); | 4263 ContextMenuParams params = context_menu_delegate.getParams(); |
4179 | 4264 |
4180 EXPECT_EQ(point.x(), params.x); | 4265 EXPECT_EQ(point.x(), params.x); |
4181 EXPECT_EQ(point.y(), params.y); | 4266 EXPECT_EQ(point.y(), params.y); |
4182 } | 4267 } |
4183 | 4268 |
4184 } // namespace content | 4269 } // namespace content |
OLD | NEW |