Skip to content

Commit 17a61e5

Browse files
committed
Stubs for element.scroll()/scrollBy()/scrollTo() added (issue #742>)
1 parent fd9057e commit 17a61e5

4 files changed

Lines changed: 74 additions & 24 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
Jetty 9 websocket-client.
1919
</action>
2020

21+
<action type="fix" dev="rbri" issue="#742">
22+
Stubs for element.scroll()/scrollBy()/scrollTo() added.
23+
</action>
2124
<action type="fix" dev="Lai Quang Duong">
2225
Invalid numbers are processed correct now when using the rowSpan/colSpan properties.
2326
</action>

src/main/java/org/htmlunit/javascript/host/Element.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,36 @@ protected void setStyle(final String style) {
11941194
getStyle().setCssText(style);
11951195
}
11961196

1197+
/**
1198+
* Implement the {@code scroll()} JavaScript function but don't actually do
1199+
* anything. The requirement
1200+
* is just to prevent scripts that call that method from failing
1201+
*/
1202+
@JsxFunction
1203+
public void scroll() {
1204+
/* do nothing at the moment */
1205+
}
1206+
1207+
/**
1208+
* Implement the {@code scrollBy()} JavaScript function but don't actually do
1209+
* anything. The requirement
1210+
* is just to prevent scripts that call that method from failing
1211+
*/
1212+
@JsxFunction
1213+
public void scrollBy() {
1214+
/* do nothing at the moment */
1215+
}
1216+
1217+
/**
1218+
* Implement the {@code scrollTo()} JavaScript function but don't actually do
1219+
* anything. The requirement
1220+
* is just to prevent scripts that call that method from failing
1221+
*/
1222+
@JsxFunction
1223+
public void scrollTo() {
1224+
/* do nothing at the moment */
1225+
}
1226+
11971227
/**
11981228
* Implement the {@code scrollIntoView()} JavaScript function but don't actually do
11991229
* anything. The requirement

src/test/java/org/htmlunit/general/ElementOwnPropertiesTest.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ public void htmlElement() throws Exception {
616616
+ "onsearch[GSCE],onwebkitfullscreenchange[GSCE],onwebkitfullscreenerror[GSCE],outerHTML[GSCE],"
617617
+ "prefix[GCE],prepend(),previousElementSibling[GCE],querySelector(),querySelectorAll(),remove(),"
618618
+ "removeAttribute(),removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),"
619-
+ "scrollHeight[GCE],scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft[GSCE],scrollTop[GSCE],"
619+
+ "scroll(),scrollBy(),scrollHeight[GCE],scrollIntoView(),scrollIntoViewIfNeeded(),"
620+
+ "scrollLeft[GSCE],scrollTo(),scrollTop[GSCE],"
620621
+ "scrollWidth[GCE],setAttribute(),setAttributeNode(),setAttributeNS(),tagName[GCE],"
621622
+ "toggleAttribute(),webkitMatchesSelector()",
622623
EDGE = "after(),append(),attributes[GCE],before(),childElementCount[GCE],children[GCE],"
@@ -630,7 +631,8 @@ public void htmlElement() throws Exception {
630631
+ "onsearch[GSCE],onwebkitfullscreenchange[GSCE],onwebkitfullscreenerror[GSCE],outerHTML[GSCE],"
631632
+ "prefix[GCE],prepend(),previousElementSibling[GCE],querySelector(),querySelectorAll(),remove(),"
632633
+ "removeAttribute(),removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),"
633-
+ "scrollHeight[GCE],scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft[GSCE],scrollTop[GSCE],"
634+
+ "scroll(),scrollBy(),scrollHeight[GCE],scrollIntoView(),scrollIntoViewIfNeeded(),"
635+
+ "scrollLeft[GSCE],scrollTo(),scrollTop[GSCE],"
634636
+ "scrollWidth[GCE],setAttribute(),setAttributeNode(),setAttributeNS(),tagName[GCE],"
635637
+ "toggleAttribute(),webkitMatchesSelector()",
636638
FF = "after(),append(),attributes[GCE],before(),childElementCount[GCE],children[GCE],classList[GCE],"
@@ -642,8 +644,9 @@ public void htmlElement() throws Exception {
642644
+ "lastElementChild[GCE],localName[GCE],matches(),mozMatchesSelector(),namespaceURI[GCE],"
643645
+ "nextElementSibling[GCE],outerHTML[GSCE],prefix[GCE],prepend(),previousElementSibling[GCE],"
644646
+ "querySelector(),querySelectorAll(),releaseCapture(),remove(),removeAttribute(),"
645-
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),scrollHeight[GCE],"
646-
+ "scrollIntoView(),scrollLeft[GSCE],scrollTop[GSCE],scrollWidth[GCE],setAttribute(),"
647+
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),"
648+
+ "scroll(),scrollBy(),scrollHeight[GCE],scrollIntoView(),scrollLeft[GSCE],scrollTo(),scrollTop[GSCE],"
649+
+ "scrollWidth[GCE],setAttribute(),"
647650
+ "setAttributeNode(),setAttributeNS(),setCapture(),tagName[GCE],toggleAttribute(),"
648651
+ "webkitMatchesSelector()",
649652
FF_ESR = "after(),append(),attributes[GCE],before(),childElementCount[GCE],children[GCE],classList[GCE],"
@@ -655,8 +658,9 @@ public void htmlElement() throws Exception {
655658
+ "lastElementChild[GCE],localName[GCE],matches(),mozMatchesSelector(),namespaceURI[GCE],"
656659
+ "nextElementSibling[GCE],outerHTML[GSCE],prefix[GCE],prepend(),previousElementSibling[GCE],"
657660
+ "querySelector(),querySelectorAll(),releaseCapture(),remove(),removeAttribute(),"
658-
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),scrollHeight[GCE],"
659-
+ "scrollIntoView(),scrollLeft[GSCE],scrollTop[GSCE],scrollWidth[GCE],setAttribute(),"
661+
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),"
662+
+ "scroll(),scrollBy(),scrollHeight[GCE],scrollIntoView(),scrollLeft[GSCE],scrollTo(),scrollTop[GSCE],"
663+
+ "scrollWidth[GCE],setAttribute(),"
660664
+ "setAttributeNode(),setAttributeNS(),setCapture(),tagName[GCE],toggleAttribute(),"
661665
+ "webkitMatchesSelector()")
662666
public void element() throws Exception {
@@ -783,8 +787,10 @@ public void element() throws Exception {
783787
+ "nextElementSibling[GCE],onbeforecopy[GSCE],onbeforecut[GSCE],onbeforepaste[GSCE],onsearch[GSCE],"
784788
+ "onwebkitfullscreenchange[GSCE],onwebkitfullscreenerror[GSCE],outerHTML[GSCE],prefix[GCE],prepend(),"
785789
+ "previousElementSibling[GCE],querySelector(),querySelectorAll(),remove(),removeAttribute(),"
786-
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),scrollHeight[GCE],"
787-
+ "scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft[GSCE],scrollTop[GSCE],scrollWidth[GCE],"
790+
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),"
791+
+ "scroll(),scrollBy(),scrollHeight[GCE],"
792+
+ "scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft[GSCE],scrollTo(),"
793+
+ "scrollTop[GSCE],scrollWidth[GCE],"
788794
+ "setAttribute(),setAttributeNode(),setAttributeNS(),"
789795
+ "tagName[GCE],toggleAttribute(),webkitMatchesSelector()",
790796
EDGE = "after(),append(),attributes[GCE],before(),childElementCount[GCE],"
@@ -798,8 +804,10 @@ public void element() throws Exception {
798804
+ "nextElementSibling[GCE],onbeforecopy[GSCE],onbeforecut[GSCE],onbeforepaste[GSCE],onsearch[GSCE],"
799805
+ "onwebkitfullscreenchange[GSCE],onwebkitfullscreenerror[GSCE],outerHTML[GSCE],prefix[GCE],prepend(),"
800806
+ "previousElementSibling[GCE],querySelector(),querySelectorAll(),remove(),removeAttribute(),"
801-
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),scrollHeight[GCE],"
802-
+ "scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft[GSCE],scrollTop[GSCE],scrollWidth[GCE],"
807+
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),"
808+
+ "scroll(),scrollBy(),scrollHeight[GCE],"
809+
+ "scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft[GSCE],scrollTo(),"
810+
+ "scrollTop[GSCE],scrollWidth[GCE],"
803811
+ "setAttribute(),setAttributeNode(),setAttributeNS(),"
804812
+ "tagName[GCE],toggleAttribute(),webkitMatchesSelector()",
805813
FF_ESR = "after(),append(),attributes[GCE],before(),childElementCount[GCE],"
@@ -814,8 +822,9 @@ public void element() throws Exception {
814822
+ "nextElementSibling[GCE],outerHTML[GSCE],prefix[GCE],prepend(),"
815823
+ "previousElementSibling[GCE],querySelector(),querySelectorAll(),releaseCapture(),"
816824
+ "remove(),removeAttribute(),"
817-
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),scrollHeight[GCE],"
818-
+ "scrollIntoView(),scrollLeft[GSCE],scrollTop[GSCE],scrollWidth[GCE],"
825+
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),"
826+
+ "scroll(),scrollBy(),scrollHeight[GCE],"
827+
+ "scrollIntoView(),scrollLeft[GSCE],scrollTo(),scrollTop[GSCE],scrollWidth[GCE],"
819828
+ "setAttribute(),setAttributeNode(),setAttributeNS(),setCapture(),"
820829
+ "tagName[GCE],toggleAttribute(),webkitMatchesSelector()",
821830
FF = "after(),append(),attributes[GCE],before(),childElementCount[GCE],"
@@ -830,8 +839,9 @@ public void element() throws Exception {
830839
+ "nextElementSibling[GCE],outerHTML[GSCE],prefix[GCE],prepend(),"
831840
+ "previousElementSibling[GCE],querySelector(),querySelectorAll(),releaseCapture(),"
832841
+ "remove(),removeAttribute(),"
833-
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),scrollHeight[GCE],"
834-
+ "scrollIntoView(),scrollLeft[GSCE],scrollTop[GSCE],scrollWidth[GCE],"
842+
+ "removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),"
843+
+ "scroll(),scrollBy(),scrollHeight[GCE],"
844+
+ "scrollIntoView(),scrollLeft[GSCE],scrollTo(),scrollTop[GSCE],scrollWidth[GCE],"
835845
+ "setAttribute(),setAttributeNode(),setAttributeNS(),setCapture(),"
836846
+ "tagName[GCE],toggleAttribute(),webkitMatchesSelector()")
837847
public void element2() throws Exception {

src/test/java/org/htmlunit/general/ElementPropertiesTest.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ public void htmlElement() throws Exception {
714714
+ "prefix,prepend(),"
715715
+ "querySelector(),querySelectorAll(),"
716716
+ "removeAttribute(),removeAttributeNode(),removeAttributeNS(),replaceChildren(),"
717-
+ "scrollHeight,scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft,scrollTop,scrollWidth,"
717+
+ "scroll(),scrollBy(),scrollHeight,scrollIntoView(),"
718+
+ "scrollIntoViewIfNeeded(),scrollLeft,scrollTo(),scrollTop,scrollWidth,"
718719
+ "setAttribute(),setAttributeNode(),setAttributeNS(),"
719720
+ "tagName,toggleAttribute(),webkitMatchesSelector()",
720721
EDGE = "append(),attributes,"
@@ -729,7 +730,8 @@ public void htmlElement() throws Exception {
729730
+ "prefix,prepend(),"
730731
+ "querySelector(),querySelectorAll(),"
731732
+ "removeAttribute(),removeAttributeNode(),removeAttributeNS(),replaceChildren(),"
732-
+ "scrollHeight,scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft,scrollTop,scrollWidth,"
733+
+ "scroll(),scrollBy(),scrollHeight,scrollIntoView(),"
734+
+ "scrollIntoViewIfNeeded(),scrollLeft,scrollTo(),scrollTop,scrollWidth,"
733735
+ "setAttribute(),setAttributeNode(),setAttributeNS(),"
734736
+ "tagName,toggleAttribute(),webkitMatchesSelector()",
735737
FF_ESR = "append(),attributes,"
@@ -742,7 +744,8 @@ public void htmlElement() throws Exception {
742744
+ "prefix,prepend(),"
743745
+ "querySelector(),querySelectorAll(),releaseCapture(),removeAttribute(),removeAttributeNode(),"
744746
+ "removeAttributeNS(),replaceChildren(),"
745-
+ "scrollHeight,scrollIntoView(),scrollLeft,scrollTop,scrollWidth,setAttribute(),"
747+
+ "scroll(),scrollBy(),scrollHeight,scrollIntoView(),"
748+
+ "scrollLeft,scrollTo(),scrollTop,scrollWidth,setAttribute(),"
746749
+ "setAttributeNode(),setAttributeNS(),setCapture(),"
747750
+ "tagName,toggleAttribute(),webkitMatchesSelector()",
748751
FF = "append(),attributes,"
@@ -755,7 +758,8 @@ public void htmlElement() throws Exception {
755758
+ "prefix,prepend(),"
756759
+ "querySelector(),querySelectorAll(),releaseCapture(),removeAttribute(),removeAttributeNode(),"
757760
+ "removeAttributeNS(),replaceChildren(),"
758-
+ "scrollHeight,scrollIntoView(),scrollLeft,scrollTop,scrollWidth,setAttribute(),"
761+
+ "scroll(),scrollBy(),scrollHeight,scrollIntoView(),"
762+
+ "scrollLeft,scrollTo(),scrollTop,scrollWidth,setAttribute(),"
759763
+ "setAttributeNode(),setAttributeNS(),setCapture(),"
760764
+ "tagName,toggleAttribute(),webkitMatchesSelector()")
761765
public void element() throws Exception {
@@ -856,7 +860,8 @@ public void element() throws Exception {
856860
+ "onsearch,onwebkitfullscreenchange,onwebkitfullscreenerror,outerHTML,prefix,prepend(),"
857861
+ "previousElementSibling,remove(),removeAttribute(),removeAttributeNode(),removeAttributeNS(),"
858862
+ "replaceChildren(),replaceWith(),"
859-
+ "scrollHeight,scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft,scrollTop,"
863+
+ "scroll(),scrollBy(),scrollHeight,scrollIntoView(),scrollIntoViewIfNeeded(),"
864+
+ "scrollLeft,scrollTo(),scrollTop,"
860865
+ "scrollWidth,setAttribute(),setAttributeNode(),setAttributeNS(),"
861866
+ "tagName,toggleAttribute(),webkitMatchesSelector()",
862867
EDGE = "after(),append(),attributes,before(),classList,className,clientHeight,clientLeft,clientTop,"
@@ -869,7 +874,8 @@ public void element() throws Exception {
869874
+ "onsearch,onwebkitfullscreenchange,onwebkitfullscreenerror,outerHTML,prefix,prepend(),"
870875
+ "previousElementSibling,remove(),removeAttribute(),removeAttributeNode(),removeAttributeNS(),"
871876
+ "replaceChildren(),replaceWith(),"
872-
+ "scrollHeight,scrollIntoView(),scrollIntoViewIfNeeded(),scrollLeft,scrollTop,"
877+
+ "scroll(),scrollBy(),scrollHeight,scrollIntoView(),scrollIntoViewIfNeeded(),"
878+
+ "scrollLeft,scrollTo(),scrollTop,"
873879
+ "scrollWidth,setAttribute(),setAttributeNode(),setAttributeNS(),"
874880
+ "tagName,toggleAttribute(),webkitMatchesSelector()",
875881
FF_ESR = "after(),append(),attributes,before(),"
@@ -881,8 +887,9 @@ public void element() throws Exception {
881887
+ "insertAdjacentHTML(),insertAdjacentText(),localName,matches(),mozMatchesSelector(),namespaceURI,"
882888
+ "nextElementSibling,outerHTML,prefix,prepend(),previousElementSibling,"
883889
+ "releaseCapture(),remove(),removeAttribute(),removeAttributeNode(),removeAttributeNS(),"
884-
+ "replaceChildren(),replaceWith(),scrollHeight,"
885-
+ "scrollIntoView(),scrollLeft,scrollTop,scrollWidth,setAttribute(),setAttributeNode(),"
890+
+ "replaceChildren(),replaceWith(),"
891+
+ "scroll(),scrollBy(),scrollHeight,"
892+
+ "scrollIntoView(),scrollLeft,scrollTo(),scrollTop,scrollWidth,setAttribute(),setAttributeNode(),"
886893
+ "setAttributeNS(),setCapture(),"
887894
+ "tagName,toggleAttribute(),webkitMatchesSelector()",
888895
FF = "after(),append(),attributes,before(),"
@@ -895,8 +902,8 @@ public void element() throws Exception {
895902
+ "nextElementSibling,outerHTML,prefix,prepend(),previousElementSibling,"
896903
+ "releaseCapture(),remove(),"
897904
+ "removeAttribute(),removeAttributeNode(),removeAttributeNS(),replaceChildren(),replaceWith(),"
898-
+ "scrollHeight,"
899-
+ "scrollIntoView(),scrollLeft,scrollTop,scrollWidth,setAttribute(),setAttributeNode(),"
905+
+ "scroll(),scrollBy(),scrollHeight,"
906+
+ "scrollIntoView(),scrollLeft,scrollTo(),scrollTop,scrollWidth,setAttribute(),setAttributeNode(),"
900907
+ "setAttributeNS(),setCapture(),"
901908
+ "tagName,toggleAttribute(),webkitMatchesSelector()")
902909
public void element2() throws Exception {

0 commit comments

Comments
 (0)