1 <html xmlns=
"http://www.w3.org/1999/xhtml">
3 https://bugzilla.mozilla.org/show_bug.cgi?id=1486952
6 <title>Test that hit-testing works after a viewBox update
</title>
12 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
13 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
17 <script class=
"testbody" type=
"text/javascript">
20 SimpleTest.waitForExplicitFinish();
24 const offsetX = div.offsetLeft;
25 const offsetY = div.offsetTop;
26 const outerRect = $(
"outerRect");
27 const innerRect = $(
"innerRect");
28 const outerSVG = $(
"outerSVG");
29 const innerSVG = $(
"innerSVG");
32 // Update the inner SVG viewBox to
"move" the inner rectangle off its current
33 // position on screen:
34 innerSVG.setAttribute(
"viewBox",
"-25 0 50 50");
35 got = document.elementFromPoint(offsetX +
150, offsetY +
25);
36 is(got, innerRect,
"Should hit inner rectangle (1)");
38 // Update the inner SVG viewBox again. (At the time of writing, a reflow is
39 // triggered the first time you change viewBox on an inner svg, so the
40 // previous test is expected to always pass. This next test will fail if we're
41 // updating overflows on the inner svg frame instead of its children).
42 innerSVG.setAttribute(
"viewBox",
"0 -25 50 50");
43 got = document.elementFromPoint(offsetX +
100, offsetY +
75);
44 is(got, innerRect,
"Should hit inner rectangle (2)");
46 // Now update the outer SVG viewBox and confirm that both rectangles are
47 // registered. (Note that in this case the overflow rectangle of the inner
48 // svg is the inner svg's viewport, so be sure to
"move" the outer svg so that
49 // the
"new" outer rectangle and inner svg are off the current outerRect
50 // union inner svg viewport - hit testing still works in that union.)
51 outerSVG.setAttribute(
"viewBox",
"-200 0 400 100");
53 got = document.elementFromPoint(offsetX +
250, offsetY +
50);
54 is(got, outerRect,
"Should hit outer rectangle");
56 got = document.elementFromPoint(offsetX +
300, offsetY +
75);
57 is(got, innerRect,
"Should hit inner rectangle (3)");
64 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=1486952">Mozilla Bug
1486952</a>
68 <div width=
"100%" height=
"1" id=
"div"></div>
69 <svg xmlns=
"http://www.w3.org/2000/svg" id=
"outerSVG" width=
"400" height=
"100"
70 viewBox=
"0 0 400 100">
71 <rect x=
"25" y=
"25" width=
"50" height=
"50" fill=
"red" id=
"outerRect" />
72 <svg x=
"75" width=
"100" height=
"100" viewBox=
"0 0 50 50" id=
"innerSVG">
73 <rect width=
"25" height=
"25" fill=
"red" id=
"innerRect" />