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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 5237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5248 new MainThreadFrameObserver(root_render_widget_host)); | 5248 new MainThreadFrameObserver(root_render_widget_host)); |
5249 observer->Wait(); | 5249 observer->Wait(); |
5250 | 5250 |
5251 // Force the renderer to generate a new frame. | 5251 // Force the renderer to generate a new frame. |
5252 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 5252 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
5253 "document.body.style.background = 'black'")); | 5253 "document.body.style.background = 'black'")); |
5254 | 5254 |
5255 // Waits for the next frame. | 5255 // Waits for the next frame. |
5256 observer->Wait(); | 5256 observer->Wait(); |
5257 } | 5257 } |
| 5258 // This class observes the first change in the text input state |
| 5259 // for a given RenderWidgetHostViewBase. |
| 5260 class TextInputStateObserver { |
| 5261 public: |
| 5262 TextInputStateObserver(RenderWidgetHostViewBase* view) |
| 5263 : view_(view), |
| 5264 state_(*view->current_text_input_state()), |
| 5265 message_loop_runner_(nullptr) {} |
| 5266 |
| 5267 // Hold and keep polling the |view_| until its text input state changes. |
| 5268 TextInputState WaitUntilStateChanges() { |
| 5269 while (!DidChangeState()) { |
| 5270 message_loop_runner_ = new MessageLoopRunner; |
| 5271 BrowserThread::ID current_thread_id; |
| 5272 EXPECT_TRUE( |
| 5273 BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id)); |
| 5274 BrowserThread::PostDelayedTask(current_thread_id, FROM_HERE, |
| 5275 message_loop_runner_->QuitClosure(), |
| 5276 base::TimeDelta::FromMicroseconds(500)); |
| 5277 message_loop_runner_->Run(); |
| 5278 } |
| 5279 return *view_->current_text_input_state(); |
| 5280 } |
| 5281 |
| 5282 private: |
| 5283 bool DidChangeState() { |
| 5284 TextInputState current = *view_->current_text_input_state(); |
| 5285 return state_.type != current.type || state_.mode != current.mode || |
| 5286 state_.value != current.value; |
| 5287 } |
| 5288 RenderWidgetHostViewBase* view_; |
| 5289 TextInputState state_; |
| 5290 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 5291 |
| 5292 DISALLOW_COPY_AND_ASSIGN(TextInputStateObserver); |
| 5293 }; |
| 5294 |
| 5295 // Verify that by moving the focus between different frames the top-level |
| 5296 // RenderWidgetHostViewBase tracks the input state properly. |
| 5297 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, TextInputStateChanged) { |
| 5298 GURL main_page_url(embedded_test_server()->GetURL( |
| 5299 "a.com", "/textinput/page_with_input_field_and_iframe.html")); |
| 5300 NavigateToURL(shell(), main_page_url); |
| 5301 GURL cross_origin_url(embedded_test_server()->GetURL( |
| 5302 "b.com", "/textinput/page_with_input_field_and_iframe.html")); |
| 5303 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 5304 ->GetFrameTree() |
| 5305 ->root(); |
| 5306 // Wait for the main frame to finish loading. |
| 5307 EXPECT_TRUE(WaitForRenderFrameReady(root->current_frame_host())); |
| 5308 |
| 5309 // Navigate the child frame. |
| 5310 FrameTreeNode* child_frame_node = root->child_at(0); |
| 5311 NavigateFrameToURL(child_frame_node, cross_origin_url); |
| 5312 |
| 5313 // Wait for the child frame to finish loading. |
| 5314 EXPECT_TRUE(WaitForRenderFrameReady(child_frame_node->current_frame_host())); |
| 5315 |
| 5316 RenderWidgetHostImpl* root_rwh = |
| 5317 root->current_frame_host()->GetRenderWidgetHost(); |
| 5318 RenderWidgetHostViewBase* root_rwhv = root_rwh->GetView(); |
| 5319 |
| 5320 EXPECT_EQ(root_rwhv->current_text_input_state()->type, |
| 5321 ui::TEXT_INPUT_TYPE_NONE); |
| 5322 // Focus the root (main-frame). This would focus the text input field. |
| 5323 TextInputStateObserver root_observer(root_rwhv); |
| 5324 SimulateMouseClick(root_rwh, 1, 1); |
| 5325 TextInputState new_state = root_observer.WaitUntilStateChanges(); |
| 5326 EXPECT_EQ(new_state.type, ui::TEXT_INPUT_TYPE_TEXT); |
| 5327 |
| 5328 // Now focus the child frame and read the text input state. |
| 5329 RenderWidgetHostImpl* child_rwh = |
| 5330 child_frame_node->current_frame_host()->GetRenderWidgetHost(); |
| 5331 RenderWidgetHostViewBase* child_rwhv = child_rwh->GetView(); |
| 5332 TextInputStateObserver child_observer(child_rwhv); |
| 5333 SimulateMouseClick(child_rwh, 1, 1); |
| 5334 new_state = child_observer.WaitUntilStateChanges(); |
| 5335 |
| 5336 EXPECT_EQ(new_state.type, ui::TEXT_INPUT_TYPE_TEXT); |
| 5337 |
| 5338 // Finally, the top level view should see the child's view. |
| 5339 new_state = *root_rwhv->current_text_input_state(); |
| 5340 EXPECT_EQ(new_state.type, ui::TEXT_INPUT_TYPE_TEXT); |
| 5341 EXPECT_EQ(new_state.value, cross_origin_url.spec()); |
| 5342 } |
5258 | 5343 |
5259 } // namespace content | 5344 } // namespace content |
OLD | NEW |