forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature policy tests for generic sensors (web-platform-tests#8491)
- Loading branch information
Showing
59 changed files
with
626 additions
and
21 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
accelerometer/Accelerometer-disabled-by-feature-policy.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_disabled(Accelerometer); | ||
run_fp_tests_disabled(LinearAccelerationSensor); | ||
run_fp_tests_disabled(GravitySensor); | ||
</script> | ||
</body> |
1 change: 1 addition & 0 deletions
1
accelerometer/Accelerometer-disabled-by-feature-policy.https.sub.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Feature-Policy: accelerometer 'none' |
14 changes: 14 additions & 0 deletions
14
...rometer/Accelerometer-enabled-by-feature-policy-attribute-redirect-on-load.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled_by_attribute_redirect_on_load(Accelerometer); | ||
run_fp_tests_enabled_by_attribute_redirect_on_load(LinearAccelerationSensor); | ||
run_fp_tests_enabled_by_attribute_redirect_on_load(GravitySensor); | ||
</script> | ||
</body> |
14 changes: 14 additions & 0 deletions
14
accelerometer/Accelerometer-enabled-by-feature-policy-attribute.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled_by_attribute(Accelerometer); | ||
run_fp_tests_enabled_by_attribute(LinearAccelerationSensor); | ||
run_fp_tests_enabled_by_attribute(GravitySensor); | ||
</script> | ||
</body> |
14 changes: 14 additions & 0 deletions
14
accelerometer/Accelerometer-enabled-by-feature-policy.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled(Accelerometer); | ||
run_fp_tests_enabled(LinearAccelerationSensor); | ||
run_fp_tests_enabled(GravitySensor); | ||
</script> | ||
</body> |
1 change: 1 addition & 0 deletions
1
accelerometer/Accelerometer-enabled-by-feature-policy.https.sub.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Feature-Policy: accelerometer * |
14 changes: 14 additions & 0 deletions
14
accelerometer/Accelerometer-enabled-on-self-origin-by-feature-policy.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled_on_self_origin(Accelerometer); | ||
run_fp_tests_enabled_on_self_origin(LinearAccelerationSensor); | ||
run_fp_tests_enabled_on_self_origin(GravitySensor); | ||
</script> | ||
</body> |
1 change: 1 addition & 0 deletions
1
accelerometer/Accelerometer-enabled-on-self-origin-by-feature-policy.https.sub.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Feature-Policy: accelerometer 'self' |
12 changes: 12 additions & 0 deletions
12
ambient-light/AmbientLightSensor-disabled-by-feature-policy.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_disabled(AmbientLightSensor); | ||
</script> | ||
</body> |
1 change: 1 addition & 0 deletions
1
ambient-light/AmbientLightSensor-disabled-by-feature-policy.https.sub.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Feature-Policy: ambient-light-sensor 'none' |
12 changes: 12 additions & 0 deletions
12
...ht/AmbientLightSensor-enabled-by-feature-policy-attribute-redirect-on-load.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled_by_attribute_redirect_on_load(AmbientLightSensor); | ||
</script> | ||
</body> |
12 changes: 12 additions & 0 deletions
12
ambient-light/AmbientLightSensor-enabled-by-feature-policy-attribute.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled_by_attribute(AmbientLightSensor); | ||
</script> | ||
</body> |
12 changes: 12 additions & 0 deletions
12
ambient-light/AmbientLightSensor-enabled-by-feature-policy.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled(AmbientLightSensor); | ||
</script> | ||
</body> |
1 change: 1 addition & 0 deletions
1
ambient-light/AmbientLightSensor-enabled-by-feature-policy.https.sub.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Feature-Policy: ambient-light-sensor * |
12 changes: 12 additions & 0 deletions
12
ambient-light/AmbientLightSensor-enabled-on-self-origin-by-feature-policy.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled_on_self_origin(AmbientLightSensor); | ||
</script> | ||
</body> |
1 change: 1 addition & 0 deletions
1
...-light/AmbientLightSensor-enabled-on-self-origin-by-feature-policy.https.sub.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Feature-Policy: ambient-light-sensor 'self' |
11 changes: 11 additions & 0 deletions
11
feature-policy/resources/feature-policy-generic-sensor.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
"use strict"; | ||
|
||
try { | ||
const sensorName = location.hash.substring(1); | ||
const sensor = new window[sensorName](); | ||
window.parent.postMessage({ enabled: true }, "*"); | ||
} catch (e) { | ||
window.parent.postMessage({ enabled: false }, "*"); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
const feature_policies = { | ||
"AmbientLightSensor" : ["ambient-light-sensor"], | ||
"Accelerometer" : ["accelerometer"], | ||
"LinearAccelerationSensor" : ["accelerometer"], | ||
"GravitySensor" : ["accelerometer"], | ||
"Gyroscope" : ["gyroscope"], | ||
"GeolocationSensor" : ["geolocation"], | ||
"Magnetometer" : ["magnetometer"], | ||
"UncalibratedMagnetometer" : ["magnetometer"], | ||
"AbsoluteOrientationSensor" : ["accelerometer", "gyroscope", "magnetometer"], | ||
"RelativeOrientationSensor" : ["accelerometer", "gyroscope"] | ||
}; | ||
|
||
const same_origin_src = | ||
"/feature-policy/resources/feature-policy-generic-sensor.html#"; | ||
const cross_origin_src = | ||
"https://{{domains[www]}}:{{ports[https][0]}}" + same_origin_src; | ||
const base_src = "/feature-policy/resources/redirect-on-load.html#"; | ||
|
||
function run_fp_tests_disabled(sensorType) { | ||
const sensorName = sensorType.name; | ||
const featureNameList = feature_policies[sensorName]; | ||
const header = "Feature-Policy header " + featureNameList.join(" 'none';") + " 'none'"; | ||
const desc = "'new " + sensorName + "()'"; | ||
|
||
test(() => { | ||
assert_throws("SecurityError", () => {new sensorType()}); | ||
}, `${sensorName}: ${header} disallows the top-level document.`); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
same_origin_src + sensorName, | ||
expect_feature_unavailable_default | ||
); | ||
}, `${sensorName}: ${header} disallows same-origin iframes.`); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
cross_origin_src + sensorName, | ||
expect_feature_unavailable_default | ||
); | ||
}, `${sensorName}: ${header} disallows cross-origin iframes.`); | ||
} | ||
|
||
function run_fp_tests_enabled(sensorType) { | ||
const sensorName = sensorType.name; | ||
const featureNameList = feature_policies[sensorName]; | ||
const header = "Feature-Policy header " + featureNameList.join(" *;") + " *"; | ||
const desc = "'new " + sensorName + "()'"; | ||
|
||
test(() => { | ||
assert_true(sensorName in window); | ||
}, `${sensorName}: ${header} allows the top-level document.`); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
same_origin_src + sensorName, | ||
expect_feature_available_default | ||
); | ||
}, `${sensorName}: ${header} allows same-origin iframes.`); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
cross_origin_src + sensorName, | ||
expect_feature_available_default | ||
); | ||
}, `${sensorName}: ${header} allows cross-origin iframes.`); | ||
} | ||
|
||
function run_fp_tests_enabled_by_attribute(sensorType) { | ||
const sensorName = sensorType.name; | ||
const featureNameList = feature_policies[sensorName]; | ||
const header = "Feature-Policy allow='" + featureNameList.join(" ") + "' attribute"; | ||
const desc = "'new " + sensorName + "()'"; | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
same_origin_src + sensorName, | ||
expect_feature_available_default, | ||
featureNameList.join(";") | ||
); | ||
}, `${sensorName}: ${header} allows same-origin iframe`); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
cross_origin_src + sensorName, | ||
expect_feature_available_default, | ||
featureNameList.join(";") | ||
); | ||
}, `${sensorName}: ${header} allows cross-origin iframe`); | ||
} | ||
|
||
function run_fp_tests_enabled_by_attribute_redirect_on_load(sensorType) { | ||
const sensorName = sensorType.name; | ||
const featureNameList = feature_policies[sensorName]; | ||
const header = "Feature-Policy allow='" + featureNameList.join(" ") + "' attribute"; | ||
const desc = "'new " + sensorName + "()'"; | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
base_src + same_origin_src + sensorName, | ||
expect_feature_available_default, | ||
featureNameList.join(";") | ||
); | ||
}, `${sensorName}: ${header} allows same-origin relocation`); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
base_src + cross_origin_src + sensorName, | ||
expect_feature_unavailable_default, | ||
featureNameList.join(";") | ||
); | ||
}, `${sensorName}: ${header} disallows cross-origin relocation`); | ||
} | ||
|
||
function run_fp_tests_enabled_on_self_origin(sensorType) { | ||
const sensorName = sensorType.name; | ||
const featureNameList = feature_policies[sensorName]; | ||
const header = "Feature-Policy header " + featureNameList.join(" 'self';") + " 'self'"; | ||
const desc = "'new " + sensorName + "()'"; | ||
|
||
test(() => { | ||
assert_true(sensorName in window); | ||
}, `${sensorName}: ${header} allows the top-level document.`); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
same_origin_src + sensorName, | ||
expect_feature_available_default | ||
); | ||
}, `${sensorName}: ${header} allows same-origin iframes.`); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
desc, | ||
t, | ||
cross_origin_src + sensorName, | ||
expect_feature_unavailable_default | ||
); | ||
}, `${sensorName}: ${header} disallows cross-origin iframes.`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
geolocation-sensor/GeolocationSensor-disabled-by-feature-policy.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_disabled(GeolocationSensor); | ||
</script> | ||
</body> |
1 change: 1 addition & 0 deletions
1
geolocation-sensor/GeolocationSensor-disabled-by-feature-policy.https.sub.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Feature-Policy: geolocation 'none' |
12 changes: 12 additions & 0 deletions
12
...sor/GeolocationSensor-enabled-by-feature-policy-attribute-redirect-on-load.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled_by_attribute_redirect_on_load(GeolocationSensor); | ||
</script> | ||
</body> |
12 changes: 12 additions & 0 deletions
12
geolocation-sensor/GeolocationSensor-enabled-by-feature-policy-attribute.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/feature-policy/resources/featurepolicy.js"></script> | ||
<script src="/generic-sensor/generic-sensor-feature-policy-test.js"></script> | ||
<script> | ||
"use strict"; | ||
|
||
run_fp_tests_enabled_by_attribute(GeolocationSensor); | ||
</script> | ||
</body> |
Oops, something went wrong.