Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 1652483002: Browser Side Text Input State Tracking for OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 #include "content/browser/frame_host/frame_tree.h" 24 #include "content/browser/frame_host/frame_tree.h"
25 #include "content/browser/frame_host/navigator.h" 25 #include "content/browser/frame_host/navigator.h"
26 #include "content/browser/frame_host/render_frame_proxy_host.h" 26 #include "content/browser/frame_host/render_frame_proxy_host.h"
27 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" 27 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
28 #include "content/browser/gpu/compositor_util.h" 28 #include "content/browser/gpu/compositor_util.h"
29 #include "content/browser/loader/resource_dispatcher_host_impl.h" 29 #include "content/browser/loader/resource_dispatcher_host_impl.h"
30 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" 30 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h"
31 #include "content/browser/renderer_host/render_view_host_impl.h" 31 #include "content/browser/renderer_host/render_view_host_impl.h"
32 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" 32 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
33 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 33 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
34 #include "content/browser/web_contents/web_contents_impl.h"
35 #include "content/common/frame_messages.h" 34 #include "content/common/frame_messages.h"
36 #include "content/common/input/synthetic_tap_gesture_params.h" 35 #include "content/common/input/synthetic_tap_gesture_params.h"
37 #include "content/common/view_messages.h" 36 #include "content/common/view_messages.h"
38 #include "content/public/browser/cert_store.h" 37 #include "content/public/browser/cert_store.h"
39 #include "content/public/browser/notification_observer.h" 38 #include "content/public/browser/notification_observer.h"
40 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
41 #include "content/public/browser/notification_types.h" 40 #include "content/public/browser/notification_types.h"
42 #include "content/public/browser/resource_dispatcher_host.h" 41 #include "content/public/browser/resource_dispatcher_host.h"
43 #include "content/public/common/browser_side_navigation_policy.h" 42 #include "content/public/common/browser_side_navigation_policy.h"
44 #include "content/public/common/content_switches.h" 43 #include "content/public/common/content_switches.h"
45 #include "content/public/common/url_constants.h" 44 #include "content/public/common/url_constants.h"
46 #include "content/public/test/browser_test_utils.h" 45 #include "content/public/test/browser_test_utils.h"
47 #include "content/public/test/content_browser_test_utils.h" 46 #include "content/public/test/content_browser_test_utils.h"
48 #include "content/public/test/test_navigation_observer.h" 47 #include "content/public/test/test_navigation_observer.h"
49 #include "content/public/test/test_utils.h" 48 #include "content/public/test/test_utils.h"
50 #include "content/shell/browser/shell.h"
51 #include "content/test/content_browser_test_utils_internal.h" 49 #include "content/test/content_browser_test_utils_internal.h"
52 #include "content/test/test_frame_navigation_observer.h" 50 #include "content/test/test_frame_navigation_observer.h"
53 #include "ipc/ipc_security_test_util.h" 51 #include "ipc/ipc_security_test_util.h"
54 #include "net/dns/mock_host_resolver.h" 52 #include "net/dns/mock_host_resolver.h"
55 #include "net/test/embedded_test_server/embedded_test_server.h" 53 #include "net/test/embedded_test_server/embedded_test_server.h"
56 #include "third_party/WebKit/public/web/WebInputEvent.h" 54 #include "third_party/WebKit/public/web/WebInputEvent.h"
57 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 55 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
58 #include "ui/events/event.h" 56 #include "ui/events/event.h"
59 #include "ui/events/event_utils.h" 57 #include "ui/events/event_utils.h"
60 #include "ui/gfx/geometry/point.h" 58 #include "ui/gfx/geometry/point.h"
(...skipping 6248 matching lines...) Expand 10 before | Expand all | Expand 10 after
6309 frame_observer.Wait(); 6307 frame_observer.Wait();
6310 EXPECT_EQ(b_url, root->current_url()); 6308 EXPECT_EQ(b_url, root->current_url());
6311 6309
6312 // Verify that the same RenderViewHost is preserved and that it is no longer 6310 // Verify that the same RenderViewHost is preserved and that it is no longer
6313 // in swapped out state. 6311 // in swapped out state.
6314 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( 6312 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost(
6315 root->current_frame_host()->GetSiteInstance())); 6313 root->current_frame_host()->GetSiteInstance()));
6316 EXPECT_FALSE(rvh->is_swapped_out_); 6314 EXPECT_FALSE(rvh->is_swapped_out_);
6317 } 6315 }
6318 6316
6317 // This class will sniff incoming IPC for ViewHostMsg_TextInputStateChanged.
6318 class TextInputStateChangedMessageFilter : public BrowserMessageFilter {
6319 public:
6320 explicit TextInputStateChangedMessageFilter(
6321 RenderWidgetHostImpl* render_widget_host)
6322 : BrowserMessageFilter(ViewMsgStart), text_input_state_changed_(false) {
6323 if (!render_widget_host || !render_widget_host->GetProcess())
6324 text_input_state_changed_ = true;
6325 old_state = *render_widget_host->GetView()->text_input_state();
6326 render_widget_host->GetProcess()->AddFilter(this);
6327 }
6328
6329 void WaitUntilTextInputStateChanges() {
6330 if (!text_input_state_changed_) {
6331 message_loop_runner_ = new MessageLoopRunner;
6332 message_loop_runner_->Run();
6333 }
6334 }
6335
6336 private:
6337 ~TextInputStateChangedMessageFilter() override {}
6338
6339 bool OnMessageReceived(const IPC::Message& msg) override {
6340 IPC_BEGIN_MESSAGE_MAP(TextInputStateChangedMessageFilter, msg)
6341 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged,
6342 OnTextInputStateChangedMessageReceived)
6343 IPC_END_MESSAGE_MAP()
6344 return false;
6345 }
6346
6347 void OnTextInputStateChangedMessageReceived(const TextInputState& new_state) {
6348 if (new_state.type != old_state.type || new_state.mode != old_state.mode ||
6349 new_state.value != old_state.value) {
6350 text_input_state_changed_ = true;
6351 if (message_loop_runner_)
6352 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
6353 message_loop_runner_->QuitClosure());
6354 }
6355 }
6356
6357 bool text_input_state_changed_;
6358 scoped_refptr<MessageLoopRunner> message_loop_runner_;
6359 TextInputState old_state;
6360
6361 DISALLOW_COPY_AND_ASSIGN(TextInputStateChangedMessageFilter);
6362 };
6363
6364 // Verify that when moving the focus between different frames, the WebContents
6365 // properly keeps track of the text input state.
6366 // The test loads a page with one input field, two out of process frames, and a
6367 // second input field positioned after the last <iframe>. Then a sequence of TAB
6368 // inputs are faked to navigate focus in between the different <input> elements.
6369 // After each change, we check with the RWHV of the frame as well as the
6370 // WebContents to make sure the text input state is as expected.
6371 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, TextInputStateChanged) {
6372 GURL main_page_url(embedded_test_server()->GetURL(
6373 "a.com", "/textinput/page_with_input_iframeX2_input.html"));
6374 NavigateToURL(shell(), main_page_url);
6375
6376 WebContents* contents = shell()->web_contents();
6377
6378 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
6379
6380 FrameTreeNode* child_b = root->child_at(0);
6381 GURL child_b_url(embedded_test_server()->GetURL(
6382 "b.com", "/textinput/page_with_input.html"));
6383 NavigateFrameToURL(child_b, child_b_url);
6384 EXPECT_TRUE(WaitForRenderFrameReady(child_b->current_frame_host()));
6385
6386 FrameTreeNode* child_c = root->child_at(1);
6387 GURL child_c_url(embedded_test_server()->GetURL(
6388 "c.com", "/textinput/page_with_input.html"));
6389 NavigateFrameToURL(child_c, child_c_url);
6390 EXPECT_TRUE(WaitForRenderFrameReady(child_c->current_frame_host()));
6391
6392 RenderWidgetHostImpl* root_rwh =
6393 root->current_frame_host()->GetRenderWidgetHost();
6394 RenderWidgetHostViewBase* root_rwhv = root_rwh->GetView();
6395
6396 RenderWidgetHostImpl* child_b_rwh =
6397 child_b->current_frame_host()->GetRenderWidgetHost();
6398 RenderWidgetHostViewBase* child_b_rwhv = child_b_rwh->GetView();
6399
6400 RenderWidgetHostImpl* child_c_rwh =
6401 child_c->current_frame_host()->GetRenderWidgetHost();
6402 RenderWidgetHostViewBase* child_c_rwhv = child_c_rwh->GetView();
6403
6404 // Change the text value in <input> field of either frame so that we can
6405 // later track the changes.
6406 EXPECT_TRUE(
6407 ExecuteScript(child_b->current_frame_host(),
6408 "document.querySelector('input').value = 'second';"));
6409 EXPECT_TRUE(
6410 ExecuteScript(child_c->current_frame_host(),
6411 "document.querySelector('input').value = 'third';"));
6412
6413 // Verify the input type is none in the beginning.
6414 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, root_rwhv->text_input_state()->type);
6415
6416 // A helper function to send a tab key to the frame and wait for a state
6417 // changed message.
6418 auto press_tab_and_wait_for_text_input_state_change =
6419 [contents](RenderWidgetHostImpl* rwh) {
6420 scoped_refptr<TextInputStateChangedMessageFilter> filter =
6421 new TextInputStateChangedMessageFilter(rwh);
6422 SimulateKeyPress(contents, ui::VKEY_TAB, false, false, false, false);
6423 filter->WaitUntilTextInputStateChanges();
6424 };
6425
6426 // Send focus to the first input field.
6427 press_tab_and_wait_for_text_input_state_change(root_rwh);
6428 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, root_rwhv->text_input_state()->type);
6429 EXPECT_EQ("first", root_rwhv->text_input_state()->value);
6430
6431 // Verify the top-level state is changed.
6432 EXPECT_EQ("first", web_contents()->GetTextInputState().value);
6433
6434 // Send focus to the input field in frame b.
6435 press_tab_and_wait_for_text_input_state_change(child_b_rwh);
6436 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, child_b_rwhv->text_input_state()->type);
6437 EXPECT_EQ("second", child_b_rwhv->text_input_state()->value);
6438
6439 EXPECT_EQ("second", web_contents()->GetTextInputState().value);
6440
6441 // Send focus to the input field in frame c.
6442 press_tab_and_wait_for_text_input_state_change(child_c_rwh);
6443 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, child_c_rwhv->text_input_state()->type);
6444 EXPECT_EQ("third", child_c_rwhv->text_input_state()->value);
6445
6446 EXPECT_EQ("third", web_contents()->GetTextInputState().value);
6447
6448 // Send focus to the last input field in top frame.
6449 press_tab_and_wait_for_text_input_state_change(root_rwh);
6450 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, root_rwhv->text_input_state()->type);
6451 EXPECT_EQ("fourth", root_rwhv->text_input_state()->value);
6452
6453 EXPECT_EQ("fourth", web_contents()->GetTextInputState().value);
6454 }
6455
6456 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
6457 TextInputStateChangesAfterRendererCrashes) {
6458 GURL main_url(
6459 embedded_test_server()->GetURL("a.com", "/page_with_iframe.html"));
6460 NavigateToURL(shell(), main_url);
6461 WebContentsImpl* contents = web_contents();
6462
6463 FrameTreeNode* root = contents->GetFrameTree()->root();
6464
6465 FrameTreeNode* child = root->child_at(0);
6466 GURL child_url(embedded_test_server()->GetURL(
6467 "b.com", "/textinput/page_with_input.html"));
6468 NavigateFrameToURL(child, child_url);
6469 EXPECT_TRUE(WaitForRenderFrameReady(child->current_frame_host()));
6470
6471 // Verify that the text input state is initially none.
6472 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, contents->GetTextInputState().type);
6473
6474 auto press_tab_and_wait_for_state_change =
6475 [contents](RenderWidgetHostImpl* rwh) {
6476 scoped_refptr<TextInputStateChangedMessageFilter> filter =
6477 new TextInputStateChangedMessageFilter(rwh);
6478 SimulateKeyPress(contents, ui::VKEY_TAB, false, false, false, false);
6479 filter->WaitUntilTextInputStateChanges();
6480 };
6481
6482 auto crash_renderer_and_wait_for_input_state_none = [contents](
6483 RenderProcessHost* host) {
6484 RenderProcessHostWatcher crash_observer(
6485 host, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
6486 host->Shutdown(0, false);
6487 crash_observer.Wait();
6488
6489 // We need to wait until the actual text input state update occurs.
6490 while (contents->GetTextInputState().type != ui::TEXT_INPUT_TYPE_NONE) {
6491 scoped_refptr<MessageLoopRunner> loop_runner_ = new MessageLoopRunner();
6492 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
6493 loop_runner_->QuitClosure(),
6494 base::TimeDelta::FromMilliseconds(0LL));
6495 loop_runner_->Run();
6496 }
6497 };
6498
6499 // Press a tab key to focus the <input> and verify that the top level
6500 // WebContents sees it.
6501 RenderWidgetHostImpl* child_rwh =
6502 child->current_frame_host()->GetRenderWidgetHost();
6503 press_tab_and_wait_for_state_change(child_rwh);
6504 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, contents->GetTextInputState().type);
6505
6506 // Crash the renderer and wait until WebContentsImpl has updates the
6507 // state.
6508 RenderProcessHost* child_process = child_rwh->GetProcess();
6509 crash_renderer_and_wait_for_input_state_none(child_process);
6510
6511 // Now repeat the same test for the top level RWHV.
6512 // First remove the <iframe> and append an <input>
6513 EXPECT_TRUE(ExecuteScript(contents,
6514 "var f = document.querySelector('iframe'); "
6515 "f.parentNode.removeChild(f);"));
6516 EXPECT_TRUE(ExecuteScript(
6517 contents, "document.body.appendChild(document.createElement('input'));"));
6518
6519 // Press tab to focus the <input> and observe the state change.
6520 RenderWidgetHostImpl* root_rwh =
6521 root->current_frame_host()->GetRenderWidgetHost();
6522 press_tab_and_wait_for_state_change(root_rwh);
6523 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, contents->GetTextInputState().type);
6524
6525 // Crash the tab renderer and observer the input state going back to none.
6526 RenderProcessHost* host_process = root_rwh->GetProcess();
6527 crash_renderer_and_wait_for_input_state_none(host_process);
6528 }
6529
6319 } // namespace content 6530 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698