How to use checkCorpReport method in wpt

Best JavaScript code snippet using wpt

reporting-navigation.https.window.js

Source:reporting-navigation.https.window.js Github

copy

Full Screen

...8const CORP_CROSS_ORIGIN =9 '|header(cross-origin-resource-policy,cross-origin)';10const FRAME_URL = `${ORIGIN}/common/blank.html?pipe=`;11const REMOTE_FRAME_URL = `${REMOTE_ORIGIN}/common/blank.html?pipe=`;12function checkCorpReport(report, contextUrl, blockedUrl, disposition) {13 assert_equals(report.type, 'coep');14 assert_equals(report.url, contextUrl);15 assert_equals(report.body.type, 'corp');16 assert_equals(report.body.blockedURL, blockedUrl);17 assert_equals(report.body.disposition, disposition);18 assert_equals(report.body.destination, 'iframe');19}20function checkCoepMismatchReport(report, contextUrl, blockedUrl, disposition) {21 assert_equals(report.type, 'coep');22 assert_equals(report.url, contextUrl);23 assert_equals(report.body.type, 'navigation');24 assert_equals(report.body.blockedURL, blockedUrl);25 assert_equals(report.body.disposition, disposition);26}27function loadFrame(document, url) {28 return new Promise((resolve, reject) => {29 const frame = document.createElement('iframe');30 frame.src = url;31 frame.onload = () => resolve(frame);32 frame.onerror = reject;33 document.body.appendChild(frame);34 });35}36// |parentSuffix| is a suffix for the parent frame URL.37// |targetUrl| is a URL for the target frame.38async function loadFrames(test, parentSuffix, targetUrl) {39 const frame = await loadFrame(document, FRAME_URL + parentSuffix);40 test.add_cleanup(() => frame.remove());41 // Here we don't need "await". This loading may or may not succeed, and42 // we're not interested in the result.43 loadFrame(frame.contentDocument, targetUrl);44 return frame;45}46async function observeReports(global, expected_count) {47 const reports = [];48 const receivedEveryReports = new Promise(resolve => {49 if (expected_count == 0)50 resolve();51 const observer = new global.ReportingObserver((rs) => {52 for (const r of rs) {53 reports.push(r.toJSON());54 }55 if (expected_count <= reports.length)56 resolve();57 });58 observer.observe();59 });60 // Wait 500ms more to catch additionnal unexpected reports.61 await receivedEveryReports;62 await new Promise(r => step_timeout(r, 500));63 return reports;64}65function desc(headers) {66 return headers === '' ? '(none)' : headers;67}68// CASES is a list of test case. Each test case consists of:69// parent_headers: the suffix of the URL of the parent frame.70// target_headers: the suffix of the URL of the target frame.71// expected_reports: one of:72// 'CORP': CORP violation73// 'CORP-RO': CORP violation (report only)74// 'NAV': COEP mismatch between the frames.75// 'NAV-RO': COEP mismatch between the frames (report only).76const reportingTest = function(77 parent_headers, target_headers, expected_reports) {78 // These tests are very slow, so they must be run in parallel using79 // async_test.80 promise_test_parallel(async t => {81 const targetUrl = REMOTE_FRAME_URL + target_headers;82 const parent = await loadFrames(t, parent_headers, targetUrl);83 const contextUrl = parent.src ? parent.src : 'about:blank';84 const reports = await observeReports(85 parent.contentWindow,86 expected_reports.length87 );88 assert_equals(reports.length, expected_reports.length);89 for (let i = 0; i < reports.length; i += 1) {90 const report = reports[i];91 switch (expected_reports[i]) {92 case 'CORP':93 checkCorpReport(report, contextUrl, targetUrl, 'enforce');94 break;95 case 'CORP-RO':96 checkCorpReport(report, contextUrl, targetUrl, 'reporting');97 break;98 case 'NAV':99 checkCoepMismatchReport(report, contextUrl, targetUrl, 'enforce');100 break;101 case 'NAV-RO':102 checkCoepMismatchReport(report, contextUrl, targetUrl, 'reporting');103 break;104 default:105 assert_unreached(106 'Unexpected report exception: ' + expected_reports[i]);107 }108 }109 }, `parent: ${desc(parent_headers)}, target: ${desc(target_headers)}, `);110}...

Full Screen

Full Screen

reporting-navigation.tentative.https.window.js

Source:reporting-navigation.tentative.https.window.js Github

copy

Full Screen

