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

Side by Side 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, 9 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 unified diff | Download patch
« no previous file with comments | « headless/lib/browser/headless_web_contents_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "content/public/test/browser_test.h" 10 #include "content/public/test/browser_test.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 HeadlessWebContents* web_contents = 54 HeadlessWebContents* web_contents =
55 browser_context->CreateWebContentsBuilder() 55 browser_context->CreateWebContentsBuilder()
56 .SetInitialURL(embedded_test_server()->GetURL("/window_open.html")) 56 .SetInitialURL(embedded_test_server()->GetURL("/window_open.html"))
57 .Build(); 57 .Build();
58 EXPECT_TRUE(WaitForLoad(web_contents)); 58 EXPECT_TRUE(WaitForLoad(web_contents));
59 59
60 EXPECT_EQ(static_cast<size_t>(2), 60 EXPECT_EQ(static_cast<size_t>(2),
61 browser_context->GetAllWebContents().size()); 61 browser_context->GetAllWebContents().size());
62 } 62 }
63 63
64 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Focus) {
65 EXPECT_TRUE(embedded_test_server()->Start());
66
67 HeadlessBrowserContext* browser_context =
68 browser()->CreateBrowserContextBuilder().Build();
69
70 HeadlessWebContents* web_contents =
71 browser_context->CreateWebContentsBuilder()
72 .SetInitialURL(embedded_test_server()->GetURL("/hello.html"))
73 .Build();
74 EXPECT_TRUE(WaitForLoad(web_contents));
75
76 bool result;
77 EXPECT_TRUE(EvaluateScript(web_contents, "document.hasFocus()")
78 ->GetResult()
79 ->GetValue()
80 ->GetAsBoolean(&result));
81 EXPECT_TRUE(result);
82
83 HeadlessWebContents* web_contents2 =
84 browser_context->CreateWebContentsBuilder()
85 .SetInitialURL(embedded_test_server()->GetURL("/hello.html"))
86 .Build();
87 EXPECT_TRUE(WaitForLoad(web_contents2));
88
89 // TODO(irisu): Focus of two web contents should be independent of the other.
90 // Both web_contents and web_contents2 should be focused at this point.
91 EXPECT_TRUE(EvaluateScript(web_contents, "document.hasFocus()")
92 ->GetResult()
93 ->GetValue()
94 ->GetAsBoolean(&result));
95 EXPECT_FALSE(result);
96 EXPECT_TRUE(EvaluateScript(web_contents2, "document.hasFocus()")
97 ->GetResult()
98 ->GetValue()
99 ->GetAsBoolean(&result));
100 EXPECT_TRUE(result);
101 }
102
64 namespace { 103 namespace {
65 bool DecodePNG(std::string base64_data, SkBitmap* bitmap) { 104 bool DecodePNG(std::string base64_data, SkBitmap* bitmap) {
66 std::string png_data; 105 std::string png_data;
67 if (!base::Base64Decode(base64_data, &png_data)) 106 if (!base::Base64Decode(base64_data, &png_data))
68 return false; 107 return false;
69 return gfx::PNGCodec::Decode( 108 return gfx::PNGCodec::Decode(
70 reinterpret_cast<unsigned const char*>(png_data.data()), png_data.size(), 109 reinterpret_cast<unsigned const char*>(png_data.data()), png_data.size(),
71 bitmap); 110 bitmap);
72 } 111 }
73 } // namespace 112 } // namespace
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 devtools_client_->GetSecurity()->GetExperimental()->Disable( 181 devtools_client_->GetSecurity()->GetExperimental()->Disable(
143 security::DisableParams::Builder().Build()); 182 security::DisableParams::Builder().Build());
144 devtools_client_->GetSecurity()->GetExperimental()->RemoveObserver(this); 183 devtools_client_->GetSecurity()->GetExperimental()->RemoveObserver(this);
145 FinishAsynchronousTest(); 184 FinishAsynchronousTest();
146 } 185 }
147 }; 186 };
148 187
149 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessWebContentsSecurityTest); 188 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessWebContentsSecurityTest);
150 189
151 } // namespace headless 190 } // namespace headless
OLDNEW
« 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