Guards explicit device.destroy() until tested.

Bug: dawn:628
Change-Id: Ib6a6be0e5467d3cdd6432834d6f9d5c2000b18be
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/76340
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp
index 559fa93..1775574 100644
--- a/src/dawn_native/Device.cpp
+++ b/src/dawn_native/Device.cpp
@@ -405,6 +405,12 @@
     }
 
     void DeviceBase::APIDestroy() {
+        // TODO(crbug.com/dawn/628) Re-enable once CTS testing is in place and passing.
+        if (IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
+            ConsumedError(DAWN_VALIDATION_ERROR(
+                "Explicit device.destroy() is disallowed because it is not fully implemented"));
+            return;
+        }
         Destroy();
     }
 
diff --git a/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp b/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp
index b115a5d..cba13c1 100644
--- a/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp
+++ b/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp
@@ -19,6 +19,10 @@
 #include "utils/ComboRenderPipelineDescriptor.h"
 #include "utils/WGPUHelpers.h"
 
+namespace {
+    using testing::HasSubstr;
+}  // anonymous namespace
+
 class UnsafeAPIValidationTest : public ValidationTest {
   protected:
     WGPUDevice CreateTestDevice() override {
@@ -49,6 +53,12 @@
     ASSERT_DEVICE_ERROR(device.CreateTexture(&desc));
 }
 
+// Check that explicit user device.destroy() is disallowed as part of unsafe APIs.
+// TODO(crbug.com/dawn/628) Remove when CTS testing is in place and passing.
+TEST_F(UnsafeAPIValidationTest, ExplicitDeviceDestroy) {
+    ASSERT_DEVICE_ERROR(device.Destroy(), HasSubstr("Explicit device.destroy() is disallowed"));
+}
+
 // Check that pipeline overridable constants are disallowed as part of unsafe APIs.
 // TODO(dawn:1041) Remove when implementation for all backend is added
 TEST_F(UnsafeAPIValidationTest, PipelineOverridableConstants) {