Skip to content

Commit

Permalink
fix ariatemplates#1074 aria.utils.Bridge now forwards url map and roo…
Browse files Browse the repository at this point in the history
…t map to the popup

This commit links the url map and root map of the popup window (created
with aria.utils.Bridge) to the ones of the parent window.
It also changes a bit the logic to create the urls of the framework and
the skin included in the popup in order to make the bridge work better
(especially, to make it work in the test environment).

close ariatemplates#1075
close ariatemplates#1531
  • Loading branch information
divdavem committed Sep 14, 2015
1 parent 413a379 commit ad7d0bf
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/aria/utils/Bridge.js
Expand Up @@ -15,7 +15,7 @@
var Aria = require("../Aria");
var ariaUtilsAriaWindow = require("./AriaWindow");
var ariaUtilsJson = require("./Json");

var ariaCoreDownloadMgr = require("../core/DownloadMgr");

/**
* Creates a subwindow and load a module inside
Expand Down Expand Up @@ -117,59 +117,49 @@ module.exports = Aria.classDefinition({
// this._subWindow = window.open("", config.title, options);

// retrieve current AT version to load the same on the subwindow
var scripts = Aria.$frameworkWindow.document.getElementsByTagName("script"), root = Aria.rootFolderPath, script, src, urlMatch, atJsName, atSkinName;
var scripts = Aria.$frameworkWindow.document.getElementsByTagName("script"), script, src, urlMatch, atJsName, atSkinName;
for (var i = 0, l = scripts.length; i < l; i++) {
script = scripts[i];
if (script.attributes && script.attributes["src"]) {
src = script.attributes["src"].nodeValue;
urlMatch = /aria\/(aria-?templates-([^\/]+)\.js)/.exec(src);
if (urlMatch && urlMatch.length > 1) {
atJsName = urlMatch[1]; // retrieve something like "aria-templates-1.0-SNAPSHOT.js"
atSkinName = "atskin-" + urlMatch[2] + ".js";
atJsName = script.src; // retrieves the full url to Aria Templates
atSkinName = ariaCoreDownloadMgr.resolveURL("aria/css/atskin-" + urlMatch[2] + ".js", true);
break;
}
if (/aria\/bootstrap.js/.test(src)) {
// not packaged
atJsName = "bootstrap.js";
atSkinName = "atskin.js";
atJsName = script.src; // retrieves the full url to Aria Templates
atSkinName = ariaCoreDownloadMgr.resolveURL("aria/css/atskin.js", true);
break;
}
}
}

// case dev mode : rootFolderPath might be wrong
if (root.match(/dev\/$/)) {
root = root.substring(0, root.length - 4);
}

if (!atJsName) {
// FIXME log Error
return false;
}

// create subwindow content
var pullTimeout = 500; // ms to wait between each check of Aria.loadTemplate
var devPart = "";

// This is use for debugging -> won't work with IE (scripts get injected after the body)
// var devPart = "dev/";

var sourceCode = [
'<!DOCTYPE html>\n',
"<html><head><title>" + config.title + "</title>", // HEAD

"<script type='text/javascript'>Aria = { _xxDebug: true, rootFolderPath : '" + root + devPart
+ "' };</script>",
"<script type='text/javascript'>Aria = { _xxDebug: true };</script>",
"<script language='JavaScript' src='", // AT script
root + devPart + "aria/" + atJsName, // AT script
atJsName, // AT script
"'></script>", // AT script

(aria.widgets && aria.widgets.AriaSkin) ? ["<script type='text/javascript'>",
"Aria['classDefinition']({$classpath : 'aria.widgets.AriaSkin',", "$singleton : true,",
"$prototype : window.aria.utils.Json.copy(",
ariaUtilsJson.convertToJsonString(aria.widgets.AriaSkin.classDefinition.$prototype), ")",
"});</script>"].join("") : ["<script language='JavaScript' src='", // AT Skin script
root + "aria/css/" + atSkinName, // AT Skin script
atSkinName, // AT Skin script
"'></script>" // AT Skin script
].join(""),

Expand Down Expand Up @@ -220,10 +210,16 @@ module.exports = Aria.classDefinition({
moduleStart : function () {

// start working in subwindow
var Aria = this._subWindow.Aria; // , aria = this._subWindow.aria;
var Aria = this._subWindow.Aria, aria = this._subWindow.aria;

clearInterval(this._bridgeAttachedInterval);

// link the url map and the root map in the sub-window
// to the corresponding maps in the main window:
Aria.rootFolderPath = this.getAria().rootFolderPath;
aria.core.DownloadMgr._urlMap = ariaCoreDownloadMgr._urlMap;
aria.core.DownloadMgr._rootMap = ariaCoreDownloadMgr._rootMap;

Aria.setRootDim({
width : {
min : 16
Expand Down
1 change: 1 addition & 0 deletions test/aria/utils/UtilsTestSuite.js
Expand Up @@ -69,6 +69,7 @@ Aria.classDefinition({
this.addTests("test.aria.utils.Xml");
this.addTests("test.aria.utils.DeviceTest");
this.addTests("test.aria.utils.OrientationTest");
this.addTests("test.aria.utils.bridge.BridgeTest");
this.addTests("test.aria.utils.dragdrop.DragTestSuite");
this.addTests("test.aria.utils.events.EventsTestSuite");
}
Expand Down
80 changes: 80 additions & 0 deletions test/aria/utils/bridge/BridgeTest.js
@@ -0,0 +1,80 @@
/*
* Copyright 2015 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Aria.classDefinition({
$classpath : "test.aria.utils.bridge.BridgeTest",
$extends : "aria.jsunit.TestCase",
$dependencies : ["aria.utils.Bridge"],
$prototype : {
tearDown: function () {
if (this.bridge) {
this.bridge.close();
this.bridge.$dispose();
this.bridge = null;
}
},

testAsyncCheckDownloadMgrMaps : function () {
aria.core.DownloadMgr.updateRootMap({
"bridgeTest": aria.core.DownloadMgr.resolveURL("test/aria/utils/bridge/root", true) + "/"
});
aria.core.DownloadMgr.updateUrlMap({
"bridgeTest": {
"BridgeCtrl": "bridgeTest/BridgeCtrl-abcde.js",
"BridgeTpl": "bridgeTest/BridgeTpl-efghi.tpl"
}
});

var bridge = this.bridge = new aria.utils.Bridge();
bridge.open({
title: "BridgeWindow",
moduleCtrlClasspath: "bridgeTest.BridgeCtrl",
displayClasspath: "bridgeTest.BridgeTpl"
});

this.waitFor({
condition: function () {
return !! bridge._subWindow.document && bridge._subWindow.document.getElementById("myElementIsThere");
},
callback: function () {
// checks that changing the root map and the url map in the main window is reflected
// in the sub window as maps are linked
aria.core.DownloadMgr.updateRootMap({
"bridgeTest": {
"later": aria.core.DownloadMgr.resolveURL("test/aria/utils/bridge/laterRoot", true) + "/"
}
});
aria.core.DownloadMgr.updateUrlMap({
"bridgeTest": {
"later" : {
"LaterClass": "LaterClass-xyz.js"
}
}
});
bridge._subWindow.Aria.load({
classes: ["bridgeTest.later.LaterClass"],
oncomplete: {
scope: this,
fn: function () {
this.assertEquals(bridge._subWindow.bridgeTest.later.LaterClass.value, "OK-LOADED");
this.notifyTestEnd();
}
}
});
}
});
}
}
});
22 changes: 22 additions & 0 deletions test/aria/utils/bridge/laterRoot/LaterClass-xyz.js
@@ -0,0 +1,22 @@
/*
* Copyright 2015 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Aria.classDefinition({
$classpath: "bridgeTest.later.LaterClass",
$singleton: true,
$prototype: {
value: "OK-LOADED"
}
});
24 changes: 24 additions & 0 deletions test/aria/utils/bridge/root/bridgeTest/BridgeCtrl-abcde.js
@@ -0,0 +1,24 @@
/*
* Copyright 2015 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Aria.classDefinition({
$classpath: "bridgeTest.BridgeCtrl",
$extends: "aria.templates.ModuleCtrl",
$prototype: {
init: function (initArgs, cb) {
this.$callback(cb);
}
}
});
24 changes: 24 additions & 0 deletions test/aria/utils/bridge/root/bridgeTest/BridgeTpl-efghi.tpl
@@ -0,0 +1,24 @@
/*
* Copyright 2015 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

{Template {
$classpath : "bridgeTest.BridgeTpl"
}}

{macro main()}
Hello <div id="myElementIsThere"></div>
{/macro}

{/Template}

0 comments on commit ad7d0bf

Please sign in to comment.