Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
adding test for bug 796917 using postMessage to an iframe from a cont…
Browse files Browse the repository at this point in the history
…ent script does not serialize data
  • Loading branch information
erikvold committed Nov 2, 2012
1 parent 5e6377d commit aa2d116
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
20 changes: 20 additions & 0 deletions data/test-iframe-postmessage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script>
window.addEventListener("message", function(msg) {
parent.postMessage(msg.data, "*");
});

parent.postMessage({
first: "a string",
second: ["an", "array"],
third: {an: 'object'}
}, '*');
</script>
</head>
<body>
<h1>Inner iframe</h1>
</body>
</html>
9 changes: 9 additions & 0 deletions data/test-iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<iframe id="inner" src="about:blank"></iframe>
</body>
</html>
11 changes: 11 additions & 0 deletions data/test-iframe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

var count = 0

setTimeout(function() {
window.addEventListener("message", function(msg) {
if (++count > 1) self.postMessage(msg.data);
else msg.source.postMessage(msg.data, '*');
});

document.getElementById('inner').src = iframePath;
}, 0);
24 changes: 23 additions & 1 deletion test/test-page-mod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

var pageMod = require("sdk/page-mod");
Expand All @@ -13,6 +12,7 @@ const { Cc, Ci } = require("chrome");
const { open, getFrames, getMostRecentBrowserWindow } = require('sdk/window/utils');
const windowUtils = require('sdk/deprecated/window-utils');
const { getTabContentWindow, getActiveTab, openTab, closeTab } = require('sdk/tabs/utils');
const { data } = require('self');

/* XXX This can be used to delay closing the test Firefox instance for interactive
* testing or visual inspection. This test is registered first so that it runs
Expand Down Expand Up @@ -894,3 +894,25 @@ exports.testBug803529 = function(test) {

window.addEventListener("load", wait4Iframes, false);
};

exports.testIFramePostMessage = function(test) {
test.waitUntilDone();

tabs.open({
url: data.url("test-iframe.html"),
onReady: function(tab) {
var worker = tab.attach({
contentScriptFile: data.url('test-iframe.js'),
contentScript: ' var iframePath = \'' + data.url('test-iframe-postmessage.html') + '\'',
onMessage: function(msg) {
test.assertEqual(msg.first, 'a string');
test.assert(msg.second[1], "array");
test.assertEqual(typeof msg.third, 'object');

worker.destroy();
tab.close(function() test.done());
}
});
}
});
};

0 comments on commit aa2d116

Please sign in to comment.