Skip to content

Commit

Permalink
Ensure ResizeObserver fires on first observe()
Browse files Browse the repository at this point in the history
If an element has the size 0x0, it won't yield an active observation
when the gather observation step is run.

Set the ResizeObservation::observation_size_ to -1x-1 in the constructor
to make sure we always produce an active observation for the element in
the first gather observation step it takes part in.

Fixed: 1128016
Change-Id: I61a077e5e74699f68a9c5230a980a5f5f0f973ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3970745
Reviewed-by: Dominic Farolino <dom@chromium.org>
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/main@{#1067471}
  • Loading branch information
Fredrik Söderquist authored and Chromium LUCI CQ committed Nov 4, 2022
1 parent d9534b5 commit f813526
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 42 deletions.
11 changes: 0 additions & 11 deletions content/browser/fenced_frame/fenced_frame_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4474,14 +4474,8 @@ IN_PROC_BROWSER_TEST_P(FencedFrameParameterizedBrowserTest,
ASSERT_TRUE(EvalJsAfterLifecycleUpdate(nodeA, "", "").error.empty());

// Check that the inner size is what we expect.
// TODO(kojii|gtanzer): There is a known bug with the size 0,0,
// where the fenced frame can be resized once.
int inner_width = EvalJs(nodeB, "innerWidth").ExtractInt();
int inner_height = EvalJs(nodeB, "innerHeight").ExtractInt();
if (input_width == 0 && input_height == 0) {
output_width = 0;
output_height = 0;
}
EXPECT_EQ(inner_width, output_width);
EXPECT_EQ(inner_height, output_height);

Expand All @@ -4502,13 +4496,8 @@ IN_PROC_BROWSER_TEST_P(FencedFrameParameterizedBrowserTest,
ASSERT_TRUE(EvalJsAfterLifecycleUpdate(nodeA, "", "").error.empty());

// Check that the inner size hasn't changed.
// TODO(kojii|gtanzer): There is still a known bug with the size 0,0.
inner_width = EvalJs(nodeB, "innerWidth").ExtractInt();
inner_height = EvalJs(nodeB, "innerHeight").ExtractInt();
if (input_width == 0 && input_height == 0) {
output_width = new_width;
output_height = new_height;
}
EXPECT_EQ(inner_width, output_width);
EXPECT_EQ(inner_height, output_height);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@ void HTMLFencedFrameElement::ResizeObserverDelegate::OnResize(
}

void HTMLFencedFrameElement::OnResize(const PhysicalRect& content_rect) {
// If we don't have a delegate, then we won't have a frame, so no reason to
// freeze.
if (!frame_delegate_)
return;
if (frozen_frame_size_.has_value() && !size_set_after_freeze_) {
// Only log this once per fenced frame.
RecordFencedFrameResizedAfterSizeFrozen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ gfx::SizeF ComputeZoomAdjustedSVGBox(ResizeObserverBoxOptions box_option,
}
}

// Set the initial observation size to something impossible so that the first
// gather observation step always will pick up a new observation.
constexpr LayoutSize kInitialObservationSize(-1, -1);

} // namespace

ResizeObservation::ResizeObservation(Element* target,
ResizeObserver* observer,
ResizeObserverBoxOptions observed_box)
: target_(target),
observer_(observer),
observation_size_(0, 0),
observation_size_(kInitialObservationSize),
observed_box_(observed_box) {
DCHECK(target_);
}
Expand Down
2 changes: 0 additions & 2 deletions third_party/blink/web_tests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -3419,8 +3419,6 @@ crbug.com/626703 virtual/plz-dedicated-worker/external/wpt/fetch/api/abort/servi
crbug.com/626703 external/wpt/avif/animated-avif-timeout.html [ Failure ]
crbug.com/626703 [ Linux ] external/wpt/encoding/unsupported-labels.window.html [ Failure Timeout ]
crbug.com/626703 [ Win ] external/wpt/encoding/unsupported-labels.window.html [ Failure Timeout ]
crbug.com/626703 external/wpt/resize-observer/notify.html [ Timeout ]
crbug.com/626703 external/wpt/resize-observer/svg.html [ Timeout ]
crbug.com/626703 [ Win11 ] wpt_internal/geolocation-api/watchPosition-page-visibility.https.html [ Timeout ]
crbug.com/626703 [ Mac11-arm64 ] external/wpt/fetch/api/redirect/redirect-upload.h2.any.sharedworker.html [ Timeout ]
crbug.com/626703 [ Mac11-arm64 ] external/wpt/infrastructure/server/http2-context.sub.h2.any.html [ Timeout ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
This is a testharness.js-based test.
PASS Basic usage
FAIL Last remembered size can be 0 assert_equals: Using last remembered size - clientWidth expected 0 but got 75
FAIL Last remembered size can be set to 0 after losing display:none assert_equals: Using the new last remembered size - clientWidth expected 0 but got 100
PASS Last remembered size can be 0
PASS Last remembered size can be set to 0 after losing display:none
PASS Last remembered size is logical
PASS Last remembered size survives box destruction
PASS Last remembered size survives display type changes
Expand All @@ -13,7 +13,7 @@ FAIL Lack of cis:auto during box creation removes last remembered size assert_eq
FAIL Last remembered size can be removed synchronously assert_equals: Size containment with no last remembered size - clientWidth expected 1 but got 100
PASS Disconnected element can briefly keep last remembered size
FAIL Disconnected element ends up losing last remembered size assert_equals: Size containment with no last remembered size - clientWidth expected 1 but got 100
FAIL Disconnected element ends up losing last remembered size even if size was 0x0 assert_equals: Size containment with no last remembered size - clientWidth expected 1 but got 100
FAIL Disconnected element ends up losing last remembered size even if size was 0x0 assert_equals: Size containment with no last remembered size - clientWidth expected 1 but got 0
FAIL Last remembered size survives becoming inline assert_equals: Still using previous last remembered size - clientWidth expected 100 but got 0
PASS Last remembered size can be set to 0x0 after losing display:inline
Harness: the test ran to completion.
Expand Down

This file was deleted.

0 comments on commit f813526

Please sign in to comment.