3 <script src=
"/resources/testharness.js"></script>
4 <script src=
"/resources/testharnessreport.js"></script>
5 <script src=
"/feature-policy/resources/featurepolicy.js"></script>
8 const sub
= 'https://{{domains[www]}}:{{ports[https][0]}}';
9 const same_origin_src
= '/feature-policy/resources/feature-policy-serial.html';
10 const cross_origin_src
= sub
+ same_origin_src
;
11 const same_origin_worker_frame_src
=
12 '/feature-policy/resources/feature-policy-serial-worker.html';
13 const cross_origin_worker_frame_src
= sub
+ same_origin_worker_frame_src
;
14 const header
= 'Feature-Policy header {"serial" : []}';
17 return navigator
.serial
.getPorts().then(() => {
18 assert_unreached('expected promise to reject with SecurityError');
20 assert_equals(error
.name
, 'SecurityError');
22 }, header
+ ' disallows getPorts in the top-level document.');
25 test_feature_availability('serial.getPorts()', t
, same_origin_src
,
26 expect_feature_unavailable_default
);
27 }, header
+ ' disallows same-origin iframes.');
30 test_feature_availability('serial.getPorts()', t
, same_origin_worker_frame_src
,
31 expect_feature_unavailable_default
);
32 }, header
+ ' disallows workers in same-origin iframes.');
35 test_feature_availability('serial.getPorts()', t
, cross_origin_src
,
36 expect_feature_unavailable_default
);
37 }, header
+ ' disallows cross-origin iframes.');
40 test_feature_availability('serial.getPorts()', t
,
41 cross_origin_worker_frame_src
,
42 expect_feature_unavailable_default
);
43 }, header
+ ' disallows workers in cross-origin iframes.');
45 fetch_tests_from_worker(new Worker(
46 'resources/serial-disabled-by-feature-policy-worker.js'));