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

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

Added Dojo 1.9.3 release.

File size: 9.7 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>Test Batch</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, packageMap:[{name:'doh',location:'util/doh'}]"></script>
11                <script type="text/javascript">
12                        require([
13                        "doh/runner",
14                        "dojo/ready",
15                        "dojo/aspect",
16                        "dojox/gfx",
17                        "dojox/gfx/shape",
18                        "dojox/gfx/svg",
19                        "dojox/gfx/canvas"],
20                        function(doh, ready, aspect, gfx, gfxshape, svg, canvas){
21                               
22                                ready(function(){
23                                        var surface, r,
24                                                checkSurface = function(){
25                                                        if(!surface){
26                                                                surface = gfx.createSurface(dojo.byId("gfxObject"), 300, 300);
27                                                        }
28                                                };
29                                       
30                                        doh.register("GFX: batching operations [SVG]", [
31                                                {
32                                                        name: "Surface.openBatch",
33                                                        timeout: 1000,
34                                                        setUp: function(){
35                                                                if(surface){
36                                                                        surface.destroy();
37                                                                        surface = null;
38                                                                }
39                                                                gfx.switchTo(svg);
40                                                                checkSurface();
41
42                                                        },
43                                                        runTest: function(){
44                                                                var ret = surface.openBatch();
45                                                                doh.assertTrue(ret === surface, "Invalid openBatch return value.");
46                                                                var rect = surface.createRect();
47                                                                var p = rect.rawNode.parentNode;
48                                                                doh.assertTrue(p !== surface.rawNode, "Unexpected DOM parent node.");
49                                                        },
50                                                        tearDown: function(){
51                                                                surface.clear();
52                                                        }
53                                                },{
54                                                        name: "Surface.closeBatch",
55                                                        timeout: 1000,
56                                                        setUp: function(){
57                                                                if(surface){
58                                                                        surface.destroy();
59                                                                        surface = null;
60                                                                }
61                                                                gfx.switchTo(svg);
62                                                                checkSurface();
63
64                                                        },
65                                                        runTest: function(){
66                                                                surface.openBatch();
67                                                                var rect = surface.createRect();
68                                                                var ret = surface.closeBatch();
69                                                                doh.assertTrue(ret === surface, "Invalid closeBatch return value.");
70                                                                var p = rect.rawNode.parentNode;
71                                                                doh.assertTrue(p === surface.rawNode, "Unexpected DOM parent node.");
72                                                        },
73                                                        tearDown: function(){
74                                                                surface.clear();
75                                                        }
76                                                },{
77                                                        name: "nested openBatch",
78                                                        timeout: 1000,
79                                                        setUp: function(){
80                                                                if(surface){
81                                                                        surface.destroy();
82                                                                        surface = null;
83                                                                }
84                                                                gfx.switchTo(svg);
85                                                                checkSurface();
86                                                        },
87                                                        runTest: function(){
88                                                                surface.openBatch();
89                                                                var rect = surface.createRect().setFill("red");
90                                                                surface.openBatch();
91                                                                var rect2 = surface.createRect({x:200}).setFill("green");
92                                                                doh.assertTrue(rect.rawNode.parentNode === rect2.rawNode.parentNode, "Unexpected parent nodes for rects.");
93                                                                surface.closeBatch();
94                                                                var p = rect2.rawNode.parentNode;
95                                                                doh.assertTrue(p !== surface.rawNode, "Unexpected rect2 DOM parent node in nested batch.");
96                                                                p = rect.rawNode.parentNode;
97                                                                doh.assertTrue(p !== surface.rawNode, "Unexpected rect DOM parent node in nested batch.");
98                                                                surface.closeBatch();
99                                                                p = rect2.rawNode.parentNode;
100                                                                doh.assertTrue(p === surface.rawNode, "Unexpected rect2 DOM parent node in nested batch. Expected: surface.parentNode");
101                                                                p = rect.rawNode.parentNode;
102                                                                doh.assertTrue(p === surface.rawNode, "Unexpected rect DOM parent node in nested batch. Expected: surface.parentNode");
103                                                        },
104                                                        tearDown: function(){
105                                                                surface.clear();
106                                                        }
107                                                },{
108                                                        name: "Group batching",
109                                                        timeout: 1000,
110                                                        setUp: function(){
111                                                                if(surface){
112                                                                        surface.destroy();
113                                                                        surface = null;
114                                                                }
115                                                                gfx.switchTo(svg);
116                                                                checkSurface();
117                                                        },
118                                                        runTest: function(){
119                                                                var g = surface.createGroup();
120                                                                g.openBatch();
121                                                                var rect = g.createRect().setFill("red");
122                                                                doh.assertTrue(rect.rawNode.parentNode !== g.rawNode, "Unexpected parent node for rect.");
123                                                                var rect2 = surface.createRect();
124                                                                doh.assertTrue(rect2.rawNode.parentNode === surface.rawNode, "Unexpected parent node for rect2.");
125                                                                g.closeBatch();
126                                                                doh.assertTrue(rect.rawNode.parentNode === g.rawNode, "Unexpected parent node for rect after closeBatch.");
127                                                        },
128                                                        tearDown: function(){
129                                                                surface.clear();
130                                                        }
131                                                },{
132                                                        name: "Nested Group/Surface batching",
133                                                        timeout: 1000,
134                                                        setUp: function(){
135                                                                if(surface){
136                                                                        surface.destroy();
137                                                                        surface = null;
138                                                                }
139                                                                gfx.switchTo(svg);
140                                                                checkSurface();
141                                                        },
142                                                        runTest: function(){
143                                                                surface.openBatch();
144                                                                var g = surface.createGroup();
145                                                                doh.assertTrue(g.rawNode.parentNode !== surface.rawNode, "Unexpected parent node for g.");
146                                                                g.openBatch();
147                                                                var rect = g.createRect().setFill("red");
148                                                                doh.assertTrue(rect.rawNode.parentNode !== g.rawNode, "Unexpected parent node for rect.");
149                                                                g.closeBatch();
150                                                                doh.assertTrue(rect.rawNode.parentNode === g.rawNode, "Unexpected parent node for rect after closeBatch.");
151                                                                doh.assertTrue(g.rawNode.parentNode !== surface.rawNode, "Unexpected parent node for g.");
152                                                                surface.closeBatch();
153                                                                doh.assertTrue(g.rawNode.parentNode === surface.rawNode, "Unexpected parent node for g after closeBatch.");
154                                                        },
155                                                        tearDown: function(){
156                                                                surface.clear();
157                                                        }
158                                                }
159                                        ]);
160                                        //
161                                        // Canvas
162                                        //
163                                        doh.register("GFX: batching operations [Canvas]", [
164                                                {
165                                                        name: "Surface.openBatch",
166                                                        timeout: 1000,
167                                                        setUp: function(){
168                                                                if(surface){
169                                                                        surface.destroy();
170                                                                        surface = null;
171                                                                }
172                                                                gfx.switchTo(canvas);
173                                                                checkSurface();
174                                                        },
175                                                        runTest: function(t){
176                                                                var ret = surface.openBatch();
177                                                                doh.assertTrue(ret === surface, "Invalid openBatch return value.");
178                                                                var called = false;
179                                                                aspect.after(surface,"makeDirty",function(){
180                                                                        called = true;
181                                                                });
182                                                                var rect = surface.createRect();
183                                                                doh.assertTrue(!called, "Unexpected surface.render() call.");
184                                                        },
185                                                        tearDown: function(){
186                                                                surface.clear();
187                                                        }
188                                                },{
189                                                        name: "Surface.closeBatch",
190                                                        timeout: 1000,
191                                                        setUp: function(){
192                                                                if(surface){
193                                                                        surface.destroy();
194                                                                        surface = null;
195                                                                }
196                                                                gfx.switchTo(canvas);
197                                                                checkSurface();
198                                                        },
199                                                        runTest: function(t){
200                                                                surface.openBatch();
201                                                                var rect = surface.createRect();
202                                                                var called = false;
203                                                                aspect.after(surface,"makeDirty",function(){
204                                                                        called = true;
205                                                                });
206                                                                var ret = surface.closeBatch();
207                                                                doh.assertTrue(ret === surface, "Invalid closeBatch return value.");
208                                                                doh.assertTrue(called, "Unexpected surface.render() call.");
209                                                        },
210                                                        tearDown: function(){
211                                                                surface.clear();
212                                                        }
213                                                },{
214                                                        name: "nested openBatch",
215                                                        timeout: 1000,
216                                                        setUp: function(){
217                                                                if(surface){
218                                                                        surface.destroy();
219                                                                        surface = null;
220                                                                }
221                                                                gfx.switchTo(canvas);
222                                                                checkSurface();
223                                                        },
224                                                        runTest: function(){
225                                                                surface.openBatch();
226                                                                var rect = surface.createRect().setFill("red");
227                                                                var called = false;
228                                                                aspect.after(surface,"makeDirty",function(){
229                                                                        called = true;
230                                                                });
231                                                                surface.openBatch();
232                                                                var rect2 = surface.createRect({x:200}).setFill("green");
233                                                                doh.assertTrue(!called, "Unexpected surface.render() call in nested batch [0].");
234                                                                surface.closeBatch();
235                                                                doh.assertTrue(!called, "Unexpected surface.render() call in nested batch [1].");
236                                                                surface.closeBatch();
237                                                                doh.assertTrue(called, "Surface.render() not called in nested batch.");
238                                                        },
239                                                        tearDown: function(){
240                                                                surface.clear();
241                                                        }
242                                                },{
243                                                        name: "Group batching",
244                                                        timeout: 1000,
245                                                        setUp: function(){
246                                                                if(surface){
247                                                                        surface.destroy();
248                                                                        surface = null;
249                                                                }
250                                                                gfx.switchTo(canvas);
251                                                                checkSurface();
252                                                                surface._render(); // flushes pendingRender coming from ctor
253                                                        },
254                                                        runTest: function(){
255                                                                var g = surface.createGroup();
256                                                                var ret = g.openBatch();
257                                                                doh.assertTrue(ret == g, "Unexpected openBatch return value");
258                                                                var called = false;
259                                                                aspect.after(surface,"makeDirty", function(){
260                                                                        called = true;
261                                                                });
262                                                                var rect = g.createRect().setFill("red");
263                                                                doh.assertTrue(!called, "Unexpected surface.render called.");
264                                                                g.closeBatch();
265                                                                doh.assertTrue(called, "surface.render not called after group.closeBatch().");
266                                                        },
267                                                        tearDown: function(){
268                                                                surface.clear();
269                                                        }
270                                                },{
271                                                        name: "Nested Group/Surface batching",
272                                                        timeout: 1000,
273                                                        setUp: function(){
274                                                                if(surface){
275                                                                        surface.destroy();
276                                                                        surface = null;
277                                                                }
278                                                                gfx.switchTo(canvas);
279                                                                checkSurface();
280                                                                surface._render(); // flushes pendingRender coming from ctor
281                                                        },
282                                                        runTest: function(){
283                                                                surface.openBatch();
284                                                                var g = surface.createGroup();
285                                                                g.openBatch();
286                                                                var called = false;
287                                                                aspect.after(surface,"makeDirty", function(){
288                                                                        called = true;
289                                                                });
290                                                                var rect = g.createRect().setFill("red");
291                                                                doh.assertTrue(!called, "Unexpected surface.render called.");
292                                                                g.closeBatch();
293                                                                doh.assertTrue(!surface.pendingRender, "Unexpected surface.render called.");
294                                                                called = false;
295                                                                surface.closeBatch();
296                                                                doh.assertTrue(called, "surface.render not called after group.closeBatch().");
297                                                        },
298                                                        tearDown: function(){
299                                                                surface.clear();
300                                                        }
301                                                }
302                                        ]);
303                                doh.run();
304                        });
305                });
306                </script>
307        </head>
308        <body>
309                <div id="gfxObject" style="width: 500px; height: 500px;font-weight:bold;"></div>
310        </body>
311</html>
Note: See TracBrowser for help on using the repository browser.