Fix dangling pointers in DawnMockTest

Bug: dawn:2346
Change-Id: I632d98c11ffd95db5a76a12ea6d0c2af5145bb0b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/183200
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn/tests/unittests/native/AllowedErrorTests.cpp b/src/dawn/tests/unittests/native/AllowedErrorTests.cpp
index 46a6ea9..4a0fde0 100644
--- a/src/dawn/tests/unittests/native/AllowedErrorTests.cpp
+++ b/src/dawn/tests/unittests/native/AllowedErrorTests.cpp
@@ -76,7 +76,7 @@
                                           mDeviceErrorCb.MakeUserdata(this));
     }
 
-    ~AllowedErrorTests() override { device = nullptr; }
+    ~AllowedErrorTests() override { DropDevice(); }
 
   protected:
     // Device mock callbacks used throughout the tests.
diff --git a/src/dawn/tests/unittests/native/CreatePipelineAsyncTaskTests.cpp b/src/dawn/tests/unittests/native/CreatePipelineAsyncTaskTests.cpp
index ea26b2c..cfae277 100644
--- a/src/dawn/tests/unittests/native/CreatePipelineAsyncTaskTests.cpp
+++ b/src/dawn/tests/unittests/native/CreatePipelineAsyncTaskTests.cpp
@@ -190,8 +190,8 @@
 
     CreateRenderPipelineAsyncTask::RunAsync(std::move(asyncTask));
 
-    device = nullptr;
     // Dropping the device should force the async task to finish.
+    DropDevice();
     EXPECT_TRUE(done);
 }
 
diff --git a/src/dawn/tests/unittests/native/DeviceAsyncTaskTests.cpp b/src/dawn/tests/unittests/native/DeviceAsyncTaskTests.cpp
index 191c998..225bfed 100644
--- a/src/dawn/tests/unittests/native/DeviceAsyncTaskTests.cpp
+++ b/src/dawn/tests/unittests/native/DeviceAsyncTaskTests.cpp
@@ -55,7 +55,7 @@
     });
 
     mDeviceMock->GetAsyncTaskManager()->PostTask(std::move(asyncTask));
-    device = nullptr;
+    DropDevice();
     // Dropping the device should force the async task to finish.
     EXPECT_TRUE(done.load());
 }
diff --git a/src/dawn/tests/unittests/native/mocks/DawnMockTest.cpp b/src/dawn/tests/unittests/native/mocks/DawnMockTest.cpp
index 1abf234..acfc2bb 100644
--- a/src/dawn/tests/unittests/native/mocks/DawnMockTest.cpp
+++ b/src/dawn/tests/unittests/native/mocks/DawnMockTest.cpp
@@ -41,8 +41,13 @@
     device = wgpu::Device::Acquire(ToAPI(ReturnToAPI<DeviceBase>(std::move(deviceMock))));
 }
 
+void DawnMockTest::DropDevice() {
+    mDeviceMock = nullptr;
+    device = nullptr;
+}
+
 DawnMockTest::~DawnMockTest() {
-    device = wgpu::Device();
+    DropDevice();
     dawnProcSetProcs(nullptr);
 }
 
diff --git a/src/dawn/tests/unittests/native/mocks/DawnMockTest.h b/src/dawn/tests/unittests/native/mocks/DawnMockTest.h
index 47eb1c2..3fef33e 100644
--- a/src/dawn/tests/unittests/native/mocks/DawnMockTest.h
+++ b/src/dawn/tests/unittests/native/mocks/DawnMockTest.h
@@ -39,8 +39,9 @@
     ~DawnMockTest() override;
 
   protected:
-    // TODO(https://crbug.com/dawn/2346): Investigate `DanglingUntriaged` pointers in dawn/test.
-    raw_ptr<::testing::NiceMock<DeviceMock>, DanglingUntriaged> mDeviceMock;
+    void DropDevice();
+
+    raw_ptr<::testing::NiceMock<DeviceMock>> mDeviceMock;
     wgpu::Device device;
 };