How to use SAME_ORIGIN method in wpt

Best JavaScript code snippet using wpt

frame-ancestors-test.js

Source:frame-ancestors-test.js Github

copy

Full Screen

1var SAME_ORIGIN = true;2var CROSS_ORIGIN = false;3var EXPECT_BLOCK = true;4var EXPECT_LOAD = false;5var SAMEORIGIN_ORIGIN = "http://127.0.0.1:8000";6var CROSSORIGIN_ORIGIN = "http://localhost:8080";7window.jsTestIsAsync = true;8window.wasPostTestScriptParsed = true;9if (window.testRunner)10 testRunner.dumpChildFramesAsText();11window.addEventListener("message", function (e) {12 if (window.parent != window) {13 window.parent.postMessage(e.data, "*");14 } else {15 if (e.data)16 testFailed("The inner IFrame failed.");17 else18 testPassed("The inner IFrame passed.");19 finishJSTest();20 }21});22function injectNestedIframe(policy, parent, child, expectation, isSandboxed) {23 var iframe = document.createElement("iframe");24 var url = "/security/contentSecurityPolicy/resources/frame-in-frame.pl?"25 + "policy=" + policy26 + "&parent=" + parent27 + "&child=" + child28 + "&expectation=" + expectation;29 url = (parent == "same" ? SAMEORIGIN_ORIGIN : CROSSORIGIN_ORIGIN) + url;30 iframe.src = url;31 if (isSandboxed)32 iframe.sandbox = 'allow-scripts';33 document.body.appendChild(iframe);34}35function injectIFrame(policy, sameOrigin, expectBlock) {36 var iframe = document.createElement("iframe");37 iframe.addEventListener("load", iframeLoaded(expectBlock));38 iframe.addEventListener("error", iframeLoaded(expectBlock));39 var url = "/security/contentSecurityPolicy/resources/frame-ancestors.pl?policy=" + policy;40 if (!sameOrigin)41 url = CROSSORIGIN_ORIGIN + url;42 iframe.src = url;43 document.body.appendChild(iframe);44}45function iframeLoaded(expectBlock) {46 return function(ev) {47 var failed = true;48 try {49 console.log("IFrame load event fired: the IFrame's location is '" + ev.target.contentWindow.location.href + "'.");50 if (expectBlock) {51 testFailed("The IFrame should have been blocked (or cross-origin). It wasn't.");52 failed = true;53 } else {54 testPassed("The IFrame should not have been blocked. It wasn't.");55 failed = false;56 }57 } catch (ex) {58 debug("IFrame load event fired: the IFrame is cross-origin (or was blocked).");59 if (expectBlock) {60 testPassed("The IFrame should have been blocked (or cross-origin). It was.");61 failed = false;62 } else {63 testFailed("The IFrame should not have been blocked. It was.");64 failed = true;65 }66 }67 if (window.parent != window)68 window.parent.postMessage(failed, '*');69 else70 finishJSTest();71 };72}73function crossOriginFrameShouldBeBlocked(policy) {74 window.onload = function () {75 injectIFrame(policy, CROSS_ORIGIN, EXPECT_BLOCK);76 };77}78function crossOriginFrameShouldBeAllowed(policy) {79 window.onload = function () {80 injectIFrame(policy, CROSS_ORIGIN, EXPECT_LOAD);81 };82}83function sameOriginFrameShouldBeBlocked(policy) {84 window.onload = function () {85 injectIFrame(policy, SAME_ORIGIN, EXPECT_BLOCK);86 };87}88function sameOriginFrameShouldBeAllowed(policy) {89 window.onload = function () {90 injectIFrame(policy, SAME_ORIGIN, EXPECT_LOAD);91 };92}93function testNestedIFrame(policy, parent, child, expectation) {94 window.onload = function () {95 injectNestedIframe(policy, parent == SAME_ORIGIN ? "same" : "cross", child == SAME_ORIGIN ? "same" : "cross", expectation == EXPECT_LOAD ? "Allowed" : "Blocked", false /* isSandboxed */);96 };97}98function testNestedSandboxedIFrame(policy, parent, child, expectation) {99 window.onload = function () {100 injectNestedIframe(policy, parent == SAME_ORIGIN ? "same" : "cross", child == SAME_ORIGIN ? "same" : "cross", expectation == EXPECT_LOAD ? "Allowed" : "Blocked", true /* isSandboxed */);101 };...

Full Screen

Full Screen

openWindow_worker.js

Source:openWindow_worker.js Github

copy

Full Screen

1// the worker won't shut down between events because we increased2// the timeout values.3var client;4var window_count = 0;5var expected_window_count = 7;6var resolve_got_all_windows = null;7var got_all_windows = new Promise(function(res, rej) {8 resolve_got_all_windows = res;9});10// |expected_window_count| needs to be updated for every new call that's11// expected to actually open a new window regardless of what |clients.openWindow|12// returns.13function testForUrl(url, throwType, clientProperties, resultsArray) {14 return clients.openWindow(url)15 .then(function(e) {16 if (throwType != null) {17 resultsArray.push({18 result: false,19 message: "openWindow should throw " + throwType20 });21 } else if (clientProperties) {22 resultsArray.push({23 result: (e instanceof WindowClient),24 message: "openWindow should resolve to a WindowClient"25 });26 resultsArray.push({27 result: e.url == clientProperties.url,28 message: "Client url should be " + clientProperties.url29 });30 // Add more properties31 } else {32 resultsArray.push({33 result: e == null,34 message: "Open window should resolve to null. Got: " + e35 });36 }37 })38 .catch(function(err) {39 if (throwType == null) {40 resultsArray.push({41 result: false,42 message: "Unexpected throw: " + err43 });44 } else {45 resultsArray.push({46 result: err.toString().indexOf(throwType) >= 0,47 message: "openWindow should throw: " + err48 });49 }50 })51}52onmessage = function(event) {53 if (event.data == "testNoPopup") {54 client = event.source;55 var results = [];56 var promises = [];57 promises.push(testForUrl("about:blank", "TypeError", null, results));58 promises.push(testForUrl("http://example.com", "InvalidAccessError", null, results));59 promises.push(testForUrl("_._*`InvalidURL", "InvalidAccessError", null, results));60 Promise.all(promises).then(function(e) {61 client.postMessage(results);62 });63 }64 if (event.data == "NEW_WINDOW") {65 window_count += 1;66 if (window_count == expected_window_count) {67 resolve_got_all_windows();68 }69 }70 if (event.data == "CHECK_NUMBER_OF_WINDOWS") {71 got_all_windows.then(function() {72 return clients.matchAll();73 }).then(function(cl) {74 event.source.postMessage({result: cl.length == expected_window_count,75 message: "The number of windows is correct."});76 for (i = 0; i < cl.length; i++) {77 cl[i].postMessage("CLOSE");78 }79 });80 }81}82onnotificationclick = function(e) {83 var results = [];84 var promises = [];85 var redirect = "http://mochi.test:8888/tests/dom/workers/test/serviceworkers/redirect.sjs?"86 var redirect_xorigin = "http://example.com/tests/dom/workers/test/serviceworkers/redirect.sjs?"87 var same_origin = "http://mochi.test:8888/tests/dom/workers/test/serviceworkers/open_window/client.html"88 var different_origin = "http://example.com/tests/dom/workers/test/serviceworkers/open_window/client.html"89 promises.push(testForUrl("about:blank", "TypeError", null, results));90 promises.push(testForUrl(different_origin, null, null, results));91 promises.push(testForUrl(same_origin, null, {url: same_origin}, results));92 promises.push(testForUrl("open_window/client.html", null, {url: same_origin}, results));93 // redirect tests94 promises.push(testForUrl(redirect + "open_window/client.html", null,95 {url: same_origin}, results));96 promises.push(testForUrl(redirect + different_origin, null, null, results));97 promises.push(testForUrl(redirect_xorigin + "open_window/client.html", null,98 null, results));99 promises.push(testForUrl(redirect_xorigin + same_origin, null,100 {url: same_origin}, results));101 Promise.all(promises).then(function(e) {102 client.postMessage(results);103 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var options = {2 videoParams: {3 },4};5wpt.runTest(options, function(err, data) {6 if (err) return console.log(err);7 console.log(data.data);8});9var options = {10 videoParams: {11 },12};13wpt.runTest(options, function(err, data) {14 if (err) return console.log(err);15 console.log(data.data);16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.page('wikipedia').then(console.log).catch(console.error);3var wptools = require('wptools');4wptools.page('wikipedia', {useProxy: true}).then(console.log).catch(console.error);5var wptools = require('wptools');6wptools.page('wikipedia').then(console.log).catch(console.error);7var wptools = require('wptools');8wptools.page('wikipedia', {useProxy: true}).then(console.log).catch(console.error);9var wptools = require('wptools');10wptools.page('wikipedia').then(console.log).catch(console.error);11var wptools = require('wptools');12wptools.page('wikipedia', {useProxy: true}).then(console.log).catch(console.error);13var wptools = require('wptools');14wptools.page('wikipedia').then(console.log).catch(console.error);15var wptools = require('wptools');16wptools.page('wikipedia', {useProxy: true}).then(console.log).catch(console.error);17var wptools = require('wptools');18wptools.page('wikipedia').then(console.log).catch(console.error);19var wptools = require('wptools');20wptools.page('wikipedia', {useProxy: true}).then(console.log).catch(console.error);21var wptools = require('wptools');22wptools.page('wikipedia').then(console.log).catch(console.error);23var wptools = require('w

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