dom/tests/mochitest/whatwg/test_MessageEvent_dispatchToOther.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE html>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage
     5 -->
     6 <head>
     7   <title>Dispatching MessageEvent across origins</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    10 </head>
    11 <body>
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a>
    13 <p id="display"></p>
    14 <div id="content" style="display: none"></div>
    16 <iframe src="http://example.com/" name="otherDomain"></iframe>
    18 <pre id="test">
    19 <script class="testbody" type="application/javascript">
    20 /** Test for Bug 387706 **/
    22 SimpleTest.waitForExplicitFinish();
    24 function run()
    25 {
    26   try
    27   {
    28     var msg = new MessageEvent('message', { bubbles: true, cancelable: true,
    29                                             data: "foo", origin: "http://evil.com",
    30                                             source: window });
    32     try
    33     {
    34       var ex;
    35       window.frames.otherDomain.dispatchEvent(msg);
    36       ok(false, "should have thrown a security exception per HTML5");
    37     }
    38     catch (e)
    39     {
    40       ok(true, "correctly threw an exception (security exception, but " +
    41                "what that entails isn't yet defined in the spec)");
    42     }
    43   }
    44   catch (e)
    45   {
    46     ok(false, "threw exception during execution: " + e);
    47   }
    48   finally
    49   {
    50     SimpleTest.finish();
    51   }
    52 }
    54 addLoadEvent(run);
    56 </script>
    57 </pre>
    58 </body>
    59 </html>

mercurial