summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/data/privileged_apis_host.html
blob: fde39e184efe342369142b0d4fe4e8a8fc2155ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<html>
  <head><title>Privileged Apis test</title>
    <script type='text/javascript' src='chrome_frame_tester_helpers.js'>
    </script>
    <script type='text/javascript'>
      var testName = 'PrivilegedApis';
      function OnNavigationFailed(msg) {
        onFailure(testName, 1, 'ChromeFrame Navigation failed: ' + msg);
      }

      function OnPrivateMessage() {
        onFailure(testName, 1, 'OnPrivateMessage should not execute');
      }

      function OnChromeFrameMessage(evt) {
        try {
          var d = new String(evt.data);
          appendStatus('Message: ' + d);
          if (d == 'succeed') {
            onSuccess(testName, 1);
          } else {
            onFailure(testName, 1, 'unexpected data');
          }
        } catch (e) {
          onFailure(testName, 1, 'exception in OnChromeFrameMessage');
        }
      }

      function tryPrivateMessage() {
        var cf = GetChromeFrame();

        try {
          // Any message received by this listener is a failure.
          // This succeeds in FF, but throws an exception in IE.
          cf.addEventListener('onprivatemessage', OnPrivateMessage, false);
        } catch(e) {
          appendStatus('addEventListener onprivatemessage threw exception')
        }

        // If this invocation succeeds, then 'fail' is reflected by the frame
        // and we fail in the OnChromeFrameMessage handler above.
        try {
          cf.postPrivateMessage('fail', String(document.location), '*');
          onFailure(testName, 1, 'postPrivateMessage should throw');
        } catch(e) {
        }
        appendStatus('After postPrivateMessage')
      }

      function tryInstallExtension() {
        var cf = GetChromeFrame();

        try {
          // Any message received by this listener is a failure.
          // This succeeds in FF, but throws an exception in IE.
          cf.installExtension('foo');
          onFailure(testName, 1, 'installExtension should throw');
        } catch(e) {
          appendStatus('installExtension threw exception')
        }

        appendStatus('After installExtension')
      }

      function tryLoadExtension() {
        var cf = GetChromeFrame();

        try {
          // Any message received by this listener is a failure.
          // This succeeds in FF, but throws an exception in IE.
          cf.loadExtension('foo');
          onFailure(testName, 1, 'loadExtension should throw');
        } catch(e) {
          appendStatus('loadExtension threw exception')
        }

        appendStatus('After loadExtension')
      }

      function OnChromeFrameLoaded(url) {
        tryPrivateMessage();
        tryInstallExtension();
        tryLoadExtension();

        // The frame reflects this twice, first to a bogus target
        // and again to the default target '*'. We succeed if we
        // get the reflected message to OnChromeFrameMessage and not to
        // OnPrivateMessage.
        var cf = GetChromeFrame();
        cf.postMessage('succeed');
        appendStatus('After cf.postMessage')
      }

      function GetChromeFrame() {
        return window.document.ChromeFrame;
      }
    </script>
  </head>
  <body>
      <div id='statusPanel' style='border: 1px solid red; width: 100%'>
      Test running....
      </div>

      <!-- TODO(siggi): Test setting onprivatemessage in these params -->
      <object id='ChromeFrame' width='500' height='500'
          codebase='http://www.google.com'
          classid='CLSID:E0A900DF-9611-4446-86BD-4B1D47E7DB2A'>
          <param name='src' value='privileged_apis_frame.html'>
          <param name='onload' value='OnChromeFrameLoaded(arguments[0]);'>
          <param name='onloaderror' value='OnNavigationFailed();'>
          <param name='onmessage' value='OnChromeFrameMessage(arguments[0]);'>
          <embed id='ChromeFramePlugin' width='500' height='500' name='ChromeFrame'
              src='privileged_apis_frame.html'
              type='application/chromeframe'
              onload='OnChromeFrameLoaded(arguments[0]);'
              onloaderror='OnNavigationFailed();'
              onmessage='return OnChromeFrameMessage(arguments[0]);'
              privileged_mode='1'
          </embed>
      </object>
      <p>Tests that privileged apis are unavailable from regular pages</p>
  </body>
</html>