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

Unified Diff: headless/lib/headless_web_contents_browsertest.cc

Issue 2709433002: Add HeadlessFocusClient to fix document.hasFocus() issues. (Closed)
Patch Set: Set FocusClient and add test Created 3 years, 10 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: headless/lib/headless_web_contents_browsertest.cc
diff --git a/headless/lib/headless_web_contents_browsertest.cc b/headless/lib/headless_web_contents_browsertest.cc
index 693e2dceeaa7ce9a1e380914e119a2923fabe70c..22e387752852b8402d05449dccb1db3ac146e275 100644
--- a/headless/lib/headless_web_contents_browsertest.cc
+++ b/headless/lib/headless_web_contents_browsertest.cc
@@ -61,6 +61,38 @@ IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, WindowOpen) {
browser_context->GetAllWebContents().size());
}
+IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Focus) {
+ EXPECT_TRUE(embedded_test_server()->Start());
+
+ HeadlessBrowserContext* browser_context =
+ browser()->CreateBrowserContextBuilder().Build();
+
+ HeadlessWebContents* web_contents =
+ browser_context->CreateWebContentsBuilder()
+ .SetInitialURL(embedded_test_server()->GetURL("/hello.html"))
+ .Build();
+ EXPECT_TRUE(WaitForLoad(web_contents));
+
+ bool result;
+ EXPECT_TRUE(EvaluateScript(web_contents, "document.hasFocus()")
+ ->GetResult()
+ ->GetValue()
+ ->GetAsBoolean(&result));
+ EXPECT_TRUE(result);
+
+ HeadlessWebContents* web_contents2 =
+ browser_context->CreateWebContentsBuilder()
+ .SetInitialURL(embedded_test_server()->GetURL("/hello.html"))
+ .Build();
+ EXPECT_TRUE(WaitForLoad(web_contents2));
+
+ EXPECT_TRUE(EvaluateScript(web_contents, "document.hasFocus()")
Eric Seckler 2017/02/22 09:00:04 nit: Let's add a todo here - focus of two web cont
irisu 2017/02/23 00:02:26 Done.
+ ->GetResult()
+ ->GetValue()
+ ->GetAsBoolean(&result));
+ EXPECT_FALSE(result);
+}
+
namespace {
bool DecodePNG(std::string base64_data, SkBitmap* bitmap) {
std::string png_data;

Powered by Google App Engine
This is Rietveld 408576698