OLD | NEW |
(Empty) | |
| 1 // Here's how waitForNotification works: |
| 2 // |
| 3 // - myTestFunction0() |
| 4 // - waitForNotification(myTestFunction1) |
| 5 // - requestAnimationFrame() |
| 6 // - Modify DOM in a way that should trigger an IntersectionObserver callback. |
| 7 // - BeginFrame |
| 8 // - requestAnimationFrame handler runs |
| 9 // - First setTimeout() |
| 10 // - Style, layout, paint |
| 11 // - IntersectionObserver generates new notifications |
| 12 // - Posts a task to deliver notifications |
| 13 // - First setTimeout handler runs |
| 14 // - Second setTimeout() |
| 15 // - Task to deliver IntersectionObserver notifications runs |
| 16 // - IntersectionObserver callbacks run |
| 17 // - Second setTimeout handler runs |
| 18 // - myTestFunction1() |
| 19 // - [optional] waitForNotification(myTestFunction2) |
| 20 // - requestAnimationFrame() |
| 21 // - Verify newly-arrived IntersectionObserver notifications |
| 22 // - [optional] Modify DOM to trigger new notifications |
| 23 function waitForNotification(f) { |
| 24 requestAnimationFrame(function() { |
| 25 setTimeout(function() { setTimeout(f); }); |
| 26 }); |
| 27 } |
| 28 |
| 29 // The timing of when runTestCycle is called is important. It should be |
| 30 // called: |
| 31 // |
| 32 // - Before or during the window load event, or |
| 33 // - Inside of a prior runTestCycle callback, *before* any assert_* methods |
| 34 // are called. |
| 35 // |
| 36 // Following these rules will ensure that the test suite will not abort before |
| 37 // all test steps have run. |
| 38 function runTestCycle(f, description) { |
| 39 async_test(function(t) { |
| 40 waitForNotification(t.step_func_done(f)); |
| 41 }, description); |
| 42 } |
| 43 |
| 44 // Root bounds for a root with an overflow clip as defined by: |
| 45 // http://wicg.github.io/IntersectionObserver/#intersectionobserver-root-inter
section-rectangle |
| 46 function contentBounds(root) { |
| 47 var left = root.offsetLeft + root.clientLeft; |
| 48 var right = left + root.clientWidth; |
| 49 var top = root.offsetTop + root.clientTop; |
| 50 var bottom = top + root.clientHeight; |
| 51 return [left, right, top, bottom]; |
| 52 } |
| 53 |
| 54 // Root bounds for a root without an overflow clip as defined by: |
| 55 // http://wicg.github.io/IntersectionObserver/#intersectionobserver-root-inter
section-rectangle |
| 56 function borderBoxBounds(root) { |
| 57 var left = root.offsetLeft; |
| 58 var right = left + root.offsetWidth; |
| 59 var top = root.offsetTop; |
| 60 var bottom = top + root.offsetHeight; |
| 61 return [left, right, top, bottom]; |
| 62 } |
| 63 |
| 64 function rectArea(rect) { |
| 65 return (rect.left - rect.right) * (rect.bottom - rect.top); |
| 66 } |
| 67 |
| 68 function checkRect(actual, expected, description) { |
| 69 if (!expected.length) |
| 70 return; |
| 71 assert_equals(actual.left, expected[0], description + '.left'); |
| 72 assert_equals(actual.right, expected[1], description + '.right'); |
| 73 assert_equals(actual.top, expected[2], description + '.top'); |
| 74 assert_equals(actual.bottom, expected[3], description + '.bottom'); |
| 75 } |
| 76 |
| 77 function checkLastEntry(entries, i, expected) { |
| 78 assert_equals(entries.length, i + 1, 'entries.length'); |
| 79 if (expected) { |
| 80 checkRect( |
| 81 entries[i].boundingClientRect, expected.slice(0, 4), |
| 82 'entries[' + i + '].boundingClientRect'); |
| 83 checkRect( |
| 84 entries[i].intersectionRect, expected.slice(4, 8), |
| 85 'entries[' + i + '].intersectionRect'); |
| 86 checkRect( |
| 87 entries[i].rootBounds, expected.slice(8, 12), |
| 88 'entries[' + i + '].rootBounds'); |
| 89 } |
| 90 } |
| 91 |
| 92 function checkJsonEntry(actual, expected) { |
| 93 checkRect( |
| 94 actual.boundingClientRect, expected.boundingClientRect, |
| 95 'entry.boundingClientRect'); |
| 96 checkRect( |
| 97 actual.intersectionRect, expected.intersectionRect, |
| 98 'entry.intersectionRect'); |
| 99 if (actual.rootBounds == 'null') |
| 100 assert_equals(expected.rootBounds, 'null', 'rootBounds is null'); |
| 101 else |
| 102 checkRect(actual.rootBounds, expected.rootBounds, 'entry.rootBounds'); |
| 103 assert_equals(actual.target, expected.target); |
| 104 } |
| 105 |
| 106 function checkJsonEntries(actual, expected, description) { |
| 107 test(function() { |
| 108 assert_equals(actual.length, expected.length); |
| 109 for (var i = 0; i < actual.length; i++) |
| 110 checkJsonEntry(actual[i], expected[i]); |
| 111 }, description); |
| 112 } |
OLD | NEW |