| <!DOCTYPE html> <!-- webkit-test-runner [ SpatialPortalEnabled=true ModelElementEnabled=true ModelProcessEnabled=true allowTestOnlyIPC=true ] --> |
| <html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="resources/spatial-portal-utils.js"></script> |
| <style> |
| .portal { spatial: portal; width: 300px; height: 150px; } |
| </style> |
| <body> |
| <script> |
| 'use strict'; |
| |
| window.internals?.disableModelLoadDelaysForTesting(); |
| |
| promise_test(async t => { |
| const portal = createPortal(t); |
| const changing = appendModel(portal, "cube.usdz"); |
| const untouched = appendModel(portal, "cube.usdz"); |
| await Promise.all([changing.ready, untouched.ready]); |
| |
| const untouchedReadyBeforeChange = untouched.ready; |
| changing.querySelector("source").src = "../model-element/resources/2x2x2-center.usdz"; |
| await changing.ready; |
| |
| assert_equals(untouched.ready, untouchedReadyBeforeChange, "the sibling's ready promise was not reset"); |
| await untouched.ready; |
| assert_equals(internals.modelElementState(changing), "Loaded", "the re-sourced model is loaded"); |
| assert_equals(internals.modelElementState(untouched), "Loaded", "its sibling is still loaded"); |
| }, "Changing the source of one <model> in a spatial portal leaves its sibling loaded"); |
| |
| promise_test(async t => { |
| const portal = createPortal(t); |
| const unloading = appendModel(portal, "cube.usdz"); |
| const untouched = appendModel(portal, "cube.usdz"); |
| await Promise.all([unloading.ready, untouched.ready]); |
| |
| const unloadingReadyBeforeChange = unloading.ready; |
| const untouchedReadyBeforeChange = untouched.ready; |
| const errored = new Promise(resolve => unloading.addEventListener("error", resolve, { once: true })); |
| |
| unloading.querySelector("source").remove(); |
| await errored; |
| |
| assert_not_equals(unloading.ready, unloadingReadyBeforeChange, "the unsourced model's ready promise was replaced"); |
| assert_equals(untouched.ready, untouchedReadyBeforeChange, "the sibling's ready promise was not reset"); |
| assert_equals(internals.numberOfHostedModelsInSpatialPortal(portal), 2, "the unsourced model stays registered with the portal"); |
| assert_equals(internals.modelElementState(unloading), "Deferred", "the unsourced model has nothing to load"); |
| assert_equals(internals.modelElementState(untouched), "Loaded", "only the sibling is still loaded"); |
| await untouched.ready; |
| }, "Clearing the source of one <model> in a spatial portal unloads only that model"); |
| |
| </script> |
| </body> |
| </html> |