Chromium Code Reviews| 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 <script src="./resources/intersection-observer-test-utils.js"></script> | |
| 5 | |
| 6 <style> | |
| 7 pre, #log { | |
| 8 position: absolute; | |
| 9 top: 0; | |
| 10 left: 200px; | |
| 11 } | |
| 12 </style> | |
| 13 | |
| 4 <div id="host"></div> | 14 <div id="host"></div> |
| 5 | 15 |
| 6 <script> | 16 <script> |
| 7 description("Tests that observations can be made across shadow DOM boundaries.") ; | |
| 8 var entries = []; | 17 var entries = []; |
| 9 var target; | 18 var target; |
| 10 var observer = new IntersectionObserver(changes => { entries = entries.concat(ch anges) }); | |
| 11 | 19 |
| 12 onload = function() { | 20 runTestCycle(function() { |
| 13 let shadowHost = document.getElementById("host"); | 21 assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide."); |
| 14 let shadowRoot = shadowHost.createShadowRoot(); | 22 assert_equals(window.innerHeight, 600, "Window must be 600 pixels high."); |
| 15 target = document.createElement('div'); | 23 |
| 16 target.style.cssText = "background-color: green; width:100px; height:100px"; | 24 var shadowHost = document.getElementById("host"); |
| 17 shadowRoot.appendChild(target); | 25 assert_true(!!shadowHost, "Host exists"); |
| 26 var shadowRoot = shadowHost.createShadowRoot(); | |
| 27 assert_true(!!shadowRoot, "Shadow root exists"); | |
|
foolip
2017/01/11 13:42:53
It would help readability with fewer of these chec
| |
| 28 shadowRoot.innerHTML = "<div id='target' style='width: 100px; height: 100px; b ackground-color: green;'></div>"; | |
| 29 target = shadowRoot.getElementById("target"); | |
| 30 assert_true(!!target, "target exists"); | |
| 31 | |
| 32 var observer = new IntersectionObserver(function(changes) { | |
| 33 entries = entries.concat(changes) | |
| 34 }); | |
| 18 observer.observe(target); | 35 observer.observe(target); |
| 36 entries = entries.concat(observer.takeRecords()); | |
| 37 assert_equals(entries.length, 0, "No initial notifications."); | |
| 38 runTestCycle(step0, "First rAF after creating shadow DOM."); | |
| 39 }, "Observing a target inside shadow DOM."); | |
| 19 | 40 |
| 20 entries = entries.concat(observer.takeRecords()); | 41 function step0() { |
| 21 shouldBeEqualToNumber("entries.length", 0); | 42 checkEntry(entries, 0, [8, 108, 8, 108, 8, 108, 8, 108, 0, 800, 0, 600, target ]); |
| 22 waitForNotification(step1); | |
| 23 }; | |
| 24 | |
| 25 function step1() { | |
| 26 shouldBeEqualToNumber("entries.length", 1); | |
| 27 if (entries.length > 0) { | |
| 28 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); | |
| 29 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); | |
| 30 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 8); | |
| 31 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 108); | |
| 32 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | |
| 33 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); | |
| 34 shouldBeEqualToNumber("entries[0].intersectionRect.top", 8); | |
| 35 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 108); | |
| 36 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); | |
| 37 shouldBeEqualToNumber("entries[0].rootBounds.right", 800); | |
| 38 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); | |
| 39 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); | |
| 40 shouldEvaluateToSameObject("entries[0].target", target); | |
| 41 } | |
| 42 finishJSTest(); | |
| 43 } | 43 } |
| 44 </script> | 44 </script> |
| OLD | NEW |