Skip to content

Commit

Permalink
Prevent nullptr exception when non box target RO entry is created
Browse files Browse the repository at this point in the history
Return empty content rect and content and border box values for
non box targets when ResizeObserverEntry is being created.

Bug: 1049709
Change-Id: I8871c7308739a239fb438f919ea416c9e921a48f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2042992
Commit-Queue: Daniel Libby <[email protected]>
Reviewed-by: Daniel Libby <[email protected]>
Reviewed-by: Philip Rogers <[email protected]>
Cr-Commit-Position: refs/heads/master@{#740103}
  • Loading branch information
sahirv authored and chromium-wpt-export-bot committed Feb 11, 2020
1 parent 549aaf3 commit 9adb08e
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
73 changes: 73 additions & 0 deletions resize-observer/observe.html
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,77 @@
return helper.start(() => t.remove());
}

function test15() {
let t = createAndAppendElement("div");
t.style.height = "100px";
t.style.width = "50px";

let helper = new ResizeTestHelper(
"test15: an observation is fired with box dimensions 0 when element's " +
"display property is set to inline",
[
{
setup: observer => {
observer.observe(t);
},
notify: entries => {
assert_equals(entries.length, 1, "1 pending notification");
assert_equals(entries[0].target, t, "target is t");
assert_equals(entries[0].contentRect.width, 50, "target width");
assert_equals(entries[0].contentRect.height, 100, "target height");
assert_equals(entries[0].contentBoxSize.inlineSize, 50,
"target content-box inline size");
assert_equals(entries[0].contentBoxSize.blockSize, 100,
"target content-box block size");
assert_equals(entries[0].borderBoxSize.inlineSize, 50,
"target content-box inline size");
assert_equals(entries[0].borderBoxSize.blockSize, 100,
"target content-box block size");
}
},
{
setup: observer => {
t.style.display = "inline";
},
notify: entries => {
assert_equals(entries[0].contentRect.width, 0, "target width");
assert_equals(entries[0].contentRect.height, 0, "target height");
assert_equals(entries[0].contentBoxSize.inlineSize, 0,
"target content-box inline size");
assert_equals(entries[0].contentBoxSize.blockSize, 0,
"target content-box block size");
assert_equals(entries[0].borderBoxSize.inlineSize, 0,
"target border-box inline size");
assert_equals(entries[0].borderBoxSize.blockSize, 0,
"target border-box block size");
}
}
]);

return helper.start(() => t.remove());
}

function test16() {
let t = createAndAppendElement("span");

let helper = new ResizeTestHelper(
// See: https://drafts.csswg.org/resize-observer/#intro.
"test16: observations do not fire for non-replaced inline elements",
[
{
setup: observer => {
observer.observe(t);
},
notify: entries => {
assert_unreached("No observation should fire for non box element")
},
timeout: () => {}
}
]);

return helper.start(() => t.remove());
}

let guard;
test(_ => {
assert_own_property(window, "ResizeObserver");
Expand All @@ -665,6 +736,8 @@
.then(() => test12())
.then(() => test13())
.then(() => test14())
.then(() => test15())
.then(() => test16())
.then(() => guard.done());

</script>
34 changes: 33 additions & 1 deletion resize-observer/svg.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<polygon points="0,200 100,200 50,250" style="fill:orange;stroke:black;stroke-width:1" />
<polyline points="0,300 100,300 50,350" style="fill:orange;stroke:black;stroke-width:1"/>
<rect x="0" y="380" width="10" height="10" style="fill:orange; stroke:black; stroke-width:1" />
<text x="0" y="400" font-size="20">svg text tag</text>
<text x="0" y="400" font-size="20" font-family="Ahem">svg text tag</text>
<g fill="white" stroke="green" stroke-width="5">
<rect x="0" y="380" width="50" height="20" id="g_rect" />
</g>
Expand Down Expand Up @@ -465,6 +465,37 @@
return helper.start();
}

function test15() {
let target = document.querySelector('text');
let helper = new ResizeTestHelper(
"test15: observe svg:text content and border box",
[
{
setup: observer => {
observer.observe(target);
},
notify: (entries, observer) => {
return true; // Delay next step
}
},
{
setup: observer => {
target.setAttribute('font-size', "30");
},
notify: (entries, observer) => {
assert_equals(entries.length, 1);
assert_equals(entries[0].contentRect.width, 360);
assert_equals(entries[0].contentRect.height, 30);
assert_equals(entries[0].contentBoxSize.inlineSize, 360);
assert_equals(entries[0].contentBoxSize.blockSize, 30);
assert_equals(entries[0].borderBoxSize.inlineSize, 360);
assert_equals(entries[0].borderBoxSize.blockSize, 30);
}
}
]);
return helper.start();
}

let guard;
test(_ => {
assert_own_property(window, "ResizeObserver");
Expand All @@ -486,6 +517,7 @@
.then(() => { return test12(); })
.then(() => { return test13(); })
.then(() => { return test14(); })
.then(() => { return test15(); })
.then(() => { guard.done(); });

</script>

0 comments on commit 9adb08e

Please sign in to comment.