diff --git a/shared-storage/permissions-policy-default.tentative.https.sub.html b/shared-storage/permissions-policy-default.tentative.https.sub.html new file mode 100644 index 00000000000000..f055ae0421f6c9 --- /dev/null +++ b/shared-storage/permissions-policy-default.tentative.https.sub.html @@ -0,0 +1,29 @@ + +
+ + + + + + diff --git a/shared-storage/permissions-policy-none.tentative.https.sub.html b/shared-storage/permissions-policy-none.tentative.https.sub.html new file mode 100644 index 00000000000000..7154061d50abad --- /dev/null +++ b/shared-storage/permissions-policy-none.tentative.https.sub.html @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/shared-storage/permissions-policy-none.tentative.https.sub.html.headers b/shared-storage/permissions-policy-none.tentative.https.sub.html.headers new file mode 100644 index 00000000000000..9903f7c578df6a --- /dev/null +++ b/shared-storage/permissions-policy-none.tentative.https.sub.html.headers @@ -0,0 +1 @@ +Permissions-Policy: shared-storage=() diff --git a/shared-storage/permissions-policy-self.tentative.https.sub.html b/shared-storage/permissions-policy-self.tentative.https.sub.html new file mode 100644 index 00000000000000..bde32a5c306602 --- /dev/null +++ b/shared-storage/permissions-policy-self.tentative.https.sub.html @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/shared-storage/permissions-policy-self.tentative.https.sub.html.headers b/shared-storage/permissions-policy-self.tentative.https.sub.html.headers new file mode 100644 index 00000000000000..36c95f2b087ba0 --- /dev/null +++ b/shared-storage/permissions-policy-self.tentative.https.sub.html.headers @@ -0,0 +1 @@ +Permissions-Policy: shared-storage=(self) diff --git a/shared-storage/resources/permissions-policy-helper.html b/shared-storage/resources/permissions-policy-helper.html new file mode 100644 index 00000000000000..d87092aad1d2ef --- /dev/null +++ b/shared-storage/resources/permissions-policy-helper.html @@ -0,0 +1,18 @@ + + + + + + + diff --git a/shared-storage/resources/simple-module.js b/shared-storage/resources/simple-module.js new file mode 100644 index 00000000000000..ad9a93a7c160f0 --- /dev/null +++ b/shared-storage/resources/simple-module.js @@ -0,0 +1 @@ +'use strict'; diff --git a/shared-storage/resources/util.js b/shared-storage/resources/util.js new file mode 100644 index 00000000000000..4dea9837646dc3 --- /dev/null +++ b/shared-storage/resources/util.js @@ -0,0 +1,69 @@ +'use strict'; + +// Execute all shared storage methods and capture their errors. Return true if +// the permissions policy allows all of them; return false if the permissions +// policy disallows all of them. Precondition: only these two outcomes are +// possible. +async function AreSharedStorageMethodsAllowedByPermissionsPolicy() { + let permissionsPolicyDeniedCount = 0; + const errorMessage = 'The \"shared-storage\" Permissions Policy denied the method on window.sharedStorage.'; + + try { + await window.sharedStorage.worklet.addModule('/shared-storage/resources/simple-module.js'); + } catch (e) { + assert_equals(e.message, errorMessage); + ++permissionsPolicyDeniedCount; + } + + try { + await window.sharedStorage.run('operation'); + } catch (e) { + assert_equals(e.message, errorMessage); + ++permissionsPolicyDeniedCount; + } + + try { + // Run selectURL() with without addModule() and this should always fail. + // Check the error message to distinguish between the permissions policy + // error and the missing addModule() error. + await sharedStorage.selectURL("operation", [{url: "1.html"}]); + assert_unreached("did not fail"); + } catch (e) { + if (e.message === errorMessage) { + ++permissionsPolicyDeniedCount; + } + } + + try { + await window.sharedStorage.set('a', 'b'); + } catch (e) { + assert_equals(e.message, errorMessage); + ++permissionsPolicyDeniedCount; + } + + try { + await window.sharedStorage.append('a', 'b'); + } catch (e) { + assert_equals(e.message, errorMessage); + ++permissionsPolicyDeniedCount; + } + + try { + await window.sharedStorage.clear(); + } catch (e) { + assert_equals(e.message, errorMessage); + ++permissionsPolicyDeniedCount; + } + + try { + await window.sharedStorage.delete('a'); + } catch (e) { + assert_equals(e.message, errorMessage); + ++permissionsPolicyDeniedCount; + } + + if (permissionsPolicyDeniedCount === 0) + return true; + + return false; +} \ No newline at end of file