Skip to content

Commit

Permalink
Make window.resizeTo() resize the web contents in web tests.
Browse files Browse the repository at this point in the history
The resizeTo() method is doing nothing in content_shell currently.

Tests that want a resize are either accidentally doing nothing or call
useUnfortunateSynchronousResizeMode() to fake out the resize in the
renderer.

This implements WebContentsDelegate::SetContentsBounds() in Shell, for
web tests, to resize the web contents to the specified size.

This is not perfect, even though the web contents is resized, the
window rect is not changed as that comes from the WebContents UI view.
For mac headless we have already plumbed the web contents' size to
override the window rect so we can get the right values there. For aura,
we are unable to do the same at this time, so after calling resizeTo,
a resizeBy will do the wrong thing as it relies on the window rect. As
most tests that try to resize useUnfortunateSynchronousResizeMode(),
they will not notice this problem.

R=avi@chromium.org

Bug: 891427
Change-Id: I95f95b7fa8631a364988769ba3d4259bfef17f30
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238384
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776982}
  • Loading branch information
danakj authored and Commit Bot committed Jun 10, 2020
1 parent b355acf commit ee2390a
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 30 deletions.
12 changes: 12 additions & 0 deletions content/shell/browser/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,18 @@ bool Shell::ShouldResumeRequestsForCreatedWindow() {
return !delay_popup_contents_delegate_for_testing_;
}

void Shell::SetContentsBounds(WebContents* source, const gfx::Rect& bounds) {
DCHECK(source == web_contents()); // There's only one WebContents per Shell.

if (switches::IsRunWebTestsSwitchPresent()) {
// Note that chrome drops these requests on normal windows.
// TODO(danakj): The position is dropped here but we use the size. Web tests
// can't move the window in headless mode anyways, but maybe we should be
// letting them pretend?
g_platform->ResizeWebContent(this, bounds.size());
}
}

gfx::Size Shell::GetShellDefaultSize() {
static gfx::Size default_shell_size;
if (!default_shell_size.IsEmpty())
Expand Down
1 change: 1 addition & 0 deletions content/shell/browser/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class Shell : public WebContentsDelegate,
const viz::SurfaceId&,
const gfx::Size& natural_size) override;
bool ShouldResumeRequestsForCreatedWindow() override;
void SetContentsBounds(WebContents* source, const gfx::Rect& bounds) override;

static gfx::Size GetShellDefaultSize();

Expand Down
13 changes: 0 additions & 13 deletions third_party/blink/web_tests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -1362,22 +1362,9 @@ crbug.com/929098 virtual/dark-color-scheme/external/wpt/css/css-color-adjust/ren
# TestExpectations file. All of those have been commented out with a pointer back
# up to this section. So if you close one of these, you should search for the
# same test elsewhere, to see if perhaps you need to uncomment the old line.
### These fail on all platforms:
## Next 10 can be viewed in this run, by clicking on "Did not pass 11183":
## https://test-results.appspot.com/data/layout_results/linux-blink-rel/1237/webkit_layout_tests%20%28with%20patch%29/layout-test-results/results.html
crbug.com/891427 virtual/threaded-no-composited-antialiasing/animations/responsive/viewport-unit-transform-responsive.html [ Timeout ]
crbug.com/891427 virtual/threaded-no-composited-antialiasing/animations/responsive/viewport-unit-translate-responsive.html [ Timeout ]
crbug.com/891427 virtual/android/fullscreen/rendering/backdrop-video.html [ Failure ]
## Next 4 here: https://ci.chromium.org/p/chromium/builders/luci.chromium.try/linux_chromium_rel_ng/216317
crbug.com/891427 virtual/threaded-no-composited-antialiasing/animations/timing/animation-duration-infinite.html [ Failure ]

### Flaky on trybots:
### Note: this list includes anything that flaked even once during my (many)
### test runs with the flag enabled. It is very possible that some of these
### were random flakes, or were already flaky before the flag was turned on.
# Next 3 here: https://ci.chromium.org/buildbot/tryserver.blink/linux-blink-rel/1215
crbug.com/891427 animations/responsive/viewport-unit-transform-responsive.html [ Pass Failure Timeout Crash ]
crbug.com/891427 animations/responsive/viewport-unit-translate-responsive.html [ Pass Failure Timeout Crash ]
# ====== OOPIF-mode failures until here ======

# ====== Form Controls Refresh (chrome://flags/#form-controls-refresh) failures from here ======
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
This box should be located in the center of the page.
<div id="target"></div>
<script>
if (window.testRunner) {
testRunner.useUnfortunateSynchronousResizeMode();
}
window.resizeTo(window.innerWidth / 2, window.innerHeight / 2);
</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<script>
setAnimationRequiresRaster();
if (window.testRunner) {
testRunner.useUnfortunateSynchronousResizeMode();
testRunner.waitUntilDone();
}
function waitForCompositor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
This box should be located in the center of the page.
<div id="target"></div>
<script>
if (window.testRunner) {
testRunner.useUnfortunateSynchronousResizeMode();
}
window.resizeTo(window.innerWidth / 2, window.innerHeight / 2);
</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<div id="target"></div>
<script>
if (window.testRunner) {
testRunner.useUnfortunateSynchronousResizeMode();
testRunner.waitUntilDone();
}
function waitForCompositor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@
}

// Test resize wont reset scroll position.
window.resizeTo(window.innerWidth, 1000);
const oldHeight = window.innerHeight;
window.resizeTo(window.innerWidth, oldHeight - 100);
window.scrollTo(expectedScrollX, expectedScrollY);
window.resizeTo(window.innerWidth, 2000);
window.resizeTo(window.innerWidth, oldHeight);
assertEqual("resize preserves scroll position", window.scrollY, expectedScrollY);

// Test HOME/END operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
if (window.testRunner)
testRunner.waitUntilDone();

window.moveBy(400, 400);
window.resizeBy(2000, 2000);
window.resizeBy(0, 0);

// Wait a frame so that the move has a chance to be ack'd by the
// browser.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script>
function repaintTest() {
window.resizeTo(400, 300);
}, true);
}
</script>
</head>
<body onload="runAfterLayoutAndPaint(repaintTest, true)">
Expand Down

0 comments on commit ee2390a

Please sign in to comment.