Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

feat #1119 inject iframe page via TemplateTestCase/FrameATLoader

In TemplateTestCase it's been possible to run a template test in an iframe
and set the `<iframe>`'s CSS itself, but it was not possible to inject the
CSS to the `<body>` of an iframe, and since CSS Templates can't modify global
CSS scope of the window, there way no way to alter global CSS for the
test.

Now it's possible to inject an arbitrary CSS text to the iframe which will
be appended as `<style>` node, as a child of `<head>`.

This fixes the failure of the test
test/aria/widgets/container/dialog/resize/test3/DialogOnResizeTestCase

Close #1119.
  • Loading branch information...
commit d2fb4bd582fbb19d0fbd4178bdee5a539e265210 1 parent 891bae0
@jakub-g jakub-g authored
View
11 src/aria/jsunit/TemplateTestCase.js
@@ -41,7 +41,8 @@ Aria.classDefinition({
moduleCtrl : null,
data : {},
iframe : false,
- baseCss : this.IFRAME_BASE_CSS_TEXT
+ baseCss : this.IFRAME_BASE_CSS_TEXT, // css that will be set on the <iframe> itself
+ iframePageCss : "" // css that will be injected into iframe as <style> tag
};
/**
@@ -792,11 +793,15 @@ Aria.classDefinition({
document.body.appendChild(containerDiv);
args.iframe = iframe;
- aria.utils.FrameATLoader.loadAriaTemplatesInFrame(iframe, {
+ var cb = {
fn : this._iframeInnerDepLoad,
scope : this,
args : args
- });
+ };
+ var options = {
+ iframePageCss : this.env.iframePageCss
+ };
+ aria.utils.FrameATLoader.loadAriaTemplatesInFrame(iframe, cb, options);
},
/**
View
35 src/aria/utils/FrameATLoader.js
@@ -77,12 +77,15 @@ Aria.classDefinition({
* @param {HTMLElement} frame frame
* @param {aria.core.CfgBeans:Callback} cb callback. The first argument is an object containing success
* information.
+ * @param {Object} options So far one option supported: iframePageCss:String which injects CSS text to the
+ * iframe. E.g. {iframePageCss : "body {font-family:Arial}"}
*/
- loadAriaTemplatesInFrame : function (frame, cb) {
+ loadAriaTemplatesInFrame : function (frame, cb, options) {
this.loadBootstrap({
fn : this._loadATInFrameCb1,
scope : this,
args : {
+ options : options || {},
frame : frame,
cb : cb
}
@@ -108,11 +111,8 @@ Aria.classDefinition({
args : args
});
-
- var href = Aria.$frameworkWindow.location.href.replace(/(\?|\#).*$/, "").
- replace(/[^\/.]+\.[^\/.]+$/, "").
- replace(/\/$/, "") +
- "/";
+ var href = Aria.$frameworkWindow.location.href.replace(/(\?|\#).*$/, "").replace(/[^\/.]+\.[^\/.]+$/, "").replace(/\/$/, "")
+ + "/";
var docUrl = [aria.core.DownloadMgr.resolveURL("aria/utils/FrameATLoaderHTML.html"), '?',
encodeURIComponent(href), '#', callbackId].join('');
// args.frame.contentWindow is defined only if the framework is loaded in an iframe. In the case of a new
@@ -181,6 +181,10 @@ Aria.classDefinition({
*/
_loadATInFrameCb4 : function (res, args) {
var window = args.frame.contentWindow || args.frame;
+ if (args.options.iframePageCss) {
+ this._injectGlobalCss(window, args.options.iframePageCss);
+ }
+
window.Aria.rootFolderPath = Aria.rootFolderPath;
var rootMap = window.aria.utils.Json.copy(aria.core.DownloadMgr._rootMap);
window.aria.core.DownloadMgr.updateRootMap(rootMap);
@@ -228,6 +232,25 @@ Aria.classDefinition({
},
/**
+ * Create <style> tag and append to the head of the window, with the content as in cssText param
+ * @param {Window} window
+ * @param {String} cssText
+ */
+ _injectGlobalCss : function (window, cssText) {
+ var document = window.document;
+ var head = document.head || document.getElementsByTagName("head")[0];
+ var style = document.createElement("style");
+
+ style.type = "text/css";
+ if (style.styleSheet) {
+ style.styleSheet.cssText = cssText;
+ } else {
+ style.appendChild(document.createTextNode(cssText));
+ }
+ head.appendChild(style);
+ },
+
+ /**
* Return a javascript id which can be used from the iframe to call the corresponding callback.
* @param {aria.core.CfgBeans:Callback} cb callback
* @return {String}
View
11 test/aria/widgets/container/dialog/resize/test3/DialogOnResizeTestCase.js
@@ -26,7 +26,8 @@ Aria.classDefinition({
this.setTestEnv({
template : "test.aria.widgets.container.dialog.resize.test3.DialogOnResizeTemplate",
data : this.data,
- iframe : true
+ iframe : true,
+ iframePageCss : "body {font:10px Arial}"
});
},
$prototype : {
@@ -77,10 +78,10 @@ Aria.classDefinition({
var left = popupPos.x;
var top = popupPos.y;
- this.assertEqualsWithTolerance(left, expectedLeft, tolerance, "Bad offset from left: "
- + left + ", should be ~311");
- this.assertEqualsWithTolerance(top, expectedTop, tolerance, "Bad offset from top: "
- + top + ", should be ~ 223");
+ this.assertEqualsWithTolerance(left, expectedLeft, tolerance, "Bad offset from left: " + left
+ + ", should be ~311");
+ this.assertEqualsWithTolerance(top, expectedTop, tolerance, "Bad offset from top: " + top
+ + ", should be ~ 223");
this.notifyTemplateTestEnd();
}
Please sign in to comment.
Something went wrong with that request. Please try again.