javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/JSONTest.java
changeset 1009 80c46ea076d3
parent 963 62d77cc38117
child 1412 a51c0d80ee24
     1.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/JSONTest.java	Wed Apr 10 11:43:46 2013 +0200
     1.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/JSONTest.java	Thu Apr 18 12:47:25 2013 +0200
     1.3 @@ -70,6 +70,25 @@
     1.4          assertEquals(o.getString("sex"), "MALE");
     1.5      }
     1.6      
     1.7 +    @BrwsrTest public void toJSONInABrowser() throws Throwable {
     1.8 +        Person p = new Person();
     1.9 +        p.setSex(Sex.MALE);
    1.10 +        p.setFirstName("Jarda");
    1.11 +        p.setLastName("Tulach");
    1.12 +
    1.13 +        Object json;
    1.14 +        try {
    1.15 +            json = parseJSON(p.toString());
    1.16 +        } catch (Throwable ex) {
    1.17 +            throw new IllegalStateException("Can't parse " + p).initCause(ex);
    1.18 +        }
    1.19 +        
    1.20 +        Person p2 = new Person(json);
    1.21 +        
    1.22 +        assert p2.getFirstName().equals(p.getFirstName()) : 
    1.23 +            "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName();
    1.24 +    }
    1.25 +    
    1.26      @Test public void personWithWildCharactersAndNulls() throws JSONException {
    1.27          Person p = new Person();
    1.28          p.setFirstName("'\"\n");
    1.29 @@ -213,6 +232,9 @@
    1.30      @JavaScriptBody(args = {  }, body = "return window.document.getElementsByTagName('script').length;")
    1.31      private static native int scriptElements();
    1.32  
    1.33 +    @JavaScriptBody(args = { "s" }, body = "return window.JSON.parse(s);")
    1.34 +    private static native Object parseJSON(String s);
    1.35 +    
    1.36      @Http(@Http.Resource(
    1.37          content = "{'firstName': 'Sitar', 'sex': 'MALE'}", 
    1.38          path="/person.json",