miscellaneous.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Virtual World Framework</title>
  5. <script type="text/javascript" src="qunit.js"></script>
  6. <script type="text/javascript" src="../lib/async.js"></script>
  7. <script type="text/javascript" src="../lib/crypto.js"></script>
  8. <script type="text/javascript" src="../lib/md5.js"></script>
  9. <script type="text/javascript" src="../lib/alea.js"></script>
  10. <script type="text/javascript" src="../lib/mash.js"></script>
  11. <script type="text/javascript" src="../lib/vwf.js"></script>
  12. <script type="text/javascript" src="../lib/require.js"></script>
  13. <script type="text/javascript">
  14. require( {
  15. baseUrl: "../lib",
  16. paths: {
  17. jquery: "jquery-1.10.2.min",
  18. },
  19. }, [
  20. "domReady",
  21. "utility.js",
  22. // This is the common model implementation and an example model that connects the
  23. // simulation to a WebGL scene manager.
  24. "jquery",
  25. "vwf/configuration",
  26. "vwf/kernel/model",
  27. "vwf/model/javascript",
  28. "vwf/model/object",
  29. "vwf/model/stage/log",
  30. "vwf/kernel/view",
  31. "vwf/kernel/utility",
  32. "vwf/utility",
  33. "logger",
  34. ], function( ready, testUtility ) {
  35. ready( function() {
  36. vwf.initialize(
  37. /* models */ [ "vwf/model/javascript", "vwf/model/object" ],
  38. /* views */ [ ]
  39. );
  40. module( "initialize() inheritance" );
  41. // node and prototype execute their own initializers.
  42. asyncTest( "node and prototype initializers", function() {
  43. create_node_prototype_with_initializers( true, true, function( nodeID, prototypeID, cleanup ) {
  44. equal( vwf.getProperty( nodeID, "property" ), "node", "node's initialization" );
  45. equal( vwf.getProperty( prototypeID, "property" ), "prototype", "prototype's initialization" );
  46. cleanup();
  47. start();
  48. } );
  49. } );
  50. // node's initializer runs for node even when prototype's initializer is not provided.
  51. asyncTest( "node initializer", function() {
  52. create_node_prototype_with_initializers( true, false, function( nodeID, prototypeID, cleanup ) {
  53. equal( vwf.getProperty( nodeID, "property" ), "node", "node's initialization" );
  54. equal( vwf.getProperty( prototypeID, "property" ), null, "prototype's initialization" );
  55. cleanup();
  56. start();
  57. } );
  58. } );
  59. // node is initialized by prototype's initializer when it doesn't provide one itself.
  60. asyncTest( "prototype initializer", function() {
  61. create_node_prototype_with_initializers( false, true, function( nodeID, prototypeID, cleanup ) {
  62. equal( vwf.getProperty( nodeID, "property" ), "prototype", "node's initialization" );
  63. equal( vwf.getProperty( prototypeID, "property" ), "prototype", "prototype's initialization" );
  64. cleanup();
  65. start();
  66. } );
  67. } );
  68. // no initializers run if none are provided.
  69. asyncTest( "no initializers", function() {
  70. create_node_prototype_with_initializers( false, false, function( nodeID, prototypeID, cleanup ) {
  71. equal( vwf.getProperty( nodeID, "property" ), null, "node's initialization" );
  72. equal( vwf.getProperty( prototypeID, "property" ), null, "prototype's initialization" );
  73. cleanup();
  74. start();
  75. } );
  76. } );
  77. // == Helper functions =====================================================================
  78. // Create a VWF object with two levels of inheritance using the given initializers. Add a
  79. // "property" property to each.
  80. function create_node_prototype( node, prototype, callback /* ( nodeID, prototypeID ) */ ) {
  81. prototype.properties = prototype.properties || {};
  82. prototype.properties.property = prototype.properties.property || null;
  83. vwf.createNode( prototype, function( prototypeID ) {
  84. node.extends = prototypeID;
  85. node.properties = node.properties || {};
  86. node.properties.property = node.properties.property || null;
  87. vwf.createChild( 0, testUtility.uniqueName( "node" ), node, undefined, function( nodeID ) {
  88. callback( nodeID, prototypeID, function() {
  89. vwf.deleteNode( nodeID );
  90. vwf.deleteNode( prototypeID );
  91. } );
  92. } );
  93. } );
  94. }
  95. // Create a node with a prototype. Add initialize() methods as specified to set the
  96. // "property" property.
  97. function create_node_prototype_with_initializers( node_init, prototype_init, callback /* ( nodeID, prototypeID ) */ ) {
  98. var node = {};
  99. if ( node_init ) {
  100. node.scripts = [ {
  101. text: "this.initialize = function() { this.property = \"node\" }",
  102. type: "application/javascript"
  103. } ];
  104. }
  105. var prototype = {};
  106. if ( prototype_init ) {
  107. prototype .scripts = [ {
  108. text: "this.initialize = function() { this.property = \"prototype\" }",
  109. type: "application/javascript"
  110. } ];
  111. }
  112. create_node_prototype( node, prototype, callback /* ( nodeID, prototypeID ) */ );
  113. }
  114. } );
  115. } );
  116. </script>
  117. <link rel="stylesheet" type="text/css" href="qunit.css" />
  118. </head>
  119. <body>
  120. <h1 id="qunit-header">Virtual World Framework</h1>
  121. <h2 id="qunit-banner"></h2>
  122. <div id="qunit-testrunner-toolbar"></div>
  123. <h2 id="qunit-userAgent"></h2>
  124. <ol id="qunit-tests"></ol>
  125. <div id="qunit-fixture">test markup, will be hidden</div>
  126. </body>
  127. </html>