Title: [288440] trunk
Revision
288440
Author
[email protected]
Date
2022-01-24 08:02:11 -0800 (Mon, 24 Jan 2022)

Log Message

[Model] Add testing coverage for camera API
https://bugs.webkit.org/show_bug.cgi?id=233643

Reviewed by Dean Jackson.

Source/WebCore:

Test: model-element/model-element-camera.html

We reject the promise returned by the getCamera() and setCamera() methods
with an Exception so that we can correctly test this behavior. We also make
the keys on HTMLModelElementCamera be required to reject incomplete objects.

* Modules/model-element/HTMLModelElement.cpp:
(WebCore::HTMLModelElement::getCamera):
(WebCore::HTMLModelElement::setCamera):
* Modules/model-element/HTMLModelElementCamera.idl:

LayoutTests:

Add a new test that exercises the getCamera() and setCamera() methods.
These are currently skipped in OpenSource and will be enabled on internal bots.

* model-element/model-element-camera-expected.txt: Added.
* model-element/model-element-camera.html: Added.
* platform/ios/TestExpectations:
* platform/mac/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288439 => 288440)


--- trunk/LayoutTests/ChangeLog	2022-01-24 15:37:20 UTC (rev 288439)
+++ trunk/LayoutTests/ChangeLog	2022-01-24 16:02:11 UTC (rev 288440)
@@ -1,3 +1,18 @@
+2022-01-24  Antoine Quint  <[email protected]>
+
+        [Model] Add testing coverage for camera API
+        https://bugs.webkit.org/show_bug.cgi?id=233643
+
+        Reviewed by Dean Jackson.
+
+        Add a new test that exercises the getCamera() and setCamera() methods.
+        These are currently skipped in OpenSource and will be enabled on internal bots.
+
+        * model-element/model-element-camera-expected.txt: Added.
+        * model-element/model-element-camera.html: Added.
+        * platform/ios/TestExpectations:
+        * platform/mac/TestExpectations:
+
 2022-01-24  Antti Koivisto  <[email protected]>
 
         [CSS Container Queries] Import WPT tests

Added: trunk/LayoutTests/model-element/model-element-camera-expected.txt (0 => 288440)


--- trunk/LayoutTests/model-element/model-element-camera-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/model-element/model-element-camera-expected.txt	2022-01-24 16:02:11 UTC (rev 288440)
@@ -0,0 +1,6 @@
+
+PASS <model> has getCamera() and setCamera() methods
+PASS <model> cannot get or set the camera until it's ready
+PASS <model> can set the camera and read it back
+PASS <model> cannot set the camera if it's not a valid HTMLModelElementCamera
+

Added: trunk/LayoutTests/model-element/model-element-camera.html (0 => 288440)


--- trunk/LayoutTests/model-element/model-element-camera.html	                        (rev 0)
+++ trunk/LayoutTests/model-element/model-element-camera.html	2022-01-24 16:02:11 UTC (rev 288440)
@@ -0,0 +1,85 @@
+<script src=""
+<script src=""
+<script>
+
+const makeModel = () => {
+    const source = document.createElement("source");
+    source.src = ""
+    const model = document.createElement("model");
+    model.appendChild(source);
+    return model;
+}
+
+const bodyAvailability = async () => {
+    return new Promise(resolve => {
+        if (document.body)
+            resolve();
+        else
+            window.addEventListener("DOMContentLoaded", event => resolve());
+    });
+};
+
+const readyModel = async (test) => {
+    await bodyAvailability();
+    const model = document.body.appendChild(makeModel());
+    test.add_cleanup(() => model.remove());
+    await model.ready;
+    return model;
+};
+
+const epsilon = 0.001;
+const expectedCamera = { pitch: 10, yaw: 40, scale: 2 };
+
+test(() => {
+    const model = document.createElement("model");
+    assert_idl_attribute(model, "getCamera", "getCamera() is defined");
+    assert_idl_attribute(model, "setCamera", "setCamera() is defined");
+}, "<model> has getCamera() and setCamera() methods");
+
+promise_test(async test => {
+    // Right now, a <model> won't be ready until it's added to the document
+    // since it requires a renderer to create the supporting ModelPlayer.
+    // But this means an initial camera can't be set, we should think about
+    // whether this is what we want. But since this is the current behavior,
+    // let's make sure to test it.
+    const model = makeModel();
+
+    const getCameraPromise = model.getCamera();
+    await promise_rejects(test, "AbortError", getCameraPromise,
+                              "The promise returned by getCamera() should be rejected if the model element is not ready.");
+
+    const setCameraPromise = model.setCamera(expectedCamera);
+    await promise_rejects(test, "AbortError", setCameraPromise,
+                            "The promise returned by setCamera() should be rejected if the model element is not ready.");
+}, "<model> cannot get or set the camera until it's ready");
+
+promise_test(async test => {
+    const model = await readyModel(test);
+    await model.setCamera(expectedCamera);
+    const actualCamera = await model.getCamera();
+    assert_approx_equals(actualCamera.pitch, expectedCamera.pitch, epsilon, "Camera has expected pitch");
+    assert_approx_equals(actualCamera.yaw, expectedCamera.yaw, epsilon, "Camera has expected yaw");
+    assert_approx_equals(actualCamera.scale, expectedCamera.scale, epsilon, "Camera has expected scale");
+}, "<model> can set the camera and read it back");
+
+promise_test(async test => {
+    const model = await readyModel(test);
+
+    const expectCameraFailure = async (camera, description) => {
+        return model.setCamera(camera).then(test.unreached_func("Should have rejected: " + description)).catch(error => {
+            assert_true(error.toString().includes("TypeError"), description);
+        });
+    };
+
+    await expectCameraFailure(undefined, "The camera should be rejected if it's undefined");
+    await expectCameraFailure(null, "The camera should be rejected if it's null");
+    await expectCameraFailure("", "The camera should be rejected if it's a string");
+    await expectCameraFailure(1, "The camera should be rejected if it's a number");
+    await expectCameraFailure({}, "The camera should be rejected if the camera is the empty object");
+    await expectCameraFailure({ pitch: "pitch", yaw: "yaw", scale: "scale" }, "The camera should be rejected if the properties don't have the expected type");
+    await expectCameraFailure({ pitch: 10, yaw: 10 }, "The camera should be rejected if all properties aren't set");
+}, "<model> cannot set the camera if it's not a valid HTMLModelElementCamera");
+
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios/TestExpectations (288439 => 288440)


