OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/js-test.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/intersection-observer-helper-functions.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <iframe id="iframe" srcdoc="<div id='target'><div style='width:1000px;height:100 0px'></div></div>"></iframe> | 4 <iframe id="iframe" srcdoc="<div id='target'><div style='width:1000px;height:100 0px'></div></div>"></iframe> |
5 | |
5 <script> | 6 <script> |
6 description("Ensure that change.boundingClientRect matches change.target.getBoun dingClientRect() for a clipped element with overflow inside an iframe."); | 7 function waitForNotification(f) { |
7 | 8 requestAnimationFrame(() => { |
8 var iframe = document.getElementById("iframe"); | 9 setTimeout(() => { |
9 var entries = []; | 10 setTimeout(f); |
foolip
2016/12/14 13:42:16
Is the spec actually this lax about the timing?
szager1
2016/12/14 19:54:11
The sequence of events is this:
- js: modify DOM
foolip
2016/12/14 22:17:56
The nested setTimeout is what looked suspicious to
szager1
2016/12/22 19:55:26
I added a lengthy comment about how this works to
| |
10 var target; | 11 }); |
12 }); | |
13 } | |
11 | 14 |
12 iframe.onload = function() { | 15 iframe.onload = function() { |
foolip
2016/12/14 13:42:16
Waiting for the load event before creating the tes
szager1
2016/12/14 19:57:02
Is this a style nit, or is there good reason to st
foolip
2016/12/14 22:17:57
testharness.js doesn't wait for tests to appear af
szager1
2016/12/22 19:55:26
I followed your suggestion for iframe tests.
| |
13 target = iframe.contentDocument.getElementById("target"); | 16 var t = async_test("Ensure that change.boundingClientRect matches change.targe t.getBoundingClientRect() for a clipped element with overflow inside an iframe." ); |
14 new IntersectionObserver((changes) => { | 17 |
15 entries.push(...changes); | 18 test(function() { assert_equals(window.innerWidth, 800) }, "Window must be 800 pixels wide."); |
foolip
2016/12/14 13:42:16
This is a bit unusual, to wrap every assertion in
szager1
2016/12/14 19:54:11
The problem is that when running an async test, th
foolip
2016/12/14 22:17:57
Yeah, this can be a bother, that an early failure
szager1
2016/12/22 19:55:26
As we discussed offline: testharness allows you to
| |
16 }).observe(target); | 19 test(function() { assert_equals(window.innerHeight, 600) }, "Window must be 60 0 pixels high."); |
20 | |
21 var target = this.contentDocument.getElementById("target"); | |
foolip
2016/12/14 13:42:16
Since this sin't associated with any test, if it h
szager1
2016/12/14 19:54:11
OK, I'll add an assert.
| |
22 var entries = []; | |
23 var observer = new IntersectionObserver((changes) => { | |
24 entries = entries.concat(changes); | |
25 }); | |
26 observer.observe(target); | |
27 entries = entries.concat(observer.takeRecords()); | |
foolip
2016/12/14 13:42:16
Is it possible per spec that there are any records
szager1
2016/12/14 19:54:11
It should not happen that there are already notifi
foolip
2016/12/14 22:17:56
If it weren't for the fact that the test still con
szager1
2016/12/22 19:55:26
This check is now a hard assert that will cause th
| |
28 test(function() { assert_equals(entries.length, 0) }, "No initial notification s."); | |
17 waitForNotification(step0); | 29 waitForNotification(step0); |
30 | |
31 function step0() { | |
32 test(function() { assert_equals(entries.length, 1) }, "One notification."); | |
foolip
2016/12/14 13:42:16
If only one entry is expected, maybe structure the
szager1
2016/12/14 19:54:11
I did define a checkEntry routine in other tests f
foolip
2016/12/14 22:17:56
It's fine to have shared scripts with helpers if i
szager1
2016/12/22 19:55:26
I moved common code into LayoutTests/intersection-
| |
33 if (entries.length > 0) { | |
34 test(function() { assert_equals(entries[0].boundingClientRect.top, | |
35 target.getBoundingClientRect().top) }, | |
36 "entries[0].boundingClientRect.top == target.getBoundingClientRect(). top"); | |
37 test(function() { assert_equals(entries[0].boundingClientRect.left, | |
38 target.getBoundingClientRect().left) }, | |
39 "entries[0].boundingClientRect.left == target.getBoundingClientRect() .left"); | |
40 test(function() { assert_equals(entries[0].boundingClientRect.width, | |
41 target.getBoundingClientRect().width) }, | |
42 "entries[0].boundingClientRect.width == target.getBoundingClientRect( ).width"); | |
43 test(function() { assert_equals(entries[0].boundingClientRect.height, | |
44 target.getBoundingClientRect().height) }, | |
45 "entries[0].boundingClientRect.height == target.getBoundingClientRect ().height"); | |
46 } | |
47 t.done(); | |
48 } | |
18 }; | 49 }; |
19 | |
20 function step0() { | |
21 shouldBeEqualToNumber("entries.length", 1); | |
22 if (entries.length > 0) { | |
23 shouldBe("entries[0].boundingClientRect.top", "target.getBoundingClientRect( ).top"); | |
24 shouldBe("entries[0].boundingClientRect.left", "target.getBoundingClientRect ().left"); | |
25 shouldBe("entries[0].boundingClientRect.width", "target.getBoundingClientRec t().width"); | |
26 shouldBe("entries[0].boundingClientRect.height", "target.getBoundingClientRe ct().height"); | |
27 } | |
28 finishJSTest(); | |
29 } | |
30 </script> | 50 </script> |
OLD | NEW |