How to use kRemoteOrigin method in wpt

Best JavaScript code snippet using wpt

FileSystemBaseHandle-postMessage-Error.js

Source:FileSystemBaseHandle-postMessage-Error.js Github

copy

Full Screen

1'use strict';2// This script depends on the following scripts:3// /native-file-system/resources/messaging-helpers.js4// /native-file-system/resources/messaging-blob-helpers.js5// /native-file-system/resources/messaging-serialize-helpers.js6// /native-file-system/resources/test-helpers.js7// /common/get-host-info.sub.js8// /service-workers/service-worker/resources/test-helpers.sub.js9// Define URL constants for cross origin windows.10const kRemoteOrigin = get_host_info().HTTPS_REMOTE_ORIGIN;11const kRemoteOriginDocumentMessageTarget = `${kRemoteOrigin}${base_path()}` +12 kDocumentMessageTarget;13// Sending a FileSystemHandle to a cross origin |target| through postMessage()14// must dispatch the 'messageerror' event.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 // 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 ' +...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require('wpt-driver');2var driver = new wptDriver();3 console.log(err, data);4});5var wptDriver = require('wpt-driver');6var driver = new wptDriver();7 console.log(err, data);8});9var wptDriver = require('wpt-driver');10var driver = new wptDriver();11 console.log(err, data);12});13var wptDriver = require('wpt-driver');14var driver = new wptDriver();15 console.log(err, data);16});17var wptDriver = require('wpt-driver');18var driver = new wptDriver();19 console.log(err, data);20});21var wptDriver = require('wpt-driver');22var driver = new wptDriver();23 console.log(err, data);24});25var wptDriver = require('wpt-driver');26var driver = new wptDriver();

Full Screen

Using AI Code Generation

copy

Full Screen

1});2});3});4});5});6});7});8});9});10});11});

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