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 5514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5525 new MainThreadFrameObserver(root_render_widget_host)); | 5525 new MainThreadFrameObserver(root_render_widget_host)); |
5526 observer->Wait(); | 5526 observer->Wait(); |
5527 | 5527 |
5528 // Force the renderer to generate a new frame. | 5528 // Force the renderer to generate a new frame. |
5529 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 5529 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
5530 "document.body.style.background = 'black'")); | 5530 "document.body.style.background = 'black'")); |
5531 | 5531 |
5532 // Waits for the next frame. | 5532 // Waits for the next frame. |
5533 observer->Wait(); | 5533 observer->Wait(); |
5534 } | 5534 } |
5535 // This class observes the first change in the text input state | |
5536 // for a given RenderWidgetHostViewBase. | |
5537 class TextInputStateObserver { | |
5538 public: | |
5539 TextInputStateObserver(RenderWidgetHostViewBase* view) | |
5540 : view_(view), | |
5541 state_(*view->current_text_input_state()), | |
5542 message_loop_runner_(nullptr) {} | |
5543 | |
5544 // Hold and keep polling the |view_| until its text input state changes. | |
5545 TextInputState WaitUntilStateChanges() { | |
5546 while (!DidChangeState()) { | |
5547 message_loop_runner_ = new MessageLoopRunner; | |
5548 BrowserThread::ID current_thread_id; | |
5549 EXPECT_TRUE( | |
5550 BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id)); | |
5551 BrowserThread::PostDelayedTask(current_thread_id, FROM_HERE, | |
5552 message_loop_runner_->QuitClosure(), | |
5553 base::TimeDelta::FromMicroseconds(500)); | |
Charlie Reis
2016/03/09 00:09:33
Is there any way to avoid this polling? It's gene
EhsanK
2016/03/14 19:58:08
Done.
| |
5554 message_loop_runner_->Run(); | |
5555 } | |
5556 return *view_->current_text_input_state(); | |
5557 } | |
5558 | |
5559 private: | |
5560 bool DidChangeState() { | |
5561 TextInputState current = *view_->current_text_input_state(); | |
5562 return state_.type != current.type || state_.mode != current.mode || | |
5563 state_.value != current.value; | |
5564 } | |
5565 RenderWidgetHostViewBase* view_; | |
5566 TextInputState state_; | |
5567 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
5568 | |
5569 DISALLOW_COPY_AND_ASSIGN(TextInputStateObserver); | |
5570 }; | |
5571 | |
5572 // Verify that by moving the focus between different frames the top-level | |
5573 // RenderWidgetHostViewBase tracks the input state properly. | |
5574 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, TextInputStateChanged) { | |
5575 GURL main_page_url(embedded_test_server()->GetURL( | |
5576 "a.com", "/textinput/page_with_input_field_and_iframe.html")); | |
5577 NavigateToURL(shell(), main_page_url); | |
5578 GURL cross_origin_url(embedded_test_server()->GetURL( | |
5579 "b.com", "/textinput/page_with_input_field_and_iframe.html")); | |
5580 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
5581 ->GetFrameTree() | |
5582 ->root(); | |
5583 // Wait for the main frame to finish loading. | |
5584 EXPECT_TRUE(WaitForRenderFrameReady(root->current_frame_host())); | |
5585 | |
5586 // Navigate the child frame. | |
5587 FrameTreeNode* child_frame_node = root->child_at(0); | |
5588 NavigateFrameToURL(child_frame_node, cross_origin_url); | |
5589 | |
5590 // Wait for the child frame to finish loading. | |
5591 EXPECT_TRUE(WaitForRenderFrameReady(child_frame_node->current_frame_host())); | |
5592 | |
5593 RenderWidgetHostImpl* root_rwh = | |
5594 root->current_frame_host()->GetRenderWidgetHost(); | |
5595 RenderWidgetHostViewBase* root_rwhv = root_rwh->GetView(); | |
5596 | |
5597 EXPECT_EQ(root_rwhv->current_text_input_state()->type, | |
5598 ui::TEXT_INPUT_TYPE_NONE); | |
Charlie Reis
2016/03/09 00:09:33
nit: Reverse the parameters, since the contract is
EhsanK
2016/03/14 19:58:08
Done.
| |
5599 // Focus the root (main-frame). This would focus the text input field. | |
Charlie Reis
2016/03/09 00:09:33
nit: Add blank line before.
EhsanK
2016/03/14 19:58:08
Done.
| |
5600 TextInputStateObserver root_observer(root_rwhv); | |
5601 SimulateMouseClick(root_rwh, 1, 1); | |
5602 TextInputState new_state = root_observer.WaitUntilStateChanges(); | |
5603 EXPECT_EQ(new_state.type, ui::TEXT_INPUT_TYPE_TEXT); | |
5604 | |
5605 // Now focus the child frame and read the text input state. | |
5606 RenderWidgetHostImpl* child_rwh = | |
5607 child_frame_node->current_frame_host()->GetRenderWidgetHost(); | |
5608 RenderWidgetHostViewBase* child_rwhv = child_rwh->GetView(); | |
5609 TextInputStateObserver child_observer(child_rwhv); | |
5610 SimulateMouseClick(child_rwh, 1, 1); | |
5611 new_state = child_observer.WaitUntilStateChanges(); | |
5612 | |
5613 EXPECT_EQ(new_state.type, ui::TEXT_INPUT_TYPE_TEXT); | |
5614 | |
5615 // Finally, the top level view should see the child's view. | |
5616 new_state = *root_rwhv->current_text_input_state(); | |
5617 EXPECT_EQ(new_state.type, ui::TEXT_INPUT_TYPE_TEXT); | |
5618 EXPECT_EQ(new_state.value, cross_origin_url.spec()); | |
5619 } | |
5535 | 5620 |
5536 // Test that a cross-origin iframe can be blocked by X-Frame-Options and CSP | 5621 // Test that a cross-origin iframe can be blocked by X-Frame-Options and CSP |
5537 // frame-ancestors. | 5622 // frame-ancestors. |
5538 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 5623 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
5539 CrossSiteIframeBlockedByXFrameOptionsOrCSP) { | 5624 CrossSiteIframeBlockedByXFrameOptionsOrCSP) { |
5540 GURL main_url(embedded_test_server()->GetURL( | 5625 GURL main_url(embedded_test_server()->GetURL( |
5541 "a.com", "/cross_site_iframe_factory.html?a(a)")); | 5626 "a.com", "/cross_site_iframe_factory.html?a(a)")); |
5542 NavigateToURL(shell(), main_url); | 5627 NavigateToURL(shell(), main_url); |
5543 | 5628 |
5544 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 5629 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5601 // affect future navigations for a frame. Verify this for the above | 5686 // affect future navigations for a frame. Verify this for the above |
5602 // navigation. | 5687 // navigation. |
5603 EXPECT_EQ(c_url.GetOrigin().spec(), | 5688 EXPECT_EQ(c_url.GetOrigin().spec(), |
5604 root->child_at(0)->current_origin().Serialize() + "/"); | 5689 root->child_at(0)->current_origin().Serialize() + "/"); |
5605 EXPECT_EQ(blink::WebSandboxFlags::None, | 5690 EXPECT_EQ(blink::WebSandboxFlags::None, |
5606 root->child_at(0)->effective_sandbox_flags()); | 5691 root->child_at(0)->effective_sandbox_flags()); |
5607 } | 5692 } |
5608 } | 5693 } |
5609 | 5694 |
5610 } // namespace content | 5695 } // namespace content |
OLD | NEW |