How to use do_send_message_error_test method in wpt

Best JavaScript code snippet using wpt

FileSystemBaseHandle-postMessage-Error.js

Source:FileSystemBaseHandle-postMessage-Error.js Github

copy

Full Screen

...15//16// This test sends a FileSystemHandle to |target|. |target| responds with a17// serialized MessageEvent from the 'messageerror' event, allowing the test18// runner to verify MessageEvent properties.19async function do_send_message_error_test(20 test,21 root_dir,22 receiver,23 target,24 target_origin,25 // False when the MessageEvent's source is null.26 expected_has_source,27 // The origin of MessageEvents received by |target|.28 expected_origin) {29 const message_watcher = new EventWatcher(test, receiver, 'message');30 // Send a file to |target|.31 const file = await createFileWithContents(32 test, 'test-error-file', 'test-error-file-contents', root_dir);33 target.postMessage(34 { type: 'receive-file-system-handles', cloned_file_system_handles: [file] },35 { targetOrigin: target_origin });36 // Wait for |target| to respond with results.37 let message_event = await message_watcher.wait_for('message');38 const first_response = message_event.data;39 assert_equals(first_response.type, 'serialized-message-error',40 'The test runner must receive a "serialized-message-error" message ' +41 'in response to a FileSystemFileHandle message.');42 // Verify the results.43 assert_equals_serialized_message_error_event(44 first_response.serialized_message_error_event,45 expected_origin, expected_has_source);46 // Send a directory to |target|.47 const directory = await createDirectory(48 test, 'test-error-directory', root_dir);49 target.postMessage(50 {51 type: 'receive-file-system-handles',52 cloned_file_system_handles: [directory]53 }, { targetOrigin: target_origin });54 // Wait for |target| to respond with results.55 message_event = await message_watcher.wait_for('message');56 const second_response = message_event.data;57 assert_equals(second_response.type, 'serialized-message-error',58 'The test runner must receive a "serialized-message-error" message ' +59 'response to a FileSystemDirectoryHandle message.');60 // Verify the results.61 assert_equals_serialized_message_error_event(62 second_response.serialized_message_error_event,63 expected_origin, expected_has_source);64}65// This test receives a FileSystemHandle from |target|. This test runner66// must dispatch the 'messageerror' event after receiving a handle from target.67async function do_receive_message_error_test(68 test,69 receiver,70 target,71 target_origin,72 // False when the MessageEvent's source is null.73 expected_has_source,74 // The origin of MessageEvents received by this test runner.75 expected_origin) {76 const error_watcher = new EventWatcher(test, receiver, 'messageerror');77 // Receive a file from |target|.78 target.postMessage(79 { type: 'create-file' }, { targetOrigin: target_origin });80 const first_error = await error_watcher.wait_for('messageerror');81 const serialized_first_error = serialize_message_error_event(first_error);82 assert_equals_serialized_message_error_event(83 serialized_first_error, expected_origin, expected_has_source);84 // Receive a directory from |target|.85 target.postMessage(86 { type: 'create-directory' }, { targetOrigin: target_origin });87 const second_error = await error_watcher.wait_for('messageerror');88 const serialized_second_error = serialize_message_error_event(second_error);89 assert_equals_serialized_message_error_event(90 serialized_second_error, expected_origin, expected_has_source);91}92// Performs the send message error test followed by the receive message error93// test.94async function do_send_and_receive_message_error_test(95 test,96 root_dir,97 receiver,98 target,99 target_origin,100 // False when the MessageEvent's source is null.101 expected_has_source,102 // The origin of MessageEvents received by |target|.103 expected_origin,104 // The origin of MessageEvents received by this test runner.105 expected_remote_origin) {106 await do_send_message_error_test(107 test, root_dir, receiver, target, target_origin, expected_has_source,108 expected_origin);109 await do_receive_message_error_test(110 test, receiver, target, target_origin, expected_has_source,111 expected_remote_origin);112}113// Runs the same test as do_send_message_error_test(), but uses a MessagePort.114// This test starts by establishing a message channel between the test runner115// and |target|.116async function do_send_message_port_error_test(117 test, root_dir, target, target_origin) {118 const message_port = create_message_channel(target, target_origin);119 await do_send_message_error_test(120 test, root_dir, /*receiver=*/message_port, /*target=*/message_port,121 /*target_origin=*/undefined, /*expected_has_source=*/false,122 /*expected_origin=*/'', /*expected_remote_origin=*/'');123}124// Runs the same test as do_receive_message_error_test(), but uses a MessagePort.125async function do_receive_message_port_error_test(126 test, target, target_origin) {127 const message_port = create_message_channel(target, target_origin);128 await do_receive_message_error_test(129 test, /*receiver=*/message_port, /*target=*/message_port,130 /*target_origin=*/undefined, /*expected_has_source=*/false,131 /*expected_origin=*/'');132}133// Runs the same test as do_send_and_receive_message_error_test(), but uses a134// MessagePort.135async function do_send_and_receive_message_port_error_test(136 test, root_dir, target, target_origin) {137 await do_send_message_port_error_test(138 test, root_dir, target, target_origin);139 await do_receive_message_port_error_test(140 test, target, target_origin);141}142directory_test(async (t, root_dir) => {143 const iframe = await add_iframe(144 t, { src: kRemoteOriginDocumentMessageTarget });145 await do_send_and_receive_message_error_test(146 t, root_dir, /*receiver=*/self, /*target=*/iframe.contentWindow,147 /*target_origin=*/'*', /*expected_has_source=*/true,148 /*expected_origin=*/location.origin,149 /*expected_remote_origin=*/kRemoteOrigin);150}, 'Fail to send and receive messages using a cross origin iframe.');151directory_test(async (t, root_dir) => {152 const iframe = await add_iframe(t, { src: kRemoteOriginDocumentMessageTarget });153 await do_send_and_receive_message_port_error_test(154 t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');155}, 'Fail to send and receive messages using a cross origin message port in ' +156'an iframe.');157directory_test(async (t, root_dir) => {158 const iframe = await add_iframe(159 t, { src: kDocumentMessageTarget, sandbox: 'allow-scripts' });160 await do_send_message_error_test(161 t, root_dir, /*receiver=*/self, /*target=*/iframe.contentWindow,162 /*target_origin=*/'*', /*expected_has_source*/true,163 /*expected_origin=*/location.origin);164}, 'Fail to send to a sandboxed iframe.');165directory_test(async (t, root_dir) => {166 const iframe = await add_iframe(167 t, { src: kDocumentMessageTarget, sandbox: 'allow-scripts' });168 await do_send_message_port_error_test(169 t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');170}, 'Fail to send messages using a message port to a sandboxed ' +171'iframe.');172directory_test(async (t, root_dir) => {173 const iframe_data_uri = await create_message_target_data_uri(t);174 const iframe = await add_iframe(t, { src: iframe_data_uri });175 await do_send_message_error_test(t, root_dir, /*receiver=*/self,176 /*target=*/iframe.contentWindow, /*target_origin=*/'*',177 /*expected_has_source*/true, /*expected_origin=*/location.origin);178 // Do not test receiving FileSystemHandles from the data URI iframe. Data URI179 // iframes are insecure and do not expose the File System Access APIs.180}, 'Fail to send messages to a data URI iframe.');181directory_test(async (t, root_dir) => {182 const iframe_data_uri = await create_message_target_data_uri(t);183 const iframe = await add_iframe(t, { src: iframe_data_uri });184 await do_send_message_port_error_test(185 t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');186}, 'Fail to send messages using a message port in a data URI iframe.');187directory_test(async (t, root_dir) => {188 const child_window = await open_window(t, kRemoteOriginDocumentMessageTarget);189 await do_send_and_receive_message_error_test(190 t, root_dir, /*receiver=*/self, /*target=*/child_window, /*target_origin=*/'*',191 /*expected_has_source=*/true, /*expected_origin=*/location.origin,192 /*expected_remote_origin=*/kRemoteOrigin);193}, 'Fail to send and receive messages using a cross origin window.');194directory_test(async (t, root_dir) => {195 const child_window = await open_window(t, kRemoteOriginDocumentMessageTarget);196 await do_send_message_port_error_test(197 t, root_dir, /*target=*/child_window, /*target_origin=*/'*');198}, 'Fail to send and receive messages using a cross origin message port in ' +199'a window.');200directory_test(async (t, root_dir) => {201 const url = `${kDocumentMessageTarget}?pipe=header(Content-Security-Policy` +202 ', sandbox allow-scripts)';203 const child_window = await open_window(t, url);204 await do_send_message_error_test(205 t, root_dir, /*receiver=*/self, /*target=*/child_window,206 /*target_origin=*/'*', /*expected_has_source*/true,207 /*expected_origin=*/location.origin);208}, 'Fail to send messages to a sandboxed window.');209directory_test(async (t, root_dir) => {210 const url = `${kDocumentMessageTarget}?pipe=header(Content-Security-Policy` +211 ', sandbox allow-scripts)';212 const child_window = await open_window(t, url);213 await do_send_message_port_error_test(214 t, root_dir, /*target=*/child_window, /*target_origin=*/'*');215}, 'Fail to send messages using a message port to a sandboxed ' +...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful