Make more WireTests use the C++ device/queue.

Left to convert are the tests for Future-related calls, and the
WireBufferMappingTests.

Bug: 353294052
Change-Id: I59c56c811f0b559649b3cd74a0bae071bb128692
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/198894
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/tests/unittests/wire/WireDisconnectTests.cpp b/src/dawn/tests/unittests/wire/WireDisconnectTests.cpp
index 5a2f94f..4957945 100644
--- a/src/dawn/tests/unittests/wire/WireDisconnectTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireDisconnectTests.cpp
@@ -47,7 +47,7 @@
 // Test that commands are not received if the client disconnects.
 TEST_F(WireDisconnectTests, CommandsAfterDisconnect) {
     // Check that commands work at all.
-    wgpuDeviceCreateCommandEncoder(cDevice, nullptr);
+    wgpu::CommandEncoder encoder1 = device.CreateCommandEncoder();
 
     WGPUCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
     EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice, nullptr))
@@ -58,7 +58,7 @@
     GetWireClient()->Disconnect();
 
     // Command is not received because client disconnected.
-    wgpuDeviceCreateCommandEncoder(cDevice, nullptr);
+    wgpu::CommandEncoder encoder2 = device.CreateCommandEncoder();
     EXPECT_CALL(api, DeviceCreateCommandEncoder(_, _)).Times(Exactly(0));
     FlushClient();
 }
