Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Unified Diff: mojo/public/cpp/bindings/tests/binding_unittest.cc

Issue 1174073002: C++ bindings: support using a callback as connection error handler. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/tests/binding_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/binding_unittest.cc b/mojo/public/cpp/bindings/tests/binding_unittest.cc
index f71401cc9f0b9383654475cdc835aab08e228f89..ef232797a43cd12e79e8f7f55b4079c1d4b30a07 100644
--- a/mojo/public/cpp/bindings/tests/binding_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/binding_unittest.cc
@@ -41,37 +41,24 @@ class IntegerAccessorImpl : public sample::IntegerAccessor {
void SetInteger(int64_t data, sample::Enum type) override {}
};
-class RecordingErrorHandler : public ErrorHandler {
- public:
- RecordingErrorHandler() : error_(false) {}
- ~RecordingErrorHandler() override {}
-
- bool encountered_error() const { return error_; }
-
- private:
- // ErrorHandler implementation.
- void OnConnectionError() override { error_ = true; }
-
- bool error_;
-};
-
class BindingTest : public testing::Test {
public:
BindingTest() {}
~BindingTest() override {}
protected:
- RecordingErrorHandler handler_;
Environment env_;
RunLoop loop_;
};
// Tests that destroying a mojo::Binding closes the bound message pipe handle.
TEST_F(BindingTest, DestroyClosesMessagePipe) {
+ bool encountered_error = false;
ServiceImpl impl;
sample::ServicePtr ptr;
auto request = GetProxy(&ptr);
- ptr.set_error_handler(&handler_);
+ ptr.set_connection_error_handler(
+ [&encountered_error]() { encountered_error = true; });
bool called = false;
auto called_cb = [&called](int32_t result) { called = true; };
{
@@ -80,12 +67,12 @@ TEST_F(BindingTest, DestroyClosesMessagePipe) {
called_cb);
loop_.RunUntilIdle();
EXPECT_TRUE(called);
- EXPECT_FALSE(handler_.encountered_error());
+ EXPECT_FALSE(encountered_error);
}
// Now that the Binding is out of scope we should detect an error on the other
// end of the pipe.
loop_.RunUntilIdle();
- EXPECT_TRUE(handler_.encountered_error());
+ EXPECT_TRUE(encountered_error);
// And calls should fail.
called = false;

Powered by Google App Engine
This is Rietveld 408576698