Source Code Cross Referenced for FormPanelTest.java in  » Ajax » GWT » com » google » gwt » user » client » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » GWT » com.google.gwt.user.client.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Google Inc.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:        package com.google.gwt.user.client.ui;
017:
018:        import com.google.gwt.core.client.GWT;
019:        import com.google.gwt.junit.client.GWTTestCase;
020:        import com.google.gwt.user.client.Element;
021:        import com.google.gwt.user.client.Timer;
022:        import com.google.gwt.user.client.ui.HasWidgetsTester.WidgetAdder;
023:
024:        /**
025:         * Tests the FormPanel.
026:         * 
027:         * @see FormPanelTestServlet
028:         */
029:        public class FormPanelTest extends GWTTestCase {
030:            public static boolean clicked = false;
031:
032:            public String getModuleName() {
033:                return "com.google.gwt.user.FormPanelTest";
034:            }
035:
036:            public void testAttachDetachOrder(HasWidgets container,
037:                    WidgetAdder adder) {
038:                HasWidgetsTester.testAll(new FormPanel());
039:            }
040:
041:            public void testCancelSubmit() {
042:                TextBox tb = new TextBox();
043:                tb.setName("q");
044:
045:                FormPanel form = new FormPanel();
046:                form.setWidget(tb);
047:                form.setAction("http://www.google.com/search");
048:
049:                form.addFormHandler(new FormHandler() {
050:                    public void onSubmit(FormSubmitEvent event) {
051:                        event.setCancelled(true);
052:                    }
053:
054:                    public void onSubmitComplete(FormSubmitCompleteEvent event) {
055:                        fail("Form was cancelled and should not have been submitted");
056:                    }
057:                });
058:
059:                form.submit();
060:            }
061:
062:            /**
063:             * Tests uploading a file using post & multipart encoding.
064:             */
065:            public void testFileUpload() {
066:                final FormPanel form = new FormPanel();
067:                form.setMethod(FormPanel.METHOD_POST);
068:                form.setEncoding(FormPanel.ENCODING_MULTIPART);
069:                assertEquals(FormPanel.ENCODING_MULTIPART, form.getEncoding());
070:                form.setAction(GWT.getModuleBaseURL() + "formHandler");
071:
072:                FileUpload file = new FileUpload();
073:                file.setName("file0");
074:                form.setWidget(file);
075:
076:                RootPanel.get().add(form);
077:
078:                delayTestFinish(5000);
079:                form.addFormHandler(new FormHandler() {
080:                    public void onSubmit(FormSubmitEvent event) {
081:                    }
082:
083:                    public void onSubmitComplete(FormSubmitCompleteEvent event) {
084:                        // The server just echoes the contents of the request. The following
085:                        // string should have been present in it.
086:                        assertTrue(event
087:                                .getResults()
088:                                .indexOf(
089:                                        "Content-Disposition: form-data; name=\"file0\";") != -1);
090:                        finishTest();
091:                    }
092:                });
093:                form.submit();
094:            }
095:
096:            /**
097:             * Tests submitting using url-encoded get, with all form widgets (other than
098:             * FileUpload, which requires post/multipart.
099:             */
100:            public void testMethodGet() {
101:                final FormPanel form = new FormPanel();
102:                form.setMethod(FormPanel.METHOD_GET);
103:                form.setEncoding(FormPanel.ENCODING_URLENCODED);
104:                form.setAction(GWT.getModuleBaseURL() + "formHandler");
105:
106:                TextBox tb = new TextBox();
107:                tb.setText("text");
108:                tb.setName("tb");
109:
110:                PasswordTextBox ptb = new PasswordTextBox();
111:                ptb.setText("password");
112:                ptb.setName("ptb");
113:
114:                CheckBox cb0 = new CheckBox(), cb1 = new CheckBox();
115:                cb1.setChecked(true);
116:                cb0.setName("cb0");
117:                cb1.setName("cb1");
118:
119:                RadioButton rb0 = new RadioButton("foo");
120:                RadioButton rb1 = new RadioButton("foo");
121:                rb0.setChecked(true);
122:                rb0.setName("rb0");
123:                rb1.setName("rb1");
124:
125:                ListBox lb = new ListBox();
126:                lb.addItem("option0");
127:                lb.addItem("option1");
128:                lb.addItem("option2");
129:                lb.setValue(0, "value0");
130:                lb.setValue(1, "value1");
131:                lb.setValue(2, "value2");
132:                lb.setSelectedIndex(1);
133:                lb.setName("lb");
134:
135:                Hidden h = new Hidden("h", "v");
136:
137:                FlowPanel panel = new FlowPanel();
138:                panel.add(tb);
139:                panel.add(ptb);
140:                panel.add(cb0);
141:                panel.add(cb1);
142:                panel.add(rb0);
143:                panel.add(rb1);
144:                panel.add(lb);
145:                panel.add(h);
146:                form.setWidget(panel);
147:                RootPanel.get().add(form);
148:
149:                delayTestFinish(5000);
150:
151:                form.addFormHandler(new FormHandler() {
152:                    public void onSubmit(FormSubmitEvent event) {
153:                    }
154:
155:                    public void onSubmitComplete(FormSubmitCompleteEvent event) {
156:                        // The server just echoes the query string. This is what it should look
157:                        // like.
158:                        assertTrue(event
159:                                .getResults()
160:                                .equals(
161:                                        "tb=text&ptb=password&cb1=on&rb0=on&lb=value1&h=v"));
162:                        finishTest();
163:                    }
164:                });
165:
166:                form.submit();
167:            }
168:
169:            public void testSubmitAndHideDialog() {
170:                final FormPanel form = new FormPanel();
171:                form.setMethod(FormPanel.METHOD_GET);
172:                form.setEncoding(FormPanel.ENCODING_URLENCODED);
173:                form.setAction(GWT.getModuleBaseURL() + "formHandler");
174:
175:                TextBox tb = new TextBox();
176:                form.add(tb);
177:                tb.setText("text");
178:                tb.setName("tb");
179:
180:                final DialogBox dlg = new DialogBox();
181:                dlg.setWidget(form);
182:                dlg.show();
183:
184:                delayTestFinish(5000);
185:                form.addFormHandler(new FormHandler() {
186:                    public void onSubmit(FormSubmitEvent event) {
187:                    }
188:
189:                    public void onSubmitComplete(FormSubmitCompleteEvent event) {
190:                        // Make sure we get our results back.
191:                        assertTrue(event.getResults().equals("tb=text"));
192:                        finishTest();
193:
194:                        // Hide the dialog on submit complete. This was causing problems at one
195:                        // point because hiding the dialog detached the form and iframe.
196:                        dlg.hide();
197:                    }
198:                });
199:
200:                form.submit();
201:            }
202:
203:            /**
204:             * Tests submitting an alternate frame.
205:             */
206:            public void testSubmitFrame() {
207:                final NamedFrame frame = new NamedFrame("myFrame");
208:                FormPanel form = new FormPanel(frame);
209:                form.setMethod(FormPanel.METHOD_POST);
210:                form.setAction(GWT.getModuleBaseURL()
211:                        + "formHandler?sendHappyHtml");
212:                RootPanel.get().add(form);
213:                RootPanel.get().add(frame);
214:
215:                delayTestFinish(10000);
216:                Timer t = new Timer() {
217:                    public void run() {
218:                        // Make sure the frame got the contents we expected.
219:                        assertTrue(isHappyDivPresent(frame.getElement()));
220:                        finishTest();
221:                    }
222:
223:                    private native boolean isHappyDivPresent(Element iframe) /*-{
224:                           return !!iframe.contentWindow.document.getElementById(':)');
225:                         }-*/;
226:                };
227:
228:                // Wait 5 seconds before checking the results.
229:                t.schedule(5000);
230:                form.submit();
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.