Skip to content

Commit

Permalink
Migrate missing block tests to Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Jun 12, 2022
1 parent 3527348 commit 078d9eb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 44 deletions.
44 changes: 0 additions & 44 deletions packages/e2e-tests/specs/editor/blocks/missing.test.js

This file was deleted.

54 changes: 54 additions & 0 deletions test/e2e/specs/editor/blocks/missing.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'missing block', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test( 'should strip potentially malicious on* attributes', async ( {
page,
} ) => {
let hasAlert = false;

page.on( 'dialog', () => {
hasAlert = true;
} );

await page.evaluate( () => {
const block = window.wp.blocks.parse(
`<!-- wp:non-existing-block-here --><img src onerror=alert(1)>`
);
window.wp.data.dispatch( 'core/block-editor' ).resetBlocks( block );
} );

// Give the browser time to show the alert.
await page.evaluate( () => new Promise( window.requestIdleCallback ) );

expect( hasAlert ).toBe( false );
} );

test( 'should strip potentially malicious script tags', async ( {
page,
} ) => {
let hasAlert = false;

page.on( 'dialog', () => {
hasAlert = true;
} );

await page.evaluate( () => {
const block = window.wp.blocks.parse(
`<!-- wp:non-existing-block-here --><script>alert("EVIL");</script>`
);
window.wp.data.dispatch( 'core/block-editor' ).resetBlocks( block );
} );

// Give the browser time to show the alert.
await page.evaluate( () => new Promise( window.requestIdleCallback ) );

expect( hasAlert ).toBe( false );
} );
} );

0 comments on commit 078d9eb

Please sign in to comment.