From: <rb...@us...> - 2014-01-27 22:02:51
|
Revision: 9080 http://sourceforge.net/p/htmlunit/code/9080 Author: rbri Date: 2014-01-27 22:02:47 +0000 (Mon, 27 Jan 2014) Log Message: ----------- fix the fix for the false execution of js when replacing with outerHtml, some more tests Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-01-27 20:25:09 UTC (rev 9079) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-01-27 22:02:47 UTC (rev 9080) @@ -1038,7 +1038,7 @@ // this disables execution of script tags final Document doc = getWindow().getDocument(); - for (final DomNode node : fragment.getChildren()) { + for (final DomNode node : fragment.getDescendants()) { node.processImportNode(doc); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2014-01-27 20:25:09 UTC (rev 9079) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2014-01-27 22:02:47 UTC (rev 9080) @@ -749,6 +749,44 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = "false", + IE8 = "true") + public void all_detection() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " alert(!(!document.all));\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "undefined", + FF = "[object HTML document.all class]", + FF17 = "undefined", + IE = "[object HTMLAllCollection]", + IE8 = "[object HTMLCollection]") + @NotYetImplemented({ CHROME, FF, IE11 }) + public void all_scriptableToString() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " alert(document.all);\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(FF = "not defined", IE = { "false", "1", "about:blank", "about:blank" }, IE11 = { "true", "1" }) Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-01-27 20:25:09 UTC (rev 9079) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-01-27 22:02:47 UTC (rev 9080) @@ -1353,6 +1353,27 @@ * @throws Exception if the test fails */ @Test + public void setOuterHTMLExecuteNestedJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var newnode = '<div><scr'+'ipt>alerter();</scr'+'ipt></div>';\n" + + " var oldnode = document.getElementById('myNode');\n" + + " oldnode.outerHTML = newnode;\n" + + " }\n" + + " function alerter() {\n" + + " alert('executed');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts("exception") public void setOuterHTMLDeclareJavaScript() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ @@ -4515,6 +4536,177 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = "executed", + IE8 = "exception-append") + // IE8 does not support appendChild for script elements + public void appendChildExecuteJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var newnode = document.createElement('script');\n" + + " try {\n" + + " newnode.appendChild(document.createTextNode('alerter();'));\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.appendChild(newnode);\n" + + " } catch(e) { alert('exception-append'); }\n" + + " }\n" + + " function alerter() {\n" + + " alert('executed');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "declared", + IE8 = "exception-append") + // IE8 does not support appendChild for script elements + public void appendChildDeclareJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var newnode = document.createElement('script');\n" + + " try {\n" + + " newnode.appendChild(document.createTextNode('function tester() { alerter(); }'));\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.appendChild(newnode);\n" + + " try {\n" + + " tester();\n" + + " } catch(e) { alert('exception'); }\n" + + " } catch(e) { alert('exception-append'); }\n" + + " }\n" + + " function alerter() {\n" + + " alert('declared');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "executed", + IE8 = "exception-append") + // IE8 does not support appendChild for script elements + public void insertBeforeExecuteJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var newnode = document.createElement('script');\n" + + " try {\n" + + " newnode.appendChild(document.createTextNode('alerter();'));\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.insertBefore(newnode, null);\n" + + " } catch(e) { alert('exception-append'); }\n" + + " }\n" + + " function alerter() {\n" + + " alert('executed');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "declared", + IE8 = "exception-append") + // IE8 does not support appendChild for script elements + public void insertBeforeDeclareJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var newnode = document.createElement('script');\n" + + " try {\n" + + " newnode.appendChild(document.createTextNode('function tester() { alerter(); }'));\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.insertBefore(newnode, null);\n" + + " try {\n" + + " tester();\n" + + " } catch(e) { alert('exception'); }\n" + + " } catch(e) { alert('exception-append'); }\n" + + " }\n" + + " function alerter() {\n" + + " alert('declared');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "executed", + IE8 = "exception-append") + // IE8 does not support appendChild for script elements + public void replaceChildExecuteJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var newnode = document.createElement('script');\n" + + " try {\n" + + " newnode.appendChild(document.createTextNode('alerter();'));\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.replaceChild(newnode, document.getElementById('inner'));\n" + + " } catch(e) { alert('exception-append'); }\n" + + " }\n" + + " function alerter() {\n" + + " alert('executed');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'><div id='inner'></div></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "declared", + IE8 = "exception-append") + // IE8 does not support appendChild for script elements + public void replaceChildDeclareJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var newnode = document.createElement('script');\n" + + " try {\n" + + " newnode.appendChild(document.createTextNode('function tester() { alerter(); }'));\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.replaceChild(newnode, document.getElementById('inner'));\n" + + " try {\n" + + " tester();\n" + + " } catch(e) { alert('exception'); }\n" + + " } catch(e) { alert('exception-append'); }\n" + + " }\n" + + " function alerter() {\n" + + " alert('declared');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'><div id='inner'></div></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts({ "outside", "1", "middle", "2", "3", "4", "before-begin after-begin inside before-end after-end" }) public void insertAdjacentHTML() throws Exception { @@ -4567,6 +4759,51 @@ * @throws Exception if the test fails */ @Test + public void insertAdjacentHTMLExecuteJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.insertAdjacentHTML('afterend', '<scr'+'ipt>alerter();</scr'+'ipt>');\n" + + " }\n" + + " function alerter() {\n" + + " alert('executed');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("exception") + public void insertAdjacentHTMLDeclareJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.insertAdjacentHTML('afterend', " + + "'<scr'+'ipt>function tester() { alerter(); }</scr'+'ipt>');\n" + + " try {\n" + + " tester();\n" + + " } catch(e) { alert('exception'); }\n" + + " }\n" + + " function alerter() {\n" + + " alert('declared');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Browsers({ CHROME, IE }) @Alerts({ "outside", "1", "middle", "2", "3", "4", "before-begin after-begin inside before-end after-end" }) @@ -4620,6 +4857,65 @@ */ @Test @Browsers({ CHROME, IE }) + @Alerts(DEFAULT = "executed", + IE8 = "exception-append") + // IE8 does not support appendChild for script elements + public void insertAdjacentElementExecuteJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var newnode = document.createElement('script');\n" + + " try {\n" + + " newnode.appendChild(document.createTextNode('alerter();'));\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.insertAdjacentElement('afterend', newnode);\n" + + " } catch(e) { alert('exception-append'); }\n" + + " }\n" + + " function alerter() {\n" + + " alert('executed');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers({ CHROME, IE }) + @Alerts(DEFAULT = "declared", + IE8 = "exception-append") + // IE8 does not support appendChild for script elements + public void insertAdjacentElementDeclareJavaScript() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " var newnode = document.createElement('script');\n" + + " try {\n" + + " newnode.appendChild(document.createTextNode('function tester() { alerter(); }'));\n" + + " var outernode = document.getElementById('myNode');\n" + + " outernode.insertAdjacentElement('afterend', newnode);\n" + + " try {\n" + + " tester();\n" + + " } catch(e) { alert('exception'); }\n" + + " } catch(e) { alert('exception-append'); }\n" + + " }\n" + + " function alerter() {\n" + + " alert('declared');\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <div id='myNode'></div>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers({ CHROME, IE }) @Alerts(DEFAULT = { "outside", "middle", "before-begin after-begin inside before-end after-end" }, IE8 = { "outside", "middle", |