Arthur Bogaart pushed to branch release/4.2 at cms-community / 
hippo-addon-channel-manager


Commits:
e77a9adf by Mathijs den Burger at 2017-03-30T12:03:58+02:00
CHANNELMGR-1226 Avoid parallel MutationObservers in unit test

The OverlayService.init() call registers the onload handler of
the iframe, which in turn registers a MutationObserver. The init
used to be done each time the iframe was reloaded, which caused
multiple load calls and hence multiple MutationObservers. These
started observing each other's changes, which in Chrome 57 led to
an endless stream of mutations (caused by setting the label text,
which is a mutation that always reaches the DOM).

With this fixed, only one test still failed. That's because it
spied upon the _onUnload method without calling it, which
prevented the current observer from being disconnected. That
again caused two parallel observers in Chrome 57.

(cherry picked from commit e8b0ea8256f5afa0cda2a136dea6ac186a4c3717)

(cherry picked from commit 48e78dd)

- - - - -


1 changed file:

- frontend-ng/src/angularjs/channel/hippoIframe/overlay/overlay.service.spec.js


Changes:

=====================================
frontend-ng/src/angularjs/channel/hippoIframe/overlay/overlay.service.spec.js
=====================================
--- 
a/frontend-ng/src/angularjs/channel/hippoIframe/overlay/overlay.service.spec.js
+++ 
b/frontend-ng/src/angularjs/channel/hippoIframe/overlay/overlay.service.spec.js
@@ -54,14 +54,18 @@ describe('OverlayService', () => {
 
     
jasmine.getFixtures().load('channel/hippoIframe/overlay/overlay.service.fixture.html');
     $iframe = $('.iframe');
+
+    // initialize the overlay service only once per test so there is only one 
MutationObserver
+    // (otherwise multiple MutationObservers will react on each other's 
changes and crash the browser)
+    OverlayService.init($iframe);
   });
 
   function loadIframeFixture(callback) {
-    OverlayService.init($iframe);
     $iframe.one('load', () => {
       iframeWindow = $iframe[0].contentWindow;
       DomService.addCss(iframeWindow, hippoIframeCss);
       try {
+        PageStructureService.clearParsedElements();
         hstCommentsProcessorService.run(
           iframeWindow.document,
           PageStructureService.registerParsedElement.bind(PageStructureService)
@@ -93,7 +97,8 @@ describe('OverlayService', () => {
   });
 
   it('attaches an unload handler to the iframe', (done) => {
-    spyOn(OverlayService, '_onUnload');
+    // call through so the mutation observer is disconnected before the second 
one is started
+    spyOn(OverlayService, '_onUnload').and.callThrough();
     loadIframeFixture(() => {
       // load URL again to cause unload
       loadIframeFixture(() => {



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/e77a9adfacc923f56bcfee8f7703654e609f61fd
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to