diff --git a/src/aria/pageEngine/PageEngine.js b/src/aria/pageEngine/PageEngine.js index d80ad4c0f..cdc33bc89 100644 --- a/src/aria/pageEngine/PageEngine.js +++ b/src/aria/pageEngine/PageEngine.js @@ -217,12 +217,18 @@ module.exports = Aria.classDefinition({ this._secondDiv.parentNode.removeChild(this._secondDiv); this._secondDiv = null; } - var siteConfigHelper = this._siteConfigHelper, cssLoader = ariaUtilsCSSLoader; + var siteConfigHelper = this._siteConfigHelper, + pageConfigHelper = this._pageConfigHelper, + cssLoader = ariaUtilsCSSLoader; if (siteConfigHelper) { cssLoader.remove(siteConfigHelper.getSiteCss()); siteConfigHelper.$dispose(); } + if (pageConfigHelper) { + pageConfigHelper.$dispose(); + pageConfigHelper = null; + } cssLoader.remove(this._previousPageCSS); cssLoader.remove(this._currentPageCSS); this._modulesInPage = null; @@ -230,9 +236,11 @@ module.exports = Aria.classDefinition({ this._rootModule.$dispose(); this._rootModule = null; } - this._pageProvider.$removeListeners({ - "pageDefinitionChange" : this._onPageDefinitionChangeListener - }); + if (this._pageProvider) { + this._pageProvider.$removeListeners({ + "pageDefinitionChange" : this._onPageDefinitionChangeListener + }); + } this._onPageDefinitionChangeListener = null; }, @@ -485,6 +493,10 @@ module.exports = Aria.classDefinition({ * @protected */ _loadPageDependencies : function (args) { + if (!this._pageConfigHelper) { + this.$callback(args.cb); + return; + } var dependencies = this._pageConfigHelper.getPageDependencies(args.lazy); var pageCommonModules = this._siteConfigHelper.getCommonModulesDescription({ priority : 2, @@ -552,6 +564,10 @@ module.exports = Aria.classDefinition({ * @protected */ _displayPage : function (args) { + if (!this._pageConfigHelper) { + this.$callback(args.cb); + return; + } var pageConfig = args.pageConfig, cfg = pageConfig.pageComposition, pageId = pageConfig.pageId; this.$raiseEvent({ name : "beforePageTransition", @@ -696,6 +712,9 @@ module.exports = Aria.classDefinition({ * @protected */ _afterLazyDependenciesLoad : function () { + if (!this._pageConfigHelper) { + return; + } var lazyPlaceholders = this._pageConfigHelper.getLazyPlaceholdersIds(); this._lazyContent = false; this.$raiseEvent({ diff --git a/test/aria/pageEngine/pageEngine/PageEngineTemplateTestSuite.js b/test/aria/pageEngine/pageEngine/PageEngineTemplateTestSuite.js index 42c495240..be4419d43 100644 --- a/test/aria/pageEngine/pageEngine/PageEngineTemplateTestSuite.js +++ b/test/aria/pageEngine/pageEngine/PageEngineTemplateTestSuite.js @@ -35,5 +35,6 @@ Aria.classDefinition({ this.addTests("test.aria.pageEngine.pageEngine.issue770.GetContentTest"); this.addTests("test.aria.pageEngine.pageEngine.customRootModule.CustomRootModuleTestSuite"); this.addTests("test.aria.pageEngine.pageEngine.externalHashNavigation.ExternalHashNavigationTest"); + this.addTests("test.aria.pageEngine.pageEngine.pageEngineDisposal.DisposalTest"); } }); diff --git a/test/aria/pageEngine/pageEngine/pageEngineDisposal/DisposalTest.js b/test/aria/pageEngine/pageEngine/pageEngineDisposal/DisposalTest.js new file mode 100644 index 000000000..6a6032c20 --- /dev/null +++ b/test/aria/pageEngine/pageEngine/pageEngineDisposal/DisposalTest.js @@ -0,0 +1,50 @@ +/* + * Copyright 2014 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.pageEngine.pageEngine.pageEngineDisposal.DisposalTest", + $dependencies : ["aria.pageEngine.PageEngine", "test.aria.pageEngine.pageEngine.pageEngineDisposal.PageProvider"], + $extends : "aria.jsunit.TestCase", + $prototype : { + + /** + * this test just checks if all the object instantiated by pageEngine and pageProvider are correctly disposed + */ + testAsyncDisposePageEngine : function () { + var document = Aria.$window.document; + var div = document.createElement("div"); + div.id = "testId"; + document.body.appendChild(div); + + this.pageEngine = new aria.pageEngine.PageEngine(); + this.pageProvider = new test.aria.pageEngine.pageEngine.pageEngineDisposal.PageProvider(); + + var startConfig = { + pageProvider : this.pageProvider, + oncomplete : { + fn : function () { + this.pageEngine.$dispose(); + this.pageProvider.$dispose(); + this.notifyTestEnd('testAsyncDisposePageEngine'); + }, + scope : this + } + }; + + this.pageEngine.start(startConfig); + + } + } +}); diff --git a/test/aria/pageEngine/pageEngine/pageEngineDisposal/MainLayout.tpl b/test/aria/pageEngine/pageEngine/pageEngineDisposal/MainLayout.tpl new file mode 100644 index 000000000..6c15968bd --- /dev/null +++ b/test/aria/pageEngine/pageEngine/pageEngineDisposal/MainLayout.tpl @@ -0,0 +1,26 @@ +/* + * Copyright 2014 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 : "test.aria.pageEngine.pageEngine.pageEngineDisposal.MainLayout" +}} + +{macro main ()} + DISPOSAL TEST +{/macro} + + +{/Template} diff --git a/test/aria/pageEngine/pageEngine/pageEngineDisposal/PageProvider.js b/test/aria/pageEngine/pageEngine/pageEngineDisposal/PageProvider.js new file mode 100644 index 000000000..23219af48 --- /dev/null +++ b/test/aria/pageEngine/pageEngine/pageEngineDisposal/PageProvider.js @@ -0,0 +1,51 @@ +/* + * 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. + */ + +/** + * Fake page processor + */ +Aria.classDefinition({ + $classpath : "test.aria.pageEngine.pageEngine.pageEngineDisposal.PageProvider", + $implements : ["aria.pageEngine.pageProviders.PageProviderInterface"], + $prototype : { + + /** + * @param {aria.pageEngine.CfgBeans.ExtendedCallback} callback + */ + loadSiteConfig : function (callback) { + this.$callback(callback.onsuccess, { + containerId : "testId" + }); + }, + + /** + * @param {String} pageId Id of the page + * @param {aria.pageEngine.CfgBeans.ExtendedCallback} callback + */ + loadPageDefinition : function (pageId, callback) { + this.$callback(callback.onsuccess, { + pageId : "aaa", + pageComposition : { + template : "test.aria.pageEngine.pageEngine.pageEngineDisposal.MainLayout", + placeholders : { + "newsInfo" : { + "contentId" : "pgen_news_and_info" + } + } + } + }); + } + } +});