<html>
<head>
    <title>Iframe Client</title>
    
    <script src="../config.js"></script>
    <script type="text/javascript">loadHub_dirDepth="2";</script>
    <script src="../util/loadHub.js"></script>
    
    <script src="../util/test_hub.js"></script>

    <script type="text/javascript">
        var hubClient;
        var myObject;
        
        function init()
        {
            new TestHubClient( "iframe", function( test ) {

                var MyObject = function()
                {
                    this.onHubClientConnect = function( client, success, error )
                    {
                        test.assertTrue( success, "hub client connect failed" );
                        setTimeout(
                            function() {
                                // now try to call disconnect
                                try {
                                    hubClient.disconnect( myObject.onHubClientDisconnect, myObject );
                                } catch( e ) {
                                    test.errback( "iframe hub client disconnect failed: " + e );
                                }
                            },
                            0
                        );
                    }

                    this.onHubClientDisconnect = function( client, success, error ) {
                        if ( success ) {
                            test.assertEqual( hubClient, client );
                            test.assertEqual( myObject, this );
                            test.callback( true, "client2" );  // test succeeded
                        } else {
                            test.errback( error );
                        }
                    }

                    this.onHubClientSecurityAlert = function( source, alertType )
                    {
                        test.errback( "security alert in iframe client: " + alertType );
                    }
                }
                
                myObject = new MyObject();
                
                try {
                    hubClient = new OpenAjax.hub.IframeHubClient({
                          HubClient: {
                              onSecurityAlert: myObject.onHubClientSecurityAlert,
                              scope: myObject,
                              log: test.log
                          }
                    });
                    hubClient.connect( myObject.onHubClientConnect, myObject );
                } catch( e ) {
                    test.errback( "iframe hub client init and connect failed: " + e );
                }

            });
        }
    </script>
</head>

<body onload="init();">
</body>
</html>
