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 LOG(INFO) << "Sending a mouse click to top level page's <input>."; | |
Charlie Reis
2016/02/17 06:22:14
nit: We generally avoid new LOG(INFO)s, unless the
EhsanK
2016/02/18 05:48:01
No. Sorry. It is there because I forgot to remove
| |
5324 TextInputStateObserver root_observer(root_rwhv); | |
5325 SimulateMouseClick(root_rwh, 1, 1); | |
5326 TextInputState new_state = root_observer.WaitUntilStateChanges(); | |
5327 EXPECT_EQ(new_state.type, ui::TEXT_INPUT_TYPE_TEXT); | |
5328 | |
5329 // Now focus the child frame and read the text input state. | |
5330 RenderWidgetHostImpl* child_rwh = | |
5331 child_frame_node->current_frame_host()->GetRenderWidgetHost(); | |
5332 RenderWidgetHostViewBase* child_rwhv = child_rwh->GetView(); | |
5333 TextInputStateObserver child_observer(child_rwhv); | |
5334 SimulateMouseClick(child_rwh, 1, 1); | |
5335 new_state = child_observer.WaitUntilStateChanges(); | |
5336 | |
5337 EXPECT_EQ(new_state.type, ui::TEXT_INPUT_TYPE_TEXT); | |
5338 | |
5339 // Finally, the top level view should see the child's view. | |
5340 new_state = *root_rwhv->current_text_input_state(); | |
5341 EXPECT_EQ(new_state.type, ui::TEXT_INPUT_TYPE_TEXT); | |
5342 EXPECT_EQ(new_state.value, cross_origin_url.spec()); | |
5343 } | |
5258 | 5344 |
5259 } // namespace content | 5345 } // namespace content |
OLD | NEW |