Skip to content

Commit

Permalink
fix #722 PageEngine animation CSS rules are added multiple times in t…
Browse files Browse the repository at this point in the history
…he DOM
  • Loading branch information
marclaval authored and flongo committed Sep 18, 2013
1 parent a407b0a commit a6c0bec
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/aria/pageEngine/utils/AnimationsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ Aria.classDefinition({
this._syncCfg.waiting -= 1;

if (this._syncCfg.waiting === 0) {
var listToDispose = this._syncCfg.toDispose;
var toDispose;
for (var i = 0; i < this._syncCfg.toDispose.length; i++) {
toDispose = this._syncCfg.toDispose[i];
for (var i = listToDispose.length - 1; i >= 0; i--) {
toDispose = listToDispose[i];
toDispose.$unregisterListeners();
toDispose.$dispose();
listToDispose.splice(listToDispose.length - 1, 1);
}

this.$raiseEvent("animationend");
Expand Down
14 changes: 9 additions & 5 deletions src/aria/templates/CSSMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ Aria.classDefinition({
// No other templates depend on this class
delete this.__cssUsage[cssClasspath];
delete this.__textLoaded[cssClasspath];
delete this.__styleTagAssociation[cssClasspath];
// keep the prefix in case the css comes back
}
} // else should never be reached
Expand Down Expand Up @@ -619,17 +618,22 @@ Aria.classDefinition({

if (tag.styleSheet) {
// IE wants to use the text
tag.styleSheet.cssText = text;
if (tag.styleSheet.cssText != text) {
tag.styleSheet.cssText = text;
}
} else {
// All the other should add a text node
var definition = Aria.$window.document.createTextNode(text);
var definition;
if (tag.firstChild) {
tag.replaceChild(definition, tag.firstChild);
if (tag.firstChild.nodeValue != text) {
definition = Aria.$window.document.createTextNode(text);
tag.replaceChild(definition, tag.firstChild);
}
} else {
definition = Aria.$window.document.createTextNode(text);
tag.appendChild(definition);
}
}

tag = null;
}
// PROFILING // this.$stopMeasure(profilingId);
Expand Down
13 changes: 10 additions & 3 deletions test/aria/pageEngine/pageEngine/PageEngineTemplateDisposalTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Aria.classDefinition({
$constructor : function () {
this.$PageEngineBaseTestCase.constructor.call(this);
this._dependencies.push("test.aria.pageEngine.pageEngine.site.PageProviderFour");
this._headChildCount = -1;
},
$prototype : {

Expand Down Expand Up @@ -63,13 +64,15 @@ Aria.classDefinition({
this._testInstanceCount("Template5", 0, 0);
this._testInstanceCount("Template6", 0, 0);

//Issue722
this._headChildCount = this._testWindow.document.getElementsByTagName("head")[0].childElementCount;

this.pageEngine.navigate({
pageId : "ccc"
}, {
fn : this._afterThirdPageReady,
scope : this
});

},

_afterThirdPageReady : function () {
Expand All @@ -82,13 +85,15 @@ Aria.classDefinition({
this._testInstanceCount("Template5", 1, 0);
this._testInstanceCount("Template6", 1, 0);

//Issue722
this.assertEquals(this._testWindow.document.getElementsByTagName("head")[0].childElementCount, this._headChildCount);

this.pageEngine.navigate({
pageId : "bbb"
}, {
fn : this._afterFourthPageReady,
scope : this
});

},

_afterFourthPageReady : function () {
Expand All @@ -101,12 +106,14 @@ Aria.classDefinition({
this._testInstanceCount("Template5", 1, 1);
this._testInstanceCount("Template6", 1, 1);

//Issue722
this.assertEquals(this._testWindow.document.getElementsByTagName("head")[0].childElementCount, this._headChildCount);

aria.core.Timer.addCallback({
fn : this.end,
scope : this,
delay : 100
});

},

_createPageEngine : function (args) {
Expand Down
10 changes: 10 additions & 0 deletions test/aria/pageEngine/pageEngine/PageEngineTestSix.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Aria.classDefinition({
this.$PageEngineBaseTestCase.constructor.call(this);
this._dependencies.push("test.aria.pageEngine.pageEngine.site.PageProviderSix");
this._animations = true;
this._headChildCount = -1;
},
$prototype : {

Expand Down Expand Up @@ -92,6 +93,9 @@ Aria.classDefinition({

this.assertTrue(firstDiv.match(/Page Name: aaa/) !== null);
this.assertTrue(secondDiv === "");

//Issue722
this._headChildCount = this._testWindow.document.getElementsByTagName("head")[0].childElementCount;
},

_checkPageBBB : function () {
Expand All @@ -100,6 +104,9 @@ Aria.classDefinition({
var secondDiv = elt.nextSibling.innerHTML;
this.assertTrue(firstDiv.match(/Page Name: bbb/) !== null);
this.assertTrue(secondDiv === "");

//Issue722
this.assertEquals(this._testWindow.document.getElementsByTagName("head")[0].childElementCount, this._headChildCount);
},

_checkPageCCC : function () {
Expand All @@ -108,6 +115,9 @@ Aria.classDefinition({
var secondDiv = elt.nextSibling.innerHTML;
this.assertTrue(firstDiv === "");
this.assertTrue(secondDiv.match(/Page Name: ccc/) !== null);

//Issue722
this.assertEquals(this._testWindow.document.getElementsByTagName("head")[0].childElementCount, this._headChildCount);
}
}
});
1 change: 1 addition & 0 deletions test/aria/templates/css/CSSTestSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Aria.classDefinition({
this.addTests("test.aria.templates.css.CSSMgrTest");
this.addTests("test.aria.templates.css.CSSParserTest");
this.addTests("test.aria.templates.css.cssMgr.CSSMgrTestCase");
this.addTests("test.aria.templates.css.cssMgr.issue722.CSSMgrIssue722TestCase");
this.addTests("test.aria.templates.css.ctxtMgr.CtxtMgrTestCase");
this.addTests("test.aria.templates.css.cssScripts.CSSScriptTestCase");
this.addTests("test.aria.templates.css.dataReadyRefresh.RefreshTest");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2013 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.
*/

{CSSTemplate {
$classpath: "test.aria.templates.css.cssMgr.issue722.CSSMgrIssue722Style"
}}

{macro main()}

div.issue722 {
background: red;
}
{/macro}

{/CSSTemplate}
47 changes: 47 additions & 0 deletions test/aria/templates/css/cssMgr/issue722/CSSMgrIssue722TestCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2013 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.templates.css.cssMgr.issue722.CSSMgrIssue722TestCase",
$extends : "aria.jsunit.TestCase",
$dependencies : ["aria.templates.CSSMgr", "test.aria.templates.css.cssMgr.issue722.HelperIssue722"],
$prototype : {
testCSSLoad : function () {
var document = Aria.$window.document;
this._count = document.getElementsByTagName("head")[0].childElementCount;

for (var i = 0; i < 5; i++) {
var helper = new test.aria.templates.css.cssMgr.issue722.HelperIssue722();
this._checkHead();
helper.$dispose();
this._checkHead();
}

var helper1 = new test.aria.templates.css.cssMgr.issue722.HelperIssue722();
this._checkHead();
var helper2 = new test.aria.templates.css.cssMgr.issue722.HelperIssue722();
this._checkHead();
helper1.$dispose();
this._checkHead();
helper2.$dispose();
this._checkHead();
},

_checkHead: function () {
var document = Aria.$window.document;
this.assertEquals(document.getElementsByTagName("head")[0].childElementCount, this._count + 1);
}
}
});
26 changes: 26 additions & 0 deletions test/aria/templates/css/cssMgr/issue722/HelperIssue722.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2012 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.templates.css.cssMgr.issue722.HelperIssue722",
$dependencies : ["aria.utils.ClassList", "aria.utils.Delegate", "aria.templates.CSSMgr"],
$css : ["test.aria.templates.css.cssMgr.issue722.CSSMgrIssue722Style"],
$constructor : function () {
aria.templates.CSSMgr.loadClassPathDependencies("test.aria.templates.css.cssMgr.issue722.HelperIssue722", ["test.aria.templates.css.cssMgr.issue722.CSSMgrIssue722Style"]);
},
$destructor : function () {
aria.templates.CSSMgr.unloadClassPathDependencies("test.aria.templates.css.cssMgr.issue722.HelperIssue722", ["test.aria.templates.css.cssMgr.issue722.CSSMgrIssue722Style"]);
}
});

0 comments on commit a6c0bec

Please sign in to comment.