Title: [290301] trunk
Revision
290301
Author
[email protected]
Date
2022-02-22 05:35:13 -0800 (Tue, 22 Feb 2022)

Log Message

Permission API: handle non-fully active documents
https://bugs.webkit.org/show_bug.cgi?id=236952

LayoutTests/imported/w3c:

Web Platform Test
https://github.com/web-platform-tests/wpt/pull/32921

Patch by Marcos Caceres <[email protected]> on 2022-02-22
Reviewed by Youenn Fablet.

* web-platform-tests/permissions/non-fully-active.https-expected.txt: Added.
* web-platform-tests/permissions/non-fully-active.https.html: Added.
* web-platform-tests/permissions/resources/empty.html: Added.

Source/WebCore:

Spec change:
https://github.com/w3c/permissions/pull/365

Patch by Marcos Caceres <[email protected]> on 2022-02-22
Reviewed by Youenn Fablet.

Test: imported/w3c/web-platform-tests/permissions/non-fully-active.https.html

* Modules/permissions/PermissionStatus.cpp:
(WebCore::PermissionStatus::stateChanged):
* Modules/permissions/Permissions.cpp:
(WebCore::Permissions::query):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (290300 => 290301)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-22 13:21:01 UTC (rev 290300)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-22 13:35:13 UTC (rev 290301)
@@ -1,3 +1,17 @@
+2022-02-22  Marcos Caceres  <[email protected]>
+
+        Permission API: handle non-fully active documents
+        https://bugs.webkit.org/show_bug.cgi?id=236952
+
+        Web Platform Test
+        https://github.com/web-platform-tests/wpt/pull/32921
+
+        Reviewed by Youenn Fablet.
+
+        * web-platform-tests/permissions/non-fully-active.https-expected.txt: Added.
+        * web-platform-tests/permissions/non-fully-active.https.html: Added.
+        * web-platform-tests/permissions/resources/empty.html: Added.
+
 2022-02-22  Asumu Takikawa  <[email protected]>
 
         Initial support for Wasm/ESM-integration in the WebCore module loader

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/permissions/non-fully-active.https-expected.txt (0 => 290301)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/permissions/non-fully-active.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/permissions/non-fully-active.https-expected.txt	2022-02-22 13:35:13 UTC (rev 290301)
@@ -0,0 +1,5 @@
+
+
+PASS Trying to query() a non-fully active document rejects with a InvalidStateError
+FAIL Permission change events shouldn't fire on non-fully active document assert_true: onchange is supported expected true got false
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/permissions/non-fully-active.https.html (0 => 290301)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/permissions/non-fully-active.https.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/permissions/non-fully-active.https.html	2022-02-22 13:35:13 UTC (rev 290301)
@@ -0,0 +1,108 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: non-fully active document</title>
+<link rel="help" href="" />
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<body></body>
+<script>
+  // Creates the iframe, wait for it to load...
+  async function attachIframe() {
+    const iframe = document.createElement("iframe");
+    iframe.src = ""
+    document.body.appendChild(iframe);
+    await new Promise((resolve) =>
+      iframe.addEventListener("load", resolve, { once: true })
+    );
+    return iframe;
+  }
+
+  promise_test(async (t) => {
+    const iframe = await attachIframe();
+
+    // Steal the needed references
+    const { permissions } = iframe.contentWindow.navigator;
+    const TypeErrorCtor = iframe.contentWindow.TypeError;
+    const DOMExceptionCtor = iframe.contentWindow.DOMException;
+
+    // Let's check that ordering is correct.
+    await promise_rejects_js(
+      t,
+      TypeErrorCtor,
+      permissions.query({ name: "xxxxx-not-supported" }),
+      "query() should reject if the feature is not supported"
+    );
+
+    // no longer fully active, let's try that again...
+    iframe.remove();
+
+    // Now, let's try with Geolocation as it's supported by all browsers.
+    await promise_rejects_dom(
+      t,
+      "InvalidStateError",
+      DOMExceptionCtor,
+      permissions.query({ name: "whatever" }),
+      "must reject in the right global when the document is not fully active"
+    );
+
+    // Re-attach, and go back to fully active.
+    document.body.appendChild(iframe);
+    await new Promise((resolve) =>
+      iframe.addEventListener("load", resolve, { once: true })
+    );
+
+    // And we are back to fully active, so this should not reject.
+    const status = await iframe.contentWindow.navigator.permissions.query({
+      name: "geolocation",
+    });
+    assert_equals(status.name, "geolocation");
+    iframe.remove();
+  }, "Trying to query() a non-fully active document rejects with a InvalidStateError");
+
+  promise_test(async (t) => {
+    // Create the iframe, wait for it to load...
+    const iframe = await attachIframe();
+
+    // Get the status
+    const initialStatus =
+      await iframe.contentWindow.navigator.permissions.query({
+        name: "geolocation",
+      });
+
+    assert_true("onchange" in initialStatus, "onchange is supported");
+
+    // Let's check events are firing...
+    await new Promise(async (resolve) => {
+      const newState = initialStatus.state === "prompt" ? "denied" : "granted";
+      initialStatus.addEventListener("change", resolve, { once: true });
+      await test_driver.set_permission({ name: "geolocation" }, newState);
+    });
+
+    // No longer fully active...
+    iframe.remove();
+
+    await new Promise(async (resolve, reject) => {
+      // Gets dropped on the floor.
+      initialStatus.addEventListener("change", reject, { once: true });
+      await test_driver.set_permission({ name: "geolocation" }, "prompt");
+      // Try to force it synthetically. This would trigger the event synchronously.
+      initialStatus.dispatchEvent(new Event("change"));
+      resolve();
+    });
+
+    // Re-attach, and go back to fully active.
+    document.body.appendChild(iframe);
+    await new Promise((resolve) =>
+      iframe.addEventListener("load", resolve, { once: true })
+    );
+
+    // Finally, let's recheck that permission state.
+    const finalStatus = await iframe.contentWindow.navigator.permissions.query({
+      name: "geolocation",
+    });
+    assert_equals(finalStatus.state, "prompt", "expected prompt state");
+    iframe.remove();
+  }, "Permission change events shouldn't fire on non-fully active document");
+</script>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/permissions/resources/empty.html (0 => 290301)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/permissions/resources/empty.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/permissions/resources/empty.html	2022-02-22 13:35:13 UTC (rev 290301)
@@ -0,0 +1,3 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Just a support file</title>

