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

Unified Diff: content/browser/frame_host/render_frame_host_impl_browsertest.cc

Issue 871443004: Expose the visibility state of a frame to the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rfh_isfocused
Patch Set: rebase Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/render_frame_host_impl_browsertest.cc
diff --git a/content/browser/frame_host/render_frame_host_impl_browsertest.cc b/content/browser/frame_host/render_frame_host_impl_browsertest.cc
index 4eba7f06429bf81b8db04ea191bf906b787196cb..11f17ac13db746d352ef73c6905d7fc9ed1276e1 100644
--- a/content/browser/frame_host/render_frame_host_impl_browsertest.cc
+++ b/content/browser/frame_host/render_frame_host_impl_browsertest.cc
@@ -5,10 +5,12 @@
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/content_client.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
+#include "content/test/test_content_browser_client.h"
namespace content {
@@ -18,6 +20,34 @@ RenderFrameHostImpl* ToRFHI(RenderFrameHost* render_frame_host) {
return static_cast<RenderFrameHostImpl*>(render_frame_host);
}
+// Implementation of ContentBrowserClient that overrides
+// OverridePageVisibilityState() and allows consumers to set a value.
+class PrerenderTestContentBrowserClient : public TestContentBrowserClient {
+ public:
+ PrerenderTestContentBrowserClient()
+ : override_enabled_(false),
+ visibility_override_(blink::WebPageVisibilityStateVisible)
+ {}
+ ~PrerenderTestContentBrowserClient() override {}
+
+ void EnableVisibilityOverride(
+ blink::WebPageVisibilityState visibility_override) {
+ override_enabled_ = true;
+ visibility_override_ = visibility_override;
+ }
+
+ void OverridePageVisibilityState(
+ RenderFrameHost* render_frame_host,
+ blink::WebPageVisibilityState* visibility_state) override {
+ if (override_enabled_)
+ *visibility_state = visibility_override_;
+ }
+
+ private:
+ bool override_enabled_;
+ blink::WebPageVisibilityState visibility_override_;
+};
jochen (gone - plz use gerrit) 2015/01/26 16:18:51 disallow copy/assign
mlamouri (slow - plz ping) 2015/01/26 17:40:43 Done.
+
} // anonymous namespace
using RenderFrameHostImplBrowserTest = ContentBrowserTest;
@@ -78,4 +108,38 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_Widget) {
#endif
}
+// Test that a frame is visible/hidden depending on its WebContents visibility
+// state.
+IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
+ GetVisibilityState_Basic) {
+ EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,foo")));
+ WebContents* web_contents = shell()->web_contents();
+
+ EXPECT_EQ(blink::WebPageVisibilityStateVisible,
+ ToRFHI(web_contents->GetMainFrame())->GetVisibilityState());
+
+ web_contents->WasHidden();
+ EXPECT_EQ(blink::WebPageVisibilityStateHidden,
+ ToRFHI(web_contents->GetMainFrame())->GetVisibilityState());
+}
+
+// Test that a frame visibility can be overridden by the ContentBrowserClient.
+IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
+ GetVisibilityState_Override) {
+ EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,foo")));
+ WebContents* web_contents = shell()->web_contents();
+
+ PrerenderTestContentBrowserClient new_client;
+ ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
+
+ EXPECT_EQ(blink::WebPageVisibilityStateVisible,
+ ToRFHI(web_contents->GetMainFrame())->GetVisibilityState());
+
+ new_client.EnableVisibilityOverride(blink::WebPageVisibilityStatePrerender);
+ EXPECT_EQ(blink::WebPageVisibilityStatePrerender,
+ ToRFHI(web_contents->GetMainFrame())->GetVisibilityState());
+
+ SetBrowserClientForTesting(old_client);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698