How to use testNavigationFails method in wpt

Best JavaScript code snippet using wpt

child-navigates-parent-cross-origin.window.js

Source:child-navigates-parent-cross-origin.window.js Github

copy

Full Screen

1// META: script=/common/get-host-info.sub.js2// META: script=resources/wait-for-messages.js3function testNavigationFails(params) {4 return async (t) => {5 // Start waiting for messages before inserting the child frame, to avoid any6 // race conditions. Note that this would be racy if we executed tests7 // concurrently, thankfully `promise_test` executes sequentially. See also:8 // https://github.com/web-platform-tests/rfcs/pull/759 const messagesPromise = waitForMessages(1);10 // Execute the test in an iframe, so that the document executing the test11 // is not navigated away mid-test in case of failure.12 const child = document.createElement("iframe");13 document.body.appendChild(child);14 t.add_cleanup(() => { document.body.removeChild(child); });15 const url = new URL(16 "resources/child-navigates-parent-cross-origin-inner.html",17 window.location);18 // Load the grandchild iframe from a different origin.19 url.host = get_host_info().REMOTE_HOST;20 for (const key in params || {}) {21 url.searchParams.set(key, params[key]);22 }23 const grandchild = child.contentDocument.createElement("iframe");24 grandchild.src = url;25 child.contentDocument.body.appendChild(grandchild);26 const messages = await messagesPromise;27 assert_array_equals(messages, ["error: SecurityError"]);28 }29}30promise_test(31 testNavigationFails(),32 "Child document attempts to navigate cross-origin parent via location");33promise_test(34 testNavigationFails({ "property": "hash" }),35 "Child document attempts to navigate cross-origin parent via "+36 "location.hash");37promise_test(38 testNavigationFails({ "property": "host" }),39 "Child document attempts to navigate cross-origin parent via "+40 "location.host");41promise_test(42 testNavigationFails({ "property": "hostname" }),43 "Child document attempts to navigate cross-origin parent via "+44 "location.hostname");45promise_test(46 testNavigationFails({ "property": "href" }),47 "Child document attempts to navigate cross-origin parent via "+48 "location.href");49promise_test(50 testNavigationFails({ "property": "pathname" }),51 "Child document attempts to navigate cross-origin parent via "+52 "location.pathname");53promise_test(54 testNavigationFails({ "property": "protocol" }),55 "Child document attempts to navigate cross-origin parent via "+56 "location.protocol");57promise_test(58 testNavigationFails({ "property": "reload" }),59 "Child document attempts to navigate cross-origin parent via "+60 "location.reload()");61promise_test(62 testNavigationFails({ "property": "replace" }),63 "Child document attempts to navigate cross-origin parent via "+64 "location.replace()");65promise_test(66 testNavigationFails({ "property": "search" }),67 "Child document attempts to navigate cross-origin parent via "+68 "location.search");69promise_test(70 testNavigationFails({ "property": "xxxNonExistent" }),71 "Child document attempts to navigate cross-origin parent via non-standard "+...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function testNavigationFails(from, to) {2}3function testNavigationFails(from, to) {4}5function testNavigationFails(from, to) {6}

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