Best JavaScript code snippet using wpt
FileSystemBaseHandle-postMessage-Error.js
Source:FileSystemBaseHandle-postMessage-Error.js
...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);...
Using AI Code Generation
1do_send_and_receive_message_error_test(2);3function do_send_and_receive_message_error_test(4) {5 do_send_message(send_message_1);6 do_check_eq(do_receive_message(receive_message_1), expected_message_1);7 do_send_message(send_message_2);8 do_check_eq(do_receive_message(receive_message_2), expected_message_2);9}10function do_send_message(message) {11 sendAsyncMessage(message);12}13function do_receive_message(message) {14 return receiveMessage(message).json;15}16function receiveMessage(message) {17 return receiveMessage(message);18}19function do_check_eq(actual, expected) {20 if (actual !== expected) {21 throw new Error("Expected " + expected + ", got " + actual);22 }23}24function do_check_true(actual) {25 if (!actual) {26 throw new Error("Expected true, got " + actual);27 }28}29function do_check_false(actual) {30 if (actual) {31 throw new Error("Expected false, got " + actual);32 }33}34function do_check_neq(actual, expected) {35 if (actual === expected) {36 throw new Error("Expected " + expected + ", got " + actual);37 }38}39function do_check_null(actual) {40 if (actual !== null) {41 throw new Error("Expected null, got " + actual);42 }43}44function do_check_notnull(actual) {45 if (actual === null) {46 throw new Error("Expected not null, got " + actual);47 }48}49function do_check_undefined(actual) {50 if (actual !== undefined) {51 throw new Error("Expected undefined, got " + actual);52 }53}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!