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

Unified Diff: headless/lib/headless_web_contents_browsertest.cc

Issue 2709433002: Add HeadlessFocusClient to fix document.hasFocus() issues. (Closed)
Patch Set: Remove unnecessary imports 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
« no previous file with comments | « headless/lib/browser/headless_web_contents_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3bb62652ee94425634e5a45587519c37f521dc26 100644
--- a/headless/lib/headless_web_contents_browsertest.cc
+++ b/headless/lib/headless_web_contents_browsertest.cc
@@ -61,6 +61,45 @@ 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));
+
+ // TODO(irisu): Focus of two web contents should be independent of the other.
+ // Both web_contents and web_contents2 should be focused at this point.
+ EXPECT_TRUE(EvaluateScript(web_contents, "document.hasFocus()")
+ ->GetResult()
+ ->GetValue()
+ ->GetAsBoolean(&result));
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(EvaluateScript(web_contents2, "document.hasFocus()")
+ ->GetResult()
+ ->GetValue()
+ ->GetAsBoolean(&result));
+ EXPECT_TRUE(result);
+}
+
namespace {
bool DecodePNG(std::string base64_data, SkBitmap* bitmap) {
std::string png_data;
« no previous file with comments | « headless/lib/browser/headless_web_contents_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698