google-code-export / gwt-test-utils

Automatically exported from code.google.com/p/gwt-test-utils
1 stars 0 forks source link

com.octo.gwt.test.internal.patchers.dom.ElementPatcher stores properties in lowercase but reads mixed case #63

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The com.octo.gwt.test.internal.patchers.dom.ElementPatcher always invokes a 
toLowerCase within each of the property setter methods. This way, properties 
like, e.g., "readOnly" are stored as "readonly". (Un-)fortunately, the getters 
for the properties do not change the requested property names, hence "readOnly" 
gets requested as such. As the property names are stored in a Map, this will 
obviously cause requesting properties containing other than lower case letters 
to fail.

The expectation is not as clear as it seems, because handling of mixed case 
property names is not consistent amongst existing web browsers. I would still 
suggest to not modify the names (i.e., no toLowerCase call).

Version: gwt-test-utils-0.28.6-20110809.075218-9

Original issue reported on code.google.com by stefan.s...@googlemail.com on 10 Aug 2011 at 9:32

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago

Original comment by gael.laz...@gmail.com on 10 Aug 2011 at 8:48

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Fix solves this issue for us.

Original comment by stefan.s...@googlemail.com on 15 Aug 2011 at 1:10

GoogleCodeExporter commented 9 years ago
Thanks again for your feedback !

Original comment by gael.laz...@gmail.com on 15 Aug 2011 at 1:37