...8const CORP_CROSS_ORIGIN =9 '|header(cross-origin-resource-policy,cross-origin)';10const FRAME_URL = `${ORIGIN}/common/blank.html?pipe=`;11const REMOTE_FRAME_URL = `${REMOTE_ORIGIN}/common/blank.html?pipe=`;12function checkCorpReport(report, contextUrl, blockedUrl, disposition) {13 assert_equals(report.type, 'coep');14 assert_equals(report.url, contextUrl);15 assert_equals(report.body.type, 'corp');16 assert_equals(report.body.blockedURL, blockedUrl);17 assert_equals(report.body.disposition, disposition);18 assert_equals(report.body.destination, 'iframe');19}20function checkCoepMismatchReport(report, contextUrl, blockedUrl, disposition) {21 assert_equals(report.type, 'coep');22 assert_equals(report.url, contextUrl);23 assert_equals(report.body.type, 'navigation');24 assert_equals(report.body.blockedURL, blockedUrl);25 assert_equals(report.body.disposition, disposition);26}27function loadFrame(document, url) {28 return new Promise((resolve, reject) => {29 const frame = document.createElement('iframe');30 frame.src = url;31 frame.onload = () => resolve(frame);32 frame.onerror = reject;33 document.body.appendChild(frame);34 });35}36// |parentSuffix| is a suffix for the parent frame URL.37// |targetUrl| is a URL for the target frame.38async function loadFrames(test, parentSuffix, targetUrl) {39 const frame = await loadFrame(document, FRAME_URL + parentSuffix);40 test.add_cleanup(() => frame.remove());41 // Here we don't need "await". This loading may or may not succeed, and42 // we're not interested in the result.43 loadFrame(frame.contentDocument, targetUrl);44 return frame;45}46async function observeReports(global, expected_count) {47 const reports = [];48 const receivedEveryReports = new Promise(resolve => {49 if (expected_count == 0)50 resolve();51 const observer = new global.ReportingObserver((rs) => {52 for (const r of rs) {53 reports.push(r.toJSON());54 }55 if (expected_count <= reports.length)56 resolve();57 });58 observer.observe();59 });60 // Wait 500ms more to catch additionnal unexpected reports.61 await receivedEveryReports;62 await new Promise(r => step_timeout(r, 500));63 return reports;64}65function desc(headers) {66 return headers === '' ? '(none)' : headers;67}68// CASES is a list of test case. Each test case consists of:69// parent_headers: the suffix of the URL of the parent frame.70// target_headers: the suffix of the URL of the target frame.71// expected_reports: one of:72// 'CORP': CORP violation73// 'CORP-RO': CORP violation (report only)74// 'NAV': COEP mismatch between the frames.75// 'NAV-RO': COEP mismatch between the frames (report only).76const reportingTest = function(77 parent_headers, target_headers, expected_reports) {78 // These tests are very slow, so they must be run in parallel using79 // async_test.80 promise_test_parallel(async t => {81 const targetUrl = REMOTE_FRAME_URL + target_headers;82 const parent = await loadFrames(t, parent_headers, targetUrl);83 const contextUrl = parent.src ? parent.src : 'about:blank';84 const reports = await observeReports(85 parent.contentWindow,86 expected_reports.length87 );88 assert_equals(reports.length, expected_reports.length);89 for (let i = 0; i < reports.length; i += 1) {90 const report = reports[i];91 switch (expected_reports[i]) {92 case 'CORP':93 checkCorpReport(report, contextUrl, targetUrl, 'enforce');94 break;95 case 'CORP-RO':96 checkCorpReport(report, contextUrl, targetUrl, 'reporting');97 break;98 case 'NAV':99 checkCoepMismatchReport(report, contextUrl, targetUrl, 'enforce');100 break;101 case 'NAV-RO':102 checkCoepMismatchReport(report, contextUrl, targetUrl, 'reporting');103 break;104 default:105 assert_unreached(106 'Unexpected report exception: ' + expected_reports[i]);107 }108 }109 }, `parent: ${desc(parent_headers)}, target: ${desc(target_headers)}, `);110}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8var wpt = require('./wpt.js');9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});15var wpt = require('./wpt.js');16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22var wpt = require('./wpt.js');23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt');2var reportId = '170916_5M_7e8f1c3e3e3d8e8d7f0e2d0c7fdd84a2';3wpt.checkCorpReport(reportId, function(err, res) {4 if(err) {5 console.log(err);6 } else {7 console.log(res);8 }9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2 if(err){3 console.log(err);4 } else {5 console.log(data);6 }7});8var wpt = require('./wpt.js');9 if(err){10 console.log(err);11 } else {12 console.log(data);13 }14});15var wpt = require('./wpt.js');16 if(err){17 console.log(err);18 } else {19 console.log(data);20 }21});22var wpt = require('./wpt.js');23 if(err){24 console.log(err);25 } else {26 console.log(data);27 }28});

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