Remove web-test-specific code for focusing.
Drops the SetFocusAndActivate() test code from RenderViewImpl and the plumbing over to it. Instead, pretend to receive the focus/activate IPCs that the browser sends in production. window.focus() on another window goes through the browser process in production, but had a synchronous override in web tests, that allowed tests to pass even though we should need to wait to see the focus occur asynchronously in chrome. It also denies the request unless there is a user action present, but in web tests we dropped that requirement. This CL removes the web test override there, and adds user gestures to the tests that are performing a window.focus() on another window. Drop the focus of the main frame when navigating to about:blank between tests. The browser already sends a Focus() IPC to the main frame of the about:blank at the start of a test. This was causing the test windows to lie about being focused - they would all claim to be focused! It caused an error in one sensor test, where it runs code in the secondary inspector window that expects the window to be focused. So a mojom method is added to mojom::WebTestControlHost to move focus to that window for the test. Remove all the other extraneous focus-moving that was happening in the WebTestControlHost and friends browser code. That code was moving focus on Linux but does nothing on Mac, because on Mac headless mode the RenderWidgetHostView::Focus() method asks the OS to focus a window that isn't visible so it does nothing. Rename the testRunner.setWindowIsKey(bool) to setWindowFocus(bool) and remove comments explaining that the method is actually setting window focus. It would be nice to remove this entirely and use a separate window to move focus around, but that doesn't work for some tests, which is a bit interesting but not addressed by this CL. Drop the "previously focused window" tracking in TestRunner, which would keep around invalid (UAF-prone) pointers. Instead, iterate through the windows (actually, RenderViews) and blur the focused one there. The http/tests/serviceworker/clients-openwindow.html test expectations are adjusted as the renderer no longer marks the main frame as focused on navigation, so the service worker no longer reports the opened window as focused. Filed bug 1074482 and bug 1076129 for WPT tests that fail after this change. The former because it's either/both expecting run_web_tests.py to focus newly recreated windows and we don't, and it was calling window.focus() of another window, which had test-only synchronous code which we have removed. The latter because it seems to have a bug in how its written that this CL has uncovered. R=nasko@chromium.org Bug: 866140, 1069111, 1074482, 1076129 Change-Id: I9d7ed8f9c41a75fc8afaf6bb0bfc3e5772e1297c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2165248 Commit-Queue: danakj <danakj@chromium.org> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org> Reviewed-by: Mustaq Ahmed <mustaq@chromium.org> Reviewed-by: Nasko Oskov <nasko@chromium.org> Cr-Commit-Position: refs/heads/master@{#764725}
This commit is contained in:
content
public
renderer
shell
browser
shell.ccshell.hshell_devtools_frontend.ccshell_devtools_frontend.hshell_mac.mmshell_web_contents_view_delegate_views.cc
web_test
common
web_test
renderer
test_runner
test
third_party/blink/web_tests
TestExpectations
editing
fast
css
invalidation
deprecated-flexbox
dom
events
script-tests
forms
selectors
http
tests
devtools
notifications
resources
serviceworker
resources
scrollbars
custom-scrollbar-adjust-on-inactive-pseudo.htmlcustom-scrollbar-change-style-crash.htmlcustom-scrollbar-inactive-only-on-windowinactive-selector.htmlcustom-scrollbar-inactive-pseudo.htmlcustom-scrollbar-thumb-focus-iframe-inactive-pseudo.htmlcustom-scrollbar-thumb-inactive-pseudo.htmlcustom-scrollbar-thumb-width-changed-on-inactive-pseudo.html
virtual
forced-high-contrast-colors
fast
css
forced-colors-mode
wpt_internal
html
interaction
focus
the-autofocus-attribute
@ -14,7 +14,6 @@
|
||||
|
||||
namespace content {
|
||||
class RenderFrame;
|
||||
class RenderView;
|
||||
|
||||
// Turn a renderer into web test mode.
|
||||
void EnableRendererWebTestMode();
|
||||
@ -24,11 +23,6 @@ void EnableRendererWebTestMode();
|
||||
// between WebFrames and RenderFrames.
|
||||
void EnableWebTestProxyCreation();
|
||||
|
||||
// Sets the focus of the render view depending on |enable|. This only overrides
|
||||
// the state of the renderer, and does not sync the focus to the browser
|
||||
// process.
|
||||
void SetFocusAndActivate(RenderView* render_view, bool enable);
|
||||
|
||||
// Run all pending idle tasks immediately, and then invoke callback.
|
||||
void SchedulerRunIdleTasks(base::OnceClosure callback);
|
||||
|
||||
|
@ -1693,9 +1693,10 @@ void RenderThreadImpl::RequestNewLayerTreeFrameSink(
|
||||
const GURL& url,
|
||||
LayerTreeFrameSinkCallback callback,
|
||||
const char* client_name) {
|
||||
const bool for_web_tests = blink::WebTestMode();
|
||||
// Misconfigured bots (eg. crbug.com/780757) could run web tests on a
|
||||
// machine where gpu compositing doesn't work. Don't crash in that case.
|
||||
if (web_test_mode() && is_gpu_compositing_disabled_) {
|
||||
if (for_web_tests && is_gpu_compositing_disabled_) {
|
||||
LOG(FATAL) << "Web tests require gpu compositing, but it is disabled.";
|
||||
return;
|
||||
}
|
||||
@ -1719,7 +1720,7 @@ void RenderThreadImpl::RequestNewLayerTreeFrameSink(
|
||||
*base::CommandLine::ForCurrentProcess();
|
||||
cc::mojo_embedder::AsyncLayerTreeFrameSink::InitParams params;
|
||||
params.compositor_task_runner = compositor_task_runner_;
|
||||
if (web_test_mode() && !compositor_task_runner_) {
|
||||
if (for_web_tests && !compositor_task_runner_) {
|
||||
// The frame sink provider expects a compositor task runner, but we might
|
||||
// not have that if we're running web tests in single threaded mode.
|
||||
// Set it to be our thread's task runner instead.
|
||||
@ -1748,7 +1749,7 @@ void RenderThreadImpl::RequestNewLayerTreeFrameSink(
|
||||
compositor_frame_sink_client.InitWithNewPipeAndPassReceiver();
|
||||
|
||||
if (is_gpu_compositing_disabled_) {
|
||||
DCHECK(!web_test_mode());
|
||||
DCHECK(!for_web_tests);
|
||||
frame_sink_provider_->CreateForWidget(
|
||||
render_widget->routing_id(), std::move(compositor_frame_sink_receiver),
|
||||
std::move(compositor_frame_sink_client));
|
||||
|
@ -1779,11 +1779,9 @@ void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
|
||||
}
|
||||
|
||||
void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
|
||||
// TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
|
||||
// we won't have to test for user gesture anymore and we can
|
||||
// move that code back to render_widget.cc
|
||||
if (calling_frame && calling_frame->HasTransientUserActivation() &&
|
||||
!RenderThreadImpl::current()->web_test_mode()) {
|
||||
// We only allow focus to move to this RenderView when the request comes from
|
||||
// a user gesture. (See also https://bugs.webkit.org/show_bug.cgi?id=33389.)
|
||||
if (calling_frame && calling_frame->HasTransientUserActivation()) {
|
||||
Send(new ViewHostMsg_Focus(GetRoutingID()));
|
||||
|
||||
// Tattle on the frame that called |window.focus()|.
|
||||
@ -1815,29 +1813,6 @@ unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
|
||||
return history_list_length_;
|
||||
}
|
||||
|
||||
void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
|
||||
// If the main frame is remote, return immediately. Page level focus
|
||||
// should be set from the browser process, so if needed by tests it should
|
||||
// be properly supported.
|
||||
if (!main_render_frame_)
|
||||
return;
|
||||
|
||||
RenderWidget* render_widget = main_render_frame_->GetLocalRootRenderWidget();
|
||||
|
||||
if (enable == render_widget->has_focus())
|
||||
return;
|
||||
|
||||
if (enable) {
|
||||
SetActiveForWidget(true);
|
||||
// Fake an IPC message so go through the IPC handler.
|
||||
render_widget->OnSetFocus(true);
|
||||
} else {
|
||||
// Fake an IPC message so go through the IPC handler.
|
||||
render_widget->OnSetFocus(false);
|
||||
SetActiveForWidget(false);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
scoped_refptr<base::SingleThreadTaskRunner>
|
||||
RenderViewImpl::GetCleanupTaskRunner() {
|
||||
|
@ -191,11 +191,6 @@ class CONTENT_EXPORT RenderViewImpl : public blink::WebViewClient,
|
||||
// RenderView is the currently active RenderView of a WebContents.
|
||||
unsigned GetLocalSessionHistoryLengthForTesting() const;
|
||||
|
||||
// Invokes OnSetFocus and marks the widget as active depending on the value
|
||||
// of |enable|. This is used for web tests that need to control the focus
|
||||
// synchronously from the renderer.
|
||||
void SetFocusAndActivateForTesting(bool enable);
|
||||
|
||||
void UpdateBrowserControlsState(BrowserControlsState constraints,
|
||||
BrowserControlsState current,
|
||||
bool animate);
|
||||
|
@ -274,7 +274,6 @@ void Shell::LoadURLForFrame(const GURL& url,
|
||||
params.frame_name = frame_name;
|
||||
params.transition_type = transition_type;
|
||||
web_contents_->GetController().LoadURLWithParams(params);
|
||||
web_contents_->Focus();
|
||||
}
|
||||
|
||||
void Shell::LoadDataWithBaseURL(const GURL& url, const std::string& data,
|
||||
@ -318,7 +317,6 @@ void Shell::LoadDataWithBaseURLInternal(const GURL& url,
|
||||
params.virtual_url_for_data_url = url;
|
||||
params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE;
|
||||
web_contents_->GetController().LoadURLWithParams(params);
|
||||
web_contents_->Focus();
|
||||
}
|
||||
|
||||
void Shell::AddNewContents(WebContents* source,
|
||||
@ -338,22 +336,18 @@ void Shell::AddNewContents(WebContents* source,
|
||||
|
||||
void Shell::GoBackOrForward(int offset) {
|
||||
web_contents_->GetController().GoToOffset(offset);
|
||||
web_contents_->Focus();
|
||||
}
|
||||
|
||||
void Shell::Reload() {
|
||||
web_contents_->GetController().Reload(ReloadType::NORMAL, false);
|
||||
web_contents_->Focus();
|
||||
}
|
||||
|
||||
void Shell::ReloadBypassingCache() {
|
||||
web_contents_->GetController().Reload(ReloadType::BYPASSING_CACHE, false);
|
||||
web_contents_->Focus();
|
||||
}
|
||||
|
||||
void Shell::Stop() {
|
||||
web_contents_->Stop();
|
||||
web_contents_->Focus();
|
||||
}
|
||||
|
||||
void Shell::UpdateNavigationControls(bool to_different_document) {
|
||||
@ -374,7 +368,6 @@ void Shell::ShowDevTools() {
|
||||
}
|
||||
|
||||
devtools_frontend_->Activate();
|
||||
devtools_frontend_->Focus();
|
||||
}
|
||||
|
||||
void Shell::CloseDevTools() {
|
||||
@ -564,7 +557,15 @@ void Shell::RendererUnresponsive(
|
||||
}
|
||||
|
||||
void Shell::ActivateContents(WebContents* contents) {
|
||||
contents->GetRenderViewHost()->GetWidget()->Focus();
|
||||
#if !defined(OS_MACOSX)
|
||||
contents->Focus();
|
||||
#else
|
||||
// Mac headless mode is quite different than other platforms. Normally
|
||||
// focusing the WebContents would cause the OS to focus the window. Because
|
||||
// headless mac doesn't actually have system windows, we can't go down the
|
||||
// normal path and have to fake it out in the browser process.
|
||||
PlatformActivateContents(contents);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::unique_ptr<WebContents> Shell::ActivatePortalWebContents(
|
||||
|
@ -249,6 +249,10 @@ class Shell : public WebContentsDelegate,
|
||||
void PlatformSetIsLoading(bool loading);
|
||||
// Set the title of shell window
|
||||
void PlatformSetTitle(const base::string16& title);
|
||||
#if defined(OS_MACOSX)
|
||||
// Activate (make key) the native window, and focus the web contents.
|
||||
void PlatformActivateContents(WebContents* contents);
|
||||
#endif
|
||||
#if defined(OS_ANDROID)
|
||||
void PlatformToggleFullscreenModeForTab(WebContents* web_contents,
|
||||
bool enter_fullscreen);
|
||||
|
@ -39,10 +39,6 @@ void ShellDevToolsFrontend::Activate() {
|
||||
frontend_shell_->ActivateContents(frontend_shell_->web_contents());
|
||||
}
|
||||
|
||||
void ShellDevToolsFrontend::Focus() {
|
||||
frontend_shell_->web_contents()->Focus();
|
||||
}
|
||||
|
||||
void ShellDevToolsFrontend::InspectElementAt(int x, int y) {
|
||||
devtools_bindings_->InspectElementAt(x, y);
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ class ShellDevToolsFrontend : public ShellDevToolsDelegate,
|
||||
static ShellDevToolsFrontend* Show(WebContents* inspected_contents);
|
||||
|
||||
void Activate();
|
||||
void Focus();
|
||||
void InspectElementAt(int x, int y);
|
||||
void Close() override;
|
||||
|
||||
|
@ -12,6 +12,9 @@
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
#include "content/public/browser/render_widget_host_view.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/shell/app/resource.h"
|
||||
#import "ui/base/cocoa/underlay_opengl_hosting_window.h"
|
||||
@ -237,10 +240,47 @@ void Shell::PlatformCreateWindow(int width, int height) {
|
||||
url_edit_view_ = url_edit_view.get();
|
||||
}
|
||||
|
||||
// show the window
|
||||
// Show the new window.
|
||||
[window_.GetNativeNSWindow() makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
void Shell::PlatformActivateContents(WebContents* top_contents) {
|
||||
if (!headless_) {
|
||||
// This focuses the main frame RenderWidgetHost in the window, but does not
|
||||
// make the window itself active. The WebContentsDelegate (this class) is
|
||||
// responsible for doing both.
|
||||
top_contents->Focus();
|
||||
// This makes the window the active window for the application, and when the
|
||||
// app is active, the window will be also. That makes all RenderWidgetHosts
|
||||
// for the window active (which is separate from focused on mac).
|
||||
[window_.GetNativeNSWindow() makeKeyAndOrderFront:nil];
|
||||
// This makes the application active so that we can actually move focus
|
||||
// between windows and the renderer can receive focus/blur events.
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
return;
|
||||
}
|
||||
|
||||
// In headless mode, there are no system windows, so we can't go down the
|
||||
// normal path which relies on calling the OS to move focus/active states.
|
||||
// Instead we fake it out by just informing the RenderWidgetHost directly.
|
||||
|
||||
// For all windows other than this one, blur them.
|
||||
for (Shell* window : windows_) {
|
||||
if (window != this) {
|
||||
WebContents* other_top_contents = window->web_contents();
|
||||
RenderWidgetHost* other_main_widget =
|
||||
other_top_contents->GetMainFrame()->GetView()->GetRenderWidgetHost();
|
||||
other_main_widget->Blur();
|
||||
other_main_widget->SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
RenderWidgetHost* main_widget =
|
||||
top_contents->GetMainFrame()->GetView()->GetRenderWidgetHost();
|
||||
main_widget->Focus();
|
||||
main_widget->SetActive(true);
|
||||
}
|
||||
|
||||
void Shell::PlatformSetContents() {
|
||||
NSView* web_view = web_contents_->GetNativeView().GetNativeNSView();
|
||||
[web_view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
|
||||
|
@ -39,7 +39,6 @@ class ContextMenuModel : public ui::SimpleMenuModel,
|
||||
ShellDevToolsFrontend* devtools_frontend =
|
||||
ShellDevToolsFrontend::Show(web_contents_);
|
||||
devtools_frontend->Activate();
|
||||
devtools_frontend->Focus();
|
||||
devtools_frontend->InspectElementAt(params_.x, params_.y);
|
||||
break;
|
||||
};
|
||||
|
@ -562,9 +562,12 @@ bool WebTestControlHost::PrepareForWebTest(const TestInfo& test_info) {
|
||||
main_window_->web_contents());
|
||||
}
|
||||
|
||||
// Focus the RenderWidgetHost. This will send an IPC message to the
|
||||
// renderer to propagate the state change.
|
||||
main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus();
|
||||
// We don't go down the normal system path of focusing RenderWidgetHostView
|
||||
// because on mac headless, there are no system windows and that path does
|
||||
// not do anything. Instead we go through the Shell::ActivateContents() path
|
||||
// which knows how to perform the activation correctly on all platforms and in
|
||||
// headless mode.
|
||||
main_window_->ActivateContents(main_window_->web_contents());
|
||||
|
||||
// Flush various interfaces to ensure a test run begins from a known
|
||||
// state.
|
||||
@ -1425,6 +1428,16 @@ void WebTestControlHost::SetFilePathForMockFileDialog(
|
||||
ui::SelectFileDialog::SetFactory(new FakeSelectFileDialogFactory(path));
|
||||
}
|
||||
|
||||
void WebTestControlHost::FocusDevtoolsSecondaryWindow() {
|
||||
CHECK(secondary_window_);
|
||||
// We don't go down the normal system path of focusing RenderWidgetHostView
|
||||
// because on mac headless, there are no system windows and that path does
|
||||
// not do anything. Instead we go through the Shell::ActivateContents() path
|
||||
// which knows how to perform the activation correctly on all platforms and in
|
||||
// headless mode.
|
||||
secondary_window_->ActivateContents(secondary_window_->web_contents());
|
||||
}
|
||||
|
||||
void WebTestControlHost::GoToOffset(int offset) {
|
||||
main_window_->GoBackOrForward(offset);
|
||||
}
|
||||
|
@ -204,6 +204,7 @@ class WebTestControlHost : public WebContentsObserver,
|
||||
void BlockThirdPartyCookies(bool block) override;
|
||||
void GetWritableDirectory(GetWritableDirectoryCallback callback) override;
|
||||
void SetFilePathForMockFileDialog(const base::FilePath& path) override;
|
||||
void FocusDevtoolsSecondaryWindow() override;
|
||||
|
||||
private:
|
||||
enum TestPhase { BETWEEN_TESTS, DURING_TEST, CLEAN_UP };
|
||||
|
@ -99,7 +99,6 @@ void WebTestDevToolsBindings::NavigateDevToolsFrontend() {
|
||||
params.transition_type = ui::PageTransitionFromInt(
|
||||
ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
|
||||
web_contents()->GetController().LoadURLWithParams(params);
|
||||
web_contents()->Focus();
|
||||
}
|
||||
|
||||
void WebTestDevToolsBindings::Attach() {
|
||||
|
@ -192,6 +192,10 @@ interface WebTestControlHost {
|
||||
// For the duration of the current test this causes all file choosers to
|
||||
// return the passed in |path|.
|
||||
SetFilePathForMockFileDialog(mojo_base.mojom.FilePath path);
|
||||
|
||||
// Moves focus and active state to the secondary devtools window, which exists
|
||||
// only in devtools JS tests.
|
||||
FocusDevtoolsSecondaryWindow();
|
||||
};
|
||||
|
||||
// Web test messages sent from the renderer process to the browser.
|
||||
|
@ -280,12 +280,6 @@ void BlinkTestRunner::SendBluetoothManualChooserEvent(
|
||||
argument);
|
||||
}
|
||||
|
||||
void BlinkTestRunner::SetFocus(blink::WebView* web_view, bool focus) {
|
||||
RenderView* render_view = RenderView::FromWebView(web_view);
|
||||
if (render_view) // Check whether |web_view| has been already closed.
|
||||
SetFocusAndActivate(render_view, focus);
|
||||
}
|
||||
|
||||
void BlinkTestRunner::SetBlockThirdPartyCookies(bool block) {
|
||||
GetWebTestControlHostRemote()->BlockThirdPartyCookies(block);
|
||||
}
|
||||
@ -558,6 +552,10 @@ void BlinkTestRunner::SetScreenOrientationChanged() {
|
||||
GetWebTestControlHostRemote()->SetScreenOrientationChanged();
|
||||
}
|
||||
|
||||
void BlinkTestRunner::FocusDevtoolsSecondaryWindow() {
|
||||
GetWebTestControlHostRemote()->FocusDevtoolsSecondaryWindow();
|
||||
}
|
||||
|
||||
void BlinkTestRunner::SetTrustTokenKeyCommitments(
|
||||
const std::string& raw_commitments,
|
||||
base::OnceClosure callback) {
|
||||
@ -695,10 +693,6 @@ void BlinkTestRunner::OnSetTestConfiguration(
|
||||
gfx::Rect window_rect(widget->WindowRect().x, widget->WindowRect().y,
|
||||
window_size.width(), window_size.height());
|
||||
widget->SetWindowRectSynchronouslyForTesting(window_rect);
|
||||
|
||||
TestInterfaces* interfaces = web_view_test_proxy_->test_interfaces();
|
||||
TestRunner* test_runner = interfaces->GetTestRunner();
|
||||
test_runner->SetFocus(web_view_test_proxy_->GetWebView(), true);
|
||||
}
|
||||
|
||||
void BlinkTestRunner::OnResetRendererAfterWebTest() {
|
||||
|
@ -122,9 +122,6 @@ class BlinkTestRunner {
|
||||
void SendBluetoothManualChooserEvent(const std::string& event,
|
||||
const std::string& argument);
|
||||
|
||||
// Controls which WebView should be focused.
|
||||
void SetFocus(blink::WebView* web_view, bool focus);
|
||||
|
||||
// Controls whether all cookies should be accepted or writing cookies in a
|
||||
// third-party context is blocked.
|
||||
void SetBlockThirdPartyCookies(bool block);
|
||||
@ -210,6 +207,10 @@ class BlinkTestRunner {
|
||||
// (https://github.com/wicg/trust-token-api).
|
||||
void ClearTrustTokenState(base::OnceClosure callback);
|
||||
|
||||
// Moves focus and active state to the secondary devtools window, which exists
|
||||
// only in devtools JS tests.
|
||||
void FocusDevtoolsSecondaryWindow();
|
||||
|
||||
// Message handlers forwarded by WebTestRenderFrameObserver.
|
||||
void OnSetTestConfiguration(mojom::WebTestRunTestConfigurationPtr params);
|
||||
void OnReplicateTestConfiguration(
|
||||
|
@ -177,6 +177,7 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
|
||||
void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
|
||||
void ExecCommand(gin::Arguments* args);
|
||||
void TriggerTestInspectorIssue(gin::Arguments* args);
|
||||
void FocusDevtoolsSecondaryWindow();
|
||||
void ForceNextDrawingBufferCreationToFail();
|
||||
void ForceNextWebGLContextCreationToFail();
|
||||
void ForceRedSelectionColors();
|
||||
@ -262,7 +263,7 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
|
||||
void SetViewSourceForFrame(const std::string& name, bool enabled);
|
||||
void SetWillSendRequestClearHeader(const std::string& header);
|
||||
void SetWillSendRequestClearReferrer();
|
||||
void SetWindowIsKey(bool value);
|
||||
void SimulateBrowserWindowFocus(bool value);
|
||||
void NavigateSecondaryWindow(const std::string& url);
|
||||
void InspectSecondaryWindow();
|
||||
void SimulateWebNotificationClick(gin::Arguments* args);
|
||||
@ -466,6 +467,8 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
|
||||
.SetMethod("triggerTestInspectorIssue",
|
||||
&TestRunnerBindings::TriggerTestInspectorIssue)
|
||||
.SetMethod("findString", &TestRunnerBindings::FindString)
|
||||
.SetMethod("focusDevtoolsSecondaryWindow",
|
||||
&TestRunnerBindings::FocusDevtoolsSecondaryWindow)
|
||||
.SetMethod("forceNextDrawingBufferCreationToFail",
|
||||
&TestRunnerBindings::ForceNextDrawingBufferCreationToFail)
|
||||
.SetMethod("forceNextWebGLContextCreationToFail",
|
||||
@ -608,7 +611,8 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
|
||||
&TestRunnerBindings::SetWillSendRequestClearHeader)
|
||||
.SetMethod("setWillSendRequestClearReferrer",
|
||||
&TestRunnerBindings::SetWillSendRequestClearReferrer)
|
||||
.SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey)
|
||||
.SetMethod("setWindowFocus",
|
||||
&TestRunnerBindings::SimulateBrowserWindowFocus)
|
||||
.SetMethod("simulateWebNotificationClick",
|
||||
&TestRunnerBindings::SimulateWebNotificationClick)
|
||||
.SetMethod("simulateWebNotificationClose",
|
||||
@ -1172,8 +1176,19 @@ void TestRunnerBindings::SetBlockThirdPartyCookies(bool block) {
|
||||
runner_->SetBlockThirdPartyCookies(block);
|
||||
}
|
||||
|
||||
void TestRunnerBindings::SetWindowIsKey(bool value) {
|
||||
view_runner_->SetWindowIsKey(value);
|
||||
void TestRunnerBindings::SimulateBrowserWindowFocus(bool value) {
|
||||
// This simulates the browser focusing or unfocusing the window,
|
||||
// but does so only for this renderer process. Other frame tree
|
||||
// fragments in other processes do not hear about the change. To
|
||||
// do so the focus change would need to go through window.focus()
|
||||
// and then watch for the focus event or do a round trip to the
|
||||
// browser.
|
||||
// TODO(danakj): This does not appear to do the same thing as the
|
||||
// browser does, because actually moving focus causes different test
|
||||
// results in tests such as editing/selection/4975120.html with the
|
||||
// inner frame not getting its caret back.
|
||||
DCHECK(frame_->IsMainFrame());
|
||||
runner_->FocusWindow(frame_, value);
|
||||
}
|
||||
|
||||
std::string TestRunnerBindings::PathToLocalResource(const std::string& path) {
|
||||
@ -1408,6 +1423,10 @@ void TestRunnerBindings::ForceNextWebGLContextCreationToFail() {
|
||||
view_runner_->ForceNextWebGLContextCreationToFail();
|
||||
}
|
||||
|
||||
void TestRunnerBindings::FocusDevtoolsSecondaryWindow() {
|
||||
runner_->blink_test_runner_->FocusDevtoolsSecondaryWindow();
|
||||
}
|
||||
|
||||
void TestRunnerBindings::ForceNextDrawingBufferCreationToFail() {
|
||||
view_runner_->ForceNextDrawingBufferCreationToFail();
|
||||
}
|
||||
@ -2476,19 +2495,43 @@ void TestRunner::SetBlockThirdPartyCookies(bool block) {
|
||||
blink_test_runner_->SetBlockThirdPartyCookies(block);
|
||||
}
|
||||
|
||||
void TestRunner::SetFocus(blink::WebView* web_view, bool focus) {
|
||||
if (focus) {
|
||||
if (previously_focused_view_ != web_view) {
|
||||
blink_test_runner_->SetFocus(previously_focused_view_, false);
|
||||
blink_test_runner_->SetFocus(web_view, true);
|
||||
previously_focused_view_ = web_view;
|
||||
void TestRunner::FocusWindow(RenderFrame* main_frame, bool focus) {
|
||||
DCHECK(main_frame->IsMainFrame());
|
||||
|
||||
auto* frame_proxy = static_cast<WebFrameTestProxy*>(main_frame);
|
||||
RenderWidget* widget = frame_proxy->GetLocalRootRenderWidget();
|
||||
|
||||
// Web tests get multiple windows in one renderer by doing same-site
|
||||
// window.open() calls (or about:blank). They want to be able to move focus
|
||||
// between those windows synchronously in the renderer, which is what we
|
||||
// do here. We only allow it to focus main frames however, for simplicitly.
|
||||
|
||||
if (!focus) {
|
||||
// This path simulates losing focus on the window, without moving it to
|
||||
// another window.
|
||||
if (widget->has_focus()) {
|
||||
widget->OnSetActive(false);
|
||||
widget->OnSetFocus(false);
|
||||
}
|
||||
} else {
|
||||
if (previously_focused_view_ == web_view) {
|
||||
blink_test_runner_->SetFocus(web_view, false);
|
||||
previously_focused_view_ = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the currently focused window, and remove its focus.
|
||||
for (WebViewTestProxy* window : test_interfaces_->GetWindowList()) {
|
||||
RenderFrameImpl* other_main_frame = window->GetMainRenderFrame();
|
||||
if (other_main_frame && other_main_frame != main_frame) {
|
||||
RenderWidget* other_widget = other_main_frame->GetLocalRootRenderWidget();
|
||||
if (other_widget->has_focus()) {
|
||||
other_widget->OnSetActive(false);
|
||||
other_widget->OnSetFocus(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!widget->has_focus()) {
|
||||
widget->OnSetFocus(true);
|
||||
widget->OnSetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TestRunner::SetPermission(const std::string& name,
|
||||
|
@ -155,9 +155,9 @@ class TestRunner {
|
||||
// Returns true if pixel results should be generated at the end of the test.
|
||||
bool ShouldGeneratePixelResults();
|
||||
|
||||
// Sets focus on the given view. Internally tracks currently focused view,
|
||||
// to aid in defocusing previously focused views at the right time.
|
||||
void SetFocus(blink::WebView* web_view, bool focus);
|
||||
// Activate the window holding the given main frame, and set focus on the
|
||||
// frame's widget.
|
||||
void FocusWindow(RenderFrame* main_frame, bool focus);
|
||||
|
||||
// Methods used by WebViewTestClient and WebFrameTestClient.
|
||||
std::string GetAcceptLanguages() const;
|
||||
@ -628,11 +628,6 @@ class TestRunner {
|
||||
// Captured drag image.
|
||||
SkBitmap drag_image_;
|
||||
|
||||
// View that was focused by a previous call to TestRunner::SetFocus method.
|
||||
// Note - this can be a dangling pointer to an already destroyed WebView (this
|
||||
// is ok, because this is taken care of in BlinkTestRunner::SetFocus).
|
||||
blink::WebView* previously_focused_view_ = nullptr;
|
||||
|
||||
// True if rasterization should be performed during tests that examine
|
||||
// fling-style animations. This includes middle-click auto-scroll behaviors.
|
||||
// This does not include most "ordinary" animations, such as CSS animations.
|
||||
|
@ -498,11 +498,6 @@ void TestRunnerForSpecificView::ForceNextDrawingBufferCreationToFail() {
|
||||
web_view()->ForceNextDrawingBufferCreationToFail();
|
||||
}
|
||||
|
||||
void TestRunnerForSpecificView::SetWindowIsKey(bool value) {
|
||||
web_view_test_proxy_->test_interfaces()->GetTestRunner()->SetFocus(web_view(),
|
||||
value);
|
||||
}
|
||||
|
||||
void TestRunnerForSpecificView::DidAcquirePointerLock() {
|
||||
DidAcquirePointerLockInternal();
|
||||
}
|
||||
|
@ -157,9 +157,6 @@ class TestRunnerForSpecificView {
|
||||
// Sets a flag causing the next call to DrawingBuffer::create to fail.
|
||||
void ForceNextDrawingBufferCreationToFail();
|
||||
|
||||
// Gives focus to the view associated with TestRunnerForSpecificView.
|
||||
void SetWindowIsKey(bool value);
|
||||
|
||||
// Pointer lock handling.
|
||||
void DidAcquirePointerLock();
|
||||
void DidNotAcquirePointerLock();
|
||||
|
@ -85,8 +85,6 @@ class TestRenderFrameObserver : public content::RenderFrameObserver {
|
||||
|
||||
// Looking for navigations to about:blank after a test completes.
|
||||
if (render_frame()->IsMainFrame() && !is_same_document_navigation) {
|
||||
render_frame()->GetRenderView()->GetWebView()->SetFocusedFrame(
|
||||
render_frame()->GetWebFrame());
|
||||
blink_test_runner()->DidCommitNavigationInMainFrame();
|
||||
}
|
||||
}
|
||||
|
@ -71,11 +71,6 @@ blink::WebString WebViewTestProxy::AcceptLanguages() {
|
||||
return blink::WebString::FromUTF8(GetTestRunner()->GetAcceptLanguages());
|
||||
}
|
||||
|
||||
void WebViewTestProxy::DidFocus(blink::WebLocalFrame* calling_frame) {
|
||||
GetTestRunner()->SetFocus(GetWebView(), true);
|
||||
RenderViewImpl::DidFocus(calling_frame);
|
||||
}
|
||||
|
||||
void WebViewTestProxy::Reset() {
|
||||
accessibility_controller_.Reset();
|
||||
// |text_input_controller_| doesn't have any state to reset.
|
||||
|
@ -78,7 +78,6 @@ class WebViewTestProxy : public content::RenderViewImpl {
|
||||
session_storage_namespace_id) override;
|
||||
void PrintPage(blink::WebLocalFrame* frame) override;
|
||||
blink::WebString AcceptLanguages() override;
|
||||
void DidFocus(blink::WebLocalFrame* calling_frame) override;
|
||||
|
||||
// Exposed for our TestRunner harness.
|
||||
using RenderViewImpl::ApplyPageVisibilityState;
|
||||
|
@ -76,11 +76,6 @@ void EnableRendererWebTestMode() {
|
||||
UniqueNameHelper::PreserveStableUniqueNameForTesting();
|
||||
}
|
||||
|
||||
void SetFocusAndActivate(RenderView* render_view, bool enable) {
|
||||
static_cast<RenderViewImpl*>(render_view)
|
||||
->SetFocusAndActivateForTesting(enable);
|
||||
}
|
||||
|
||||
void SchedulerRunIdleTasks(base::OnceClosure callback) {
|
||||
blink::scheduler::WebThreadScheduler* scheduler =
|
||||
content::RenderThreadImpl::current()->GetWebMainThreadScheduler();
|
||||
|
9
third_party/blink/web_tests/TestExpectations
vendored
9
third_party/blink/web_tests/TestExpectations
vendored
@ -214,6 +214,15 @@ crbug.com/974666 [ Mac10.13 ] http/tests/misc/object-embedding-svg-delayed-size-
|
||||
crbug.com/974720 [ Mac10.13 ] virtual/text-antialias/firstline/capitalize-transform-2.html [ Pass Crash ]
|
||||
crbug.com/974720 [ Mac10.13 ] virtual/text-antialias/firstline/capitalize-transform.html [ Pass Crash ]
|
||||
|
||||
# This test depends on synchronous focus() which does not exist (anymore?).
|
||||
crbug.com/1074482 external/wpt/html/interaction/focus/the-autofocus-attribute/update-the-rendering.html [ Failure ]
|
||||
# This test has a bug in it that prevents it from being able to deal with order
|
||||
# differences it claims to support.
|
||||
crbug.com/1076129 external/wpt/service-workers/service-worker/clients-matchall-frozen.https.html [ Pass Failure ]
|
||||
crbug.com/1076129 virtual/cache-storage-eager-reading/external/wpt/service-workers/service-worker/clients-matchall-frozen.https.html [ Pass Failure ]
|
||||
crbug.com/1076129 virtual/cache-storage-sequence/external/wpt/service-workers/service-worker/clients-matchall-frozen.https.html [ Pass Failure ]
|
||||
crbug.com/1076129 virtual/omt-worker-fetch/external/wpt/service-workers/service-worker/clients-matchall-frozen.https.html [ Pass Failure ]
|
||||
|
||||
# Flakily timing out or failing.
|
||||
# TODO(ccameron): Investigate this.
|
||||
crbug.com/730267 virtual/gpu-rasterization/images/color-profile-group.html [ Pass Timeout Failure ]
|
||||
|
@ -13,17 +13,22 @@ function runTest() {
|
||||
|
||||
if (!window.testRunner)
|
||||
return;
|
||||
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowIsKey(true);
|
||||
|
||||
testRunner.setWindowFocus(false);
|
||||
testRunner.setWindowFocus(true);
|
||||
testRunner.notifyDone();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>This tests for a bug that caused the parent of an active frame to paint as though it were active when its window becomes key. To run manually, make another window active and then make this window active. Only the subframe should appear active.</p>
|
||||
<input id="input" type="text" value="foo"><br>
|
||||
<iframe src="../resources/contenteditable-iframe-src.html" onload="runTest()"></iframe></body>
|
||||
<p>This tests for a bug that caused the parent of an active frame to paint as
|
||||
though it were active when its window becomes key. To run manually, make
|
||||
another window active and then make this window active. Only the subframe
|
||||
should appear active.</p>
|
||||
<input id="input" type="text" value="foo"><br>
|
||||
<iframe src="../resources/contenteditable-iframe-src.html" onload="runTest()">
|
||||
</iframe>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
</script>
|
||||
|
@ -12,7 +12,7 @@ if (window.testRunner) {
|
||||
|
||||
function runTest() {
|
||||
if (window.testRunner) {
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
testRunner.setMainFrameIsFirstResponder(false);
|
||||
}
|
||||
var s = window.getSelection();
|
||||
|
@ -16,13 +16,16 @@ window.onload = function() {
|
||||
frames[0].getSelection().setBaseAndExtent(div, 0, div, 1);
|
||||
frames[0].focus();
|
||||
|
||||
window.addEventListener('focus', afterFocus);
|
||||
window.focus();
|
||||
document.getElementById('input').focus();
|
||||
function afterFocus() {
|
||||
document.getElementById('input').focus();
|
||||
|
||||
var selectionString = frames[0].getSelection().toString();
|
||||
if (div.innerText == selectionString)
|
||||
document.getElementById('console').innerHTML = 'PASS: inactive selection retained.';
|
||||
else
|
||||
document.getElementById('console').innerHTML = 'FAIL: inactive selection should be "' + div.innerText + '" but instead is ' + selectionString + '.';
|
||||
var selectionString = frames[0].getSelection().toString();
|
||||
if (div.innerText == selectionString)
|
||||
document.getElementById('console').innerHTML = 'PASS: inactive selection retained.';
|
||||
else
|
||||
document.getElementById('console').innerHTML = 'FAIL: inactive selection should be "' + div.innerText + '" but instead is ' + selectionString + '.';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -11,7 +11,7 @@ if (window.testRunner) {
|
||||
|
||||
function runTest() {
|
||||
if (window.testRunner) {
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
testRunner.setMainFrameIsFirstResponder(false);
|
||||
}
|
||||
var s = window.getSelection();
|
||||
|
@ -55,7 +55,7 @@ if (window.internals)
|
||||
shouldBe("getComputedStyle(select[0], '::selection').backgroundColor", "green");
|
||||
|
||||
shouldBeDefined(window.testRunner);
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
|
||||
setSelection(select[1].firstChild);
|
||||
shouldBe("getComputedStyle(select[1], '::selection').backgroundColor", "red");
|
||||
|
@ -16,8 +16,8 @@
|
||||
test.parentNode.removeChild(test);
|
||||
if (window.testRunner) {
|
||||
// Force a focus in which forces a paint that can trigger the crash.
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowIsKey(true);
|
||||
testRunner.setWindowFocus(false);
|
||||
testRunner.setWindowFocus(true);
|
||||
document.getElementById("results").innerHTML = "PASS";
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../../resources/user-gesture-utils.js"></script>
|
||||
<script>
|
||||
if (window.testRunner) {
|
||||
testRunner.dumpAsText();
|
||||
@ -29,7 +30,7 @@ function focusShouldNotChange(action, nextTest) {
|
||||
|
||||
action(w);
|
||||
|
||||
originatingWindow.setTimeout(function () {
|
||||
roundTripToBrowserThen(() => {
|
||||
originatingWindow.removeEventListener('focus', failHandler, false);
|
||||
w.removeEventListener('blur', failHandler, false);
|
||||
|
||||
@ -69,7 +70,7 @@ function test1() {
|
||||
}
|
||||
|
||||
function test2() {
|
||||
focusShouldNotChange(function () { originatingWindow.focus(); }, test3);
|
||||
focusShouldNotChange(function () { focusWithUserGesture(originatingWindow); }, test3);
|
||||
}
|
||||
|
||||
function test3() {
|
||||
@ -79,7 +80,7 @@ function test3() {
|
||||
function test4() {
|
||||
focusShouldNotChange2('resources/mozilla-focus-blur-popup-blur.html', test5);
|
||||
}
|
||||
|
||||
|
||||
function test5()
|
||||
{
|
||||
var w = window.open('about:blank', '', 'foo');
|
||||
@ -89,16 +90,16 @@ function test5()
|
||||
|
||||
w.addEventListener('focus', handler, false);
|
||||
|
||||
w.focus();
|
||||
focusWithUserGesture(w);
|
||||
|
||||
originatingWindow.setTimeout(function () {
|
||||
roundTripToBrowserThen(() => {
|
||||
w.removeEventListener('focus', handler, false);
|
||||
|
||||
log(!fail, 'The last opened window should be able to get focus');
|
||||
|
||||
w.close();
|
||||
originatingWindow.setTimeout(finished, 0);
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
|
||||
function finished() {
|
||||
|
@ -7,7 +7,7 @@ function runTest() {
|
||||
window.onblur = windowBlurred;
|
||||
|
||||
if (window.testRunner) {
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
window.open('javascript:window.focus()', '_self', '');
|
||||
setTimeout(function() { testRunner.notifyDone(); }, 0);
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ function runTest() {
|
||||
testRunner.dumpAsText();
|
||||
testRunner.setMainFrameIsFirstResponder(true);
|
||||
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowIsKey(true);
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
testRunner.setWindowFocus(true);
|
||||
testRunner.setWindowFocus(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
4
third_party/blink/web_tests/fast/events/script-tests/blur-focus-window-should-blur-focus-element.js
vendored
4
third_party/blink/web_tests/fast/events/script-tests/blur-focus-window-should-blur-focus-element.js
vendored
@ -29,8 +29,8 @@ divElement.onfocus = divElement.onblur = window.onfocus = window.onblur =
|
||||
};
|
||||
|
||||
if (window.testRunner) {
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowIsKey(true);
|
||||
testRunner.setWindowFocus(false);
|
||||
testRunner.setWindowFocus(true);
|
||||
|
||||
innerDiv.focus();
|
||||
divElement.focus();
|
||||
|
@ -26,7 +26,7 @@ function runTest() {
|
||||
shouldEvaluateTo('blurEventCounter', 0);
|
||||
shouldEvaluateTo('changeEventCounter', 0);
|
||||
testRunner.setMainFrameIsFirstResponder(true);
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
}
|
||||
if (window.testRunner)
|
||||
window.jsTestIsAsync = true;
|
||||
|
@ -21,11 +21,11 @@
|
||||
test(() => assert_equals(getComputedStyle(input).backgroundColor, "rgb(250, 200, 150)"),
|
||||
"Check ':focus-within' is applied after focusing the input");
|
||||
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
test(() => assert_equals(getComputedStyle(input).backgroundColor, "rgb(50, 150, 200)"),
|
||||
"Check ':focus-within' is not applied when the window is inactive");
|
||||
|
||||
testRunner.setWindowIsKey(true);
|
||||
testRunner.setWindowFocus(true);
|
||||
test(() => assert_equals(getComputedStyle(input).backgroundColor, "rgb(250, 200, 150)"),
|
||||
"Check ':focus-within' is applied when the window is active again");
|
||||
</script>
|
||||
|
@ -14,5 +14,5 @@
|
||||
var span = document.querySelector("span");
|
||||
window.getSelection().setBaseAndExtent(span, 0, span, 1);
|
||||
if (window.testRunner)
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
</script>
|
||||
|
@ -64,6 +64,10 @@
|
||||
},
|
||||
|
||||
function setUpOrientationSensor(next) {
|
||||
// The devtools inspector window needs to be focused to hear about
|
||||
// sensor changes.
|
||||
if (window.testRunner)
|
||||
testRunner.focusDevtoolsSecondaryWindow();
|
||||
TestRunner.evaluateInPage('setUpOrientationSensor()', next);
|
||||
},
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
<script src="../resources/testharness.js"></script>
|
||||
<script src="../resources/testharnessreport.js"></script>
|
||||
<script src="../resources/permissions-helper.js"></script>
|
||||
<script src="../resources/user-gesture-utils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
@ -16,6 +17,23 @@
|
||||
testRunner.setCloseRemainingWindowsWhenComplete();
|
||||
}
|
||||
|
||||
function simulateUserClick(x, y) {
|
||||
if (window.eventSender) {
|
||||
eventSender.mouseMoveTo(x, y);
|
||||
eventSender.mouseDown();
|
||||
eventSender.mouseUp();
|
||||
}
|
||||
}
|
||||
function focusWithUserGesture(w) {
|
||||
var focus_w = document.createElement('a');
|
||||
focus_w.onclick = () => { w.focus(); };
|
||||
focus_w.innerText = 'focus_w';
|
||||
document.body.appendChild(focus_w);
|
||||
simulateUserClick(focus_w.getBoundingClientRect().x,
|
||||
focus_w.getBoundingClientRect().y);
|
||||
document.body.removeChild(focus_w);
|
||||
}
|
||||
|
||||
async_test(function(test) {
|
||||
PermissionsHelper.setPermission('notifications', 'granted').then(test.step_func(function() {
|
||||
if (Notification.permission != 'granted') {
|
||||
@ -28,7 +46,7 @@
|
||||
}));
|
||||
|
||||
var childWindow = window.open('about:blank');
|
||||
childWindow.focus();
|
||||
focusWithUserGesture(childWindow);
|
||||
|
||||
var notification = new Notification('My Notification');
|
||||
notification.addEventListener('show', test.step_func(function() {
|
||||
@ -46,6 +64,5 @@
|
||||
}));
|
||||
}, 'Clicking on a notification enables it to focus the window it was created from.');
|
||||
</script>
|
||||
<script src="resources/click-focus-test.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
44
third_party/blink/web_tests/http/tests/resources/user-gesture-utils.js
vendored
Normal file
44
third_party/blink/web_tests/http/tests/resources/user-gesture-utils.js
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Simulates a user click on coordinates [x], [y].
|
||||
* For example, for vibrate to be allowed:
|
||||
* https://www.chromestatus.com/feature/5644273861001216.
|
||||
*/
|
||||
function simulateUserClick(x, y) {
|
||||
if (window.eventSender) {
|
||||
eventSender.mouseMoveTo(x, y);
|
||||
eventSender.mouseDown();
|
||||
eventSender.mouseUp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls `focus()` on |w|, but via a user gesture.
|
||||
* This is needed to move system focus to another window, as we drop
|
||||
* the request in the renderer without a user gesture.
|
||||
*/
|
||||
function focusWithUserGesture(w) {
|
||||
var focus_w = document.createElement('a');
|
||||
focus_w.onclick = () => { w.focus(); };
|
||||
focus_w.innerText = 'focus_w';
|
||||
document.body.appendChild(focus_w);
|
||||
simulateUserClick(focus_w.getBoundingClientRect().x,
|
||||
focus_w.getBoundingClientRect().y);
|
||||
document.body.removeChild(focus_w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures any events that involve the browser have a chance to be processed
|
||||
* and replied to, then calls the given function.
|
||||
* When testing focus, this is useful to avoid long timeouts waiting to see
|
||||
* if a focus event will be dispatched or not.
|
||||
*/
|
||||
function roundTripToBrowserThen(f) {
|
||||
var frame = document.createElement('iframe');
|
||||
// An OOPIF navigation requires the browser to participate.
|
||||
frame.src = "http://localhost:8080/resources/blank.html";
|
||||
frame.addEventListener('load', () => {
|
||||
document.body.removeChild(frame);
|
||||
f();
|
||||
});
|
||||
document.body.appendChild(frame);
|
||||
}
|
@ -37,7 +37,7 @@ t.step(function() {
|
||||
'openWindow() result: [object WindowClient]',
|
||||
' url: ' + location.origin + '/serviceworker/resources/blank.html',
|
||||
' visibilityState: visible',
|
||||
' focused: true',
|
||||
' focused: false',
|
||||
' frameType: top-level',
|
||||
'openWindow() can open about:blank',
|
||||
'openWindow() result: null',
|
||||
|
@ -60,13 +60,6 @@ t.step(function() {
|
||||
'focused clients: 1',
|
||||
];
|
||||
|
||||
// On Mac, focusing and LayoutTests are no friend. This is amending the
|
||||
// above |expected| array to match Mac's expectations.
|
||||
var isMac = navigator.platform.indexOf('Mac') == 0;
|
||||
if (isMac) {
|
||||
expected[29] = 'focused clients: 3';
|
||||
}
|
||||
|
||||
function onMessage(e) {
|
||||
var message = e.data;
|
||||
|
||||
|
@ -11,3 +11,34 @@ function simulateUserClick(x, y) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls `focus()` on |w|, but via a user gesture.
|
||||
* This is needed to move system focus to another window, as we drop
|
||||
* the request in the renderer without a user gesture.
|
||||
*/
|
||||
function focusWithUserGesture(w) {
|
||||
var focus_w = document.createElement('a');
|
||||
focus_w.onclick = () => { w.focus(); };
|
||||
focus_w.innerText = 'focus_w';
|
||||
document.body.appendChild(focus_w);
|
||||
simulateUserClick(focus_w.getBoundingClientRect().x,
|
||||
focus_w.getBoundingClientRect().y);
|
||||
document.body.removeChild(focus_w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures any events that involve the browser have a chance to be processed
|
||||
* and replied to, then calls the given function.
|
||||
* When testing focus, this is useful to avoid long timeouts waiting to see
|
||||
* if a focus event will be dispatched or not.
|
||||
*/
|
||||
function roundTripToBrowserThen(f) {
|
||||
var frame = document.createElement('iframe');
|
||||
// An OOPIF navigation requires the browser to participate.
|
||||
frame.src = "http://localhost:8080/resources/blank.html";
|
||||
frame.addEventListener('load', () => {
|
||||
document.body.removeChild(frame);
|
||||
f();
|
||||
});
|
||||
document.body.appendChild(frame);
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ div{
|
||||
</body>
|
||||
<script>
|
||||
document.body.offsetTop;
|
||||
// setWindowIsKey shall set the focus of the window.
|
||||
if (window.testRunner)
|
||||
testRunner.setWindowIsKey(false);
|
||||
</script>
|
||||
testRunner.setWindowFocus(false);
|
||||
</script>
|
||||
|
@ -17,6 +17,6 @@
|
||||
test(function() {
|
||||
document.body.offsetTop;
|
||||
if (window.testRunner)
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
}, 'crash test when a custom scrollbar changes style related to stacking context');
|
||||
</script>
|
||||
|
@ -19,8 +19,7 @@ div {
|
||||
<div><div></div></div>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// setWindowIsKey shall set the focus of the window.
|
||||
if (window.testRunner)
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
@ -10,11 +10,22 @@
|
||||
box-shadow: inset 0 0 6px red;
|
||||
}
|
||||
</style>
|
||||
<script src="../resources/user-gesture-utils.js"></script>
|
||||
<script>
|
||||
if (window.testRunner)
|
||||
testRunner.setCanOpenWindows();
|
||||
|
||||
var win = window.open('about:blank');
|
||||
win.focus();
|
||||
function run() {
|
||||
if (window.testRunner) {
|
||||
testRunner.waitUntilDone();
|
||||
testRunner.setCanOpenWindows();
|
||||
}
|
||||
|
||||
var win = window.open('about:blank');
|
||||
if (window.testRunner) {
|
||||
window.addEventListener('blur', () => {
|
||||
testRunner.notifyDone();
|
||||
});
|
||||
}
|
||||
focusWithUserGesture(win);
|
||||
}
|
||||
</script>
|
||||
<body style="overflow: scroll;"></body>
|
||||
<body onload="run()" style="overflow: scroll;"></body>
|
||||
|
5
third_party/blink/web_tests/scrollbars/custom-scrollbar-thumb-focus-iframe-inactive-pseudo.html
vendored
5
third_party/blink/web_tests/scrollbars/custom-scrollbar-thumb-focus-iframe-inactive-pseudo.html
vendored
@ -40,8 +40,7 @@ div {
|
||||
window.onload = function() {
|
||||
var ifra = document.getElementById('iframeactive');
|
||||
ifra.focus();
|
||||
// setWindowIsKey shall set the focus of the window.
|
||||
if (window.testRunner)
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
@ -38,8 +38,7 @@ div {
|
||||
</body>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// setWindowIsKey shall set the focus of the window.
|
||||
if (window.testRunner)
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
5
third_party/blink/web_tests/scrollbars/custom-scrollbar-thumb-width-changed-on-inactive-pseudo.html
vendored
5
third_party/blink/web_tests/scrollbars/custom-scrollbar-thumb-width-changed-on-inactive-pseudo.html
vendored
@ -117,8 +117,7 @@ Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.
|
||||
</body>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// setWindowIsKey shall set the focus of the window.
|
||||
if (window.testRunner)
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
@ -37,7 +37,6 @@
|
||||
range.setEnd(node2, node2.length);
|
||||
window.getSelection().addRange(range);
|
||||
|
||||
// Make the window inactive.
|
||||
if (window.testRunner)
|
||||
testRunner.setWindowIsKey(false);
|
||||
testRunner.setWindowFocus(false);
|
||||
</script>
|
||||
|
33
third_party/blink/web_tests/wpt_internal/html/interaction/focus/the-autofocus-attribute/object-fallback.html
vendored
33
third_party/blink/web_tests/wpt_internal/html/interaction/focus/the-autofocus-attribute/object-fallback.html
vendored
@ -2,14 +2,45 @@
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/html/interaction/focus/the-autofocus-attribute/resources/utils.js"></script>
|
||||
<script src="/resources/user-gesture-utils.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
// Returns a promise that will perform `w.focus()` but via a user action in
|
||||
// order to allow moving the system focus to the window. It then waits for the
|
||||
// system focus to be applied which requires a round trip through the browser
|
||||
// process.
|
||||
function focusWithUserGestureAndAwaitSystemFocus(w) {
|
||||
var focus_w = document.createElement('a');
|
||||
focus_w.onclick = () => { w.focus(); };
|
||||
focus_w.innerText = 'focus_w';
|
||||
document.body.appendChild(focus_w);
|
||||
if (eventSender) {
|
||||
eventSender.mouseMoveTo(focus_w.getBoundingClientRect().x,
|
||||
focus_w.getBoundingClientRect().y);
|
||||
eventSender.mouseDown();
|
||||
eventSender.mouseUp();
|
||||
}
|
||||
document.body.removeChild(focus_w);
|
||||
return new Promise((resolve, reject) => {
|
||||
// Ensures any events that involve the browser have a chance to be processed
|
||||
// and replied to, then calls the given function.
|
||||
var frame = document.createElement('iframe');
|
||||
// An OOPIF navigation requires the browser to participate.
|
||||
frame.src = "http://localhost:8080/resources/blank.html";
|
||||
frame.addEventListener('load', () => {
|
||||
document.body.removeChild(frame);
|
||||
resolve();
|
||||
});
|
||||
document.body.appendChild(frame);
|
||||
});
|
||||
}
|
||||
|
||||
async function setupBlankWindow(t) {
|
||||
let w = window.open('/common/blank.html');
|
||||
await waitForLoad(w);
|
||||
t.add_cleanup(() => { w.close(); });
|
||||
w.focus();
|
||||
await focusWithUserGestureAndAwaitSystemFocus(w);
|
||||
return w;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user