Home | History | Annotate | Download | only in data
      1 <html>
      2   <head><title>Privileged Apis test</title>
      3     <script type='text/javascript' src='chrome_frame_tester_helpers.js'>
      4     </script>
      5     <script type='text/javascript'>
      6       var testName = 'PrivilegedApis';
      7       function OnNavigationFailed(msg) {
      8         onFailure(testName, 1, 'ChromeFrame Navigation failed: ' + msg);
      9       }
     10 
     11       function OnPrivateMessage() {
     12         onFailure(testName, 1, 'OnPrivateMessage should not execute');
     13       }
     14 
     15       function OnChromeFrameMessage(evt) {
     16         try {
     17           var d = new String(evt.data);
     18           appendStatus('Message: ' + d);
     19           if (d == 'succeed') {
     20             onSuccess(testName, 1);
     21           } else {
     22             onFailure(testName, 1, 'unexpected data');
     23           }
     24         } catch (e) {
     25           onFailure(testName, 1, 'exception in OnChromeFrameMessage');
     26         }
     27       }
     28 
     29       function tryPrivateMessage() {
     30         var cf = GetChromeFrame();
     31 
     32         try {
     33           // Any message received by this listener is a failure.
     34           // This succeeds in FF, but throws an exception in IE.
     35           cf.addEventListener('onprivatemessage', OnPrivateMessage, false);
     36         } catch(e) {
     37           appendStatus('addEventListener onprivatemessage threw exception')
     38         }
     39 
     40         // If this invocation succeeds, then 'fail' is reflected by the frame
     41         // and we fail in the OnChromeFrameMessage handler above.
     42         try {
     43           cf.postPrivateMessage('fail', String(document.location), '*');
     44           onFailure(testName, 1, 'postPrivateMessage should throw');
     45         } catch(e) {
     46         }
     47         appendStatus('After postPrivateMessage')
     48       }
     49 
     50       function OnChromeFrameLoaded(url) {
     51         tryPrivateMessage();
     52 
     53         // The frame reflects this twice, first to a bogus target
     54         // and again to the default target '*'. We succeed if we
     55         // get the reflected message to OnChromeFrameMessage and not to
     56         // OnPrivateMessage.
     57         var cf = GetChromeFrame();
     58         cf.postMessage('succeed');
     59         appendStatus('After cf.postMessage')
     60       }
     61 
     62       function GetChromeFrame() {
     63         return window.document.ChromeFrame;
     64       }
     65     </script>
     66   </head>
     67   <body>
     68       <div id='statusPanel' style='border: 1px solid red; width: 100%'>
     69       Test running....
     70       </div>
     71 
     72       <span id='ChromeFrameSpan'></span>
     73       <!-- TODO(siggi): Test setting onprivatemessage in these params -->
     74       <script type='text/javascript'>
     75 insertControl(
     76     'ChromeFrameSpan',
     77     { "src": "privileged_apis_frame.html",
     78       "eventHandlers": {
     79         "onload": "OnChromeFrameLoaded(arguments[0]);",
     80         "onloaderror": "OnNavigationFailed();",
     81         "onmessage": "return OnChromeFrameMessage(arguments[0]);"
     82       },
     83       "embedAttributes": { "privileged_mode": "1" }
     84     });
     85       </script>
     86       <p>Tests that privileged apis are unavailable from regular pages</p>
     87   </body>
     88 </html>
     89