1 5 package net.sourceforge.jwebunit; 6 7 import com.meterware.httpunit.HttpUnitOptions; 8 9 14 15 public class JavaScriptEventsTest extends JWebUnitTest { 16 17 public void testFormOnSubmit() { 18 defineWebPage("TargetPage", "Target"); 19 defineWebPage("FormOnSubmit", 20 "<form method=GET action=\"\" " + 21 "onSubmit=\"javascript:window.open('TargetPage.html', 'child');\">" + 22 "<input type=\"submit\"/>" + 23 "</form>"); 24 beginAt("FormOnSubmit.html"); 25 submit(); 26 gotoWindow("child"); 27 assertTextPresent("Target"); 28 } 29 30 public void testFormOnReset() { 31 defineWebPage("TargetPage", "Target"); 32 defineWebPage("FormOnSubmit", 33 "<form method=GET action=\"\" " + 34 "onReset=\"javascript:window.open('TargetPage.html', 'child');\">" + 35 "<input type=\"reset\"/>" + 36 "</form>"); 37 beginAt("FormOnSubmit.html"); 38 reset(); 39 gotoWindow("child"); 40 assertTextPresent("Target"); 41 } 42 43 public void testButtonOnClick() { 44 defineWebPage("TargetPage", "Target"); 45 defineWebPage("FormOnSubmit", 46 "<form method=GET action=\"\" " + 47 "onReset=\"javascript:window.open('TargetPage.html', 'child');\">" + 48 "<input id=\"b1\" type=\"button\" value=\"click me\" onClick=\"javascript:window.open('TargetPage.html', 'child');\"/>" + 49 "</form>"); 50 beginAt("FormOnSubmit.html"); 51 clickButton("b1"); 52 gotoWindow("child"); 53 assertTextPresent("Target"); 54 } 55 56 public void testJavaScriptInFile() { 57 defineResource("nav.js", "function gotoNext() { window.location='next.html'; return true; }"); 58 defineResource("index.html", "<html> <head>" + 59 "<script SRC=\"nav.js\" type=\"text/javascript\" language=\"javascript\"></script>" + 60 "</head> <body>" + 61 "<h1>Javascript Test</h1>" + 62 "<form><input type=\"button\" onclick=\"gotoNext()\" value=\"Next\" id=\"next\"></form>" + 63 "</body></html>"); 64 defineResource("next.html", "<html><head>" + 65 "<script SRC=\"nav.js\" type=\"text/javascript\" language=\"javascript\"></script>" + 66 "</head><body><h1>Next</h1><p>Here is the text we expect</p></body></html>"); 67 beginAt("index.html"); 68 clickButton("next"); 69 assertTextPresent("Here is the text we expect"); 70 beginAt("index.html"); 71 } 77 78 public void testLinkAssertsWorkJavascriptDisabled() { 79 defineResource("foobar.js", "function sayWoo() { return true; }"); 80 defineResource("test.html", "<html><head>" + 81 "<SCRIPT language=\"JavaScript\" SRC=\"/foobar.js\"></script></head>" + 82 "<body><a HREF=\"foo1.html\">foo1</a><a HREF=\"foo1.html\">foo2</a></body></html> "); 83 HttpUnitOptions.setScriptingEnabled(false); 84 beginAt("test.html"); 85 assertLinkPresentWithText("foo1"); 86 assertLinkPresentWithText("foo2"); 87 } 88 89 } 90 | Popular Tags |