--- trunk/LayoutTests/platform/ios/TestExpectations	2022-01-24 15:37:20 UTC (rev 288439)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2022-01-24 16:02:11 UTC (rev 288440)
@@ -3420,6 +3420,9 @@
 [ Release ] fast/canvas/canvas-composite-text-alpha.html [ Pass Timeout Failure ]
 fast/canvas/canvas-blending-text.html [ Pass Failure ]
 
+# This test requires ARQL SPIs not yet available to OpenSource builds.
+model-element/model-element-camera.html [ Skip ]
+
 # These tests require the design system ui fonts to be installed.
 fast/text/design-system-ui-11.html [ Pass ]
 fast/text/design-system-ui-12.html [ Pass ]

Modified: trunk/LayoutTests/platform/mac/TestExpectations (288439 => 288440)


--- trunk/LayoutTests/platform/mac/TestExpectations	2022-01-24 15:37:20 UTC (rev 288439)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2022-01-24 16:02:11 UTC (rev 288440)
@@ -107,6 +107,9 @@
 model-element/model-element-contents-layer-updates-with-clipping.html [ Skip ]
 model-element/model-element-contents-layer-updates.html [ Skip ]
 
+# This test requires ARQL SPIs not yet available to OpenSource builds.
+model-element/model-element-camera.html [ Skip ]
+
 # Accessibility tests for notifications that don't exist or aren't needed on Mac OS X.
 accessibility/aria-checkbox-sends-notification.html
 accessibility/aria-switch-sends-notification.html

Modified: trunk/Source/WebCore/ChangeLog (288439 => 288440)


--- trunk/Source/WebCore/ChangeLog	2022-01-24 15:37:20 UTC (rev 288439)
+++ trunk/Source/WebCore/ChangeLog	2022-01-24 16:02:11 UTC (rev 288440)
@@ -1,3 +1,21 @@
+2022-01-24  Antoine Quint  <[email protected]>
+
+        [Model] Add testing coverage for camera API
+        https://bugs.webkit.org/show_bug.cgi?id=233643
+
+        Reviewed by Dean Jackson.
+
+        Test: model-element/model-element-camera.html
+
+        We reject the promise returned by the getCamera() and setCamera() methods
+        with an Exception so that we can correctly test this behavior. We also make
+        the keys on HTMLModelElementCamera be required to reject incomplete objects.
+
+        * Modules/model-element/HTMLModelElement.cpp:
+        (WebCore::HTMLModelElement::getCamera):
+        (WebCore::HTMLModelElement::setCamera):
+        * Modules/model-element/HTMLModelElementCamera.idl:
+
 2022-01-24  Youenn Fablet  <[email protected]>
 
         Reconfiguring the CoreAudioSharedUnit should take into account that there is a speaker sample producer

Modified: trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp (288439 => 288440)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp	2022-01-24 15:37:20 UTC (rev 288439)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp	2022-01-24 16:02:11 UTC (rev 288440)
@@ -391,7 +391,7 @@
 void HTMLModelElement::getCamera(CameraPromise&& promise)
 {
     if (!m_modelPlayer) {
-        promise.reject();
+        promise.reject(Exception { AbortError });
         return;
     }
 
@@ -406,7 +406,7 @@
 void HTMLModelElement::setCamera(HTMLModelElementCamera camera, DOMPromiseDeferred<void>&& promise)
 {
     if (!m_modelPlayer) {
-        promise.reject();
+        promise.reject(Exception { AbortError });
         return;
     }
 

Modified: trunk/Source/WebCore/Modules/model-element/HTMLModelElementCamera.idl (288439 => 288440)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElementCamera.idl	2022-01-24 15:37:20 UTC (rev 288439)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElementCamera.idl	2022-01-24 16:02:11 UTC (rev 288440)
@@ -28,7 +28,7 @@
     EnabledBySetting=ModelElementEnabled,
     JSGenerateToJSObject
 ] dictionary HTMLModelElementCamera {
-    double pitch;
-    double yaw;
-    double scale;
+    required double pitch;
+    required double yaw;
+    required double scale;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to