Browse Source

Corrected view.DowncastWriter() tests.

Kamil Piechaczek 5 years ago
parent
commit
c809c76261

+ 13 - 13
packages/ckeditor5-engine/tests/view/downcastwriter/breakattributes.js

@@ -152,8 +152,8 @@ describe( 'DowncastWriter', () => {
 			}
 			}
 
 
 			it( 'should throw when range placed in two containers', () => {
 			it( 'should throw when range placed in two containers', () => {
-				const p1 = new ContainerElement( 'p' );
-				const p2 = new ContainerElement( 'p' );
+				const p1 = new ContainerElement( document, 'p' );
+				const p2 = new ContainerElement( document, 'p' );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
 					writer.breakAttributes( Range._createFromParentsAndOffsets( p1, 0, p2, 0 ) );
 					writer.breakAttributes( Range._createFromParentsAndOffsets( p1, 0, p2, 0 ) );
@@ -161,7 +161,7 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw when range has no parent container', () => {
 			it( 'should throw when range has no parent container', () => {
-				const el = new AttributeElement( 'b' );
+				const el = new AttributeElement( document, 'b' );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
 					writer.breakAttributes( Range._createFromParentsAndOffsets( el, 0, el, 0 ) );
 					writer.breakAttributes( Range._createFromParentsAndOffsets( el, 0, el, 0 ) );
@@ -241,8 +241,8 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw if breaking inside EmptyElement #1', () => {
 			it( 'should throw if breaking inside EmptyElement #1', () => {
-				const img = new EmptyElement( 'img' );
-				new ContainerElement( 'p', null, img ); // eslint-disable-line no-new
+				const img = new EmptyElement( document, 'img' );
+				new ContainerElement( document, 'p', null, img ); // eslint-disable-line no-new
 				const position = new Position( img, 0 );
 				const position = new Position( img, 0 );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
@@ -251,9 +251,9 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw if breaking inside EmptyElement #2', () => {
 			it( 'should throw if breaking inside EmptyElement #2', () => {
-				const img = new EmptyElement( 'img' );
-				const b = new AttributeElement( 'b' );
-				new ContainerElement( 'p', null, [ img, b ] ); // eslint-disable-line no-new
+				const img = new EmptyElement( document, 'img' );
+				const b = new AttributeElement( document, 'b' );
+				new ContainerElement( document, 'p', null, [ img, b ] ); // eslint-disable-line no-new
 				const range = Range._createFromParentsAndOffsets( img, 0, b, 0 );
 				const range = Range._createFromParentsAndOffsets( img, 0, b, 0 );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
@@ -262,8 +262,8 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw if breaking inside UIElement #1', () => {
 			it( 'should throw if breaking inside UIElement #1', () => {
-				const span = new UIElement( 'span' );
-				new ContainerElement( 'p', null, span ); // eslint-disable-line no-new
+				const span = new UIElement( document, 'span' );
+				new ContainerElement( document, 'p', null, span ); // eslint-disable-line no-new
 				const position = new Position( span, 0 );
 				const position = new Position( span, 0 );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
@@ -272,9 +272,9 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw if breaking inside UIElement #2', () => {
 			it( 'should throw if breaking inside UIElement #2', () => {
-				const span = new UIElement( 'span' );
-				const b = new AttributeElement( 'b' );
-				new ContainerElement( 'p', null, [ span, b ] ); // eslint-disable-line no-new
+				const span = new UIElement( document, 'span' );
+				const b = new AttributeElement( document, 'b' );
+				new ContainerElement( document, 'p', null, [ span, b ] ); // eslint-disable-line no-new
 				const range = Range._createFromParentsAndOffsets( span, 0, b, 0 );
 				const range = Range._createFromParentsAndOffsets( span, 0, b, 0 );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {

+ 4 - 3
packages/ckeditor5-engine/tests/view/downcastwriter/breakcontainer.js

@@ -13,7 +13,7 @@ import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_uti
 
 
 describe( 'DowncastWriter', () => {
 describe( 'DowncastWriter', () => {
 	describe( 'breakContainer()', () => {
 	describe( 'breakContainer()', () => {
-		let writer;
+		let writer, document;
 
 
 		// Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
 		// Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
 		// test break position.
 		// test break position.
@@ -28,7 +28,8 @@ describe( 'DowncastWriter', () => {
 		}
 		}
 
 
 		before( () => {
 		before( () => {
-			writer = new DowncastWriter( new Document() );
+			document = new Document();
+			writer = new DowncastWriter( document );
 		} );
 		} );
 
 
 		it( 'break inside element - should break container element at given position', () => {
 		it( 'break inside element - should break container element at given position', () => {
@@ -73,7 +74,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw if position parent is root', () => {
 		it( 'should throw if position parent is root', () => {
-			const element = new ContainerElement( 'div' );
+			const element = new ContainerElement( document, 'div' );
 			const position = Position._createAt( element, 0 );
 			const position = Position._createAt( element, 0 );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {

+ 15 - 15
packages/ckeditor5-engine/tests/view/downcastwriter/clear.js

@@ -37,8 +37,8 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw when range placed in two containers', () => {
 		it( 'should throw when range placed in two containers', () => {
-			const p1 = new ContainerElement( 'p' );
-			const p2 = new ContainerElement( 'p' );
+			const p1 = new ContainerElement( document, 'p' );
+			const p2 = new ContainerElement( document, 'p' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.clear( Range._createFromParentsAndOffsets( p1, 0, p2, 0 ) );
 				writer.clear( Range._createFromParentsAndOffsets( p1, 0, p2, 0 ) );
@@ -46,7 +46,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw when range has no parent container', () => {
 		it( 'should throw when range has no parent container', () => {
-			const el = new AttributeElement( 'b' );
+			const el = new AttributeElement( document, 'b' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.clear( Range._createFromParentsAndOffsets( el, 0, el, 0 ) );
 				writer.clear( Range._createFromParentsAndOffsets( el, 0, el, 0 ) );
@@ -54,7 +54,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove matched element from range', () => {
 		it( 'should remove matched element from range', () => {
-			const elementToRemove = new AttributeElement( 'b' );
+			const elementToRemove = new AttributeElement( document, 'b' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -64,7 +64,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove matched element from range when range is inside text node', () => {
 		it( 'should remove matched element from range when range is inside text node', () => {
-			const elementToRemove = new AttributeElement( 'b' );
+			const elementToRemove = new AttributeElement( document, 'b' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -74,7 +74,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove multiple matched elements from range', () => {
 		it( 'should remove multiple matched elements from range', () => {
-			const elementToRemove = new AttributeElement( 'b' );
+			const elementToRemove = new AttributeElement( document, 'b' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -84,7 +84,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove multiple matched elements from range when range is inside text node', () => {
 		it( 'should remove multiple matched elements from range when range is inside text node', () => {
-			const elementToRemove = new AttributeElement( 'b' );
+			const elementToRemove = new AttributeElement( document, 'b' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -94,7 +94,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove only matched element', () => {
 		it( 'should remove only matched element', () => {
-			const elementToRemove = new AttributeElement( 'b' );
+			const elementToRemove = new AttributeElement( document, 'b' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -104,7 +104,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove part of node when range ends inside this node', () => {
 		it( 'should remove part of node when range ends inside this node', () => {
-			const elementToRemove = new AttributeElement( 'b' );
+			const elementToRemove = new AttributeElement( document, 'b' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -114,7 +114,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove part of node when range starts inside this node', () => {
 		it( 'should remove part of node when range starts inside this node', () => {
-			const elementToRemove = new AttributeElement( 'b' );
+			const elementToRemove = new AttributeElement( document, 'b' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -124,7 +124,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove part of node when range starts and ends inside this node', () => {
 		it( 'should remove part of node when range starts and ends inside this node', () => {
-			const elementToRemove = new AttributeElement( 'b' );
+			const elementToRemove = new AttributeElement( document, 'b' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -134,7 +134,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should merge after removing', () => {
 		it( 'should merge after removing', () => {
-			const elementToRemove = new AttributeElement( 'b' );
+			const elementToRemove = new AttributeElement( document, 'b' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -146,7 +146,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove EmptyElement', () => {
 		it( 'should remove EmptyElement', () => {
-			const elementToRemove = new EmptyElement( 'img' );
+			const elementToRemove = new EmptyElement( document, 'img' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -156,7 +156,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove UIElement', () => {
 		it( 'should remove UIElement', () => {
-			const elementToRemove = new UIElement( 'span' );
+			const elementToRemove = new UIElement( document, 'span' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,
@@ -166,7 +166,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should remove ContainerElement', () => {
 		it( 'should remove ContainerElement', () => {
-			const elementToRemove = new ContainerElement( 'p' );
+			const elementToRemove = new ContainerElement( document, 'p' );
 
 
 			test(
 			test(
 				elementToRemove,
 				elementToRemove,

+ 13 - 13
packages/ckeditor5-engine/tests/view/downcastwriter/insert.js

@@ -155,8 +155,8 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw when inserting Element', () => {
 		it( 'should throw when inserting Element', () => {
-			const element = new Element( 'b' );
-			const container = new ContainerElement( 'p' );
+			const element = new Element( document, 'b' );
+			const container = new ContainerElement( document, 'p' );
 			const position = new Position( container, 0 );
 			const position = new Position( container, 0 );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
@@ -165,9 +165,9 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw when Element is inserted as child node', () => {
 		it( 'should throw when Element is inserted as child node', () => {
-			const element = new Element( 'b' );
-			const root = new ContainerElement( 'p', null, element );
-			const container = new ContainerElement( 'p' );
+			const element = new Element( document, 'b' );
+			const root = new ContainerElement( document, 'p', null, element );
+			const container = new ContainerElement( document, 'p' );
 			const position = new Position( container, 0 );
 			const position = new Position( container, 0 );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
@@ -176,9 +176,9 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw when position is not placed inside container', () => {
 		it( 'should throw when position is not placed inside container', () => {
-			const element = new Element( 'b' );
+			const element = new Element( document, 'b' );
 			const position = new Position( element, 0 );
 			const position = new Position( element, 0 );
-			const attributeElement = new AttributeElement( 'i' );
+			const attributeElement = new AttributeElement( document, 'i' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.insert( position, attributeElement );
 				writer.insert( position, attributeElement );
@@ -194,10 +194,10 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw if trying to insert inside EmptyElement', () => {
 		it( 'should throw if trying to insert inside EmptyElement', () => {
-			const emptyElement = new EmptyElement( 'img' );
-			new ContainerElement( 'p', null, emptyElement ); // eslint-disable-line no-new
+			const emptyElement = new EmptyElement( document, 'img' );
+			new ContainerElement( document, 'p', null, emptyElement ); // eslint-disable-line no-new
 			const position = new Position( emptyElement, 0 );
 			const position = new Position( emptyElement, 0 );
-			const attributeElement = new AttributeElement( 'i' );
+			const attributeElement = new AttributeElement( document, 'i' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.insert( position, attributeElement );
 				writer.insert( position, attributeElement );
@@ -205,10 +205,10 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw if trying to insert inside UIElement', () => {
 		it( 'should throw if trying to insert inside UIElement', () => {
-			const uiElement = new UIElement( 'span' );
-			new ContainerElement( 'p', null, uiElement ); // eslint-disable-line no-new
+			const uiElement = new UIElement( document, 'span' );
+			new ContainerElement( document, 'p', null, uiElement ); // eslint-disable-line no-new
 			const position = new Position( uiElement, 0 );
 			const position = new Position( uiElement, 0 );
-			const attributeElement = new AttributeElement( 'i' );
+			const attributeElement = new AttributeElement( document, 'i' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.insert( position, attributeElement );
 				writer.insert( position, attributeElement );

+ 6 - 5
packages/ckeditor5-engine/tests/view/downcastwriter/mergeattributes.js

@@ -12,7 +12,7 @@ import Document from '../../../src/view/document';
 
 
 describe( 'DowncastWriter', () => {
 describe( 'DowncastWriter', () => {
 	describe( 'mergeAttributes', () => {
 	describe( 'mergeAttributes', () => {
-		let writer;
+		let writer, document;
 
 
 		// Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
 		// Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
 		// test merge position.
 		// test merge position.
@@ -26,7 +26,8 @@ describe( 'DowncastWriter', () => {
 		}
 		}
 
 
 		before( () => {
 		before( () => {
-			writer = new DowncastWriter( new Document() );
+			document = new Document();
+			writer = new DowncastWriter( document );
 		} );
 		} );
 
 
 		it( 'should not merge if inside text node', () => {
 		it( 'should not merge if inside text node', () => {
@@ -63,9 +64,9 @@ describe( 'DowncastWriter', () => {
 
 
 		it( 'should merge when placed between two text nodes', () => {
 		it( 'should merge when placed between two text nodes', () => {
 			// <p>foobar</p> -> <p>foo|bar</p>
 			// <p>foobar</p> -> <p>foo|bar</p>
-			const t1 = new Text( 'foo' );
-			const t2 = new Text( 'bar' );
-			const p = new ContainerElement( 'p', null, [ t1, t2 ] );
+			const t1 = new Text( document, 'foo' );
+			const t2 = new Text( document, 'bar' );
+			const p = new ContainerElement( document, 'p', null, [ t1, t2 ] );
 			const position = new Position( p, 1 );
 			const position = new Position( p, 1 );
 
 
 			const newPosition = writer.mergeAttributes( position );
 			const newPosition = writer.mergeAttributes( position );

+ 16 - 15
packages/ckeditor5-engine/tests/view/downcastwriter/move.js

@@ -19,7 +19,7 @@ import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_uti
 
 
 describe( 'DowncastWriter', () => {
 describe( 'DowncastWriter', () => {
 	describe( 'move()', () => {
 	describe( 'move()', () => {
-		let writer;
+		let writer, document;
 
 
 		// Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
 		// Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
 		// test ranges.
 		// test ranges.
@@ -38,7 +38,8 @@ describe( 'DowncastWriter', () => {
 		}
 		}
 
 
 		before( () => {
 		before( () => {
-			writer = new DowncastWriter( new Document() );
+			document = new Document();
+			writer = new DowncastWriter( document );
 		} );
 		} );
 
 
 		it( 'should move single text node', () => {
 		it( 'should move single text node', () => {
@@ -148,12 +149,12 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw if trying to move to EmptyElement', () => {
 		it( 'should throw if trying to move to EmptyElement', () => {
-			const srcAttribute = new AttributeElement( 'b' );
-			const srcContainer = new ContainerElement( 'p', null, srcAttribute );
+			const srcAttribute = new AttributeElement( document, 'b' );
+			const srcContainer = new ContainerElement( document, 'p', null, srcAttribute );
 			const srcRange = Range._createFromParentsAndOffsets( srcContainer, 0, srcContainer, 1 );
 			const srcRange = Range._createFromParentsAndOffsets( srcContainer, 0, srcContainer, 1 );
 
 
-			const dstEmpty = new EmptyElement( 'img' );
-			new ContainerElement( 'p', null, dstEmpty ); // eslint-disable-line no-new
+			const dstEmpty = new EmptyElement( document, 'img' );
+			new ContainerElement( document, 'p', null, dstEmpty ); // eslint-disable-line no-new
 			const dstPosition = new Position( dstEmpty, 0 );
 			const dstPosition = new Position( dstEmpty, 0 );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
@@ -171,12 +172,12 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw if trying to move to UIElement', () => {
 		it( 'should throw if trying to move to UIElement', () => {
-			const srcAttribute = new AttributeElement( 'b' );
-			const srcContainer = new ContainerElement( 'p', null, srcAttribute );
+			const srcAttribute = new AttributeElement( document, 'b' );
+			const srcContainer = new ContainerElement( document, 'p', null, srcAttribute );
 			const srcRange = Range._createFromParentsAndOffsets( srcContainer, 0, srcContainer, 1 );
 			const srcRange = Range._createFromParentsAndOffsets( srcContainer, 0, srcContainer, 1 );
 
 
-			const dstUI = new UIElement( 'span' );
-			new ContainerElement( 'p', null, dstUI ); // eslint-disable-line no-new
+			const dstUI = new UIElement( document, 'span' );
+			new ContainerElement( document, 'p', null, dstUI ); // eslint-disable-line no-new
 			const dstPosition = new Position( dstUI, 0 );
 			const dstPosition = new Position( dstUI, 0 );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
@@ -187,16 +188,16 @@ describe( 'DowncastWriter', () => {
 		it( 'should not break marker mappings if marker element was split and the original element was removed', () => {
 		it( 'should not break marker mappings if marker element was split and the original element was removed', () => {
 			const mapper = new Mapper();
 			const mapper = new Mapper();
 
 
-			const srcContainer = new ContainerElement( 'p' );
-			const dstContainer = new ContainerElement( 'p' );
+			const srcContainer = new ContainerElement( document, 'p' );
+			const dstContainer = new ContainerElement( document, 'p' );
 
 
-			const root = new RootEditableElement( 'div' );
+			const root = new RootEditableElement( document, 'div' );
 			root._appendChild( [ srcContainer, dstContainer ] );
 			root._appendChild( [ srcContainer, dstContainer ] );
 
 
-			const attrElemA = new AttributeElement( 'span' );
+			const attrElemA = new AttributeElement( document, 'span' );
 			attrElemA._id = 'foo';
 			attrElemA._id = 'foo';
 
 
-			const attrElemB = new AttributeElement( 'span' );
+			const attrElemB = new AttributeElement( document, 'span' );
 			attrElemB._id = 'foo';
 			attrElemB._id = 'foo';
 
 
 			writer.insert( new Position( srcContainer, 0 ), [ attrElemA, attrElemB ] );
 			writer.insert( new Position( srcContainer, 0 ), [ attrElemA, attrElemB ] );

+ 11 - 11
packages/ckeditor5-engine/tests/view/downcastwriter/remove.js

@@ -43,8 +43,8 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw when range placed in two containers', () => {
 		it( 'should throw when range placed in two containers', () => {
-			const p1 = new ContainerElement( 'p' );
-			const p2 = new ContainerElement( 'p' );
+			const p1 = new ContainerElement( document, 'p' );
+			const p2 = new ContainerElement( document, 'p' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.remove( Range._createFromParentsAndOffsets( p1, 0, p2, 0 ) );
 				writer.remove( Range._createFromParentsAndOffsets( p1, 0, p2, 0 ) );
@@ -52,7 +52,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw when range has no parent container', () => {
 		it( 'should throw when range has no parent container', () => {
-			const el = new AttributeElement( 'b' );
+			const el = new AttributeElement( document, 'b' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.remove( Range._createFromParentsAndOffsets( el, 0, el, 0 ) );
 				writer.remove( Range._createFromParentsAndOffsets( el, 0, el, 0 ) );
@@ -60,7 +60,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should return empty DocumentFragment when range is collapsed', () => {
 		it( 'should return empty DocumentFragment when range is collapsed', () => {
-			const p = new ContainerElement( 'p' );
+			const p = new ContainerElement( document, 'p' );
 			const range = Range._createFromParentsAndOffsets( p, 0, p, 0 );
 			const range = Range._createFromParentsAndOffsets( p, 0, p, 0 );
 			const fragment = writer.remove( range );
 			const fragment = writer.remove( range );
 
 
@@ -130,9 +130,9 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw if range is placed inside EmptyElement', () => {
 		it( 'should throw if range is placed inside EmptyElement', () => {
-			const emptyElement = new EmptyElement( 'img' );
-			const attributeElement = new AttributeElement( 'b' );
-			new ContainerElement( 'p', null, [ emptyElement, attributeElement ] ); // eslint-disable-line no-new
+			const emptyElement = new EmptyElement( document, 'img' );
+			const attributeElement = new AttributeElement( document, 'b' );
+			new ContainerElement( document, 'p', null, [ emptyElement, attributeElement ] ); // eslint-disable-line no-new
 			const range = Range._createFromParentsAndOffsets( emptyElement, 0, attributeElement, 0 );
 			const range = Range._createFromParentsAndOffsets( emptyElement, 0, attributeElement, 0 );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
@@ -149,9 +149,9 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw if range is placed inside UIElement', () => {
 		it( 'should throw if range is placed inside UIElement', () => {
-			const uiElement = new UIElement( 'span' );
-			const attributeElement = new AttributeElement( 'b' );
-			new ContainerElement( 'p', null, [ uiElement, attributeElement ] ); // eslint-disable-line no-new
+			const uiElement = new UIElement( document, 'span' );
+			const attributeElement = new AttributeElement( document, 'b' );
+			new ContainerElement( document, 'p', null, [ uiElement, attributeElement ] ); // eslint-disable-line no-new
 			const range = Range._createFromParentsAndOffsets( uiElement, 0, attributeElement, 0 );
 			const range = Range._createFromParentsAndOffsets( uiElement, 0, attributeElement, 0 );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
@@ -201,7 +201,7 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw when item has no parent container', () => {
 		it( 'should throw when item has no parent container', () => {
-			const el = new AttributeElement( 'b' );
+			const el = new AttributeElement( document, 'b' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.remove( el );
 				writer.remove( el );

+ 13 - 13
packages/ckeditor5-engine/tests/view/downcastwriter/unwrap.js

@@ -55,12 +55,12 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw error when element is not instance of AttributeElement', () => {
 		it( 'should throw error when element is not instance of AttributeElement', () => {
-			const container = new ContainerElement( 'p', null, new AttributeElement( 'b', null, new Text( 'foo' ) ) );
+			const container = new ContainerElement( document, 'p', null, new AttributeElement( document, 'b', null, new Text( 'foo' ) ) );
 			const range = new Range(
 			const range = new Range(
 				new Position( container, 0 ),
 				new Position( container, 0 ),
 				new Position( container, 1 )
 				new Position( container, 1 )
 			);
 			);
-			const b = new Element( 'b' );
+			const b = new Element( document, 'b' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.unwrap( range, b );
 				writer.unwrap( range, b );
@@ -68,13 +68,13 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw error when range placed in two containers', () => {
 		it( 'should throw error when range placed in two containers', () => {
-			const container1 = new ContainerElement( 'p' );
-			const container2 = new ContainerElement( 'p' );
+			const container1 = new ContainerElement( document, 'p' );
+			const container2 = new ContainerElement( document, 'p' );
 			const range = new Range(
 			const range = new Range(
 				new Position( container1, 0 ),
 				new Position( container1, 0 ),
 				new Position( container2, 1 )
 				new Position( container2, 1 )
 			);
 			);
-			const b = new AttributeElement( 'b' );
+			const b = new AttributeElement( document, 'b' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.unwrap( range, b );
 				writer.unwrap( range, b );
@@ -82,8 +82,8 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw when range has no parent container', () => {
 		it( 'should throw when range has no parent container', () => {
-			const el = new AttributeElement( 'b' );
-			const b = new AttributeElement( 'b' );
+			const el = new AttributeElement( document, 'b' );
+			const b = new AttributeElement( document, 'b' );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
 				writer.unwrap( Range._createFromParentsAndOffsets( el, 0, el, 0 ), b );
 				writer.unwrap( Range._createFromParentsAndOffsets( el, 0, el, 0 ), b );
@@ -396,9 +396,9 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw if range is inside EmptyElement', () => {
 		it( 'should throw if range is inside EmptyElement', () => {
-			const empty = new EmptyElement( 'img' );
-			const attribute = new AttributeElement( 'b' );
-			const container = new ContainerElement( 'p', null, [ empty, attribute ] );
+			const empty = new EmptyElement( document, 'img' );
+			const attribute = new AttributeElement( document, 'b' );
+			const container = new ContainerElement( document, 'p', null, [ empty, attribute ] );
 			const range = Range._createFromParentsAndOffsets( empty, 0, container, 2 );
 			const range = Range._createFromParentsAndOffsets( empty, 0, container, 2 );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {
@@ -415,9 +415,9 @@ describe( 'DowncastWriter', () => {
 		} );
 		} );
 
 
 		it( 'should throw if range is placed inside UIElement', () => {
 		it( 'should throw if range is placed inside UIElement', () => {
-			const uiElement = new UIElement( 'span' );
-			const attribute = new AttributeElement( 'b' );
-			const container = new ContainerElement( 'p', null, [ uiElement, attribute ] );
+			const uiElement = new UIElement( document, 'span' );
+			const attribute = new AttributeElement( document, 'b' );
+			const container = new ContainerElement( document, 'p', null, [ uiElement, attribute ] );
 			const range = Range._createFromParentsAndOffsets( uiElement, 0, container, 2 );
 			const range = Range._createFromParentsAndOffsets( uiElement, 0, container, 2 );
 
 
 			expectToThrowCKEditorError( () => {
 			expectToThrowCKEditorError( () => {

+ 16 - 16
packages/ckeditor5-engine/tests/view/downcastwriter/wrap.js

@@ -62,12 +62,12 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw error when element is not instance of AttributeElement', () => {
 			it( 'should throw error when element is not instance of AttributeElement', () => {
-				const container = new ContainerElement( 'p', null, new Text( 'foo' ) );
+				const container = new ContainerElement( document, 'p', null, new Text( 'foo' ) );
 				const range = new Range(
 				const range = new Range(
 					new Position( container, 0 ),
 					new Position( container, 0 ),
 					new Position( container, 1 )
 					new Position( container, 1 )
 				);
 				);
-				const b = new Element( 'b' );
+				const b = new Element( document, 'b' );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
 					writer.wrap( range, b );
 					writer.wrap( range, b );
@@ -75,13 +75,13 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw error when range placed in two containers', () => {
 			it( 'should throw error when range placed in two containers', () => {
-				const container1 = new ContainerElement( 'p' );
-				const container2 = new ContainerElement( 'p' );
+				const container1 = new ContainerElement( document, 'p' );
+				const container2 = new ContainerElement( document, 'p' );
 				const range = new Range(
 				const range = new Range(
 					new Position( container1, 0 ),
 					new Position( container1, 0 ),
 					new Position( container2, 1 )
 					new Position( container2, 1 )
 				);
 				);
-				const b = new AttributeElement( 'b' );
+				const b = new AttributeElement( document, 'b' );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
 					writer.wrap( range, b );
 					writer.wrap( range, b );
@@ -89,8 +89,8 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw when range has no parent container', () => {
 			it( 'should throw when range has no parent container', () => {
-				const el = new AttributeElement( 'b' );
-				const b = new AttributeElement( 'b' );
+				const el = new AttributeElement( document, 'b' );
+				const b = new AttributeElement( document, 'b' );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
 					writer.wrap( Range._createFromParentsAndOffsets( el, 0, el, 0 ), b );
 					writer.wrap( Range._createFromParentsAndOffsets( el, 0, el, 0 ), b );
@@ -394,12 +394,12 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw if range is inside EmptyElement', () => {
 			it( 'should throw if range is inside EmptyElement', () => {
-				const emptyElement = new EmptyElement( 'img' );
-				const container = new ContainerElement( 'p', null, emptyElement );
+				const emptyElement = new EmptyElement( document, 'img' );
+				const container = new ContainerElement( document, 'p', null, emptyElement );
 				const range = Range._createFromParentsAndOffsets( emptyElement, 0, container, 1 );
 				const range = Range._createFromParentsAndOffsets( emptyElement, 0, container, 1 );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
-					writer.wrap( range, new AttributeElement( 'b' ) );
+					writer.wrap( range, new AttributeElement( document, 'b' ) );
 				}, 'view-writer-cannot-break-empty-element', document );
 				}, 'view-writer-cannot-break-empty-element', document );
 			} );
 			} );
 
 
@@ -412,12 +412,12 @@ describe( 'DowncastWriter', () => {
 			} );
 			} );
 
 
 			it( 'should throw if range is inside UIElement', () => {
 			it( 'should throw if range is inside UIElement', () => {
-				const uiElement = new UIElement( 'span' );
-				const container = new ContainerElement( 'p', null, uiElement );
+				const uiElement = new UIElement( document, 'span' );
+				const container = new ContainerElement( document, 'p', null, uiElement );
 				const range = Range._createFromParentsAndOffsets( uiElement, 0, container, 1 );
 				const range = Range._createFromParentsAndOffsets( uiElement, 0, container, 1 );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
-					writer.wrap( range, new AttributeElement( 'b' ) );
+					writer.wrap( range, new AttributeElement( document, 'b' ) );
 				}, 'view-writer-cannot-break-ui-element', document );
 				}, 'view-writer-cannot-break-ui-element', document );
 			} );
 			} );
 
 
@@ -543,15 +543,15 @@ describe( 'DowncastWriter', () => {
 				const newPosition = writer.wrap( selection.getFirstRange(), parse( wrapAttribute ) );
 				const newPosition = writer.wrap( selection.getFirstRange(), parse( wrapAttribute ) );
 
 
 				// Moving parsed elements to a document fragment so the view root is not shown in `stringify`.
 				// Moving parsed elements to a document fragment so the view root is not shown in `stringify`.
-				const viewChildren = new DocumentFragment( view.getChildren() );
+				const viewChildren = new DocumentFragment( viewDocument, view.getChildren() );
 
 
 				expect( stringify( viewChildren, newPosition, { showType: true, showPriority: true } ) ).to.equal( expected );
 				expect( stringify( viewChildren, newPosition, { showType: true, showPriority: true } ) ).to.equal( expected );
 			}
 			}
 
 
 			it( 'should throw error when element is not instance of AttributeElement', () => {
 			it( 'should throw error when element is not instance of AttributeElement', () => {
-				const container = new ContainerElement( 'p', null, new Text( 'foo' ) );
+				const container = new ContainerElement( document, 'p', null, new Text( 'foo' ) );
 				const position = new Position( container, 0 );
 				const position = new Position( container, 0 );
-				const b = new Element( 'b' );
+				const b = new Element( document, 'b' );
 
 
 				expectToThrowCKEditorError( () => {
 				expectToThrowCKEditorError( () => {
 					writer.wrap( new Range( position ), b );
 					writer.wrap( new Range( position ), b );