1 38 package com.gargoylesoftware.htmlunit; 39 40 import java.util.ArrayList; 41 import java.util.Arrays; 42 import java.util.List; 43 44 49 public class ScriptFilterTest extends WebTestCase { 50 51 55 public ScriptFilterTest(final String name) { 56 super(name); 57 } 58 59 62 public void testScriptForEvent() throws Exception { 63 testScriptForEvent("onload"); 65 testScriptForEvent("onload()"); 66 } 67 68 private void testScriptForEvent(final String eventName) throws Exception { 69 final String content 70 = "<html><head><title>foo</title>" 71 + "<script FOR='window' EVENT='" + eventName + "' LANGUAGE='javascript'>" 72 + " document.form1.txt.value='hello';" 73 + " alert(document.form1.txt.value);" 74 + "</script></head><body>" 75 + "<form name='form1'><input type=text name='txt'></form></body></html>"; 76 final List collectedAlerts = new ArrayList(); 77 78 final List expectedAlerts = Arrays.asList( new String[]{ 79 "hello" 80 }); 81 createTestPageForRealBrowserIfNeeded(content, expectedAlerts); 82 83 loadPage(content, collectedAlerts); 84 assertEquals( expectedAlerts, collectedAlerts ); 85 } 86 } 87 | Popular Tags |