import static com.google.gwt.query.client.GQuery.*;\r
\r
import com.google.gwt.core.client.EntryPoint;\r
+import com.google.gwt.dom.client.InputElement;\r
+import com.google.gwt.event.dom.client.ClickEvent;\r
+import com.google.gwt.event.dom.client.ClickHandler;\r
+import com.google.gwt.query.client.css.CSS;\r
+import com.google.gwt.query.client.css.RGBColor;\r
import com.google.gwt.query.client.js.JsUtils;\r
import com.google.gwt.user.client.Timer;\r
import com.google.gwt.user.client.Window;\r
+import com.google.gwt.user.client.ui.Button;\r
+import com.google.gwt.user.client.ui.RootPanel;\r
\r
/**\r
* This module is thought to emulate a test environment similar to\r
public void onModuleLoad() {\r
try {\r
gwtSetUp();\r
- testCheckedAttr_Issue97();\r
+ testAttr_Issue97();\r
} catch (Exception ex) {\r
ex.printStackTrace();\r
$(e).html("").after("<div>ERROR: " + ex.getMessage() + "</div>");\r
}\r
}\r
\r
+ public void testAttr_Issue97() {\r
+ $(e).html("<input type='checkbox' id='cb' name='cb' value='1' />");\r
+ assertNull($("#cb:checked", e).val());\r
+ \r
+ $("#cb", e).attr("checked", "checked");\r
+ assertEquals(1, $("#cb:checked", e).length());\r
+ assertEquals(true, InputElement.as($("#cb", e).get(0)).isChecked());\r
+ assertEquals("checked", $("#cb", e).get(0).getAttribute("checked"));\r
+ assertEquals(true, $("#cb", e).get(0).getPropertyBoolean("checked"));\r
+ \r
+ $("#cb", e).removeAttr("checked");\r
+ assertEquals(0, $("#cb:checked", e).length());\r
+ assertEquals(false, InputElement.as($("#cb", e).get(0)).isChecked());\r
+ assertEquals("", $("#cb", e).get(0).getAttribute("checked"));\r
+ assertEquals(false, $("#cb", e).get(0).getPropertyBoolean("checked"));\r
+ \r
+ $("#cb", e).attr("checked", true);\r
+ assertEquals(1, $("#cb:checked", e).length());\r
+ assertEquals(true, InputElement.as($("#cb", e).get(0)).isChecked());\r
+ assertEquals("checked", $("#cb", e).get(0).getAttribute("checked"));\r
+ assertEquals(true, $("#cb", e).get(0).getPropertyBoolean("checked"));\r
+ \r
+ $("#cb", e).attr("checked", false);\r
+ assertEquals(0, $("#cb:checked", e).length());\r
+ assertEquals(false, InputElement.as($("#cb", e).get(0)).isChecked());\r
+ assertEquals("", $("#cb", e).get(0).getAttribute("checked"));\r
+ assertEquals(false, $("#cb", e).get(0).getPropertyBoolean("checked"));\r
+ \r
+ $("#cb", e).attr("checked", "");\r
+ assertEquals(1, $("#cb:checked", e).length());\r
+ assertEquals(true, InputElement.as($("#cb", e).get(0)).isChecked());\r
+ assertEquals("checked", $("#cb", e).get(0).getAttribute("checked"));\r
+ assertEquals(true, $("#cb", e).get(0).getPropertyBoolean("checked"));\r
+ \r
+ GQuery gq = $("<div></div>test<!-- a comment-->");\r
+ gq.attr("class", "test1");\r
+ \r
+ assertEquals("test1", gq.get(0).getClassName());\r
+ assertEquals("test1", gq.attr("class"));\r
+ assertNull(gq.get(0).getPropertyString("class"));\r
+ \r
+ gq.removeAttr("class");\r
+ assertEquals("", gq.get(0).getClassName());\r
+ assertEquals("", gq.attr("class"));\r
+ \r
+ //test on value\r
+ $("#cb", e).attr("value", "mail");\r
+ assertEquals("mail", InputElement.as($("#cb", e).get(0)).getValue());\r
+ assertEquals("mail", $("#cb", e).get(0).getAttribute("value"));\r
+ \r
+ $("#cb", e).removeAttr("value");\r
+ \r
+ // Now HtmlUnit returns a null, before it returned empty\r
+ String val = InputElement.as($("#cb", e).get(0)).getValue();\r
+ if (val == null) {\r
+ val = "";\r
+ }\r
+ assertEquals("", val);\r
+ assertEquals("", $("#cb", e).get(0).getAttribute("value"));\r
+ \r
+ try{\r
+ $("#cb", e).attr("type", "hidden");\r
+ fail("Cannnot change a type of an element already attached to the dom");\r
+ }catch (Exception e){}\r
+ \r
+ gq = $("<input type='text' value='blop'></input>");\r
+ gq.attr("type", "radio");\r
+ assertEquals("radio", InputElement.as(gq.get(0)).getType());\r
+ assertEquals("blop", InputElement.as(gq.get(0)).getValue());\r
+ \r
+ gq.attr(Properties.create("{class:'test2', disabled:true}"));\r
+ InputElement ie = InputElement.as(gq.get(0));\r
+ \r
+ assertEquals("test2", ie.getClassName());\r
+ assertEquals(true, ie.isDisabled());\r
+ assertEquals("disabled", ie.getAttribute("disabled"));\r
+ \r
+ }\r
+ \r
public void testCheckedAttr_Issue97() {\r
$(e).html("<input type='checkbox' id='cb' name='cb' value='1' />");\r
assertEquals("", $("#cb").val());\r
JsNodeArray result = JsNodeArray.create();\r
for (Element e : elements) {\r
if (JsUtils.isWindow(e) || "iframe".equalsIgnoreCase(e.getTagName())) {\r
- result.addNode(styleImpl.getContentDocument(e));\r
+ result.addNode(getStyleImpl().getContentDocument(e));\r
} else {\r
NodeList<Node> children = e.getChildNodes();\r
for (int i = 0, l = children.getLength(); i < l; i++) {\r
public GQuery empty() {\r
for (Element e : elements) {\r
if (e.getNodeType() == Element.DOCUMENT_NODE) {\r
- styleImpl.emptyDocument(e.<Document> cast());\r
+ getStyleImpl().emptyDocument(e.<Document> cast());\r
} else {\r
Node c = e.getFirstChild();\r
while (c != null) {\r
}\r
}\r
\r
- // set the display value in a separate for loop to avoid constant reflow\r
- // Broswer reflow is triggered each time we gonna set and after get (in styleImpl.curCSS(e, "display", false) method)\r
- // the diplay property. Reflows is very bad in performance point of view\r
+ // Set the display value in a separate for loop to avoid constant reflow\r
+ // Reflows is very bad in performance point of view\r
for (Element e : elements){\r
e.getStyle().setDisplay(Display.NONE);\r
}\r
elements = new Element[l];\r
for (int i = 0; i < l; i++) {\r
elements[i] = list.getItem(i);\r
- nodeList.<JsObjectArray>cast().add(list.getItem(i));\r
+ nodeList.<JsObjectArray<Element>>cast().add(list.getItem(i));\r
}\r
}\r
return this;\r