source: Dev/trunk/src/client/dijit/tests/_Widget-subscribe.html @ 529

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

Added Dojo 1.9.3 release.

File size: 2.8 KB
Line 
1<!DOCTYPE html>
2<html>
3<head>
4
5        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
6
7        <title>Test Dijit Subscribe</title>
8
9        <script type="text/javascript" src="../../dojo/dojo.js" data-dojo-config="isDebug: true"></script>
10        <script type="text/javascript">
11                dojo.require("doh.runner");
12                dojo.require("dijit._Widget");
13                dojo.require("dojo.parser");
14
15                dojo.ready(function(){
16                        var numCallsInternal = 0;
17                        var numCallsExternal = 0;
18                        var externalString = "";
19                        var internalSubscribe = null;
20       
21                        dojo.declare("MyWidget", dijit._Widget, {
22                                _subscribeHandlerInternal: function(){ numCallsInternal++; }
23                        });
24
25                        doh.register("parse", function(){
26                                dojo.parser.parse();
27                        });
28
29                        doh.register("_widgetSubscribe",
30                                [
31                                        {
32                                                name: "_Widget.subscribe - set up subscriptions",
33                                                runTest: function(t){
34                                                        var w = dijit.byId("widget1");
35                                                        internalSubscribe = w.subscribe("/custom/event",
36                                                                                                        "_subscribeHandlerInternal");
37                                                        w.subscribe("/custom/event", function(){
38                                                                if(this == w){
39                                                                        numCallsExternal++;
40                                                                }
41                                                        });
42                                                        w.subscribe("/custom/setString", function(str){
43                                                                if(this == w){
44                                                                        externalString = str;
45                                                                }
46                                                        });
47                                                        doh.is(0, numCallsInternal);
48                                                        doh.is(0, numCallsExternal);
49                                                        doh.is("", externalString);
50                                                        doh.isNot(null, internalSubscribe);
51                                                }
52                                        },
53                                        {
54                                                name: "_Widget.subscribe - publish events",
55                                                runTest: function(t){
56                                                        var w = dijit.byId("widget1");
57                                                        dojo.publish("/custom/event", []);
58                                                        doh.is(1, numCallsInternal);
59                                                        doh.is(1, numCallsExternal);
60                                                        dojo.publish("/custom/setString", ["myString"]);
61                                                        doh.is("myString", externalString);
62                                                        dojo.publish("/custom/setString", ["anotherString"]);
63                                                        doh.is("anotherString", externalString);
64                                                }
65                                        },
66                                        {
67                                                name: "_Widget.unsubscribe",
68                                                runTest: function(t){
69                                                        var w = dijit.byId("widget1");
70                                                        dojo.publish("/custom/event", []);
71                                                        doh.is(2, numCallsInternal, "numCallsInternal");
72                                                        doh.is(2, numCallsExternal, "numCallsExternal");
73                                                        w.unsubscribe(internalSubscribe);
74                                                        dojo.publish("/custom/event", []);
75                                                        doh.is(2, numCallsInternal, "numCallsInternal again");
76                                                        doh.is(3, numCallsExternal, "numCallsExternal again");
77                                                }
78                                        },
79                                        {
80                                                name: "_Widget.destroy",
81                                                runTest: function(t){
82                                                        var w = dijit.byId("widget1");
83                                                        w.destroy();
84                                                        dojo.publish("/custom/event", []);
85                                                        doh.is(2, numCallsInternal, "numCallsInternal");
86                                                        doh.is(3, numCallsExternal, "numCallsExternal");
87                                                        dojo.publish("/custom/setString", ["myString"]);
88                                                        doh.is("anotherString", externalString, "externalString");
89                                                }
90                                        }
91                                ]
92                        );
93
94                        doh.run();
95                });
96
97        </script>
98</head>
99<body class="claro">
100        <div id="widget1" data-dojo-type="MyWidget"></div>
101</body>
102</html>
Note: See TracBrowser for help on using the repository browser.