Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>postMessage chrome tests</title> |
michael@0 | 8 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | |
michael@0 | 14 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a> |
michael@0 | 15 | <p id="display"></p> |
michael@0 | 16 | <div id="content" style="display: none"></div> |
michael@0 | 17 | |
michael@0 | 18 | <iframe src="http://example.org/tests/dom/tests/mochitest/whatwg/postMessage_chrome_helper.html" |
michael@0 | 19 | name="contentDomain"></iframe> |
michael@0 | 20 | |
michael@0 | 21 | |
michael@0 | 22 | <pre id="test"> |
michael@0 | 23 | <script class="testbody" type="application/javascript"> |
michael@0 | 24 | /** Test for Bug 387706 **/ |
michael@0 | 25 | |
michael@0 | 26 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 27 | |
michael@0 | 28 | var finished = false; |
michael@0 | 29 | function finish() |
michael@0 | 30 | { |
michael@0 | 31 | if (!finished) |
michael@0 | 32 | { |
michael@0 | 33 | finished = true; |
michael@0 | 34 | SimpleTest.finish(); |
michael@0 | 35 | } |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | /** Receives MessageEvents to this window. */ |
michael@0 | 39 | function messageReceiver(evt) |
michael@0 | 40 | { |
michael@0 | 41 | ok(evt instanceof MessageEvent, "umm, how did we get this?"); |
michael@0 | 42 | is(evt.type, "message", "expected events of type 'message'"); |
michael@0 | 43 | is(evt.lastEventId, "", "postMessage creates events with empty lastEventId"); |
michael@0 | 44 | |
michael@0 | 45 | switch (evt.data) |
michael@0 | 46 | { |
michael@0 | 47 | case "path-is-set": |
michael@0 | 48 | chromePathIsSet(evt); |
michael@0 | 49 | break; |
michael@0 | 50 | |
michael@0 | 51 | case "post-to-self": |
michael@0 | 52 | checkSelf(evt); |
michael@0 | 53 | break; |
michael@0 | 54 | |
michael@0 | 55 | case "post-to-content-response": |
michael@0 | 56 | receiveContent(evt); |
michael@0 | 57 | break; |
michael@0 | 58 | |
michael@0 | 59 | default: |
michael@0 | 60 | ok(false, "unexpected message: " + evt.data); |
michael@0 | 61 | finish(); |
michael@0 | 62 | break; |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | /****************** |
michael@0 | 68 | * SELF-RESPONDER * |
michael@0 | 69 | ******************/ |
michael@0 | 70 | |
michael@0 | 71 | function checkSelf(evt) |
michael@0 | 72 | { |
michael@0 | 73 | var prepath = getChromePrePath(window.location.href); |
michael@0 | 74 | |
michael@0 | 75 | is(evt.isTrusted, true, "should have sent a trusted event"); |
michael@0 | 76 | is(evt.origin, prepath, "wrong origin for chrome: URL"); |
michael@0 | 77 | is(evt.source, null, "chrome posters get a null source, for security"); |
michael@0 | 78 | |
michael@0 | 79 | window.frames.contentDomain.postMessage(prepath, "*"); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | |
michael@0 | 83 | function chromePathIsSet(evt) |
michael@0 | 84 | { |
michael@0 | 85 | window.frames.contentDomain.postMessage("post-to-content", |
michael@0 | 86 | "http://example.org"); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | /************* |
michael@0 | 90 | * RECEIVERS * |
michael@0 | 91 | *************/ |
michael@0 | 92 | |
michael@0 | 93 | function receiveContent(evt) |
michael@0 | 94 | { |
michael@0 | 95 | is(evt.isTrusted, true, "should have sent a trusted event"); |
michael@0 | 96 | finish(); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | /************** |
michael@0 | 101 | * TEST SETUP * |
michael@0 | 102 | **************/ |
michael@0 | 103 | |
michael@0 | 104 | function run() |
michael@0 | 105 | { |
michael@0 | 106 | window.addEventListener("message", messageReceiver, false); |
michael@0 | 107 | window.postMessage("post-to-self", "*"); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | window.addEventListener("load", run, false); |
michael@0 | 111 | </script> |
michael@0 | 112 | </pre> |
michael@0 | 113 | </body> |
michael@0 | 114 | </html> |