source: Dev/trunk/src/client/dojox/gfx/tests/test_utils.html

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

  • Property svn:executable set to *
File size: 7.4 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2                "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4        <head>
5                <title>GFX Test: Test the basic utils functions</title>
6                <style type="text/css">
7                        @import "../../../dojo/resources/dojo.css";
8                        @import "../../../dijit/tests/css/dijitTests.css";
9                </style>
10                <script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="isDebug: true"></script>
11                <script type="text/javascript" src="../../../util/doh/runner.js"></script>
12                <script type="text/javascript">
13                        dojo.require("doh.runner");
14                        dojo.require("dojox.gfx");
15                        dojo.require("dojox.gfx.utils");
16                </script>
17                <script type="text/javascript">
18                        dojo.addOnLoad(function(){
19                                var drawing;
20                                var ta;
21                                doh.register("GFX: Utils Tests", [
22                                        {
23                                                name: "toJson",
24                                                timeout: 1000,
25                                                setUp: function(){
26                                                        if(!drawing){
27                                                                var dn = dojo.byId("gfxObject");
28                                                                drawing = dojox.gfx.createSurface(dn, 300, 300);
29                                                                drawing.createRect({
30                                                                         width:  100,
31                                                                         height: 100,
32                                                                         x: 100,
33                                                                         y: 100
34                                                                }).setFill("blue").setStroke("black");
35                                                                drawing.createImage({width:200,height:200,src:'http://demos.dojotoolkit.org/demos/resources/images/no_thumb.gif'});
36                                                        }
37                                                        if(!ta){
38                                                                ta = dojo.byId("outputArea");
39                                                        }
40                                                },
41                                                runTest: function(){
42                                                        var d = new doh.Deferred();
43                                                        try{
44                                                                var json = dojox.gfx.utils.toJson(drawing);
45                                                                doh.assertTrue(json != null, "Checking that non-null was returned.");
46                                                                ta.value = json;
47                                                                var obj = dojo.fromJson(json);
48                                                                doh.assertTrue(1, obj.length, "Checking that the json is an array of one entry.");
49                                                                doh.assertTrue(obj[0].shape != null, "Checking that a toplevel shape object is present.");
50                                                                doh.assertEqual("rect", obj[0].shape.type, "Checking that the shape type is rect.");
51                                                                doh.assertEqual(100, obj[0].shape.width, "Checking that the width is 100.");
52                                                                doh.assertEqual(100, obj[0].shape.height, "Checking that the height is 100.");
53                                                                d.callback(true);
54                                                        }catch(e){
55                                                                d.errback(e);
56                                                        }
57                                                        return d;
58                                                }
59                                        },
60                                        {
61                                                name: "fromJson",
62                                                timeout: 1000,
63                                                setUp: function(){
64                                                        if(!drawing){
65                                                                var dn = dojo.byId("gfxObject");
66                                                                drawing = dojox.gfx.createSurface(dn, 300, 300);
67                                                                drawing.createRect({
68                                                                         width:  100,
69                                                                         height: 100,
70                                                                         x: 100,
71                                                                         y: 100
72                                                                }).setFill("blue").setStroke("black");
73                                                                drawing.createImage({width:200,height:200,src:'http://demos.dojotoolkit.org/demos/resources/images/no_thumb.gif'});
74                                                        }
75                                                        if(!ta){
76                                                                ta = dojo.byId("outputArea");
77                                                        }
78                                                },
79                                                runTest: function(){
80                                                        var d = new doh.Deferred();
81                                                        try{
82                                                                var json = dojox.gfx.utils.toJson(drawing);
83                                                                doh.assertTrue(json != null, "Checking that non-null was returned.");
84                                                                var targetNode = dojo.byId("scratchObject");
85                                                                var tempSurface = dojox.gfx.createSurface(targetNode, 300, 300);
86                                                                dojox.gfx.utils.fromJson(tempSurface, json);
87
88                                                                var nsJson = dojox.gfx.utils.toJson(tempSurface);
89                                                                tempSurface.destroy();
90
91                                                                var obj = dojo.fromJson(nsJson);
92                                                                doh.assertTrue(1, obj.length, "Checking that the json is an array of one entry.");
93                                                                doh.assertTrue(obj[0].shape != null, "Checking that a toplevel shape object is present.");
94                                                                doh.assertEqual("rect", obj[0].shape.type, "Checking that the shape type is rect.");
95                                                                doh.assertEqual(100, obj[0].shape.width, "Checking that the width is 100.");
96                                                                doh.assertEqual(100, obj[0].shape.height, "Checking that the height is 100.");
97                                                                d.callback(true);
98                                                        }catch(e){
99                                                                d.errback(e);
100                                                        }
101                                                        return d;
102                                                }
103                                        },
104                                        {
105                                                name: "toSvg",
106                                                timeout: 10000,
107                                                setUp: function(){
108                                                        if(!drawing){
109                                                                var dn = dojo.byId("gfxObject");
110                                                                drawing = dojox.gfx.createSurface(dn, 300, 300);
111                                                                drawing.createRect({
112                                                                         width:  100,
113                                                                         height: 100,
114                                                                         x: 100,
115                                                                         y: 100
116                                                                }).setFill("blue").setStroke("black");
117                                                                drawing.createImage({width:200,height:200,src:'http://demos.dojotoolkit.org/demos/resources/images/no_thumb.gif'});
118                                                        }
119                                                        if(!ta){
120                                                                ta = dojo.byId("outputArea");
121                                                        }
122                                                },
123                                                runTest: function(){
124                                                        var d = new doh.Deferred();
125                                                        var def= dojox.gfx.utils.toSvg(drawing);
126                                                        def.addCallback(function(svg){
127                                                                try{
128                                                                        doh.assertTrue(svg != null, "Checking that non-null was returned.");
129                                                                        ta.value = svg;
130                                                                        doh.assertTrue(svg.length > 0, "Checking that svg length > 0");
131                                                                        var low = svg.toLowerCase();
132                                                                        doh.assertTrue(low.indexOf("<svg") === 0, "Checking that the string starts with SVG open tag.");
133                                                                        doh.assertTrue(low.indexOf("xmlns:xlink=\"http://www.w3.org/1999/xlink\"") !== -1, "Checking the xmlns:xlink attribute.");
134                                                                        doh.assertFalse(/\s+href\s*=/g.test(low), "Checking there's no href attributes.");
135                                                                        doh.assertTrue(low.indexOf("xlink:href=") !== -1, "Checking the xlink:href attribute.");
136                                                                        doh.assertTrue(low.indexOf("<img") === -1, "Checking the <img> cleanup.");
137                                                                        doh.assertTrue(svg.indexOf("__gfxObject__") === -1, "Checking __gfxObject__ attribute cleanup.");
138                                                                        d.callback(true);
139                                                                }catch(e){
140                                                                        d.errback(e);
141                                                                }
142                                                        });
143                                                        def.addErrback(function(e){
144                                                                d.errback(e);
145                                                        });
146                                                        return d;
147                                                }
148                                        },
149                                        {
150                                                name: "serialize/deserialize",
151                                                timeout: 1000,
152                                                setUp: function(){
153                                                        if(!drawing){
154                                                                var dn = dojo.byId("gfxObject");
155                                                                drawing = dojox.gfx.createSurface(dn, 300, 300);
156                                                                drawing.createRect({
157                                                                         width:  100,
158                                                                         height: 100,
159                                                                         x: 100,
160                                                                         y: 100
161                                                                }).setFill("blue").setStroke("black");
162                                                        }
163                                                        if(!ta){
164                                                                ta = dojo.byId("outputArea");
165                                                        }
166                                                },
167                                                runTest: function(){
168                                                        var d = new doh.Deferred();
169                                                        try{
170                                                                var sObj = dojox.gfx.utils.serialize(drawing);
171                                                                doh.assertTrue(sObj != null, "Checking that non-null was returned.");
172
173                                                                //Lets try to deserialize it!
174                                                                var targetNode = dojo.byId("scratchObject");
175                                                                var tempSurface = dojox.gfx.createSurface(targetNode, 300, 300);
176                                                                dojox.gfx.utils.deserialize(tempSurface, sObj);
177                                                                var nsJson = dojox.gfx.utils.toJson(tempSurface);
178                                                                tempSurface.destroy();
179
180                                                                var obj = dojo.fromJson(nsJson);
181                                                                doh.assertTrue(1, obj.length, "Checking that the json is an array of one entry.");
182                                                                doh.assertTrue(obj[0].shape != null, "Checking that a toplevel shape object is present.");
183                                                                doh.assertEqual("rect", obj[0].shape.type, "Checking that the shape type is rect.");
184                                                                doh.assertEqual(100, obj[0].shape.width, "Checking that the width is 100.");
185                                                                doh.assertEqual(100, obj[0].shape.height, "Checking that the height is 100.");
186                                                                d.callback(true);
187                                                        }catch(e){
188                                                                d.errback(e);
189                                                        }
190                                                        return d;
191                                                }
192                                        }
193                                ]);
194                                doh.run();
195                        });
196                        </script>
197        </head>
198        <body class="tundra">
199                <h1>Test of GFX Utils functions</h1>
200                <p>This page is intended for testing of the functions of the utils package, such as toJson, fromJson, and toSvg.</p>
201                <p>This test is not adapted for Silverlight or Canvas.</p>
202                <div id="gfxObject"></div>
203                <div id="scratchObject"></div>
204                <div>
205                        <textarea style="width: 100%; height: 300px" id="outputArea"></textarea>
206                </div>
207        </body>
208</html>
Note: See TracBrowser for help on using the repository browser.