Best JavaScript code snippet using wpt
FileSystemBaseHandle-postMessage-Error.js
Source:FileSystemBaseHandle-postMessage-Error.js
...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 // https://crbug.com/1014248 Should sandboxed iframes expose the165 // NativeFileSystem?166 //167 // await do_receive_message_error_test(168 // t, /*receiver=*/self, /*target=*/iframe.contentWindow,169 // /*target_origin=*/'*', /*expected_has_source=*/true,170 // /*expected_origin=*/kRemoteOrigin);171}, 'Fail to send and receive messages using a sandboxed iframe.');172directory_test(async (t, root_dir) => {173 const iframe = await add_iframe(174 t, { src: kDocumentMessageTarget, sandbox: 'allow-scripts' });175 await do_send_message_port_error_test(176 t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');177 // https://crbug.com/1014248 Should sandboxed iframes expose the178 // NativeFileSystem?179 //180 // await do_receive_message_port_error_test(181 // t, /*target=*/iframe.contentWindow, /*target_origin=*/'*');182}, 'Fail to send and receive messages using a message port in a sandboxed ' +183'iframe.');184directory_test(async (t, root_dir) => {185 const iframe_data_uri = await create_message_target_data_uri(t);186 const iframe = await add_iframe(t, { src: iframe_data_uri });187 await do_send_message_error_test(t, root_dir, /*receiver=*/self,188 /*target=*/iframe.contentWindow, /*target_origin=*/'*',189 /*expected_has_source*/true, /*expected_origin=*/location.origin);190 // Do not test receiving FileSystemHandles from the data URI iframe.191 // Data URI iframes are insecure and do not expose the NativeFileSystem APIs.192}, 'Fail to send messages to a data URI iframe.');193directory_test(async (t, root_dir) => {194 const iframe_data_uri = await create_message_target_data_uri(t);195 const iframe = await add_iframe(t, { src: iframe_data_uri });196 await do_send_message_port_error_test(197 t, root_dir, /*target=*/iframe.contentWindow, /*target_origin=*/'*');198}, 'Fail to send messages using a message port in a data URI iframe.');199directory_test(async (t, root_dir) => {200 const child_window = await open_window(t, kRemoteOriginDocumentMessageTarget);201 await do_send_and_receive_message_error_test(202 t, root_dir, /*receiver=*/self, /*target=*/child_window, /*target_origin=*/'*',203 /*expected_has_source=*/true, /*expected_origin=*/location.origin,204 /*expected_remote_origin=*/kRemoteOrigin);205}, 'Fail to send and receive messages using a cross origin window.');206directory_test(async (t, root_dir) => {207 const child_window = await open_window(t, kRemoteOriginDocumentMessageTarget);208 await do_send_message_port_error_test(209 t, root_dir, /*target=*/child_window, /*target_origin=*/'*');210}, 'Fail to send and receive messages using a cross origin message port in ' +211'a window.');212directory_test(async (t, root_dir) => {213 const url = `${kDocumentMessageTarget}?pipe=header(Content-Security-Policy` +214 ', sandbox allow-scripts)';215 const child_window = await open_window(t, url);216 await do_send_message_error_test(217 t, root_dir, /*receiver=*/self, /*target=*/child_window,218 /*target_origin=*/'*', /*expected_has_source*/true,219 /*expected_origin=*/location.origin);220 // https://crbug.com/1014248 Should sandboxed windows expose the221 // NativeFileSystem?222 //223 // await do_receive_message_error_test(224 // t, /*receiver=*/self, /*target=*/child_window,225 // /*target_origin=*/'*', /*expected_has_source=*/true,226 // /*expected_origin=*/kRemoteOrigin);227}, 'Fail to send and receive messages using a sandboxed window.');228directory_test(async (t, root_dir) => {229 const url = `${kDocumentMessageTarget}?pipe=header(Content-Security-Policy` +230 ', sandbox allow-scripts)';231 const child_window = await open_window(t, url);232 await do_send_message_port_error_test(233 t, root_dir, /*target=*/child_window, /*target_origin=*/'*');234 // https://crbug.com/1014248 Should sandboxed windows expose the235 // NativeFileSystem?236 //237 // await do_receive_message_port_error_test(238 // t, /*target=*/child_window, /*target_origin=*/'*');239}, 'Fail to send and receive messages using a message port in a sandboxed ' +...
Using AI Code Generation
1do_receive_message_port_error_test();2do_post_message_port_error_test();3do_send_message_port_error_test();4do_receive_message_port_error_test();5do_post_message_port_error_test();6do_send_message_port_error_test();7do_receive_message_port_error_test();8do_post_message_port_error_test();9do_send_message_port_error_test();10do_receive_message_port_error_test();11do_post_message_port_error_test();12do_send_message_port_error_test();13do_receive_message_port_error_test();14do_post_message_port_error_test();15do_send_message_port_error_test();16do_receive_message_port_error_test();17do_post_message_port_error_test();18do_send_message_port_error_test();19do_receive_message_port_error_test();20do_post_message_port_error_test();21do_send_message_port_error_test();
Using AI Code Generation
1do_receive_message_port_error_test();2function do_receive_message_port_error_test() {3 var port = new MessagePort();4 var t = async_test();5 t.step(function() {6 assert_throws(new TypeError(), function() {7 port.postMessage();8 });9 t.done();10 });11}12function assert_throws(expected, func, description) {13 var actual;14 try {15 func();16 } catch (e) {17 actual = e;18 }19 if (actual === undefined) {20 throw new AssertionError(description, "Expected " + expected + " but no exception thrown");21 }22 if (!(actual instanceof expected)) {23 throw new AssertionError(description, "Expected " + expected + " but got " + actual);24 }25}26function async_test() {27 var t = new Test();28 t.step(function() {29 t.done();30 });31 return t;32}33function Test() {34 this.phase = 'test_start';35 this.steps = [];36 this.step_timeout = 5000;37 this.timeout_multiplier = 1;38 this.timeout_id = null;39 this.timeout_func = null;40 this.unreached_func = null;41 this.done_called = false;42 this.phase = 'test_start';43 this.steps = [];44 this.step_timeout = 5000;45 this.timeout_multiplier = 1;46 this.timeout_id = null;47 this.timeout_func = null;48 this.unreached_func = null;49 this.done_called = false;50 this.phase = 'test_start';51 this.steps = [];52 this.step_timeout = 5000;53 this.timeout_multiplier = 1;54 this.timeout_id = null;55 this.timeout_func = null;56 this.unreached_func = null;57 this.done_called = false;58 this.phase = 'test_start';59 this.steps = [];60 this.step_timeout = 5000;61 this.timeout_multiplier = 1;62 this.timeout_id = null;63 this.timeout_func = null;64 this.unreached_func = null;65 this.done_called = false;66 this.phase = 'test_start';67 this.steps = [];68 this.step_timeout = 5000;69 this.timeout_multiplier = 1;70 this.timeout_id = null;
Using AI Code Generation
1do_receive_message_port_error_test("message port error test", "message port error test");2do_receive_message_port_error_test("message port error test", "message port error test");3do_receive_message_port_error_test("message port error test", "message port error test");4do_receive_message_port_error_test("message port error test", "message port error test");5do_receive_message_port_error_test("message port error test", "message port error test");6do_receive_message_port_error_test("message port error test", "message port error test");7do_receive_message_port_error_test("message port error test", "message port error test");8do_receive_message_port_error_test("message port error test", "message port error test");9do_receive_message_port_error_test("message port error test", "message port error test");10do_receive_message_port_error_test("message port error test", "message port error test");11do_receive_message_port_error_test("message port error test", "message port error test");12do_receive_message_port_error_test("message port error test", "message port error test");13do_receive_message_port_error_test("message port error test", "message port error test");
Using AI Code Generation
1do_receive_message_port_error_test();2promise_test(() => {3 return new Promise((resolve, reject) => {4 try {5 worker = new Worker("worker.js");6 const mc = new MessageChannel();7 worker.postMessage("message", [mc.port1]);8 } catch (e) {9 reject(e);10 }11 });12}, "Uncaught exception in worker should be reported after message port error.");13self.onmessage = t.step_func((e) => {14 e.ports[0].close();15 throw new Error("Uncaught exception");16});17const port = new MessagePort();18const mc = new MessageChannel();19port.postMessage("message", [mc.port1]);20mc.port1.close();21throw new Error("Uncaught exception");
Using AI Code Generation
1do_receive_message_port_error_test(2 "MessagePort.postMessage() should throw a DataCloneError when the message is too large",3 function() {4 var port = new MessagePort();5 port.start();6 var message = new Array(100000000).join('a');7 port.postMessage(message);8 },9 function(error) {10 assert_equals(error.name, "DataCloneError");11 }12);
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!!