Modified: trunk/Source/WebCore/ChangeLog (290300 => 290301)


--- trunk/Source/WebCore/ChangeLog	2022-02-22 13:21:01 UTC (rev 290300)
+++ trunk/Source/WebCore/ChangeLog	2022-02-22 13:35:13 UTC (rev 290301)
@@ -1,3 +1,20 @@
+2022-02-22  Marcos Caceres  <[email protected]>
+
+        Permission API: handle non-fully active documents
+        https://bugs.webkit.org/show_bug.cgi?id=236952
+
+        Spec change:
+        https://github.com/w3c/permissions/pull/365
+
+        Reviewed by Youenn Fablet.
+
+        Test: imported/w3c/web-platform-tests/permissions/non-fully-active.https.html
+
+        * Modules/permissions/PermissionStatus.cpp:
+        (WebCore::PermissionStatus::stateChanged):
+        * Modules/permissions/Permissions.cpp:
+        (WebCore::Permissions::query):
+
 2022-02-22  Asumu Takikawa  <[email protected]>
 
         Initial support for Wasm/ESM-integration in the WebCore module loader

Modified: trunk/Source/WebCore/Modules/permissions/PermissionStatus.cpp (290300 => 290301)


--- trunk/Source/WebCore/Modules/permissions/PermissionStatus.cpp	2022-02-22 13:21:01 UTC (rev 290300)
+++ trunk/Source/WebCore/Modules/permissions/PermissionStatus.cpp	2022-02-22 13:35:13 UTC (rev 290301)
@@ -69,6 +69,9 @@
     if (m_state == newState)
         return;
 
+    if (auto* document = dynamicDowncast<Document>(scriptExecutionContext()); !document->isFullyActive())
+        return;
+
     m_state = newState;
     queueTaskToDispatchEvent(*this, TaskSource::Permission, Event::create(eventNames().changeEvent, Event::CanBubble::No, Event::IsCancelable::No));
 }

Modified: trunk/Source/WebCore/Modules/permissions/Permissions.cpp (290300 => 290301)


--- trunk/Source/WebCore/Modules/permissions/Permissions.cpp	2022-02-22 13:21:01 UTC (rev 290300)
+++ trunk/Source/WebCore/Modules/permissions/Permissions.cpp	2022-02-22 13:35:13 UTC (rev 290301)
@@ -84,11 +84,17 @@
     }
 
     auto context = m_navigator ? m_navigator->scriptExecutionContext() : nullptr;
+
     if (!context || !context->globalObject()) {
         promise.reject(Exception { InvalidStateError, "The context is invalid"_s });
         return;
     }
 
+    if (auto* document = dynamicDowncast<Document>(context); !document->isFullyActive()) {
+        promise.reject(Exception { InvalidStateError, "The document is not fully active"_s });
+        return;
+    }
+
     if (!permissionDescriptorValue) {
         promise.reject(Exception { DataError, "The parameter is invalid"_s });
         return;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to