1616
1717import org .htmlunit .WebDriverTestCase ;
1818import org .htmlunit .junit .annotation .Alerts ;
19+ import org .htmlunit .junit .annotation .HtmlUnitNYI ;
1920import org .junit .jupiter .api .Test ;
2021
2122/**
@@ -31,19 +32,57 @@ public class DOMStringMapTest extends WebDriverTestCase {
3132 * @throws Exception if the test fails
3233 */
3334 @ Test
34- @ Alerts ({"undefined" , "there" })
35+ @ Alerts ({"undefined" , "there" , "heho" })
3536 public void get () throws Exception {
3637 final String html = DOCTYPE_HTML
3738 + "<html><head>\n "
3839 + "<script>\n "
3940 + LOG_TITLE_FUNCTION
4041 + "function test() {\n "
41- + " if (document.body.dataset) {\n "
42- + " log(document.body.dataset.hi);\n "
43- + " log(document.body.dataset.hello);\n "
44- + " }\n "
42+ + " log(document.body.dataset.hi);\n "
43+ + " log(document.body.dataset.hello);\n "
44+ + " log(document.body.dataset.helloWorld);\n "
4545 + "}\n "
46- + "</script></head><body onload='test()' data-hello='there'>\n "
46+ + "</script></head>\n "
47+ + "<body onload='test()' data-hello='there' data-hello-world='heho'>\n "
48+ + "</body></html>" ;
49+
50+ loadPageVerifyTitle2 (html );
51+ }
52+
53+ /**
54+ * @throws Exception if the test fails
55+ */
56+ @ Test
57+ @ Alerts ({"heho" , "ReferenceError" , "world is not defined" ,
58+ "ReferenceError" , "World is not defined" })
59+ @ HtmlUnitNYI (
60+ CHROME = {"heho" , "ReferenceError" , "\" world\" is not defined" ,
61+ "ReferenceError" , "\" World\" is not defined" },
62+ EDGE = {"heho" , "ReferenceError" , "\" world\" is not defined" ,
63+ "ReferenceError" , "\" World\" is not defined" },
64+ FF = {"heho" , "ReferenceError" , "\" world\" is not defined" ,
65+ "ReferenceError" , "\" World\" is not defined" },
66+ FF_ESR = {"heho" , "ReferenceError" , "\" world\" is not defined" ,
67+ "ReferenceError" , "\" World\" is not defined" })
68+ public void getInvalidName () throws Exception {
69+ final String html = DOCTYPE_HTML
70+ + "<html><head>\n "
71+ + "<script>\n "
72+ + LOG_TITLE_FUNCTION
73+ + "function test() {\n "
74+ + " log(document.body.dataset.helloWorld);\n "
75+
76+ + " try {\n "
77+ + " log(document.body.dataset.hello-world);\n "
78+ + " } catch(e) { logEx(e); log(e.message);}\n "
79+
80+ + " try {\n "
81+ + " log(document.body.dataset.hello-World);\n "
82+ + " } catch(e) { logEx(e); log(e.message);}\n "
83+ + "}\n "
84+ + "</script></head>\n "
85+ + "<body onload='test()' data-hello='hi' data-world='huhu' data-hello-world='heho'>\n "
4786 + "</body></html>" ;
4887
4988 loadPageVerifyTitle2 (html );
@@ -60,16 +99,45 @@ public void put() throws Exception {
6099 + "<script>\n "
61100 + LOG_TITLE_FUNCTION
62101 + "function test() {\n "
63- + " if (document.body.dataset) {\n "
64- + " document.body.dataset.dateOfBirth = 'old';\n "
65- + " log(document.body.dataset.dateOfBirth);\n "
66- + " log(document.body.getAttribute('data-date-of-birth'));\n "
67- + " document.body.dataset.dateOfBirth = null;\n "
68- + " log(document.body.dataset.dateOfBirth);\n "
69- + " log(document.body.getAttribute('data-date-of-birth'));\n "
70- + " }\n "
102+ + " document.body.dataset.dateOfBirth = 'old';\n "
103+ + " log(document.body.dataset.dateOfBirth);\n "
104+ + " log(document.body.getAttribute('data-date-of-birth'));\n "
105+
106+ + " document.body.dataset.dateOfBirth = null;\n "
107+ + " log(document.body.dataset.dateOfBirth);\n "
108+ + " log(document.body.getAttribute('data-date-of-birth'));\n "
109+ + "}\n "
110+ + "</script></head>\n "
111+ + "<body onload='test()'>\n "
112+ + "</body></html>" ;
113+
114+ loadPageVerifyTitle2 (html );
115+ }
116+ /**
117+ * @throws Exception if the test fails
118+ */
119+ @ Test
120+ @ Alerts ({"undefined" , "undefined" , "there" , "undefined" , "heho" , "undefined" })
121+ public void delete () throws Exception {
122+ final String html = DOCTYPE_HTML
123+ + "<html><head>\n "
124+ + "<script>\n "
125+ + LOG_TITLE_FUNCTION
126+ + "function test() {\n "
127+ + " log(document.body.dataset.hi);\n "
128+ + " delete document.body.dataset.hi;\n "
129+ + " log(document.body.dataset.hi);\n "
130+
131+ + " log(document.body.dataset.hello);\n "
132+ + " delete document.body.dataset.hello;\n "
133+ + " log(document.body.dataset.hello);\n "
134+
135+ + " log(document.body.dataset.helloWorld);\n "
136+ + " delete document.body.dataset.helloWorld;\n "
137+ + " log(document.body.dataset.helloWorld);\n "
71138 + "}\n "
72- + "</script></head><body onload='test()'>\n "
139+ + "</script></head>\n "
140+ + "<body onload='test()' data-hello='there' data-hello-world='heho'>\n "
73141 + "</body></html>" ;
74142
75143 loadPageVerifyTitle2 (html );
0 commit comments