Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src="../../resources/js-test.js"></script> | |
| 3 | |
| 4 <body> | |
|
ojan
2015/09/21 03:49:08
Nit: No need for the body element
MikeB
2015/09/24 19:04:03
Done.
| |
| 5 | |
| 6 <div id="top_div" style="background-color:blue;position:absolute; top:50px; left :20px; width:600px; height:800px"> | |
| 7 </div> | |
| 8 | |
| 9 <div id="target_div" style="background-color:red;position:absolute; top:855px; left:66px; width:300px; height:250px"> | |
|
ojan
2015/09/21 03:49:08
Please add test cases for the following or add app
| |
| 10 </div> | |
| 11 | |
| 12 </body> | |
| 13 | |
| 14 | |
| 15 | |
| 16 <script> | |
| 17 window.jsTestIsAsync = true; | |
| 18 | |
| 19 var entries = []; | |
| 20 var expectedEntries = [ | |
| 21 { | |
| 22 time:'mark', | |
| 23 quads:[{top:855, right:366, bottom: 1000, left: 66}], | |
| 24 viewport: {top:400, right:785, bottom:1000, left:0}, | |
| 25 target: document.getElementById('target_div') | |
| 26 } | |
| 27 ]; | |
| 28 | |
| 29 var a = {}, b = {}; | |
| 30 function shouldBeClientRect(name, value1, value2) | |
| 31 { | |
| 32 a[name] = value1; | |
| 33 b[name] = value2; | |
| 34 shouldBe('a.'+name+'.top', 'b.'+name+'.top'); | |
| 35 shouldBe('a.'+name+'.right', 'b.'+name+'.right'); | |
| 36 shouldBe('a.'+name+'.bottom', 'b.'+name+'.bottom'); | |
| 37 shouldBe('a.'+name+'.left', 'b.'+name+'.left'); | |
| 38 } | |
| 39 | |
| 40 function testIntersectionObserver() | |
| 41 { | |
| 42 var observer = new IntersectionObserver(intersectionCallback); | |
| 43 | |
| 44 function intersectionCallback(changes) | |
| 45 { | |
| 46 entries = entries.concat(changes); | |
| 47 if (entries.length != expectedEntries.length) | |
| 48 return; | |
| 49 shouldBe('entries[0].time', '0'); | |
| 50 shouldBeClientRect('quads_0', changes[0].quads[0], expectedEntries[0].qu ads[0]); | |
| 51 shouldBeClientRect('viewport', changes[0].viewport, expectedEntries[0].v iewport); | |
| 52 shouldBe('entries[0].target', 'expectedEntries[0].target'); | |
| 53 testRunner.notifyDone(); | |
| 54 } | |
| 55 | |
| 56 var config = { entryTypes: ['mark', 'measure'] }; | |
|
ojan
2015/09/21 03:49:08
I think this is probably leftover from the test ca
MikeB
2015/09/24 19:04:03
Done.
| |
| 57 var target_div = document.getElementById('target_div'); | |
| 58 observer.observe(target_div, config); | |
| 59 window.setTimeout(function() { window.scrollBy(0, 400); }, 0); | |
|
ojan
2015/09/21 03:49:09
Do you need the setTimeout? I think you should be
| |
| 60 } | |
| 61 | |
| 62 description("This tests that IntersectionObserver gets called the right number o f times."); | |
| 63 | |
| 64 testIntersectionObserver(); | |
| 65 testRunner.waitUntilDone(); | |
| 66 </script> | |
| OLD | NEW |