permissions-policy-util.sub.js (1119B)
1 const TOPICS_PERMISSIONS_POLICY_ERROR_MESSAGE = 'The \"browsing-topics\" Permissions Policy denied the use of document.browsingTopics().'; 2 3 function test_topics_feature_availability_in_subframe(test, is_same_origin, expect_feature_available_func) { 4 const same_origin_src = '/browsing-topics/resources/document-api-notify-parent.tentative.https.html'; 5 const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' + 6 same_origin_src; 7 8 let frame = document.createElement('iframe'); 9 frame.src = is_same_origin ? same_origin_src : cross_origin_src; 10 11 window.addEventListener('message', test.step_func(function handler(evt) { 12 if (evt.source === frame.contentWindow) { 13 expect_feature_available_func(evt.data); 14 15 document.body.removeChild(frame); 16 window.removeEventListener('message', handler); 17 test.done(); 18 } 19 })); 20 21 document.body.appendChild(frame); 22 } 23 24 function expect_topics_feature_unavailable(data) { 25 assert_equals(data.error, TOPICS_PERMISSIONS_POLICY_ERROR_MESSAGE); 26 } 27 28 function expect_topics_feature_available(data) { 29 assert_equals(data.error, 'No error'); 30 }