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

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

Added Dojo 1.9.3 release.

File size: 5.6 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 lifecycle</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/dom",
16                                "dojox/gfx",
17                                "dojox/gfx/shape",
18                                "dojox/gfx/svg",
19                                "dojox/gfx/registry"
20                        ],
21                                        function(doh, ready, dom, gfx, gfxshape, svg){
22
23                                        var drawing, r,
24                                                checkSurface = function(){
25                                                        if(!drawing){
26                                                                var dn = dom.byId("gfxObject");
27                                                                drawing = gfx.createSurface(dn, 300, 300);
28                                                        }
29                                                };
30                                       
31                                        doh.register("GFX: shape lifecycle", [
32                                                {
33                                                        name: "Shape.destroy",
34                                                        timeout: 1000,
35                                                        setUp: function(){
36                                                                checkSurface();
37                                                                r = drawing.createRect({
38                                                                         x: 100,
39                                                                         y: 100
40                                                                }).setFill("black");
41                                                        },
42                                                        runTest: function(){
43                                                                var uid = r.getUID();
44                                                                r.removeShape();
45                                                                r.destroy();
46                                                                doh.assertTrue(!gfxshape.byId(uid), "Unexpected shape.byId return value.");
47                                                        },
48                                                        tearDown: function(){
49                                                                drawing.clear();
50                                                        }
51                                                },{
52                                                        name: "Group.clear",
53                                                        timeout: 1000,
54                                                        setUp: function(){
55                                                                checkSurface();
56                                                                r = drawing.createGroup();
57                                                                r.createRect({
58                                                                                 x: 100,
59                                                                                 y: 100
60                                                                        }).setFill("black");
61                                                        },
62                                                        runTest: function(){
63                                                                var c = r.children[0];
64                                                                r.clear(true);
65                                                                doh.assertTrue(r.children.length == 0, "Unexpected children length on disposed group.");
66                                                                doh.assertTrue(!gfxshape.byId(c.getUID()), "Unexpected shape.byId return value.");
67                                                        }
68                                                },{
69                                                        name: "Group.destroy",
70                                                        timeout: 1000,
71                                                        setUp: function(){
72                                                                checkSurface();
73                                                                r = drawing.createGroup();
74                                                                r.createRect({
75                                                                                 x: 100,
76                                                                                 y: 100
77                                                                        }).setFill("black");
78                                                        },
79                                                        runTest: function(){
80                                                                var uid = r.getUID();
81                                                                var c = r.children[0];
82                                                                r.removeShape();
83                                                                r.destroy();
84                                                                doh.assertTrue(!gfxshape.byId(uid), "Unexpected shape.byId return value.");
85                                                                doh.assertTrue(r.children.length == 0, "Unexpected children length on disposed group.");
86                                                                doh.assertTrue(!gfxshape.byId(r.getUID()), "Unexpected shape.byId return value.");
87                                                               
88                                                                r = drawing.createGroup();
89                                                                var t2 = r.createGroup();
90                                                                c = t2.createRect();
91                                                                r.removeShape();
92                                                                r.destroy();
93                                                                doh.assertTrue(!gfxshape.byId(r.getUID()), "Unexpected shape.byId return value.");
94                                                                doh.assertTrue(r.children.length == 0, "Unexpected children length on disposed group.");
95                                                                doh.assertTrue(!gfxshape.byId(t2.getUID()), "Unexpected shape.byId return value.");
96                                                                doh.assertTrue(t2.children.length == 0, "Unexpected children length on disposed group.");
97                                                                doh.assertTrue(!gfxshape.byId(c.getUID()), "Unexpected shape.byId return value.");
98                                                        }
99                                                },{
100                                                        name: "SVG-specific : shape clean-up",
101                                                        timeout: 1000,
102                                                        setUp: function(){
103                                                                if(drawing){
104                                                                        drawing.destroy();
105                                                                        drawing = null;
106                                                                }
107                                                                gfx.switchTo(svg);
108                                                                checkSurface();
109                                                                var grad = {
110                                                                        type: "linear",
111                                                                        x1: 0, y1: 0,
112                                                                        x2: 600, y2: 0,
113                                                                        colors: [
114                                                                                { offset: 0.2, color: "red" },
115                                                                                { offset: 0.8, color: "yellow" }
116                                                                        ]
117                                                                };
118                                                                r = drawing.createRect().setFill(grad).setClip({x:0,y:0,width:300,height:300});
119                                                        },
120                                                        runTest: function(){                                                           
121                                                                var defs = drawing.defNode;
122                                                                doh.assertTrue(defs.childNodes.length == 1, "Unexpected defs children count.");
123                                                                var c = drawing.children[0];
124                                                                c.removeShape();
125                                                                c.destroy();
126                                                                doh.assertTrue(defs.childNodes.length == 0, "Unexpected defs children count. Expected: 0.");
127                                                                doh.assertTrue(drawing.rawNode.childNodes.length == 1 && drawing.rawNode.childNodes[0] == defs, "Unexpected surface children nodes.");
128                                                        }
129                                                },{
130                                                        name: "SVG-specific : Group clean-up",
131                                                        timeout: 1000,
132                                                        setUp: function(){
133                                                                if(drawing){
134                                                                        drawing.destroy();
135                                                                        drawing = null;
136                                                                }
137                                                                gfx.switchTo(svg);
138                                                                checkSurface();
139                                                                var grad = {
140                                                                        type: "linear",
141                                                                        x1: 0, y1: 0,
142                                                                        x2: 600, y2: 0,
143                                                                        colors: [
144                                                                                { offset: 0.2, color: "red" },
145                                                                                { offset: 0.8, color: "yellow" }
146                                                                        ]
147                                                                };
148                                                                var sub1 = drawing.createGroup();
149                                                                for(var i=0; i<100; ++i){
150                                                                        var r = Math.floor(i/10), offs=4,
151                                                                                cc = r%2 == 0 ? -offs : offs,
152                                                                                x = (i%10)*60+cc, y = r*60+5, w = 50, h = 50;
153                                                                        sub1.createRect({x:x, y:y, width:w, height:h}).setFill(grad).setClip({cx:x+w/2, cy:y+w/2, rx:20, ry:20});
154                                                                }
155                                                        },
156                                                        runTest: function(){                                                           
157                                                                var defs = drawing.defNode;
158                                                                doh.assertTrue(defs.childNodes.length == 100, "Unexpected defs children count.");
159                                                                var g = drawing.children[0];
160                                                                g.clear(true);
161                                                                doh.assertTrue(defs.childNodes.length == 0, "Unexpected defs children count. Expected: 0.");
162                                                                doh.assertTrue(g.rawNode.firstChild == null, "Unexpected group children count. Expected: 0.");
163                                                        }
164                                                }
165                                        ]);
166
167                                        ready(function(){
168                                                doh.run()
169                                        });
170                        });
171                </script>
172        </head>
173        <body>
174                <div id="gfxObject" style="width: 500px; height: 500px;font-weight:bold;"></div>
175        </body>
176</html>
Note: See TracBrowser for help on using the repository browser.