@@ -67,7 +67,7 @@
 // after are received.
 TEST_F(WireDisconnectTests, FlushAfterDisconnect) {
     // Check that commands work at all.
-    wgpuDeviceCreateCommandEncoder(cDevice, nullptr);
+    wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
 
     // Disconnect.
     GetWireClient()->Disconnect();
@@ -109,8 +109,8 @@
 // callback again.
 TEST_F(WireDisconnectTests, ServerLostThenDisconnectInCallback) {
     MockCallback<WGPUDeviceLostCallback> mockDeviceLostCallback;
-    wgpuDeviceSetDeviceLostCallback(cDevice, mockDeviceLostCallback.Callback(),
-                                    mockDeviceLostCallback.MakeUserdata(this));
+    device.SetDeviceLostCallback(mockDeviceLostCallback.Callback(),
+                                 mockDeviceLostCallback.MakeUserdata(this));
 
     api.CallDeviceSetDeviceLostCallbackCallback(apiDevice, WGPUDeviceLostReason_Unknown,
                                                 "lost reason");
@@ -129,8 +129,8 @@
 // Check that a device loss after a disconnect does not trigger the callback again.
 TEST_F(WireDisconnectTests, DisconnectThenServerLost) {
     MockCallback<WGPUDeviceLostCallback> mockDeviceLostCallback;
-    wgpuDeviceSetDeviceLostCallback(cDevice, mockDeviceLostCallback.Callback(),
-                                    mockDeviceLostCallback.MakeUserdata(this));
+    device.SetDeviceLostCallback(mockDeviceLostCallback.Callback(),
+                                 mockDeviceLostCallback.MakeUserdata(this));
 
     // Disconnect the client. We should see the callback once.
     EXPECT_CALL(mockDeviceLostCallback, Call(WGPUDeviceLostReason_InstanceDropped, _, this))
@@ -147,9 +147,8 @@
 
 // Test that client objects are all destroyed if the WireClient is destroyed.
 TEST_F(WireDisconnectTests, DeleteClientDestroysObjects) {
-    WGPUSamplerDescriptor desc = {};
-    wgpuDeviceCreateCommandEncoder(cDevice, nullptr);
-    wgpuDeviceCreateSampler(cDevice, &desc);
+    wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+    wgpu::Sampler sampler = device.CreateSampler();
 
     WGPUCommandEncoder apiCommandEncoder = api.GetNewCommandEncoder();
     EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice, nullptr))
diff --git a/src/dawn/tests/unittests/wire/WireErrorCallbackTests.cpp b/src/dawn/tests/unittests/wire/WireErrorCallbackTests.cpp
index ed44cac..5e92160 100644
--- a/src/dawn/tests/unittests/wire/WireErrorCallbackTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireErrorCallbackTests.cpp
@@ -106,7 +106,7 @@
 
 // Test the return wire for device validation error callbacks
 TEST_F(WireErrorCallbackTests, DeviceValidationErrorCallback) {
-    wgpuDeviceSetUncapturedErrorCallback(cDevice, ToMockDeviceErrorCallback, this);
+    device.SetUncapturedErrorCallback(ToMockDeviceErrorCallback, this);
 
     // Setting the error callback should stay on the client side and do nothing
     FlushClient();
@@ -125,7 +125,7 @@
 
 // Test the return wire for device OOM error callbacks
 TEST_F(WireErrorCallbackTests, DeviceOutOfMemoryErrorCallback) {
-    wgpuDeviceSetUncapturedErrorCallback(cDevice, ToMockDeviceErrorCallback, this);
+    device.SetUncapturedErrorCallback(ToMockDeviceErrorCallback, this);
 
     // Setting the error callback should stay on the client side and do nothing
     FlushClient();
@@ -144,7 +144,7 @@
 
 // Test the return wire for device internal error callbacks
 TEST_F(WireErrorCallbackTests, DeviceInternalErrorCallback) {
-    wgpuDeviceSetUncapturedErrorCallback(cDevice, ToMockDeviceErrorCallback, this);
+    device.SetUncapturedErrorCallback(ToMockDeviceErrorCallback, this);
 
     // Setting the error callback should stay on the client side and do nothing
     FlushClient();
@@ -163,7 +163,7 @@
 
 // Test the return wire for device user warning callbacks
 TEST_F(WireErrorCallbackTests, DeviceLoggingCallback) {
-    wgpuDeviceSetLoggingCallback(cDevice, ToMockDeviceLoggingCallback, this);
+    device.SetLoggingCallback(ToMockDeviceLoggingCallback, this);
 
     // Setting the injected warning callback should stay on the client side and do nothing
     FlushClient();
@@ -201,21 +201,23 @@
   protected:
     // Overridden version of wgpuDevicePopErrorScope that defers to the API call based on the test
     // callback mode.
-    void DevicePopErrorScope(WGPUDevice d, void* userdata = nullptr) {
+    void DevicePopErrorScope(const wgpu::Device& d, void* userdata = nullptr) {
         if (IsAsync()) {
-            wgpuDevicePopErrorScope(d, mMockOldCb.Callback(), mMockOldCb.MakeUserdata(userdata));
+            d.PopErrorScope(mMockOldCb.Callback(), mMockOldCb.MakeUserdata(userdata));
         } else {
-            WGPUPopErrorScopeCallbackInfo callbackInfo = {};
-            callbackInfo.mode = ToWGPUCallbackMode(GetParam().mCallbackMode);
+            wgpu::PopErrorScopeCallbackInfo callbackInfo = {};
+            callbackInfo.mode =
+                static_cast<wgpu::CallbackMode>(ToWGPUCallbackMode(GetParam().mCallbackMode));
             callbackInfo.callback = mMockCb.Callback();
             callbackInfo.userdata = mMockCb.MakeUserdata(userdata);
-            this->mFutureIDs.push_back(wgpuDevicePopErrorScopeF(d, callbackInfo).id);
+            this->mFutureIDs.push_back(d.PopErrorScope(callbackInfo).id);
         }
     }
 
-    void PushErrorScope(WGPUErrorFilter filter) {
-        EXPECT_CALL(api, DevicePushErrorScope(apiDevice, filter)).Times(1);
-        wgpuDevicePushErrorScope(cDevice, filter);
+    void PushErrorScope(wgpu::ErrorFilter filter) {
+        EXPECT_CALL(api, DevicePushErrorScope(apiDevice, static_cast<WGPUErrorFilter>(filter)))
+            .Times(1);
+        device.PushErrorScope(filter);
         FlushClient();
     }
 
@@ -239,15 +241,15 @@
 
 // Test the return wire for validation error scopes.
 TEST_P(WirePopErrorScopeCallbackTests, TypeAndFilters) {
-    static constexpr std::array<std::pair<WGPUErrorType, WGPUErrorFilter>, 3> kErrorTypeAndFilters =
-        {{{WGPUErrorType_Validation, WGPUErrorFilter_Validation},
-          {WGPUErrorType_OutOfMemory, WGPUErrorFilter_OutOfMemory},
-          {WGPUErrorType_Internal, WGPUErrorFilter_Internal}}};
+    static constexpr std::array<std::pair<WGPUErrorType, wgpu::ErrorFilter>, 3>
+        kErrorTypeAndFilters = {{{WGPUErrorType_Validation, wgpu::ErrorFilter::Validation},
+                                 {WGPUErrorType_OutOfMemory, wgpu::ErrorFilter::OutOfMemory},
+                                 {WGPUErrorType_Internal, wgpu::ErrorFilter::Internal}}};
 
     for (const auto& [type, filter] : kErrorTypeAndFilters) {
         PushErrorScope(filter);
 
-        DevicePopErrorScope(cDevice, this);
+        DevicePopErrorScope(device, this);
         EXPECT_CALL(api, OnDevicePopErrorScope2(apiDevice, _)).WillOnce([&] {
             api.CallDevicePopErrorScope2Callback(apiDevice, WGPUPopErrorScopeStatus_Success, type,
                                                  "Some error message");
@@ -274,9 +276,9 @@
 // Wire disconnect before server response calls the callback with Unknown error type.
 // TODO(crbug.com/dawn/2021) When using new callback signature, check for InstanceDropped status.
 TEST_P(WirePopErrorScopeCallbackTests, DisconnectBeforeServerReply) {
-    PushErrorScope(WGPUErrorFilter_Validation);
+    PushErrorScope(wgpu::ErrorFilter::Validation);
 
-    DevicePopErrorScope(cDevice, this);
+    DevicePopErrorScope(device, this);
     EXPECT_CALL(api, OnDevicePopErrorScope2(apiDevice, _)).Times(1);
 
     FlushClient();
@@ -302,9 +304,9 @@
     // reponse, the callback would also be fired.
     DAWN_SKIP_TEST_IF(IsSpontaneous());
 
-    PushErrorScope(WGPUErrorFilter_Validation);
+    PushErrorScope(wgpu::ErrorFilter::Validation);
 
-    DevicePopErrorScope(cDevice, this);
+    DevicePopErrorScope(device, this);
     EXPECT_CALL(api, OnDevicePopErrorScope2(apiDevice, _)).WillOnce(InvokeWithoutArgs([&] {
         api.CallDevicePopErrorScope2Callback(apiDevice, WGPUPopErrorScopeStatus_Success,
                                              WGPUErrorType_Validation, "Some error message");
diff --git a/src/dawn/tests/unittests/wire/WireExtensionTests.cpp b/src/dawn/tests/unittests/wire/WireExtensionTests.cpp
index 923b854..02a6c74 100644
--- a/src/dawn/tests/unittests/wire/WireExtensionTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireExtensionTests.cpp
@@ -44,28 +44,26 @@
 
 // Serialize/Deserializes a chained struct correctly.
 TEST_F(WireExtensionTests, ChainedStruct) {
-    WGPUShaderModuleDescriptor shaderModuleDesc = {};
+    wgpu::ShaderModuleDescriptor shaderModuleDesc = {};
     WGPUShaderModule apiShaderModule = api.GetNewShaderModule();
-    WGPUShaderModule shaderModule = wgpuDeviceCreateShaderModule(cDevice, &shaderModuleDesc);
+    wgpu::ShaderModule shaderModule = device.CreateShaderModule(&shaderModuleDesc);
     EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule));
     FlushClient();
 
-    WGPUPrimitiveDepthClipControl clientExt = {};
-    clientExt.chain.sType = WGPUSType_PrimitiveDepthClipControl;
-    clientExt.chain.next = nullptr;
+    wgpu::PrimitiveDepthClipControl clientExt;
     clientExt.unclippedDepth = true;
 
-    WGPURenderPipelineDescriptor renderPipelineDesc = {};
+    wgpu::RenderPipelineDescriptor renderPipelineDesc;
     renderPipelineDesc.vertex.module = shaderModule;
-    renderPipelineDesc.primitive.nextInChain = &clientExt.chain;
+    renderPipelineDesc.primitive.nextInChain = &clientExt;
 
-    wgpuDeviceCreateRenderPipeline(cDevice, &renderPipelineDesc);
+    wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&renderPipelineDesc);
     EXPECT_CALL(api, DeviceCreateRenderPipeline(apiDevice, NotNull()))
         .WillOnce(Invoke(
             [&](Unused, const WGPURenderPipelineDescriptor* serverDesc) -> WGPURenderPipeline {
                 const auto* ext = reinterpret_cast<const WGPUPrimitiveDepthClipControl*>(
                     serverDesc->primitive.nextInChain);
-                EXPECT_EQ(ext->chain.sType, clientExt.chain.sType);
+                EXPECT_EQ(ext->chain.sType, WGPUSType_PrimitiveDepthClipControl);
                 EXPECT_EQ(ext->unclippedDepth, true);
                 EXPECT_EQ(ext->chain.next, nullptr);
 
@@ -76,38 +74,35 @@
 
 // Serialize/Deserializes multiple chained structs correctly.
 TEST_F(WireExtensionTests, MutlipleChainedStructs) {
-    WGPUShaderModuleDescriptor shaderModuleDesc = {};
+    wgpu::ShaderModuleDescriptor shaderModuleDesc = {};
     WGPUShaderModule apiShaderModule = api.GetNewShaderModule();
-    WGPUShaderModule shaderModule = wgpuDeviceCreateShaderModule(cDevice, &shaderModuleDesc);
+    wgpu::ShaderModule shaderModule = device.CreateShaderModule(&shaderModuleDesc);
     EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule));
     FlushClient();
 
-    WGPUPrimitiveDepthClipControl clientExt2 = {};
-    clientExt2.chain.sType = WGPUSType_PrimitiveDepthClipControl;
-    clientExt2.chain.next = nullptr;
+    wgpu::PrimitiveDepthClipControl clientExt2;
     clientExt2.unclippedDepth = false;
 
-    WGPUPrimitiveDepthClipControl clientExt1 = {};
-    clientExt1.chain.sType = WGPUSType_PrimitiveDepthClipControl;
-    clientExt1.chain.next = &clientExt2.chain;
+    wgpu::PrimitiveDepthClipControl clientExt1;
+    clientExt1.nextInChain = &clientExt2;
     clientExt1.unclippedDepth = true;
 
-    WGPURenderPipelineDescriptor renderPipelineDesc = {};
+    wgpu::RenderPipelineDescriptor renderPipelineDesc;
     renderPipelineDesc.vertex.module = shaderModule;
-    renderPipelineDesc.primitive.nextInChain = &clientExt1.chain;
+    renderPipelineDesc.primitive.nextInChain = &clientExt1;
 
-    wgpuDeviceCreateRenderPipeline(cDevice, &renderPipelineDesc);
+    wgpu::RenderPipeline pipeline1 = device.CreateRenderPipeline(&renderPipelineDesc);
     EXPECT_CALL(api, DeviceCreateRenderPipeline(apiDevice, NotNull()))
         .WillOnce(Invoke(
             [&](Unused, const WGPURenderPipelineDescriptor* serverDesc) -> WGPURenderPipeline {
                 const auto* ext1 = reinterpret_cast<const WGPUPrimitiveDepthClipControl*>(
                     serverDesc->primitive.nextInChain);
-                EXPECT_EQ(ext1->chain.sType, clientExt1.chain.sType);
+                EXPECT_EQ(ext1->chain.sType, WGPUSType_PrimitiveDepthClipControl);
                 EXPECT_EQ(ext1->unclippedDepth, true);
 
                 const auto* ext2 =
                     reinterpret_cast<const WGPUPrimitiveDepthClipControl*>(ext1->chain.next);
-                EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType);
+                EXPECT_EQ(ext2->chain.sType, WGPUSType_PrimitiveDepthClipControl);
                 EXPECT_EQ(ext2->unclippedDepth, false);
                 EXPECT_EQ(ext2->chain.next, nullptr);
 
@@ -116,22 +111,22 @@
     FlushClient();
 
     // Swap the order of the chained structs.
-    renderPipelineDesc.primitive.nextInChain = &clientExt2.chain;
-    clientExt2.chain.next = &clientExt1.chain;
-    clientExt1.chain.next = nullptr;
+    renderPipelineDesc.primitive.nextInChain = &clientExt2;
+    clientExt2.nextInChain = &clientExt1;
+    clientExt1.nextInChain = nullptr;
 
-    wgpuDeviceCreateRenderPipeline(cDevice, &renderPipelineDesc);
+    wgpu::RenderPipeline pipeline2 = device.CreateRenderPipeline(&renderPipelineDesc);
     EXPECT_CALL(api, DeviceCreateRenderPipeline(apiDevice, NotNull()))
         .WillOnce(Invoke(
             [&](Unused, const WGPURenderPipelineDescriptor* serverDesc) -> WGPURenderPipeline {
                 const auto* ext2 = reinterpret_cast<const WGPUPrimitiveDepthClipControl*>(
                     serverDesc->primitive.nextInChain);
-                EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType);
+                EXPECT_EQ(ext2->chain.sType, WGPUSType_PrimitiveDepthClipControl);
                 EXPECT_EQ(ext2->unclippedDepth, false);
 
                 const auto* ext1 =
                     reinterpret_cast<const WGPUPrimitiveDepthClipControl*>(ext2->chain.next);
-                EXPECT_EQ(ext1->chain.sType, clientExt1.chain.sType);
+                EXPECT_EQ(ext1->chain.sType, WGPUSType_PrimitiveDepthClipControl);
                 EXPECT_EQ(ext1->unclippedDepth, true);
                 EXPECT_EQ(ext1->chain.next, nullptr);
 
@@ -142,21 +137,20 @@
 
 // Test that a chained struct with Invalid sType passes through as Invalid.
 TEST_F(WireExtensionTests, InvalidSType) {
-    WGPUShaderModuleDescriptor shaderModuleDesc = {};
+    wgpu::ShaderModuleDescriptor shaderModuleDesc = {};
     WGPUShaderModule apiShaderModule = api.GetNewShaderModule();
-    WGPUShaderModule shaderModule = wgpuDeviceCreateShaderModule(cDevice, &shaderModuleDesc);
+    wgpu::ShaderModule shaderModule = device.CreateShaderModule(&shaderModuleDesc);
     EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule));
     FlushClient();
 
-    WGPUPrimitiveDepthClipControl clientExt = {};
-    clientExt.chain.sType = WGPUSType(0);
-    clientExt.chain.next = nullptr;
+    wgpu::PrimitiveDepthClipControl clientExt = {};
+    clientExt.sType = wgpu::SType(0);
 
-    WGPURenderPipelineDescriptor renderPipelineDesc = {};
+    wgpu::RenderPipelineDescriptor renderPipelineDesc;
     renderPipelineDesc.vertex.module = shaderModule;
-    renderPipelineDesc.primitive.nextInChain = &clientExt.chain;
+    renderPipelineDesc.primitive.nextInChain = &clientExt;
 
-    wgpuDeviceCreateRenderPipeline(cDevice, &renderPipelineDesc);
+    wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&renderPipelineDesc);
     EXPECT_CALL(api, DeviceCreateRenderPipeline(apiDevice, NotNull()))
         .WillOnce(Invoke(
             [&](Unused, const WGPURenderPipelineDescriptor* serverDesc) -> WGPURenderPipeline {
@@ -169,21 +163,20 @@
 
 // Test that a chained struct with unknown sType passes through as Invalid.
 TEST_F(WireExtensionTests, UnknownSType) {
-    WGPUShaderModuleDescriptor shaderModuleDesc = {};
+    wgpu::ShaderModuleDescriptor shaderModuleDesc = {};
     WGPUShaderModule apiShaderModule = api.GetNewShaderModule();
-    WGPUShaderModule shaderModule = wgpuDeviceCreateShaderModule(cDevice, &shaderModuleDesc);
+    wgpu::ShaderModule shaderModule = device.CreateShaderModule(&shaderModuleDesc);
     EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiShaderModule));
     FlushClient();
 
-    WGPUPrimitiveDepthClipControl clientExt = {};
-    clientExt.chain.sType = static_cast<WGPUSType>(-1);
-    clientExt.chain.next = nullptr;
+    wgpu::PrimitiveDepthClipControl clientExt = {};
+    clientExt.sType = static_cast<wgpu::SType>(-1);
 
-    WGPURenderPipelineDescriptor renderPipelineDesc = {};
+    wgpu::RenderPipelineDescriptor renderPipelineDesc;
     renderPipelineDesc.vertex.module = shaderModule;
-    renderPipelineDesc.primitive.nextInChain = &clientExt.chain;
+    renderPipelineDesc.primitive.nextInChain = &clientExt;
 
-    wgpuDeviceCreateRenderPipeline(cDevice, &renderPipelineDesc);
+    wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&renderPipelineDesc);
     EXPECT_CALL(api, DeviceCreateRenderPipeline(apiDevice, NotNull()))
         .WillOnce(Invoke(
             [&](Unused, const WGPURenderPipelineDescriptor* serverDesc) -> WGPURenderPipeline {
diff --git a/src/dawn/tests/unittests/wire/WireInjectBufferTests.cpp b/src/dawn/tests/unittests/wire/WireInjectBufferTests.cpp
index 8c0bac6..0b719b6 100644
--- a/src/dawn/tests/unittests/wire/WireInjectBufferTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireInjectBufferTests.cpp
@@ -25,8 +25,9 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#include "dawn/tests/unittests/wire/WireTest.h"
+#include <utility>
 
+#include "dawn/tests/unittests/wire/WireTest.h"
 #include "dawn/wire/WireClient.h"
 #include "dawn/wire/WireServer.h"
 
@@ -41,95 +42,108 @@
     WireInjectBufferTests() {}
     ~WireInjectBufferTests() override = default;
 
+    std::pair<ReservedBuffer, wgpu::Buffer> ReserveBuffer(
+        const wgpu::BufferDescriptor* desc = &kPlaceholderDesc) {
+        auto reservation = GetWireClient()->ReserveBuffer(
+            device.Get(), reinterpret_cast<const WGPUBufferDescriptor*>(desc));
+        return {reservation, wgpu::Buffer::Acquire(reservation.buffer)};
+    }
+
     // A placeholder buffer format for ReserveBuffer. The data in it doesn't matter as long as
     // we don't call buffer reflection methods.
-    WGPUBufferDescriptor placeholderDesc = {};
+    static constexpr wgpu::BufferDescriptor kPlaceholderDesc = {};
 };
 
 // Test that reserving and injecting a buffer makes calls on the client object forward to the
 // server object correctly.
 TEST_F(WireInjectBufferTests, CallAfterReserveInject) {
-    auto reserved = GetWireClient()->ReserveBuffer(cDevice, &placeholderDesc);
+    auto [reservation, buffer] = ReserveBuffer();
 
     WGPUBuffer apiBuffer = api.GetNewBuffer();
     EXPECT_CALL(api, BufferAddRef(apiBuffer));
-    ASSERT_TRUE(GetWireServer()->InjectBuffer(apiBuffer, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(
+        GetWireServer()->InjectBuffer(apiBuffer, reservation.handle, reservation.deviceHandle));
 
-    wgpuBufferDestroy(reserved.buffer);
+    buffer.Destroy();
     EXPECT_CALL(api, BufferDestroy(apiBuffer));
     FlushClient();
 }
 
 // Test that reserve correctly returns different IDs each time.
 TEST_F(WireInjectBufferTests, ReserveDifferentIDs) {
-    auto reserved1 = GetWireClient()->ReserveBuffer(cDevice, &placeholderDesc);
-    auto reserved2 = GetWireClient()->ReserveBuffer(cDevice, &placeholderDesc);
+    auto [reservation1, buffer1] = ReserveBuffer();
+    auto [reservation2, buffer2] = ReserveBuffer();
 
-    ASSERT_NE(reserved1.handle.id, reserved2.handle.id);
-    ASSERT_NE(reserved1.buffer, reserved2.buffer);
+    ASSERT_NE(reservation1.handle.id, reservation2.handle.id);
+    ASSERT_NE(buffer1.Get(), buffer2.Get());
 }
 
 // Test that injecting the same id without a destroy first fails.
 TEST_F(WireInjectBufferTests, InjectExistingID) {
-    auto reserved = GetWireClient()->ReserveBuffer(cDevice, &placeholderDesc);
+    auto [reservation, buffer] = ReserveBuffer();
 
     WGPUBuffer apiBuffer = api.GetNewBuffer();
     EXPECT_CALL(api, BufferAddRef(apiBuffer));
-    ASSERT_TRUE(GetWireServer()->InjectBuffer(apiBuffer, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(
+        GetWireServer()->InjectBuffer(apiBuffer, reservation.handle, reservation.deviceHandle));
 
     // ID already in use, call fails.
-    ASSERT_FALSE(GetWireServer()->InjectBuffer(apiBuffer, reserved.handle, reserved.deviceHandle));
+    ASSERT_FALSE(
+        GetWireServer()->InjectBuffer(apiBuffer, reservation.handle, reservation.deviceHandle));
 }
 
 // Test that injecting the same id without a destroy first fails.
 TEST_F(WireInjectBufferTests, ReuseIDAndGeneration) {
     // Do this loop multiple times since the first time, we can't test `generation - 1` since
     // generation == 0.
-    ReservedBuffer reserved;
+    ReservedBuffer reservation;
+    wgpu::Buffer buffer;
     WGPUBuffer apiBuffer = nullptr;
     for (int i = 0; i < 2; ++i) {
-        reserved = GetWireClient()->ReserveBuffer(cDevice, &placeholderDesc);
+        std::tie(reservation, buffer) = ReserveBuffer();
 
         apiBuffer = api.GetNewBuffer();
         EXPECT_CALL(api, BufferAddRef(apiBuffer));
         ASSERT_TRUE(
-            GetWireServer()->InjectBuffer(apiBuffer, reserved.handle, reserved.deviceHandle));
+            GetWireServer()->InjectBuffer(apiBuffer, reservation.handle, reservation.deviceHandle));
 
         // Release the buffer. It should be possible to reuse the ID now, but not the generation
-        wgpuBufferRelease(reserved.buffer);
+        buffer = nullptr;
         EXPECT_CALL(api, BufferRelease(apiBuffer));
         FlushClient();
 
         // Invalid to inject with the same ID and generation.
         ASSERT_FALSE(
-            GetWireServer()->InjectBuffer(apiBuffer, reserved.handle, reserved.deviceHandle));
+            GetWireServer()->InjectBuffer(apiBuffer, reservation.handle, reservation.deviceHandle));
         if (i > 0) {
-            EXPECT_GE(reserved.handle.generation, 1u);
+            EXPECT_GE(reservation.handle.generation, 1u);
 
             // Invalid to inject with the same ID and lesser generation.
-            reserved.handle.generation -= 1;
-            ASSERT_FALSE(
-                GetWireServer()->InjectBuffer(apiBuffer, reserved.handle, reserved.deviceHandle));
+            reservation.handle.generation -= 1;
+            ASSERT_FALSE(GetWireServer()->InjectBuffer(apiBuffer, reservation.handle,
+                                                       reservation.deviceHandle));
         }
     }
 
     // Valid to inject with the same ID and greater generation.
     EXPECT_CALL(api, BufferAddRef(apiBuffer));
-    reserved.handle.generation += 2;
-    ASSERT_TRUE(GetWireServer()->InjectBuffer(apiBuffer, reserved.handle, reserved.deviceHandle));
+    reservation.handle.generation += 2;
+    ASSERT_TRUE(
+        GetWireServer()->InjectBuffer(apiBuffer, reservation.handle, reservation.deviceHandle));
 }
 
 // Test that the server only borrows the buffer and does a single reference-release
 TEST_F(WireInjectBufferTests, InjectedBufferLifetime) {
-    auto reserved = GetWireClient()->ReserveBuffer(cDevice, &placeholderDesc);
+    auto [reservation, buffer] = ReserveBuffer();
 
     // Injecting the buffer adds a reference
     WGPUBuffer apiBuffer = api.GetNewBuffer();
     EXPECT_CALL(api, BufferAddRef(apiBuffer));
-    ASSERT_TRUE(GetWireServer()->InjectBuffer(apiBuffer, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(
+        GetWireServer()->InjectBuffer(apiBuffer, reservation.handle, reservation.deviceHandle));
 
     // Releasing the buffer removes a single reference.
-    wgpuBufferRelease(reserved.buffer);
+    buffer = nullptr;
     EXPECT_CALL(api, BufferRelease(apiBuffer));
     FlushClient();
 
@@ -143,21 +157,21 @@
 TEST_F(WireInjectBufferTests, ReclaimBufferReservation) {
     // Test that doing a reservation and full release is an error.
     {
-        auto reserved = GetWireClient()->ReserveBuffer(cDevice, &placeholderDesc);
-        wgpuBufferRelease(reserved.buffer);
+        auto [reservation, buffer] = ReserveBuffer();
+        buffer = nullptr;
         FlushClient(false);
     }
 
     // Test that doing a reservation and then reclaiming it recycles the ID.
     {
-        auto reserved1 = GetWireClient()->ReserveBuffer(cDevice, &placeholderDesc);
-        GetWireClient()->ReclaimBufferReservation(reserved1);
+        auto [reservation1, buffer1] = ReserveBuffer();
+        GetWireClient()->ReclaimBufferReservation(reservation1);
 
-        auto reserved2 = GetWireClient()->ReserveBuffer(cDevice, &placeholderDesc);
+        auto [reservation2, buffer2] = ReserveBuffer();
 
         // The ID is the same, but the generation is still different.
-        ASSERT_EQ(reserved1.handle.id, reserved2.handle.id);
-        ASSERT_NE(reserved1.handle.generation, reserved2.handle.generation);
+        ASSERT_EQ(reservation1.handle.id, reservation2.handle.id);
+        ASSERT_NE(reservation1.handle.generation, reservation2.handle.generation);
 
         // No errors should occur.
         FlushClient();
@@ -166,15 +180,13 @@
 
 // Test the reflection of buffer creation parameters for reserved buffer.
 TEST_F(WireInjectBufferTests, ReservedBufferReflection) {
-    WGPUBufferDescriptor desc = {};
+    wgpu::BufferDescriptor desc;
     desc.size = 10;
-    desc.usage = WGPUBufferUsage_Storage;
+    desc.usage = wgpu::BufferUsage::Storage;
 
-    auto reserved = GetWireClient()->ReserveBuffer(cDevice, &desc);
-    WGPUBuffer buffer = reserved.buffer;
-
-    ASSERT_EQ(desc.size, wgpuBufferGetSize(buffer));
-    ASSERT_EQ(desc.usage, wgpuBufferGetUsage(buffer));
+    auto [reservation, buffer] = ReserveBuffer(&desc);
+    ASSERT_EQ(desc.size, buffer.GetSize());
+    ASSERT_EQ(desc.usage, buffer.GetUsage());
 }
 
 }  // anonymous namespace
diff --git a/src/dawn/tests/unittests/wire/WireInjectSwapChainTests.cpp b/src/dawn/tests/unittests/wire/WireInjectSwapChainTests.cpp
index 39c3287..e64b4c6 100644
--- a/src/dawn/tests/unittests/wire/WireInjectSwapChainTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireInjectSwapChainTests.cpp
@@ -25,8 +25,9 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#include "dawn/tests/unittests/wire/WireTest.h"
+#include <utility>
 
+#include "dawn/tests/unittests/wire/WireTest.h"
 #include "dawn/wire/WireClient.h"
 #include "dawn/wire/WireServer.h"
 
@@ -39,68 +40,78 @@
 class WireInjectSwapChainTests : public WireTest {
   public:
     WireInjectSwapChainTests() {
-        swapChainDesc = {};
-        swapChainDesc.usage = WGPUTextureUsage_RenderAttachment;
-        swapChainDesc.format = WGPUTextureFormat_RGBA8Unorm;
+        swapChainDesc.usage = wgpu::TextureUsage::RenderAttachment;
+        swapChainDesc.format = wgpu::TextureFormat::RGBA8Unorm;
         swapChainDesc.width = 17;
         swapChainDesc.height = 42;
-        swapChainDesc.presentMode = WGPUPresentMode_Mailbox;
+        swapChainDesc.presentMode = wgpu::PresentMode::Mailbox;
     }
     ~WireInjectSwapChainTests() override = default;
 
-    WGPUSwapChainDescriptor swapChainDesc;
+    std::pair<ReservedSwapChain, wgpu::SwapChain> ReserveSwapChain(
+        const wgpu::SwapChainDescriptor* desc = nullptr) {
+        if (desc == nullptr) {
+            desc = &swapChainDesc;
+        }
+
+        auto reservation = GetWireClient()->ReserveSwapChain(
+            device.Get(), reinterpret_cast<const WGPUSwapChainDescriptor*>(desc));
+        return {reservation, wgpu::SwapChain::Acquire(reservation.swapchain)};
+    }
+
+    wgpu::SwapChainDescriptor swapChainDesc;
 };
 
 // Test that reserving and injecting a swapchain makes calls on the client object forward to the
 // server object correctly.
 TEST_F(WireInjectSwapChainTests, CallAfterReserveInject) {
-    auto reserved = GetWireClient()->ReserveSwapChain(cDevice, &swapChainDesc);
+    auto [reservation, swapchain] = ReserveSwapChain();
 
     WGPUSwapChain apiSwapchain = api.GetNewSwapChain();
     EXPECT_CALL(api, SwapChainAddRef(apiSwapchain));
-    ASSERT_TRUE(
-        GetWireServer()->InjectSwapChain(apiSwapchain, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
+                                                 reservation.deviceHandle));
 
-    wgpuSwapChainPresent(reserved.swapchain);
+    swapchain.Present();
     EXPECT_CALL(api, SwapChainPresent(apiSwapchain));
     FlushClient();
 }
 
 // Test that reserve correctly returns different IDs each time.
 TEST_F(WireInjectSwapChainTests, ReserveDifferentIDs) {
-    auto reserved1 = GetWireClient()->ReserveSwapChain(cDevice, &swapChainDesc);
-    auto reserved2 = GetWireClient()->ReserveSwapChain(cDevice, &swapChainDesc);
+    auto [reservation1, swapchain1] = ReserveSwapChain();
+    auto [reservation2, swapchain2] = ReserveSwapChain();
 
-    ASSERT_NE(reserved1.handle.id, reserved2.handle.id);
-    ASSERT_NE(reserved1.swapchain, reserved2.swapchain);
+    ASSERT_NE(reservation1.handle.id, reservation2.handle.id);
+    ASSERT_NE(swapchain1.Get(), swapchain2.Get());
 }
 
 // Test that injecting the same id without a destroy first fails.
 TEST_F(WireInjectSwapChainTests, InjectExistingID) {
-    auto reserved = GetWireClient()->ReserveSwapChain(cDevice, &swapChainDesc);
+    auto [reservation, swapchain] = ReserveSwapChain();
 
     WGPUSwapChain apiSwapchain = api.GetNewSwapChain();
     EXPECT_CALL(api, SwapChainAddRef(apiSwapchain));
-    ASSERT_TRUE(
-        GetWireServer()->InjectSwapChain(apiSwapchain, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
+                                                 reservation.deviceHandle));
 
     // ID already in use, call fails.
-    ASSERT_FALSE(
-        GetWireServer()->InjectSwapChain(apiSwapchain, reserved.handle, reserved.deviceHandle));
+    ASSERT_FALSE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
+                                                  reservation.deviceHandle));
 }
 
 // Test that the server only borrows the swapchain and does a single addref-release
 TEST_F(WireInjectSwapChainTests, InjectedSwapChainLifetime) {
-    auto reserved = GetWireClient()->ReserveSwapChain(cDevice, &swapChainDesc);
+    auto [reservation, swapchain] = ReserveSwapChain();
 
     // Injecting the swapchain adds a reference
     WGPUSwapChain apiSwapchain = api.GetNewSwapChain();
     EXPECT_CALL(api, SwapChainAddRef(apiSwapchain));
-    ASSERT_TRUE(
-        GetWireServer()->InjectSwapChain(apiSwapchain, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
+                                                 reservation.deviceHandle));
 
     // Releasing the swapchain removes a single reference.
-    wgpuSwapChainRelease(reserved.swapchain);
+    swapchain = nullptr;
     EXPECT_CALL(api, SwapChainRelease(apiSwapchain));
     FlushClient();
 
@@ -114,21 +125,21 @@
 TEST_F(WireInjectSwapChainTests, ReclaimSwapChainReservation) {
     // Test that doing a reservation and full release is an error.
     {
-        auto reserved = GetWireClient()->ReserveSwapChain(cDevice, &swapChainDesc);
-        wgpuSwapChainRelease(reserved.swapchain);
+        auto [reservation, swapchain] = ReserveSwapChain();
+        swapchain = nullptr;
         FlushClient(false);
     }
 
     // Test that doing a reservation and then reclaiming it recycles the ID.
     {
-        auto reserved1 = GetWireClient()->ReserveSwapChain(cDevice, &swapChainDesc);
-        GetWireClient()->ReclaimSwapChainReservation(reserved1);
+        auto [reservation1, swapchain1] = ReserveSwapChain();
+        GetWireClient()->ReclaimSwapChainReservation(reservation1);
 
-        auto reserved2 = GetWireClient()->ReserveSwapChain(cDevice, &swapChainDesc);
+        auto [reservation2, swapchain2] = ReserveSwapChain();
 
         // The ID is the same, but the generation is still different.
-        ASSERT_EQ(reserved1.handle.id, reserved2.handle.id);
-        ASSERT_NE(reserved1.handle.generation, reserved2.handle.generation);
+        ASSERT_EQ(reservation1.handle.id, reservation2.handle.id);
+        ASSERT_NE(reservation1.handle.generation, reservation2.handle.generation);
 
         // No errors should occur.
         FlushClient();
@@ -137,26 +148,26 @@
 
 // Test that the texture's reflection is correct for injected swapchains in the wire.
 TEST_F(WireInjectSwapChainTests, SwapChainTextureReflection) {
-    auto reserved = GetWireClient()->ReserveSwapChain(cDevice, &swapChainDesc);
+    auto [reservation, swapchain] = ReserveSwapChain();
 
     WGPUSwapChain apiSwapchain = api.GetNewSwapChain();
     EXPECT_CALL(api, SwapChainAddRef(apiSwapchain));
-    ASSERT_TRUE(
-        GetWireServer()->InjectSwapChain(apiSwapchain, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
+                                                 reservation.deviceHandle));
 
-    WGPUTexture tex = wgpuSwapChainGetCurrentTexture(reserved.swapchain);
+    wgpu::Texture tex = swapchain.GetCurrentTexture();
     WGPUTexture apiTex = api.GetNewTexture();
     EXPECT_CALL(api, SwapChainGetCurrentTexture(apiSwapchain)).WillOnce(Return(apiTex));
     FlushClient();
 
-    EXPECT_EQ(swapChainDesc.width, wgpuTextureGetWidth(tex));
-    EXPECT_EQ(swapChainDesc.height, wgpuTextureGetHeight(tex));
-    EXPECT_EQ(swapChainDesc.usage, wgpuTextureGetUsage(tex));
-    EXPECT_EQ(swapChainDesc.format, wgpuTextureGetFormat(tex));
-    EXPECT_EQ(1u, wgpuTextureGetDepthOrArrayLayers(tex));
-    EXPECT_EQ(1u, wgpuTextureGetMipLevelCount(tex));
-    EXPECT_EQ(1u, wgpuTextureGetSampleCount(tex));
-    EXPECT_EQ(WGPUTextureDimension_2D, wgpuTextureGetDimension(tex));
+    EXPECT_EQ(swapChainDesc.width, tex.GetWidth());
+    EXPECT_EQ(swapChainDesc.height, tex.GetHeight());
+    EXPECT_EQ(swapChainDesc.usage, tex.GetUsage());
+    EXPECT_EQ(swapChainDesc.format, tex.GetFormat());
+    EXPECT_EQ(1u, tex.GetDepthOrArrayLayers());
+    EXPECT_EQ(1u, tex.GetMipLevelCount());
+    EXPECT_EQ(1u, tex.GetSampleCount());
+    EXPECT_EQ(wgpu::TextureDimension::e2D, tex.GetDimension());
 }
 
 }  // anonymous namespace
diff --git a/src/dawn/tests/unittests/wire/WireInjectTextureTests.cpp b/src/dawn/tests/unittests/wire/WireInjectTextureTests.cpp
index c642449..8009a38 100644
--- a/src/dawn/tests/unittests/wire/WireInjectTextureTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireInjectTextureTests.cpp
@@ -25,8 +25,9 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#include "dawn/tests/unittests/wire/WireTest.h"
+#include <utility>
 
+#include "dawn/tests/unittests/wire/WireTest.h"
 #include "dawn/wire/WireClient.h"
 #include "dawn/wire/WireServer.h"
 
@@ -41,21 +42,29 @@
     WireInjectTextureTests() {}
     ~WireInjectTextureTests() override = default;
 
+    std::pair<ReservedTexture, wgpu::Texture> ReserveTexture(
+        const wgpu::TextureDescriptor* desc = &kPlaceholderDesc) {
+        auto reservation = GetWireClient()->ReserveTexture(
+            device.Get(), reinterpret_cast<const WGPUTextureDescriptor*>(desc));
+        return {reservation, wgpu::Texture::Acquire(reservation.texture)};
+    }
+
     // A placeholder texture format for ReserveTexture. The data in it doesn't matter as long as
     // we don't call texture reflection methods.
-    WGPUTextureDescriptor placeholderDesc = {};
+    static constexpr wgpu::TextureDescriptor kPlaceholderDesc = {};
 };
 
 // Test that reserving and injecting a texture makes calls on the client object forward to the
 // server object correctly.
 TEST_F(WireInjectTextureTests, CallAfterReserveInject) {
-    auto reserved = GetWireClient()->ReserveTexture(cDevice, &placeholderDesc);
+    auto [reservation, texture] = ReserveTexture();
 
     WGPUTexture apiTexture = api.GetNewTexture();
     EXPECT_CALL(api, TextureAddRef(apiTexture));
-    ASSERT_TRUE(GetWireServer()->InjectTexture(apiTexture, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(
+        GetWireServer()->InjectTexture(apiTexture, reservation.handle, reservation.deviceHandle));
 
-    wgpuTextureCreateView(reserved.texture, nullptr);
+    wgpu::TextureView view = texture.CreateView();
     WGPUTextureView apiPlaceholderView = api.GetNewTextureView();
     EXPECT_CALL(api, TextureCreateView(apiTexture, nullptr)).WillOnce(Return(apiPlaceholderView));
     FlushClient();
@@ -63,75 +72,79 @@
 
 // Test that reserve correctly returns different IDs each time.
 TEST_F(WireInjectTextureTests, ReserveDifferentIDs) {
-    auto reserved1 = GetWireClient()->ReserveTexture(cDevice, &placeholderDesc);
-    auto reserved2 = GetWireClient()->ReserveTexture(cDevice, &placeholderDesc);
+    auto [reservation1, texture1] = ReserveTexture();
+    auto [reservation2, texture2] = ReserveTexture();
 
-    ASSERT_NE(reserved1.handle.id, reserved2.handle.id);
-    ASSERT_NE(reserved1.texture, reserved2.texture);
+    ASSERT_NE(reservation1.handle.id, reservation2.handle.id);
+    ASSERT_NE(texture1.Get(), texture2.Get());
 }
 
 // Test that injecting the same id without a destroy first fails.
 TEST_F(WireInjectTextureTests, InjectExistingID) {
-    auto reserved = GetWireClient()->ReserveTexture(cDevice, &placeholderDesc);
+    auto [reservation, texture] = ReserveTexture();
 
     WGPUTexture apiTexture = api.GetNewTexture();
     EXPECT_CALL(api, TextureAddRef(apiTexture));
-    ASSERT_TRUE(GetWireServer()->InjectTexture(apiTexture, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(
+        GetWireServer()->InjectTexture(apiTexture, reservation.handle, reservation.deviceHandle));
 
     // ID already in use, call fails.
     ASSERT_FALSE(
-        GetWireServer()->InjectTexture(apiTexture, reserved.handle, reserved.deviceHandle));
+        GetWireServer()->InjectTexture(apiTexture, reservation.handle, reservation.deviceHandle));
 }
 
 // Test that injecting the same id without a destroy first fails.
 TEST_F(WireInjectTextureTests, ReuseIDAndGeneration) {
     // Do this loop multiple times since the first time, we can't test `generation - 1` since
     // generation == 0.
-    ReservedTexture reserved;
+    ReservedTexture reservation;
+    wgpu::Texture texture;
     WGPUTexture apiTexture = nullptr;
     for (int i = 0; i < 2; ++i) {
-        reserved = GetWireClient()->ReserveTexture(cDevice, &placeholderDesc);
+        std::tie(reservation, texture) = ReserveTexture();
 
         apiTexture = api.GetNewTexture();
         EXPECT_CALL(api, TextureAddRef(apiTexture));
-        ASSERT_TRUE(
-            GetWireServer()->InjectTexture(apiTexture, reserved.handle, reserved.deviceHandle));
+        ASSERT_TRUE(GetWireServer()->InjectTexture(apiTexture, reservation.handle,
+                                                   reservation.deviceHandle));
 
         // Release the texture. It should be possible to reuse the ID now, but not the generation
-        wgpuTextureRelease(reserved.texture);
+        texture = nullptr;
         EXPECT_CALL(api, TextureRelease(apiTexture));
         FlushClient();
 
         // Invalid to inject with the same ID and generation.
-        ASSERT_FALSE(
-            GetWireServer()->InjectTexture(apiTexture, reserved.handle, reserved.deviceHandle));
+        ASSERT_FALSE(GetWireServer()->InjectTexture(apiTexture, reservation.handle,
+                                                    reservation.deviceHandle));
         if (i > 0) {
-            EXPECT_GE(reserved.handle.generation, 1u);
+            EXPECT_GE(reservation.handle.generation, 1u);
 
             // Invalid to inject with the same ID and lesser generation.
-            reserved.handle.generation -= 1;
-            ASSERT_FALSE(
-                GetWireServer()->InjectTexture(apiTexture, reserved.handle, reserved.deviceHandle));
+            reservation.handle.generation -= 1;
+            ASSERT_FALSE(GetWireServer()->InjectTexture(apiTexture, reservation.handle,
+                                                        reservation.deviceHandle));
         }
     }
 
     // Valid to inject with the same ID and greater generation.
     EXPECT_CALL(api, TextureAddRef(apiTexture));
-    reserved.handle.generation += 2;
-    ASSERT_TRUE(GetWireServer()->InjectTexture(apiTexture, reserved.handle, reserved.deviceHandle));
+    reservation.handle.generation += 2;
+    ASSERT_TRUE(
+        GetWireServer()->InjectTexture(apiTexture, reservation.handle, reservation.deviceHandle));
 }
 
 // Test that the server only borrows the texture and does a single addref-release
 TEST_F(WireInjectTextureTests, InjectedTextureLifetime) {
-    auto reserved = GetWireClient()->ReserveTexture(cDevice, &placeholderDesc);
+    auto [reservation, texture] = ReserveTexture();
 
     // Injecting the texture adds a reference
     WGPUTexture apiTexture = api.GetNewTexture();
     EXPECT_CALL(api, TextureAddRef(apiTexture));
-    ASSERT_TRUE(GetWireServer()->InjectTexture(apiTexture, reserved.handle, reserved.deviceHandle));
+    ASSERT_TRUE(
+        GetWireServer()->InjectTexture(apiTexture, reservation.handle, reservation.deviceHandle));
 
     // Releasing the texture removes a single reference.
-    wgpuTextureRelease(reserved.texture);
+    texture = nullptr;
     EXPECT_CALL(api, TextureRelease(apiTexture));
     FlushClient();
 
@@ -145,21 +158,21 @@
 TEST_F(WireInjectTextureTests, ReclaimTextureReservation) {
     // Test that doing a reservation and full release is an error.
     {
-        auto reserved = GetWireClient()->ReserveTexture(cDevice, &placeholderDesc);
-        wgpuTextureRelease(reserved.texture);
+        auto [reservation, texture] = ReserveTexture();
+        texture = nullptr;
         FlushClient(false);
     }
 
     // Test that doing a reservation and then reclaiming it recycles the ID.
     {
-        auto reserved1 = GetWireClient()->ReserveTexture(cDevice, &placeholderDesc);
-        GetWireClient()->ReclaimTextureReservation(reserved1);
+        auto [reservation1, texture1] = ReserveTexture();
+        GetWireClient()->ReclaimTextureReservation(reservation1);
 
-        auto reserved2 = GetWireClient()->ReserveTexture(cDevice, &placeholderDesc);
+        auto [reservation2, texture2] = ReserveTexture();
 
         // The ID is the same, but the generation is still different.
-        ASSERT_EQ(reserved1.handle.id, reserved2.handle.id);
-        ASSERT_NE(reserved1.handle.generation, reserved2.handle.generation);
+        ASSERT_EQ(reservation1.handle.id, reservation2.handle.id);
+        ASSERT_NE(reservation1.handle.generation, reservation2.handle.generation);
 
         // No errors should occur.
         FlushClient();
@@ -168,24 +181,23 @@
 
 // Test the reflection of texture creation parameters for reserved textures.
 TEST_F(WireInjectTextureTests, ReservedTextureReflection) {
-    WGPUTextureDescriptor desc = {};
+    wgpu::TextureDescriptor desc = {};
     desc.size = {10, 11, 12};
-    desc.format = WGPUTextureFormat_R32Float;
-    desc.dimension = WGPUTextureDimension_3D;
+    desc.format = wgpu::TextureFormat::R32Float;
+    desc.dimension = wgpu::TextureDimension::e3D;
     desc.mipLevelCount = 1000;
     desc.sampleCount = 3;
-    desc.usage = WGPUTextureUsage_RenderAttachment;
+    desc.usage = wgpu::TextureUsage::RenderAttachment;
 
-    auto reserved = GetWireClient()->ReserveTexture(cDevice, &desc);
-    WGPUTexture texture = reserved.texture;
+    auto [reservation, texture] = ReserveTexture(&desc);
 
-    ASSERT_EQ(desc.size.width, wgpuTextureGetWidth(texture));
-    ASSERT_EQ(desc.size.height, wgpuTextureGetHeight(texture));
-    ASSERT_EQ(desc.size.depthOrArrayLayers, wgpuTextureGetDepthOrArrayLayers(texture));
-    ASSERT_EQ(desc.format, wgpuTextureGetFormat(texture));
-    ASSERT_EQ(desc.dimension, wgpuTextureGetDimension(texture));
-    ASSERT_EQ(desc.mipLevelCount, wgpuTextureGetMipLevelCount(texture));
-    ASSERT_EQ(desc.sampleCount, wgpuTextureGetSampleCount(texture));
+    ASSERT_EQ(desc.size.width, texture.GetWidth());
+    ASSERT_EQ(desc.size.height, texture.GetHeight());
+    ASSERT_EQ(desc.size.depthOrArrayLayers, texture.GetDepthOrArrayLayers());
+    ASSERT_EQ(desc.format, texture.GetFormat());
+    ASSERT_EQ(desc.dimension, texture.GetDimension());
+    ASSERT_EQ(desc.mipLevelCount, texture.GetMipLevelCount());
+    ASSERT_EQ(desc.sampleCount, texture.GetSampleCount());
 }
 
 }  // anonymous namespace
diff --git a/src/dawn/tests/unittests/wire/WireOptionalTests.cpp b/src/dawn/tests/unittests/wire/WireOptionalTests.cpp
index 61b38b7..078e42d 100644
--- a/src/dawn/tests/unittests/wire/WireOptionalTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireOptionalTests.cpp
@@ -41,28 +41,28 @@
 
 // Test passing nullptr instead of objects - object as value version
 TEST_F(WireOptionalTests, OptionalObjectValue) {
-    WGPUBindGroupLayoutDescriptor bglDesc = {};
+    wgpu::BindGroupLayoutDescriptor bglDesc = {};
     bglDesc.entryCount = 0;
-    WGPUBindGroupLayout bgl = wgpuDeviceCreateBindGroupLayout(cDevice, &bglDesc);
+    wgpu::BindGroupLayout bgl = device.CreateBindGroupLayout(&bglDesc);
 
     WGPUBindGroupLayout apiBindGroupLayout = api.GetNewBindGroupLayout();
     EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _))
         .WillOnce(Return(apiBindGroupLayout));
 
     // The `sampler`, `textureView` and `buffer` members of a binding are optional.
-    WGPUBindGroupEntry entry;
+    wgpu::BindGroupEntry entry;
     entry.binding = 0;
     entry.sampler = nullptr;
     entry.textureView = nullptr;
     entry.buffer = nullptr;
     entry.nextInChain = nullptr;
 
-    WGPUBindGroupDescriptor bgDesc = {};
+    wgpu::BindGroupDescriptor bgDesc = {};
     bgDesc.layout = bgl;
     bgDesc.entryCount = 1;
     bgDesc.entries = &entry;
 
-    wgpuDeviceCreateBindGroup(cDevice, &bgDesc);
+    wgpu::BindGroup bg = device.CreateBindGroup(&bgDesc);
 
     WGPUBindGroup apiPlaceholderBindGroup = api.GetNewBindGroup();
     EXPECT_CALL(api, DeviceCreateBindGroup(
@@ -81,35 +81,35 @@
 // Test that the wire is able to send optional pointers to structures
 TEST_F(WireOptionalTests, OptionalStructPointer) {
     // Create shader module
-    WGPUShaderModuleDescriptor vertexDescriptor = {};
-    WGPUShaderModule vsModule = wgpuDeviceCreateShaderModule(cDevice, &vertexDescriptor);
+    wgpu::ShaderModuleDescriptor vertexDescriptor = {};
+    wgpu::ShaderModule vsModule = device.CreateShaderModule(&vertexDescriptor);
     WGPUShaderModule apiVsModule = api.GetNewShaderModule();
     EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiVsModule));
 
     // Create the color state descriptor
-    WGPUBlendComponent blendComponent = {};
-    blendComponent.operation = WGPUBlendOperation_Add;
-    blendComponent.srcFactor = WGPUBlendFactor_One;
-    blendComponent.dstFactor = WGPUBlendFactor_One;
-    WGPUBlendState blendState = {};
+    wgpu::BlendComponent blendComponent = {};
+    blendComponent.operation = wgpu::BlendOperation::Add;
+    blendComponent.srcFactor = wgpu::BlendFactor::One;
+    blendComponent.dstFactor = wgpu::BlendFactor::One;
+    wgpu::BlendState blendState = {};
     blendState.alpha = blendComponent;
     blendState.color = blendComponent;
-    WGPUColorTargetState colorTargetState = {};
-    colorTargetState.format = WGPUTextureFormat_RGBA8Unorm;
+    wgpu::ColorTargetState colorTargetState = {};
+    colorTargetState.format = wgpu::TextureFormat::RGBA8Unorm;
     colorTargetState.blend = &blendState;
-    colorTargetState.writeMask = WGPUColorWriteMask_All;
+    colorTargetState.writeMask = wgpu::ColorWriteMask::All;
 
     // Create the depth-stencil state
-    WGPUStencilFaceState stencilFace = {};
-    stencilFace.compare = WGPUCompareFunction_Always;
-    stencilFace.failOp = WGPUStencilOperation_Keep;
-    stencilFace.depthFailOp = WGPUStencilOperation_Keep;
-    stencilFace.passOp = WGPUStencilOperation_Keep;
+    wgpu::StencilFaceState stencilFace = {};
+    stencilFace.compare = wgpu::CompareFunction::Always;
+    stencilFace.failOp = wgpu::StencilOperation::Keep;
+    stencilFace.depthFailOp = wgpu::StencilOperation::Keep;
+    stencilFace.passOp = wgpu::StencilOperation::Keep;
 
-    WGPUDepthStencilState depthStencilState = {};
-    depthStencilState.format = WGPUTextureFormat_Depth24PlusStencil8;
+    wgpu::DepthStencilState depthStencilState = {};
+    depthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
     depthStencilState.depthWriteEnabled = false;
-    depthStencilState.depthCompare = WGPUCompareFunction_Always;
+    depthStencilState.depthCompare = wgpu::CompareFunction::Always;
     depthStencilState.stencilBack = stencilFace;
     depthStencilState.stencilFront = stencilFace;
     depthStencilState.stencilReadMask = 0xff;
@@ -119,21 +119,21 @@
     depthStencilState.depthBiasClamp = 0.0;
 
     // Create the pipeline layout
-    WGPUPipelineLayoutDescriptor layoutDescriptor = {};
+    wgpu::PipelineLayoutDescriptor layoutDescriptor = {};
     layoutDescriptor.bindGroupLayoutCount = 0;
     layoutDescriptor.bindGroupLayouts = nullptr;
-    WGPUPipelineLayout layout = wgpuDeviceCreatePipelineLayout(cDevice, &layoutDescriptor);
+    wgpu::PipelineLayout layout = device.CreatePipelineLayout(&layoutDescriptor);
     WGPUPipelineLayout apiLayout = api.GetNewPipelineLayout();
     EXPECT_CALL(api, DeviceCreatePipelineLayout(apiDevice, _)).WillOnce(Return(apiLayout));
 
     // Create pipeline
-    WGPURenderPipelineDescriptor pipelineDescriptor = {};
+    wgpu::RenderPipelineDescriptor pipelineDescriptor = {};
 
     pipelineDescriptor.vertex.module = vsModule;
     pipelineDescriptor.vertex.bufferCount = 0;
     pipelineDescriptor.vertex.buffers = nullptr;
 
-    WGPUFragmentState fragment = {};
+    wgpu::FragmentState fragment = {};
     fragment.module = vsModule;
     fragment.targetCount = 1;
     fragment.targets = &colorTargetState;
@@ -143,13 +143,13 @@
     pipelineDescriptor.multisample.mask = 0xFFFFFFFF;
     pipelineDescriptor.multisample.alphaToCoverageEnabled = false;
     pipelineDescriptor.layout = layout;
-    pipelineDescriptor.primitive.topology = WGPUPrimitiveTopology_TriangleList;
-    pipelineDescriptor.primitive.frontFace = WGPUFrontFace_CCW;
-    pipelineDescriptor.primitive.cullMode = WGPUCullMode_None;
+    pipelineDescriptor.primitive.topology = wgpu::PrimitiveTopology::TriangleList;
+    pipelineDescriptor.primitive.frontFace = wgpu::FrontFace::CCW;
+    pipelineDescriptor.primitive.cullMode = wgpu::CullMode::None;
 
     // First case: depthStencil is not null.
     pipelineDescriptor.depthStencil = &depthStencilState;
-    wgpuDeviceCreateRenderPipeline(cDevice, &pipelineDescriptor);
+    wgpu::RenderPipeline pipeline1 = device.CreateRenderPipeline(&pipelineDescriptor);
 
     WGPURenderPipeline apiPlaceholderPipeline = api.GetNewRenderPipeline();
     EXPECT_CALL(
@@ -180,7 +180,7 @@
 
     // Second case: depthStencil is null.
     pipelineDescriptor.depthStencil = nullptr;
-    wgpuDeviceCreateRenderPipeline(cDevice, &pipelineDescriptor);
+    wgpu::RenderPipeline pipeline2 = device.CreateRenderPipeline(&pipelineDescriptor);
     EXPECT_CALL(api,
                 DeviceCreateRenderPipeline(
                     apiDevice, MatchesLambda([](const WGPURenderPipelineDescriptor* desc) -> bool {