summaryrefslogtreecommitdiff
path: root/web-ui
diff options
context:
space:
mode:
authorFelix Hammerl <fhammerl@thoughtworks.com>2016-04-01 14:51:27 +0200
committerFelix Hammerl <fhammerl@thoughtworks.com>2016-04-01 14:51:27 +0200
commitf41cea02299dc41dcc1f934d57430b564cf708ef (patch)
treee2b2b5ab8ebf896a88f55829aad63af6ae7a097c /web-ui
parentd75a8878d20117bc595f80a2ea2a68f84f48f508 (diff)
Run event test async with source passed to iframe via Blob URI
Diffstat (limited to 'web-ui')
-rw-r--r--web-ui/app/js/mixins/with_mail_sandbox.js58
-rw-r--r--web-ui/test/spec/mixins/with_mail_sandbox.spec.js30
2 files changed, 57 insertions, 31 deletions
diff --git a/web-ui/app/js/mixins/with_mail_sandbox.js b/web-ui/app/js/mixins/with_mail_sandbox.js
index c292cb70..1a51840d 100644
--- a/web-ui/app/js/mixins/with_mail_sandbox.js
+++ b/web-ui/app/js/mixins/with_mail_sandbox.js
@@ -34,41 +34,43 @@ define(
});
iframe.onload = function() {
- // use iframe-resizer to dynamically adapt iframe size to its content
- var config = {
- resizedCallback: scaleToFit,
- checkOrigin: false
- };
- $iframe.iFrameResize(config);
+ if ($iframe.iFrameResize) {
+ // use iframe-resizer to dynamically adapt iframe size to its content
+ var config = {
+ resizedCallback: scaleToFit,
+ checkOrigin: false
+ };
+ $iframe.iFrameResize(config);
+ }
+
+ iframe.contentWindow.postMessage({
+ html: content
+ }, '*');
// transform scale iframe to fit container width
// necessary if iframe is wider than container
function scaleToFit() {
- var parentWidth = $iframe.parent().width();
- var w = $iframe.width();
- var scale = 'none';
+ var parentWidth = $iframe.parent().width();
+ var w = $iframe.width();
+ var scale = 'none';
- // only scale html mails
- if (mail && mail.htmlBody && (w > parentWidth)) {
- scale = parentWidth / w;
- scale = 'scale(' + scale + ',' + scale + ')';
- }
+ // only scale html mails
+ if (mail && mail.htmlBody && (w > parentWidth)) {
+ scale = parentWidth / w;
+ scale = 'scale(' + scale + ',' + scale + ')';
+ }
- $iframe.css({
- '-webkit-transform-origin': '0 0',
- '-moz-transform-origin': '0 0',
- '-ms-transform-origin': '0 0',
- 'transform-origin': '0 0',
- '-webkit-transform': scale,
- '-moz-transform': scale,
- '-ms-transform': scale,
- 'transform': scale
- });
+ $iframe.css({
+ '-webkit-transform-origin': '0 0',
+ '-moz-transform-origin': '0 0',
+ '-ms-transform-origin': '0 0',
+ 'transform-origin': '0 0',
+ '-webkit-transform': scale,
+ '-moz-transform': scale,
+ '-ms-transform': scale,
+ 'transform': scale
+ });
}
-
- iframe.contentWindow.postMessage({
- html: content
- }, '*');
};
};
}
diff --git a/web-ui/test/spec/mixins/with_mail_sandbox.spec.js b/web-ui/test/spec/mixins/with_mail_sandbox.spec.js
index a1c2d624..daa8cc39 100644
--- a/web-ui/test/spec/mixins/with_mail_sandbox.spec.js
+++ b/web-ui/test/spec/mixins/with_mail_sandbox.spec.js
@@ -2,13 +2,37 @@ describeMixin('mixins/with_mail_sandbox', function() {
'use strict';
beforeEach(function() {
- this.setupComponent('<iframe id="read-sandbox" sandbox="allow-popups allow-scripts" src="sandbox/sandbox.html" scrolling="no"></iframe>');
+ this.setupComponent('<iframe id="read-sandbox" sandbox="allow-popups allow-scripts" src scrolling="no"></iframe>');
+ var iframe = document.querySelector('iframe');
+ var template = ['',
+ '<!DOCTYPE html>',
+ '<html>',
+ '<head>',
+ '<meta charset="utf-8">',
+ '<script>(function () {',
+ '\'use strict\'',
+ ';window.onmessage = function (e) {',
+ 'if (e.data.html) {',
+ 'var mainWindow = e.source;',
+ 'mainWindow.postMessage(\'data ok\', e.origin);',
+ '}',
+ '};',
+ '})();',
+ '</script>',
+ '</head>',
+ '<body>',
+ '</body>',
+ '</html>'].join('');
+ iframe.src = URL.createObjectURL(new Blob([template], {type: "text/html"}));
});
- it('should open reply container', function () {
+ it('should open reply container', function (done) {
var showContainerEvent = spyOnEvent(document, Pixelated.events.ui.replyBox.showReplyContainer);
this.component.showMailOnSandbox(Pixelated.testData().parsedMail.html);
- expect(showContainerEvent).toHaveBeenTriggeredOn(document);
+ setTimeout(function() {
+ expect(showContainerEvent).toHaveBeenTriggeredOn(document);
+ done();
+ }, 200);
});
});