Nuke Builders Part 1: remove the testing BufferBuilder.

This requires deleting wire tests for builders that were using it, and
leads to small simplifications in the WireTest harness. Also allows
removing the BuilderBase class from dawn_native.

BUG=dawn:125

Change-Id: I3cbac609207aa652cdc9d37e0b700cce3ac6e093
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6120
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/tests/unittests/wire/WireArgumentTests.cpp b/src/tests/unittests/wire/WireArgumentTests.cpp
index 8ed66c8..10dbd89 100644
--- a/src/tests/unittests/wire/WireArgumentTests.cpp
+++ b/src/tests/unittests/wire/WireArgumentTests.cpp
@@ -21,7 +21,7 @@
 
 class WireArgumentTests : public WireTest {
   public:
-    WireArgumentTests() : WireTest(true) {
+    WireArgumentTests() {
     }
     ~WireArgumentTests() override = default;
 };
diff --git a/src/tests/unittests/wire/WireBasicTests.cpp b/src/tests/unittests/wire/WireBasicTests.cpp
index b7c8e29..38bff0b 100644
--- a/src/tests/unittests/wire/WireBasicTests.cpp
+++ b/src/tests/unittests/wire/WireBasicTests.cpp
@@ -19,7 +19,7 @@
 
 class WireBasicTests : public WireTest {
   public:
-    WireBasicTests() : WireTest(true) {
+    WireBasicTests() {
     }
     ~WireBasicTests() override = default;
 };
diff --git a/src/tests/unittests/wire/WireBufferMappingTests.cpp b/src/tests/unittests/wire/WireBufferMappingTests.cpp
index 6a3126a..e1037ff 100644
--- a/src/tests/unittests/wire/WireBufferMappingTests.cpp
+++ b/src/tests/unittests/wire/WireBufferMappingTests.cpp
@@ -63,7 +63,7 @@
 
 class WireBufferMappingTests : public WireTest {
   public:
-    WireBufferMappingTests() : WireTest(true) {
+    WireBufferMappingTests() {
     }
     ~WireBufferMappingTests() override = default;
 
diff --git a/src/tests/unittests/wire/WireCallbackTests.cpp b/src/tests/unittests/wire/WireCallbackTests.cpp
deleted file mode 100644
index 7525839..0000000
--- a/src/tests/unittests/wire/WireCallbackTests.cpp
+++ /dev/null
@@ -1,251 +0,0 @@
-// Copyright 2019 The Dawn Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "tests/unittests/wire/WireTest.h"
-
-using namespace testing;
-using namespace dawn_wire;
-
-namespace {
-
-    // Mock classes to add expectations on the wire calling callbacks
-    class MockDeviceErrorCallback {
-      public:
-        MOCK_METHOD2(Call, void(const char* message, DawnCallbackUserdata userdata));
-    };
-
-    std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback;
-    void ToMockDeviceErrorCallback(const char* message, DawnCallbackUserdata userdata) {
-        mockDeviceErrorCallback->Call(message, userdata);
-    }
-
-    class MockBuilderErrorCallback {
-      public:
-        MOCK_METHOD4(Call,
-                     void(DawnBuilderErrorStatus status,
-                          const char* message,
-                          DawnCallbackUserdata userdata1,
-                          DawnCallbackUserdata userdata2));
-    };
-
-    std::unique_ptr<StrictMock<MockBuilderErrorCallback>> mockBuilderErrorCallback;
-    void ToMockBuilderErrorCallback(DawnBuilderErrorStatus status,
-                                    const char* message,
-                                    DawnCallbackUserdata userdata1,
-                                    DawnCallbackUserdata userdata2) {
-        mockBuilderErrorCallback->Call(status, message, userdata1, userdata2);
-    }
-
-}  // anonymous namespace
-
-class WireCallbackTests : public WireTest {
-  public:
-    WireCallbackTests() : WireTest(true) {
-    }
-    ~WireCallbackTests() override = default;
-
-    void SetUp() override {
-        WireTest::SetUp();
-
-        mockDeviceErrorCallback = std::make_unique<StrictMock<MockDeviceErrorCallback>>();
-        mockBuilderErrorCallback = std::make_unique<StrictMock<MockBuilderErrorCallback>>();
-    }
-
-    void TearDown() override {
-        WireTest::TearDown();
-
-        mockDeviceErrorCallback = nullptr;
-        mockBuilderErrorCallback = nullptr;
-    }
-
-    void FlushServer() {
-        WireTest::FlushServer();
-
-        Mock::VerifyAndClearExpectations(&mockDeviceErrorCallback);
-        Mock::VerifyAndClearExpectations(&mockBuilderErrorCallback);
-    }
-};
-
-// Test that we get a success builder error status when no error happens
-TEST_F(WireCallbackTests, SuccessCallbackOnBuilderSuccess) {
-    DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
-    dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2);
-    dawnBufferBuilderGetResult(bufferBuilder);
-
-    DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
-        .WillOnce(Return(apiBufferBuilder));
-
-    DawnBuffer apiBuffer = api.GetNewBuffer();
-    EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
-        .WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
-            api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS,
-                                         "I like cheese");
-            return apiBuffer;
-        }));
-
-    FlushClient();
-
-    EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_SUCCESS, _, 1, 2));
-
-    FlushServer();
-}
-
-// Test that the client calls the builder callback with unknown when it HAS to fire the callback but
-// can't know the status yet.
-TEST_F(WireCallbackTests, UnknownBuilderErrorStatusCallback) {
-    // The builder is destroyed before the object is built
-    {
-        DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
-        dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2);
-
-        EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 1, 2))
-            .Times(1);
-
-        dawnBufferBuilderRelease(bufferBuilder);
-    }
-
-    // If the builder has been consumed, it doesn't fire the callback with unknown
-    {
-        DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
-        dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 3, 4);
-        dawnBufferBuilderGetResult(bufferBuilder);
-
-        EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 3, 4))
-            .Times(0);
-
-        dawnBufferBuilderRelease(bufferBuilder);
-    }
-
-    // If the builder has been consumed, and the object is destroyed before the result comes from
-    // the server, then the callback is fired with unknown
-    {
-        DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
-        dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 5, 6);
-        DawnBuffer buffer = dawnBufferBuilderGetResult(bufferBuilder);
-
-        EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 5, 6))
-            .Times(1);
-
-        dawnBufferRelease(buffer);
-    }
-}
-
-// Test that a builder success status doesn't get forwarded to the device
-TEST_F(WireCallbackTests, SuccessCallbackNotForwardedToDevice) {
-    dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, 0);
-
-    DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
-    dawnBufferBuilderGetResult(bufferBuilder);
-
-    DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
-        .WillOnce(Return(apiBufferBuilder));
-
-    DawnBuffer apiBuffer = api.GetNewBuffer();
-    EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
-        .WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
-            api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS,
-                                         "I like cheese");
-            return apiBuffer;
-        }));
-
-    FlushClient();
-    FlushServer();
-}
-
-// Test that a builder error status gets forwarded to the device
-TEST_F(WireCallbackTests, ErrorCallbackForwardedToDevice) {
-    uint64_t userdata = 30495;
-    dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
-
-    DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
-    dawnBufferBuilderGetResult(bufferBuilder);
-
-    DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
-        .WillOnce(Return(apiBufferBuilder));
-
-    EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
-        .WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
-            api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_ERROR,
-                                         "Error :(");
-            return nullptr;
-        }));
-
-    FlushClient();
-
-    EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1);
-
-    FlushServer();
-}
-
-// Test the return wire for device error callbacks
-TEST_F(WireCallbackTests, DeviceErrorCallback) {
-    uint64_t userdata = 3049785;
-    dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
-
-    // Setting the error callback should stay on the client side and do nothing
-    FlushClient();
-
-    // Calling the callback on the server side will result in the callback being called on the
-    // client side
-    api.CallDeviceErrorCallback(apiDevice, "Some error message");
-
-    EXPECT_CALL(*mockDeviceErrorCallback, Call(StrEq("Some error message"), userdata)).Times(1);
-
-    FlushServer();
-}
-
-// Test the return wire for device error callbacks
-TEST_F(WireCallbackTests, BuilderErrorCallback) {
-    uint64_t userdata1 = 982734;
-    uint64_t userdata2 = 982734239028;
-
-    // Create the buffer builder, the callback is set immediately on the server side
-    DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
-
-    DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
-        .WillOnce(Return(apiBufferBuilder));
-
-    EXPECT_CALL(api, OnBuilderSetErrorCallback(apiBufferBuilder, _, _, _)).Times(1);
-
-    FlushClient();
-
-    // Setting the callback on the client side doesn't do anything on the server side
-    dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, userdata1,
-                                      userdata2);
-    FlushClient();
-
-    // Create an object so that it is a valid case to call the error callback
-    dawnBufferBuilderGetResult(bufferBuilder);
-
-    DawnBuffer apiBuffer = api.GetNewBuffer();
-    EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
-        .WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
-            api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS,
-                                         "Success!");
-            return apiBuffer;
-        }));
-
-    FlushClient();
-
-    // The error callback gets called on the client side
-    EXPECT_CALL(*mockBuilderErrorCallback,
-                Call(DAWN_BUILDER_ERROR_STATUS_SUCCESS, StrEq("Success!"), userdata1, userdata2))
-        .Times(1);
-
-    FlushServer();
-}
diff --git a/src/tests/unittests/wire/WireErrorCallbackTests.cpp b/src/tests/unittests/wire/WireErrorCallbackTests.cpp
new file mode 100644
index 0000000..d92b83c
--- /dev/null
+++ b/src/tests/unittests/wire/WireErrorCallbackTests.cpp
@@ -0,0 +1,75 @@
+// Copyright 2019 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "tests/unittests/wire/WireTest.h"
+
+using namespace testing;
+using namespace dawn_wire;
+
+namespace {
+
+    // Mock classes to add expectations on the wire calling callbacks
+    class MockDeviceErrorCallback {
+      public:
+        MOCK_METHOD2(Call, void(const char* message, DawnCallbackUserdata userdata));
+    };
+
+    std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback;
+    void ToMockDeviceErrorCallback(const char* message, DawnCallbackUserdata userdata) {
+        mockDeviceErrorCallback->Call(message, userdata);
+    }
+
+}  // anonymous namespace
+
+class WireErrorCallbackTests : public WireTest {
+  public:
+    WireErrorCallbackTests() {
+    }
+    ~WireErrorCallbackTests() override = default;
+
+    void SetUp() override {
+        WireTest::SetUp();
+
+        mockDeviceErrorCallback = std::make_unique<StrictMock<MockDeviceErrorCallback>>();
+    }
+
+    void TearDown() override {
+        WireTest::TearDown();
+
+        mockDeviceErrorCallback = nullptr;
+    }
+
+    void FlushServer() {
+        WireTest::FlushServer();
+
+        Mock::VerifyAndClearExpectations(&mockDeviceErrorCallback);
+    }
+};
+
+// Test the return wire for device error callbacks
+TEST_F(WireErrorCallbackTests, DeviceErrorCallback) {
+    uint64_t userdata = 3049785;
+    dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
+
+    // Setting the error callback should stay on the client side and do nothing
+    FlushClient();
+
+    // Calling the callback on the server side will result in the callback being called on the
+    // client side
+    api.CallDeviceErrorCallback(apiDevice, "Some error message");
+
+    EXPECT_CALL(*mockDeviceErrorCallback, Call(StrEq("Some error message"), userdata)).Times(1);
+
+    FlushServer();
+}
diff --git a/src/tests/unittests/wire/WireFenceTests.cpp b/src/tests/unittests/wire/WireFenceTests.cpp
index a5275a3..f8d415f 100644
--- a/src/tests/unittests/wire/WireFenceTests.cpp
+++ b/src/tests/unittests/wire/WireFenceTests.cpp
@@ -45,7 +45,7 @@
 
 class WireFenceTests : public WireTest {
   public:
-    WireFenceTests() : WireTest(true) {
+    WireFenceTests() {
     }
     ~WireFenceTests() override = default;
 
diff --git a/src/tests/unittests/wire/WireInjectTextureTests.cpp b/src/tests/unittests/wire/WireInjectTextureTests.cpp
index 7c3a83b..b8e0cbe 100644
--- a/src/tests/unittests/wire/WireInjectTextureTests.cpp
+++ b/src/tests/unittests/wire/WireInjectTextureTests.cpp
@@ -22,7 +22,7 @@
 
 class WireInjectTextureTests : public WireTest {
   public:
-    WireInjectTextureTests() : WireTest(true) {
+    WireInjectTextureTests() {
     }
     ~WireInjectTextureTests() override = default;
 };
diff --git a/src/tests/unittests/wire/WireOptionalTests.cpp b/src/tests/unittests/wire/WireOptionalTests.cpp
index 59b5206..55b67ed 100644
--- a/src/tests/unittests/wire/WireOptionalTests.cpp
+++ b/src/tests/unittests/wire/WireOptionalTests.cpp
@@ -19,7 +19,7 @@
 
 class WireOptionalTests : public WireTest {
   public:
-    WireOptionalTests() : WireTest(true) {
+    WireOptionalTests() {
     }
     ~WireOptionalTests() override = default;
 };
diff --git a/src/tests/unittests/wire/WireTest.cpp b/src/tests/unittests/wire/WireTest.cpp
index 7bc94e0..94aa7cd 100644
--- a/src/tests/unittests/wire/WireTest.cpp
+++ b/src/tests/unittests/wire/WireTest.cpp
@@ -21,7 +21,7 @@
 using namespace testing;
 using namespace dawn_wire;
 
-WireTest::WireTest(bool ignoreSetCallbackCalls) : mIgnoreSetCallbackCalls(ignoreSetCallbackCalls) {
+WireTest::WireTest() {
 }
 
 WireTest::~WireTest() {
@@ -87,8 +87,5 @@
 }
 
 void WireTest::SetupIgnoredCallExpectations() {
-    if (mIgnoreSetCallbackCalls) {
-        EXPECT_CALL(api, OnBuilderSetErrorCallback(_, _, _, _)).Times(AnyNumber());
-    }
     EXPECT_CALL(api, DeviceTick(_)).Times(AnyNumber());
 }
diff --git a/src/tests/unittests/wire/WireTest.h b/src/tests/unittests/wire/WireTest.h
index 3d32437..3173292 100644
--- a/src/tests/unittests/wire/WireTest.h
+++ b/src/tests/unittests/wire/WireTest.h
@@ -77,7 +77,7 @@
 
 class WireTest : public testing::Test {
   protected:
-    WireTest(bool ignoreSetCallbackCalls);
+    WireTest();
     ~WireTest() override;
 
     void SetUp() override;
@@ -96,7 +96,6 @@
 
   private:
     void SetupIgnoredCallExpectations();
-    bool mIgnoreSetCallbackCalls = false;
 
     std::unique_ptr<dawn_wire::WireServer> mWireServer;
     std::unique_ptr<dawn_wire::WireClient> mWireClient;