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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/site_per_process_browsertest.cc
diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc
index 007c6cd1a724abf7b2f7e11ea854ef7dfd2f894e..9c6b0dac293dfa138f3f68a0ac68aeaa1dc260c8 100644
--- a/content/browser/site_per_process_browsertest.cc
+++ b/content/browser/site_per_process_browsertest.cc
@@ -483,6 +483,49 @@ class SwapoutACKMessageFilter : public BrowserMessageFilter {
DISALLOW_COPY_AND_ASSIGN(SwapoutACKMessageFilter);
};
+class RenderWidgetHostVisibilityObserver : public NotificationObserver {
+ public:
+ explicit RenderWidgetHostVisibilityObserver(RenderWidgetHostImpl* rwhi,
+ bool expected_visibility_state)
+ : expected_visibility_state_(expected_visibility_state),
+ observed_(false),
+ failed_(false),
+ source_(rwhi) {
+ registrar_.Add(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
+ source_);
+ message_loop_runner_ = new MessageLoopRunner;
+ }
+
+ bool WaitUntilSatisfied() {
+ if (!observed_)
+ message_loop_runner_->Run();
+ registrar_.Remove(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
+ source_);
+ return !failed_;
+ }
+
+ private:
+ void Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) override {
+ observed_ = true;
+ failed_ = expected_visibility_state_ !=
+ (*static_cast<const Details<bool>&>(details).ptr());
+ if (message_loop_runner_->loop_running())
+ message_loop_runner_->Quit();
+ }
+
+ RenderWidgetHostImpl* render_widget_host_;
+ bool expected_visibility_state_;
+ scoped_refptr<MessageLoopRunner> message_loop_runner_;
+ NotificationRegistrar registrar_;
+ bool observed_;
Charlie Reis 2015/12/08 19:18:34 nit: was_observed_
EhsanK 2015/12/09 00:14:17 Done.
+ bool failed_;
Charlie Reis 2015/12/08 19:18:34 nit: did_fail_
EhsanK 2015/12/09 00:14:16 Done.
+ Source<RenderWidgetHost> source_;
+
+ DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostVisibilityObserver);
+};
+
} // namespace
//
@@ -4181,4 +4224,44 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, MAYBE_CreateContextMenuTest) {
EXPECT_EQ(point.y(), params.y);
}
+IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, VisibilityChanged) {
+ GURL main_url(
+ embedded_test_server()->GetURL("a.com", "/page_with_iframe.html"));
+ EXPECT_TRUE(NavigateToURL(shell(), main_url));
+ EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), main_url);
+
+ GURL cross_site_url =
+ embedded_test_server()->GetURL("oopif.com", "/title1.html");
+
+ FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
+ ->GetFrameTree()
+ ->root();
+
+ TestNavigationObserver observer(shell()->web_contents());
+
+ NavigateFrameToURL(root->child_at(0), cross_site_url);
+ EXPECT_EQ(cross_site_url, observer.last_navigation_url());
+ EXPECT_TRUE(observer.last_navigation_succeeded());
+
+ RenderWidgetHostImpl* render_widget_host =
+ root->child_at(0)->current_frame_host()->GetRenderWidgetHost();
+ EXPECT_FALSE(render_widget_host->is_hidden());
+
+ std::string show_script =
+ "document.querySelector('iframe').style.visibility = 'visible';";
+ std::string hide_script =
+ "document.querySelector('iframe').style.visibility = 'hidden';";
+
+ // Verify that hiding leads to a notification from RenderWidgetHost
Charlie Reis 2015/12/08 19:18:33 nit: End with period.
EhsanK 2015/12/09 00:14:16 Done.
+ RenderWidgetHostVisibilityObserver hide_observer(
+ root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), false);
+ EXPECT_TRUE(ExecuteScript(shell()->web_contents(), hide_script));
+ EXPECT_TRUE(hide_observer.WaitUntilSatisfied());
+ // Verify showing leads to a notification as well.
Charlie Reis 2015/12/08 19:18:34 nit: Add blank line above.
EhsanK 2015/12/09 00:14:17 Done.
+ RenderWidgetHostVisibilityObserver show_observer(
+ root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), true);
+ EXPECT_TRUE(ExecuteScript(shell()->web_contents(), show_script));
+ EXPECT_TRUE(show_observer.WaitUntilSatisfied());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698