Closed GoogleCodeExporter closed 9 years ago
I just saw that a similar issue is given with setAttribute and removeAttribute,
the first using toLowerCase.
Original comment by stefan.s...@googlemail.com
on 10 Aug 2011 at 9:35
Original comment by gael.laz...@gmail.com
on 10 Aug 2011 at 8:48
Since DOM attributes and its related method, getAttribute, setAttribute,
hasAttribute and removeAttribute are case insensitive in a real GWT execution,
I would have to always call toLowerCase. See the small test I've made :
Element e = Document.get().createAnchorElement();
e.setAttribute("test", "testAttr");
System.out.println(e.getAttribute("test")); // prints "testAttr"
System.out.println(e.getAttribute("Test")); // prints "testAttr"
e.setAttribute("ID", "myId");
System.out.println(e.hasAttribute("id")); // prints "true"
System.out.println(e.getId()); // prints "myId"
e.removeAttribute("iD");
System.out.println(e.hasAttribute("id")); // prints "false"
System.out.println(e.getId()); // prints ""
System.out.println(e.getAttribute("foo")); // prints ""
System.out.print(e.getPropertyString("foo")); // prints null
System.out.println(e.getAttribute("className")); // prints ""
System.out.println(e.getPropertyString("className")); // prints ""
System.out.println(e.getAttribute("style")); // prints ""
System.out.println(e.getPropertyString("style")); // prints "[object CSSStyleDeclaration]"
The JsoProperties.getPropertyName() was designed to be able to make the
difference between "standard" DOM attributes ("className") and custom
attributes ("foo").
When calling Element.getPropertyXXX on a standard DOM attributes which has not
been set, the method returns "". If you call the same method on an non standard
attributes, it will return null (for JavaScript 'undefined' value).
I will correct every method to only use lowercase, and handle nicely
'undefined' case for getPropertyXXX :-)
The fix I will provide will directly fix the issue you've opened for
DOMImpl.hasAttribute
(http://code.google.com/p/gwt-test-utils/issues/detail?id=64), which was
patched without calling toLowerCase...
Original comment by gael.laz...@gmail.com
on 13 Aug 2011 at 7:54
I have refactored the entire DOM implementation on the trunk (and it's
available in the lastest snapshots).
The following test pass :
@Test
public void domImplementation() {
// Arrange
e.setAttribute("test", "testAttr");
// Assert getAttribute() is case insensitive
assertEquals("testAttr", e.getAttribute("test"));
assertEquals("testAttr", e.getAttribute("Test"));
// Assert hasAttribute is case insensitive
assertTrue(e.hasAttribute("teST"));
// Assert removeAttribute is case insensitve
e.removeAttribute("tEst");
assertEquals("", e.getAttribute("test"));
assertFalse(e.hasAttribute("teST"));
// Assert "non standard" DOM properties returns 'undefined' for String,
// Object and JSO
assertNull(e.getPropertyString("test"));
assertFalse(e.getPropertyBoolean("test"));
assertEquals(0, e.getPropertyInt("test"));
assertEquals(new Double(0.0), (Double) e.getPropertyDouble("test"));
assertNull(e.getPropertyObject("test"));
assertNull(e.getPropertyJSO("test"));
// Assert "standard" DOM properties returns "" for String
assertEquals("", e.getPropertyString("className"));
assertNull(e.getPropertyString("classnamE"));
e.setPropertyString("className", "testClass");
assertEquals("testClass", e.getPropertyString("className"));
// Special case "class" and "className"
assertNull(e.getPropertyString("class"));
assertEquals("testClass", e.getAttribute("class"));
assertEquals("", e.getAttribute("CLASSNAME"));
assertNull(e.getPropertyString("CLASSNAME"));
// Assert on Style JSO
System.out.println(e.getPropertyString("style"));
assertEquals("", e.getAttribute("style")); // prints ""
assertEquals("[object CSSStyleDeclaration]", e.getPropertyString("style"));
}
Can you give it a try and give me some feedback ?
Note the fix I provide cover issue
http://code.google.com/p/gwt-test-utils/issues/detail?id=64.
Original comment by gael.laz...@gmail.com
on 14 Aug 2011 at 4:58
Fix solves this issue for us.
Original comment by stefan.s...@googlemail.com
on 15 Aug 2011 at 1:10
Thanks again for your feedback !
Original comment by gael.laz...@gmail.com
on 15 Aug 2011 at 1:37
Original issue reported on code.google.com by
stefan.s...@googlemail.com
on 10 Aug 2011 at 9:32