Fix dawn_end2end_tests -w

Code surrounding the swapchain needs to Flush the wire so that the
native swapchain implementation is initialized before GetPreferredFormat
is called. Likewise the swapchain should be destroyed before the last
FlushWire otherwise the native swapchain will still be using the window
at the beginning of the next test.

Also fixes the newly added ASSERT_DEVICE_ERROR not working with -w.

BUG=dawn:143

Change-Id: Ie3d6fa8c9236f68f5bff1ad7abd112ab25035843
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6860
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp
index af6e716..ec1f7c6 100644
--- a/src/tests/DawnTest.cpp
+++ b/src/tests/DawnTest.cpp
@@ -344,6 +344,7 @@
     dawn::SwapChainDescriptor swapChainDesc;
     swapChainDesc.implementation = mBinding->GetSwapChainImplementation();
     swapchain = device.CreateSwapChain(&swapChainDesc);
+    FlushWire();
     swapchain.Configure(
         static_cast<dawn::TextureFormat>(mBinding->GetPreferredSwapChainTextureFormat()),
         dawn::TextureUsageBit::OutputAttachment, 400, 400);
@@ -353,6 +354,7 @@
 }
 
 void DawnTest::TearDown() {
+    swapchain = dawn::SwapChain();
     FlushWire();
 
     MapSlotsSynchronously();
diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h
index a098a14..c3c9d45 100644
--- a/src/tests/DawnTest.h
+++ b/src/tests/DawnTest.h
@@ -47,6 +47,7 @@
 #define ASSERT_DEVICE_ERROR(statement) \
     StartExpectDeviceError();          \
     statement;                         \
+    FlushWire();                       \
     ASSERT_TRUE(EndExpectDeviceError());
 
 struct RGBA8 {
@@ -173,6 +174,7 @@
                                               detail::Expectation* expectation);
 
     void WaitABit();
+    void FlushWire();
 
     void SwapBuffersForCapture();
 
@@ -182,7 +184,6 @@
     std::unique_ptr<dawn_wire::WireClient> mWireClient;
     std::unique_ptr<utils::TerribleCommandBuffer> mC2sBuf;
     std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;
-    void FlushWire();
 
     // Tracking for validation errors
     static void OnDeviceError(const char* message, DawnCallbackUserdata userdata);