1- name: 2d.scrollPathIntoView.basic 2 desc: scrollPathIntoView() works 3 testing: 4 - 2d.scrollPathIntoView.basic 5 code: | 6 var div = document.createElement('div'); 7 div.style.cssText = 'width: 200vw; height: 200vh'; 8 document.body.appendChild(div); 9 canvas.style.cssText = 'position: absolute; top: 100px; left: 200px; border: none;'; 10 window.scrollTo(0, 0); 11 12 ctx.beginPath(); 13 ctx.rect(4, 8, 16, 32); 14 ctx.scrollPathIntoView(); 15 var rect = canvas.getBoundingClientRect(); 16 @assert Math.round(rect.top) === -8; 17 @assert Math.round(rect.left) === 200; 18 19- name: 2d.scrollPathIntoView.verticalLR 20 desc: scrollPathIntoView() works in vertical-lr writing mode 21 testing: 22 - 2d.scrollPathIntoView.basic 23 code: | 24 document.documentElement.style.cssText = 'writing-mode: vertical-lr'; 25 var div = document.createElement('div'); 26 div.style.cssText = 'width: 200vw; height: 200vh'; 27 document.body.appendChild(div); 28 canvas.style.cssText = 'position: absolute; top: 100px; left: 200px; border: none;'; 29 window.scrollTo(0, 0); 30 31 ctx.beginPath(); 32 ctx.rect(4, 8, 16, 32); 33 ctx.scrollPathIntoView(); 34 var rect = canvas.getBoundingClientRect(); 35 @assert Math.round(rect.top) === 100; 36 @assert Math.round(rect.left) === -4; 37 38- name: 2d.scrollPathIntoView.verticalRL 39 desc: scrollPathIntoView() works in vertical-rl writing mode 40 testing: 41 - 2d.scrollPathIntoView.basic 42 code: | 43 document.documentElement.style.cssText = 'writing-mode: vertical-rl'; 44 var div = document.createElement('div'); 45 div.style.cssText = 'width: 200vw; height: 200vh'; 46 document.body.appendChild(div); 47 canvas.style.cssText = 'position: absolute; top: 100px; right: 200px; border: none;'; 48 window.scrollTo(0, 0); 49 50 ctx.beginPath(); 51 ctx.rect(4, 8, 16, 32); 52 ctx.scrollPathIntoView(); 53 var rect = canvas.getBoundingClientRect(); 54 var viewportWidth = document.scrollingElement.clientWidth; 55 var canvasWidth = canvas.width; 56 @assert Math.round(rect.top) === 100; 57 @assert Math.round(rect.right) === viewportWidth + (canvasWidth - 4 - 16); 58 59- name: 2d.scrollPathIntoView.path 60 desc: scrollPathIntoView() with path argument works 61 testing: 62 - 2d.scrollPathIntoView.basic 63 code: | 64 var div = document.createElement('div'); 65 div.style.cssText = 'width: 200vw; height: 200vh'; 66 document.body.appendChild(div); 67 canvas.style.cssText = 'position: absolute; top: 100px; left: 200px; border: none;'; 68 window.scrollTo(0, 0); 69 70 var path = new Path2D(); 71 path.rect(4, 8, 16, 32); 72 ctx.scrollPathIntoView(path); 73 var rect = canvas.getBoundingClientRect(); 74 @assert Math.round(rect.top) === -8; 75 @assert Math.round(rect.left) === 200; 76 77