| 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 506 |
| 507 private: | 507 private: |
| 508 // BrowserMessageFilter: | 508 // BrowserMessageFilter: |
| 509 bool OnMessageReceived(const IPC::Message& message) override { | 509 bool OnMessageReceived(const IPC::Message& message) override { |
| 510 return message.type() == FrameHostMsg_SwapOut_ACK::ID; | 510 return message.type() == FrameHostMsg_SwapOut_ACK::ID; |
| 511 } | 511 } |
| 512 | 512 |
| 513 DISALLOW_COPY_AND_ASSIGN(SwapoutACKMessageFilter); | 513 DISALLOW_COPY_AND_ASSIGN(SwapoutACKMessageFilter); |
| 514 }; | 514 }; |
| 515 | 515 |
| 516 class RenderWidgetHostVisibilityObserver : public NotificationObserver { |
| 517 public: |
| 518 explicit RenderWidgetHostVisibilityObserver(RenderWidgetHostImpl* rwhi, |
| 519 bool expected_visibility_state) |
| 520 : expected_visibility_state_(expected_visibility_state), |
| 521 was_observed_(false), |
| 522 did_fail_(false), |
| 523 source_(rwhi) { |
| 524 registrar_.Add(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 525 source_); |
| 526 message_loop_runner_ = new MessageLoopRunner; |
| 527 } |
| 528 |
| 529 bool WaitUntilSatisfied() { |
| 530 if (!was_observed_) |
| 531 message_loop_runner_->Run(); |
| 532 registrar_.Remove(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 533 source_); |
| 534 return !did_fail_; |
| 535 } |
| 536 |
| 537 private: |
| 538 void Observe(int type, |
| 539 const NotificationSource& source, |
| 540 const NotificationDetails& details) override { |
| 541 was_observed_ = true; |
| 542 did_fail_ = expected_visibility_state_ != |
| 543 (*static_cast<const Details<bool>&>(details).ptr()); |
| 544 if (message_loop_runner_->loop_running()) |
| 545 message_loop_runner_->Quit(); |
| 546 } |
| 547 |
| 548 RenderWidgetHostImpl* render_widget_host_; |
| 549 bool expected_visibility_state_; |
| 550 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 551 NotificationRegistrar registrar_; |
| 552 bool was_observed_; |
| 553 bool did_fail_; |
| 554 Source<RenderWidgetHost> source_; |
| 555 |
| 556 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostVisibilityObserver); |
| 557 }; |
| 558 |
| 516 } // namespace | 559 } // namespace |
| 517 | 560 |
| 518 // | 561 // |
| 519 // SitePerProcessBrowserTest | 562 // SitePerProcessBrowserTest |
| 520 // | 563 // |
| 521 | 564 |
| 522 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { | 565 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { |
| 523 }; | 566 }; |
| 524 | 567 |
| 525 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { | 568 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { |
| (...skipping 4128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4654 // RenderFrame will be properly created and there will be no crash. | 4697 // RenderFrame will be properly created and there will be no crash. |
| 4655 // Therefore, navigate the remaining subframe to completely different site, | 4698 // Therefore, navigate the remaining subframe to completely different site, |
| 4656 // which will cause the original process to exit cleanly. | 4699 // which will cause the original process to exit cleanly. |
| 4657 NavigateFrameToURL( | 4700 NavigateFrameToURL( |
| 4658 web_contents->GetFrameTree()->root()->child_at(0), | 4701 web_contents->GetFrameTree()->root()->child_at(0), |
| 4659 embedded_test_server()->GetURL("d.com", "/title3.html")); | 4702 embedded_test_server()->GetURL("d.com", "/title3.html")); |
| 4660 watcher.Wait(); | 4703 watcher.Wait(); |
| 4661 EXPECT_TRUE(watcher.did_exit_normally()); | 4704 EXPECT_TRUE(watcher.did_exit_normally()); |
| 4662 } | 4705 } |
| 4663 | 4706 |
| 4707 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, VisibilityChanged) { |
| 4708 GURL main_url( |
| 4709 embedded_test_server()->GetURL("a.com", "/page_with_iframe.html")); |
| 4710 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 4711 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), main_url); |
| 4712 |
| 4713 GURL cross_site_url = |
| 4714 embedded_test_server()->GetURL("oopif.com", "/title1.html"); |
| 4715 |
| 4716 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 4717 ->GetFrameTree() |
| 4718 ->root(); |
| 4719 |
| 4720 TestNavigationObserver observer(shell()->web_contents()); |
| 4721 |
| 4722 NavigateFrameToURL(root->child_at(0), cross_site_url); |
| 4723 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
| 4724 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 4725 |
| 4726 RenderWidgetHostImpl* render_widget_host = |
| 4727 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(); |
| 4728 EXPECT_FALSE(render_widget_host->is_hidden()); |
| 4729 |
| 4730 std::string show_script = |
| 4731 "document.querySelector('iframe').style.visibility = 'visible';"; |
| 4732 std::string hide_script = |
| 4733 "document.querySelector('iframe').style.visibility = 'hidden';"; |
| 4734 |
| 4735 // Verify that hiding leads to a notification from RenderWidgetHost. |
| 4736 RenderWidgetHostVisibilityObserver hide_observer( |
| 4737 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), false); |
| 4738 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), hide_script)); |
| 4739 EXPECT_TRUE(hide_observer.WaitUntilSatisfied()); |
| 4740 |
| 4741 // Verify showing leads to a notification as well. |
| 4742 RenderWidgetHostVisibilityObserver show_observer( |
| 4743 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), true); |
| 4744 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), show_script)); |
| 4745 EXPECT_TRUE(show_observer.WaitUntilSatisfied()); |
| 4746 } |
| 4747 |
| 4664 } // namespace content | 4748 } // namespace content |
| OLD | NEW |