8
0

mutationobserver.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import View from '../../../src/view/view';
  7. import MutationObserver from '../../../src/view/observer/mutationobserver';
  8. import UIElement from '../../../src/view/uielement';
  9. import createViewRoot from '../_utils/createroot';
  10. import { parse } from '../../../src/dev-utils/view';
  11. describe( 'MutationObserver', () => {
  12. let view, domEditor, viewDocument, viewRoot, mutationObserver, lastMutations, domRoot;
  13. beforeEach( () => {
  14. domRoot = document.createElement( 'div' );
  15. domRoot.innerHTML = '<div contenteditable="true" id="main"></div><div contenteditable="true" id="additional"></div>';
  16. document.body.appendChild( domRoot );
  17. view = new View();
  18. viewDocument = view.document;
  19. domEditor = document.getElementById( 'main' );
  20. lastMutations = null;
  21. createViewRoot( viewDocument );
  22. view.attachDomRoot( domEditor );
  23. viewDocument.selection._setTo( null );
  24. document.getSelection().removeAllRanges();
  25. mutationObserver = view.getObserver( MutationObserver );
  26. viewDocument.on( 'mutations', ( evt, mutations ) => {
  27. lastMutations = mutations;
  28. } );
  29. viewRoot = viewDocument.getRoot();
  30. viewRoot.appendChildren( parse( '<container:p>foo</container:p><container:p>bar</container:p>' ) );
  31. view.render();
  32. } );
  33. afterEach( () => {
  34. mutationObserver.disable();
  35. domRoot.parentElement.removeChild( domRoot );
  36. view.destroy();
  37. } );
  38. it( 'should handle typing', () => {
  39. domEditor.childNodes[ 0 ].childNodes[ 0 ].data = 'foom';
  40. mutationObserver.flush();
  41. expectDomEditorNotToChange();
  42. expect( lastMutations.length ).to.equal( 1 );
  43. expect( lastMutations[ 0 ].type ).to.equal( 'text' );
  44. expect( lastMutations[ 0 ].node ).to.equal( viewRoot.getChild( 0 ).getChild( 0 ) );
  45. expect( lastMutations[ 0 ].newText ).to.equal( 'foom' );
  46. expect( lastMutations[ 0 ].oldText ).to.equal( 'foo' );
  47. } );
  48. it( 'should not observe if disabled', () => {
  49. const additional = document.getElementById( 'additional' );
  50. mutationObserver.disable();
  51. createViewRoot( viewDocument, 'div', 'additional' );
  52. view.attachDomRoot( additional, 'additional' );
  53. additional.textContent = 'foobar';
  54. mutationObserver.flush();
  55. expect( lastMutations ).to.be.null;
  56. } );
  57. it( 'should handle bold', () => {
  58. domEditor.childNodes[ 0 ].childNodes[ 0 ].data = 'f';
  59. const domB = document.createElement( 'b' );
  60. domB.appendChild( document.createTextNode( 'oo' ) );
  61. domEditor.childNodes[ 0 ].appendChild( domB );
  62. mutationObserver.flush();
  63. expectDomEditorNotToChange();
  64. expect( lastMutations.length ).to.equal( 1 );
  65. expect( lastMutations[ 0 ].type ).to.equal( 'children' );
  66. expect( lastMutations[ 0 ].node ).to.equal( viewRoot.getChild( 0 ) );
  67. expect( lastMutations[ 0 ].newChildren.length ).to.equal( 2 );
  68. expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( 'f' );
  69. expect( lastMutations[ 0 ].newChildren[ 1 ].name ).to.equal( 'b' );
  70. expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 1 );
  71. expect( lastMutations[ 0 ].oldChildren[ 0 ].data ).to.equal( 'foo' );
  72. } );
  73. it( 'should handle unbold', () => {
  74. viewRoot.removeChildren( 0, viewRoot.childCount );
  75. viewRoot.appendChildren( parse( '<container:p><attribute:b>foo</attribute:b></container:p>' ) );
  76. view.render();
  77. const domP = domEditor.childNodes[ 0 ];
  78. const domB = domP.childNodes[ 0 ];
  79. domP.removeChild( domB );
  80. domP.appendChild( document.createTextNode( 'foo' ) );
  81. mutationObserver.flush();
  82. // "expectDomEditorNotToChange()".
  83. expect( domEditor.childNodes.length ).to.equal( 1 );
  84. expect( domEditor.childNodes[ 0 ].tagName ).to.equal( 'P' );
  85. expect( domEditor.childNodes[ 0 ].childNodes.length ).to.equal( 1 );
  86. expect( domEditor.childNodes[ 0 ].childNodes[ 0 ].tagName ).to.equal( 'B' );
  87. expect( domEditor.childNodes[ 0 ].childNodes[ 0 ].childNodes.length ).to.equal( 1 );
  88. expect( domEditor.childNodes[ 0 ].childNodes[ 0 ].childNodes[ 0 ].data ).to.equal( 'foo' );
  89. // Check mutations.
  90. expect( lastMutations.length ).to.equal( 1 );
  91. expect( lastMutations[ 0 ].type ).to.equal( 'children' );
  92. expect( lastMutations[ 0 ].node ).to.equal( viewRoot.getChild( 0 ) );
  93. expect( lastMutations[ 0 ].newChildren.length ).to.equal( 1 );
  94. expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( 'foo' );
  95. expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 1 );
  96. expect( lastMutations[ 0 ].oldChildren[ 0 ].name ).to.equal( 'b' );
  97. } );
  98. it( 'should deduplicate text changes', () => {
  99. domEditor.childNodes[ 0 ].childNodes[ 0 ].data = 'foox';
  100. domEditor.childNodes[ 0 ].childNodes[ 0 ].data = 'fooxy';
  101. mutationObserver.flush();
  102. expectDomEditorNotToChange();
  103. expect( lastMutations.length ).to.equal( 1 );
  104. expect( lastMutations[ 0 ].type ).to.equal( 'text' );
  105. expect( lastMutations[ 0 ].node ).to.equal( viewRoot.getChild( 0 ).getChild( 0 ) );
  106. expect( lastMutations[ 0 ].newText ).to.equal( 'fooxy' );
  107. expect( lastMutations[ 0 ].oldText ).to.equal( 'foo' );
  108. } );
  109. it( 'should ignore changes in elements not attached to tree view', () => {
  110. const domP = document.createElement( 'p' );
  111. const domB = document.createElement( 'b' );
  112. const domText = document.createTextNode( 'bom' );
  113. domEditor.appendChild( domP );
  114. domP.appendChild( domB );
  115. domB.appendChild( domText );
  116. mutationObserver.flush();
  117. expectDomEditorNotToChange();
  118. expect( lastMutations.length ).to.equal( 1 );
  119. expect( lastMutations[ 0 ].type ).to.equal( 'children' );
  120. expect( lastMutations[ 0 ].node ).to.equal( viewRoot );
  121. } );
  122. it( 'should fire mutations event with view selection instance, if dom selection can be mapped to view', done => {
  123. const textNode = domEditor.childNodes[ 0 ].childNodes[ 0 ];
  124. textNode.data = 'foom';
  125. const domSelection = document.getSelection();
  126. domSelection.collapse( textNode, 4 );
  127. viewDocument.on( 'mutations', ( evt, viewMutations, viewSelection ) => {
  128. expect( viewSelection.anchor.parent ).to.equal( viewRoot.getChild( 0 ).getChild( 0 ) );
  129. expect( viewSelection.anchor.offset ).to.equal( 4 );
  130. done();
  131. } );
  132. mutationObserver.flush();
  133. expectDomEditorNotToChange();
  134. } );
  135. it( 'should fire mutations event with viewSelection param set to null, if dom selection cannot be mapped to view', done => {
  136. const textNode = domEditor.ownerDocument.createTextNode( 'foo' );
  137. domEditor.childNodes[ 0 ].appendChild( textNode );
  138. const domSelection = document.getSelection();
  139. domSelection.collapse( textNode, 3 );
  140. viewDocument.on( 'mutations', ( evt, viewMutations, viewSelection ) => {
  141. expect( viewSelection ).to.be.null;
  142. done();
  143. } );
  144. mutationObserver.flush();
  145. expectDomEditorNotToChange();
  146. } );
  147. it( 'should be able to observe multiple roots', () => {
  148. const domAdditionalEditor = document.getElementById( 'additional' );
  149. // Prepare AdditionalEditor
  150. createViewRoot( viewDocument, 'div', 'additional' );
  151. view.attachDomRoot( domAdditionalEditor, 'additional' );
  152. viewDocument.getRoot( 'additional' ).appendChildren(
  153. parse( '<container:p>foo</container:p><container:p>bar</container:p>' ) );
  154. // Render AdditionalEditor (first editor has been rendered in the beforeEach function)
  155. view.render();
  156. domEditor.childNodes[ 0 ].childNodes[ 0 ].data = 'foom';
  157. domAdditionalEditor.childNodes[ 0 ].childNodes[ 0 ].data = 'foom';
  158. mutationObserver.flush();
  159. expect( lastMutations.length ).to.equal( 2 );
  160. } );
  161. it( 'should fire nothing if there were no mutations', () => {
  162. mutationObserver.flush();
  163. expectDomEditorNotToChange();
  164. expect( lastMutations ).to.be.null;
  165. } );
  166. it( 'should fire children mutation if the mutation occurred in the inline filler', () => {
  167. const { view: viewContainer, selection } = parse( '<container:p>foo<attribute:b>[]</attribute:b>bar</container:p>' );
  168. view.change( writer => {
  169. viewRoot.appendChildren( viewContainer );
  170. writer.setSelection( selection );
  171. } );
  172. const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 1 ].childNodes[ 0 ];
  173. inlineFiller.data += 'x';
  174. mutationObserver.flush();
  175. expect( lastMutations.length ).to.equal( 1 );
  176. expect( lastMutations[ 0 ].type ).to.equal( 'children' );
  177. expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent );
  178. } );
  179. it( 'should have no inline filler in mutation', () => {
  180. const { view: viewContainer, selection } = parse( '<container:p>foo<attribute:b>[]</attribute:b>bar</container:p>' );
  181. view.change( writer => {
  182. viewRoot.appendChildren( viewContainer );
  183. writer.setSelection( selection );
  184. } );
  185. let inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 1 ].childNodes[ 0 ];
  186. inlineFiller.data += 'x';
  187. view.change( () => {
  188. viewContainer.getChild( 1 ).appendChildren( parse( 'x' ) );
  189. mutationObserver.flush();
  190. } );
  191. inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 1 ].childNodes[ 0 ];
  192. inlineFiller.data += 'y';
  193. mutationObserver.flush();
  194. expect( lastMutations.length ).to.equal( 1 );
  195. expect( lastMutations[ 0 ].type ).to.equal( 'text' );
  196. expect( lastMutations[ 0 ].oldText ).to.equal( 'x' );
  197. expect( lastMutations[ 0 ].newText ).to.equal( 'xy' );
  198. } );
  199. // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 1.
  200. it( 'should handle space after inline filler at the end of container', () => {
  201. const { view: viewContainer, selection } = parse(
  202. '<container:p>' +
  203. 'foo' +
  204. '<attribute:b>[]</attribute:b>' +
  205. '</container:p>'
  206. );
  207. view.change( writer => {
  208. viewRoot.appendChildren( viewContainer );
  209. writer.setSelection( selection );
  210. } );
  211. // Appended container is third in the tree.
  212. const container = domEditor.childNodes[ 2 ];
  213. const inlineFiller = container.childNodes[ 1 ].childNodes[ 0 ];
  214. inlineFiller.data += ' ';
  215. mutationObserver.flush();
  216. expect( lastMutations.length ).to.equal( 1 );
  217. expect( lastMutations[ 0 ].type ).to.equal( 'children' );
  218. expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 0 );
  219. expect( lastMutations[ 0 ].newChildren.length ).to.equal( 1 );
  220. expect( lastMutations[ 0 ].newChildren[ 0 ].is( 'text' ) ).to.be.true;
  221. expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( ' ' );
  222. expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent );
  223. } );
  224. // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 3.
  225. it( 'should handle space after inline filler at the end of container #2', () => {
  226. const { view: viewContainer, selection } = parse(
  227. '<container:p>' +
  228. 'foo' +
  229. '<attribute:b>bar</attribute:b>' +
  230. '[]' +
  231. '</container:p>'
  232. );
  233. view.change( writer => {
  234. viewRoot.appendChildren( viewContainer );
  235. writer.setSelection( selection );
  236. } );
  237. // Appended container is third in the tree.
  238. const container = domEditor.childNodes[ 2 ];
  239. const inlineFiller = container.childNodes[ 2 ];
  240. inlineFiller.data += ' ';
  241. mutationObserver.flush();
  242. expect( lastMutations.length ).to.equal( 1 );
  243. expect( lastMutations[ 0 ].type ).to.equal( 'children' );
  244. expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 2 );
  245. expect( lastMutations[ 0 ].newChildren.length ).to.equal( 3 );
  246. // Foo and attribute is removed and reinserted.
  247. expect( lastMutations[ 0 ].oldChildren[ 0 ].is( 'text' ) ).to.be.true;
  248. expect( lastMutations[ 0 ].oldChildren[ 0 ].data ).to.equal( 'foo' );
  249. expect( lastMutations[ 0 ].newChildren[ 0 ].is( 'text' ) ).to.be.true;
  250. expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( 'foo' );
  251. expect( lastMutations[ 0 ].oldChildren[ 1 ].is( 'attributeElement' ) ).to.be.true;
  252. expect( lastMutations[ 0 ].oldChildren[ 1 ].name ).to.equal( 'b' );
  253. expect( lastMutations[ 0 ].newChildren[ 1 ].is( 'attributeElement' ) ).to.be.true;
  254. expect( lastMutations[ 0 ].newChildren[ 1 ].name ).to.equal( 'b' );
  255. expect( lastMutations[ 0 ].newChildren[ 2 ].is( 'text' ) ).to.be.true;
  256. expect( lastMutations[ 0 ].newChildren[ 2 ].data ).to.equal( ' ' );
  257. expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent );
  258. } );
  259. // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 2.
  260. it( 'should handle space after inline filler at the beginning of container', () => {
  261. const { view: viewContainer, selection } = parse(
  262. '<container:p>' +
  263. '<attribute:b>[]</attribute:b>' +
  264. 'foo' +
  265. '</container:p>'
  266. );
  267. view.change( writer => {
  268. viewRoot.appendChildren( viewContainer );
  269. writer.setSelection( selection );
  270. } );
  271. // Appended container is third in the tree.
  272. const container = domEditor.childNodes[ 2 ];
  273. const inlineFiller = container.childNodes[ 0 ].childNodes[ 0 ];
  274. inlineFiller.data += ' ';
  275. mutationObserver.flush();
  276. expect( lastMutations.length ).to.equal( 1 );
  277. expect( lastMutations[ 0 ].type ).to.equal( 'children' );
  278. expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 0 );
  279. expect( lastMutations[ 0 ].newChildren.length ).to.equal( 1 );
  280. expect( lastMutations[ 0 ].newChildren[ 0 ].is( 'text' ) ).to.be.true;
  281. expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( ' ' );
  282. expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent );
  283. } );
  284. it( 'should have no block filler in mutation', () => {
  285. viewRoot.appendChildren( parse( '<container:p></container:p>' ) );
  286. view.render();
  287. const domP = domEditor.childNodes[ 2 ];
  288. domP.removeChild( domP.childNodes[ 0 ] );
  289. domP.appendChild( document.createTextNode( 'foo' ) );
  290. mutationObserver.flush();
  291. expect( lastMutations.length ).to.equal( 1 );
  292. expect( lastMutations[ 0 ].newChildren.length ).to.equal( 1 );
  293. expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( 'foo' );
  294. expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 0 );
  295. } );
  296. it( 'should ignore mutation with bogus br inserted on the end of the empty paragraph', () => {
  297. viewRoot.appendChildren( parse( '<container:p></container:p>' ) );
  298. view.render();
  299. const domP = domEditor.childNodes[ 2 ];
  300. domP.appendChild( document.createElement( 'br' ) );
  301. mutationObserver.flush();
  302. expect( lastMutations.length ).to.equal( 0 );
  303. } );
  304. it( 'should ignore mutation with bogus br inserted on the end of the paragraph with text', () => {
  305. viewRoot.appendChildren( parse( '<container:p>foo</container:p>' ) );
  306. view.render();
  307. const domP = domEditor.childNodes[ 2 ];
  308. domP.appendChild( document.createElement( 'br' ) );
  309. mutationObserver.flush();
  310. expect( lastMutations.length ).to.equal( 0 );
  311. } );
  312. it( 'should ignore mutation with bogus br inserted on the end of the paragraph while processing text mutations', () => {
  313. viewRoot.appendChildren( parse( '<container:p>foo</container:p>' ) );
  314. view.render();
  315. const domP = domEditor.childNodes[ 2 ];
  316. domP.childNodes[ 0 ].data = 'foo ';
  317. domP.appendChild( document.createElement( 'br' ) );
  318. mutationObserver.flush();
  319. expect( lastMutations.length ).to.equal( 1 );
  320. expect( lastMutations[ 0 ].oldText ).to.equal( 'foo' );
  321. expect( lastMutations[ 0 ].newText ).to.equal( 'foo ' );
  322. } );
  323. it( 'should ignore child mutations which resulted in no changes – when element contains elements', () => {
  324. viewRoot.appendChildren( parse( '<container:p><container:x></container:x></container:p>' ) );
  325. view.render();
  326. const domP = domEditor.childNodes[ 2 ];
  327. const domY = document.createElement( 'y' );
  328. domP.appendChild( domY );
  329. domY.remove();
  330. mutationObserver.flush();
  331. expect( lastMutations.length ).to.equal( 0 );
  332. } );
  333. // This case is more tricky than the previous one because DOMConverter will return a different
  334. // instances of view text nodes every time it converts a DOM text node.
  335. it( 'should ignore child mutations which resulted in no changes – when element contains text nodes', () => {
  336. const domP = domEditor.childNodes[ 0 ];
  337. const domText = document.createTextNode( 'x' );
  338. domP.appendChild( domText );
  339. domText.remove();
  340. const domP2 = domEditor.childNodes[ 1 ];
  341. domP2.appendChild( document.createTextNode( 'x' ) );
  342. mutationObserver.flush();
  343. // There was only P2 change. P1 must be ignored.
  344. const viewP2 = viewRoot.getChild( 1 );
  345. expect( lastMutations.length ).to.equal( 1 );
  346. expect( lastMutations[ 0 ].node ).to.equal( viewP2 );
  347. } );
  348. it( 'should not ignore mutation with br inserted not on the end of the paragraph', () => {
  349. viewRoot.appendChildren( parse( '<container:p>foo</container:p>' ) );
  350. view.render();
  351. const domP = domEditor.childNodes[ 2 ];
  352. domP.insertBefore( document.createElement( 'br' ), domP.childNodes[ 0 ] );
  353. mutationObserver.flush();
  354. expect( lastMutations.length ).to.equal( 1 );
  355. expect( lastMutations[ 0 ].newChildren.length ).to.equal( 2 );
  356. expect( lastMutations[ 0 ].newChildren[ 0 ].name ).to.equal( 'br' );
  357. expect( lastMutations[ 0 ].newChildren[ 1 ].data ).to.equal( 'foo' );
  358. expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 1 );
  359. } );
  360. it( 'should not ignore mutation inserting element different than br on the end of the empty paragraph', () => {
  361. viewRoot.appendChildren( parse( '<container:p></container:p>' ) );
  362. view.render();
  363. const domP = domEditor.childNodes[ 2 ];
  364. domP.appendChild( document.createElement( 'span' ) );
  365. mutationObserver.flush();
  366. expect( lastMutations.length ).to.equal( 1 );
  367. expect( lastMutations[ 0 ].newChildren.length ).to.equal( 1 );
  368. expect( lastMutations[ 0 ].newChildren[ 0 ].name ).to.equal( 'span' );
  369. expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 0 );
  370. } );
  371. it( 'should not ignore mutation inserting element different than br on the end of the paragraph with text', () => {
  372. viewRoot.appendChildren( parse( '<container:p>foo</container:p>' ) );
  373. view.render();
  374. const domP = domEditor.childNodes[ 2 ];
  375. domP.appendChild( document.createElement( 'span' ) );
  376. mutationObserver.flush();
  377. expect( lastMutations.length ).to.equal( 1 );
  378. expect( lastMutations[ 0 ].newChildren.length ).to.equal( 2 );
  379. expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( 'foo' );
  380. expect( lastMutations[ 0 ].newChildren[ 1 ].name ).to.equal( 'span' );
  381. expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 1 );
  382. } );
  383. describe( 'UIElement integration', () => {
  384. function createUIElement( name ) {
  385. const element = new UIElement( name );
  386. element.render = function( domDocument ) {
  387. const root = this.toDomElement( domDocument );
  388. root.innerHTML = 'foo bar';
  389. return root;
  390. };
  391. return element;
  392. }
  393. beforeEach( () => {
  394. const uiElement = createUIElement( 'div' );
  395. viewRoot.appendChildren( uiElement );
  396. view.render();
  397. } );
  398. it( 'should not collect text mutations from UIElement', () => {
  399. domEditor.childNodes[ 2 ].childNodes[ 0 ].data = 'foom';
  400. mutationObserver.flush();
  401. expect( lastMutations.length ).to.equal( 0 );
  402. } );
  403. it( 'should not collect child mutations from UIElement', () => {
  404. const span = document.createElement( 'span' );
  405. domEditor.childNodes[ 2 ].appendChild( span );
  406. mutationObserver.flush();
  407. expect( lastMutations.length ).to.equal( 0 );
  408. } );
  409. } );
  410. function expectDomEditorNotToChange() {
  411. expect( domEditor.childNodes.length ).to.equal( 2 );
  412. expect( domEditor.childNodes[ 0 ].tagName ).to.equal( 'P' );
  413. expect( domEditor.childNodes[ 1 ].tagName ).to.equal( 'P' );
  414. expect( domEditor.childNodes[ 0 ].childNodes.length ).to.equal( 1 );
  415. expect( domEditor.childNodes[ 0 ].childNodes[ 0 ].data ).to.equal( 'foo' );
  416. expect( domEditor.childNodes[ 1 ].childNodes.length ).to.equal( 1 );
  417. expect( domEditor.childNodes[ 1 ].childNodes[ 0 ].data ).to.equal( 'bar' );
  418. }
  419. } );