<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <title>testcase</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
        <p id="log">FAILED (script did not run)</p>
        
        <script type="text/javascript">
        //showModelessDialog
        var testno = parseInt(location.href.split('test=')[1]);
        
        window.onload = window['test_'+testno] || default_onload;
        
        function assert(expr,description){
                if(!expr){
                        throw new Error('ASSERTION FAILED: '+description);
                };
        };
        
        function trace(msg){
                if(window.opera){
                        opera.postError(msg);
                }
                else if(window.console && console.log){
                        console.log(msg);
                }
                else if(window.dump){
                        dump(msg);
                }
                else{
                        //alert(msg)
                }
        };
        
        function default_onload(){
                var log = document.getElementById('log').firstChild;
                if( !window.showModalDialog ){
                        log.nodeValue ='FAIL (showModalDialog not supported)';
                        return;
                };
                var url = location.pathname + (location.search ? location.search+'&' : '?' );
                
                var answer = window.showModalDialog(url+'test=1#hash',{a:1,b:[2,3],w:window},
                        'dialogHeight:300px;dialogWidth:300px;dialogLeft:300px;dialogTop:300px;');
                if( answer == 'PASS'){
                        answer = window.showModalDialog(url+'test=2');
                        if( answer === undefined){
                                var longstring = '0123456789abcdef', longarray = [];
                                for( var k=0; k<1024; k++ ) longarray.push(longstring);
                                //16 x 1024 = 16384 char long string
                                answer = window.showModalDialog(url+'test=3',longarray.join(''));
                        }
                        else{
                                answer = 'after test_2, answer is not undefined'
                        };
                };
                
                log.nodeValue = (answer == 'PASS' ? 'PASS' : 'FAIL ('+(answer||'returnValue empty')+')');
        };
        
        function do_foo(){
                return 'bar';
        };
        
        function test_1(){
                trace('test_1');
                try{
                        //test 1: dialogFoo props, and window dimensions (we use an interval of values,
                        // instead of the fixed 300 pixels because of the border of the window chrome)
                        var iw = (window.innerWidth||document.documentElement.clientWidth);
                        var ih = (window.innerHeight||document.documentElement.clientHeight);
                        var ih = (window.innerHeight||document.documentElement.clientHeight);
                        assert( 270 <= iw && iw <= 300, 'viewport width wrong');
                        assert( 200 <= ih && ih <= 300, 'viewport height wrong');
                        assert( dialogHeight == '300px', 'dialogHeight is not 300px');
                        assert( dialogLeft == '300px', 'dialogLeft is not 300px');
                        assert( dialogTop == '300px', 'dialogTop is not 300px');
                        assert( dialogWidth == '300px', 'dialogWidth is not 300px');
                        
                        //test 2: dialogArguments, the 2nd parameter to showModalDialog
                        var da = window.dialogArguments;
                        assert(da!=null,'dialogArguments is null');
                        assert(da.a==1 && da.b && da.b[0]==2 && da.b[1]==3,'dialogArguments invalid value');
                        
                        //test 3: hashes are never passed
                        assert(!location.hash,'location.hash not empty');
                        
                        //test 4: accessing window.opener
                        assert(window.opener===undefined,'window.opener is not undefined');
                        
                        //test 5: default value for returnValue
                        assert(window.returnValue===undefined,'default returnValue is not undefined');
                        
                        //test 6: accessing function in origin window
                        var w = da.w;
                        assert(w.do_foo,'do_foo in origin window must be defined');
                        assert(w.do_foo()=='bar','do_foo in origin window returned wrong value');
                        
                        window.returnValue = 'PASS';
                }
                catch(ex){
                        window.returnValue = ex.message;
                };
                
                window.close();
        };
        
        function test_2(){
                trace('test_2');
                //no returnValue... return default value which should be undefined
                window.close();
        };
        
        function test_3(){
                trace('test_3');
                try{
                        //test 5: long string in dialogArguments is truncated to 4096 chars
                        var da = window.dialogArguments;
                        assert( da!=null && (typeof da == 'string'),'dialogArguments is not a string');
                        assert( da.length == 4096 ,'dialogArguments not truncated to 4096 chars');
                        window.returnValue = 'PASS';
                }
                catch(ex){
                        window.returnValue = ex.message;
                };
                
                window.close();
        };
        </script>
</body>
</html>