Files
openlayers/master/examples/_Widget-lifecycle.html
Éric Lemoine 5d14b9e2d4 Updated
2013-02-20 10:38:25 +01:00

116 lines
2.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>_Widget.destroy() unit test</title>
<script type="text/javascript" src="../../dojo/dojo.js" djConfig="isDebug: true"></script>
<script type="text/javascript">
dojo.require("doh.runner");
dojo.require("dijit._Widget");
dojo.ready(function(){
var obj = {
foo: function(){
// summary: empty function that we connect to
}
};
// Number of times foo was called while TestWidget existed
var calls = 0;
dojo.declare("dijit.TestWidget", dijit._Widget, {
postCreate: function(){
// Rather odd call to this.connect() For testing the connections are dropped on destroy()
this.connect(obj, "foo", function(){
calls++;
});
}
});
var w;
doh.register("dijit._Widget-lifecycle",
[
{
name: "create",
runTest: function(t){
w = new dijit.TestWidget({id: "w1"}, "w1");
doh.t(dijit.byId("w1"), "widget in registry");
// since there's no template, the widget just points to the srcNodeRef
doh.is(w.domNode, dojo.byId("w1"), "srcNodeRef read in");
// test the connection
doh.is(0, calls, "foo() not called yet");
obj.foo();
doh.is(1, calls, "foo() called");
}
},
{
name: "destroy",
runTest: function(t){
w.destroy();
doh.f(dijit.byId("w1"), "widget no longer in registry");
// test the connection was destroyed
calls = 0;
obj.foo();
doh.is(0, calls, "connection was deleted");
// test the DOM node was removed
doh.f(dojo.byId("w1"), "DOM Node removed");
}
},
{
name: "destroy(true) (preserving DOM node)",
runTest: function(t){
w = new dijit.TestWidget({id: "w2"}, "w2");
doh.t(dijit.byId("w2"), "widget in registry");
w.destroy(true);
doh.f(dijit.byId("w2"), "widget no longer in registry");
// test the DOM node *wasn't* removed
doh.t(dojo.byId("w2"), "DOM Node left");
}
}
]
);
doh.register("setter calls on creation", function(){
// Make sure setters are called even for anonymous classes (#12122),
// and even when there's no value explicitly specified in the parameters
var fooSetterCalled,
Widget1 = dojo.declare([dijit._Widget], {}),
Widget2 = dojo.declare([dijit._Widget], {
foo: 345,
_setFooAttr: function(val){
fooSetterCalled = val;
this.foo = val;
}
});
new Widget1();
new Widget2();
doh.is(345, fooSetterCalled, "fooSetterCalled");
});
doh.run();
});
</script>
</head>
<body class="claro">
<div id="w1"></div>
<div id="w2"></div>
</body>
</html>