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

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

Issue 1414663011: Notifying the Out of Process Renderer about Visibility Change of a Remote Frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased & Added Blink Unit Tests Created 5 years 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 <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 501
502 private: 502 private:
503 // BrowserMessageFilter: 503 // BrowserMessageFilter:
504 bool OnMessageReceived(const IPC::Message& message) override { 504 bool OnMessageReceived(const IPC::Message& message) override {
505 return message.type() == FrameHostMsg_SwapOut_ACK::ID; 505 return message.type() == FrameHostMsg_SwapOut_ACK::ID;
506 } 506 }
507 507
508 DISALLOW_COPY_AND_ASSIGN(SwapoutACKMessageFilter); 508 DISALLOW_COPY_AND_ASSIGN(SwapoutACKMessageFilter);
509 }; 509 };
510 510
511 class RenderWidgetHostVisibilityObserver : public NotificationObserver {
512 public:
513 explicit RenderWidgetHostVisibilityObserver(RenderWidgetHostImpl* rwhi,
514 bool expected_visibility_state)
515 : expected_visibility_state_(expected_visibility_state),
516 was_observed_(false),
517 did_fail_(false),
518 source_(rwhi) {
519 registrar_.Add(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
520 source_);
521 message_loop_runner_ = new MessageLoopRunner;
522 }
523
524 bool WaitUntilSatisfied() {
525 if (!was_observed_)
526 message_loop_runner_->Run();
527 registrar_.Remove(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
528 source_);
529 return !did_fail_;
530 }
531
532 private:
533 void Observe(int type,
534 const NotificationSource& source,
535 const NotificationDetails& details) override {
536 was_observed_ = true;
537 did_fail_ = expected_visibility_state_ !=
538 (*static_cast<const Details<bool>&>(details).ptr());
539 if (message_loop_runner_->loop_running())
540 message_loop_runner_->Quit();
541 }
542
543 RenderWidgetHostImpl* render_widget_host_;
544 bool expected_visibility_state_;
545 scoped_refptr<MessageLoopRunner> message_loop_runner_;
546 NotificationRegistrar registrar_;
547 bool was_observed_;
548 bool did_fail_;
549 Source<RenderWidgetHost> source_;
550
551 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostVisibilityObserver);
552 };
553
511 } // namespace 554 } // namespace
512 555
513 // 556 //
514 // SitePerProcessBrowserTest 557 // SitePerProcessBrowserTest
515 // 558 //
516 559
517 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { 560 SitePerProcessBrowserTest::SitePerProcessBrowserTest() {
518 }; 561 };
519 562
520 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { 563 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) {
(...skipping 4128 matching lines...) Expand 10 before | Expand all | Expand 10 after
4649 // RenderFrame will be properly created and there will be no crash. 4692 // RenderFrame will be properly created and there will be no crash.
4650 // Therefore, navigate the remaining subframe to completely different site, 4693 // Therefore, navigate the remaining subframe to completely different site,
4651 // which will cause the original process to exit cleanly. 4694 // which will cause the original process to exit cleanly.
4652 NavigateFrameToURL( 4695 NavigateFrameToURL(
4653 web_contents->GetFrameTree()->root()->child_at(0), 4696 web_contents->GetFrameTree()->root()->child_at(0),
4654 embedded_test_server()->GetURL("d.com", "/title3.html")); 4697 embedded_test_server()->GetURL("d.com", "/title3.html"));
4655 watcher.Wait(); 4698 watcher.Wait();
4656 EXPECT_TRUE(watcher.did_exit_normally()); 4699 EXPECT_TRUE(watcher.did_exit_normally());
4657 } 4700 }
4658 4701
4702 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, VisibilityChanged) {
4703 GURL main_url(
4704 embedded_test_server()->GetURL("a.com", "/page_with_iframe.html"));
4705 EXPECT_TRUE(NavigateToURL(shell(), main_url));
4706 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), main_url);
4707
4708 GURL cross_site_url =
4709 embedded_test_server()->GetURL("oopif.com", "/title1.html");
4710
4711 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
4712 ->GetFrameTree()
4713 ->root();
4714
4715 TestNavigationObserver observer(shell()->web_contents());
4716
4717 NavigateFrameToURL(root->child_at(0), cross_site_url);
4718 EXPECT_EQ(cross_site_url, observer.last_navigation_url());
4719 EXPECT_TRUE(observer.last_navigation_succeeded());
4720
4721 RenderWidgetHostImpl* render_widget_host =
4722 root->child_at(0)->current_frame_host()->GetRenderWidgetHost();
4723 EXPECT_FALSE(render_widget_host->is_hidden());
4724
4725 std::string show_script =
4726 "document.querySelector('iframe').style.visibility = 'visible';";
4727 std::string hide_script =
4728 "document.querySelector('iframe').style.visibility = 'hidden';";
4729
4730 // Verify that hiding leads to a notification from RenderWidgetHost.
4731 RenderWidgetHostVisibilityObserver hide_observer(
4732 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), false);
4733 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), hide_script));
4734 EXPECT_TRUE(hide_observer.WaitUntilSatisfied());
4735
4736 // Verify showing leads to a notification as well.
4737 RenderWidgetHostVisibilityObserver show_observer(
4738 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), true);
4739 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), show_script));
4740 EXPECT_TRUE(show_observer.WaitUntilSatisfied());
4741 }
4742
4659 } // namespace content 4743 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698