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

Unified Diff: mojo/public/bindings/tests/remote_ptr_unittest.cc

Issue 150713002: Mojo: Add ErrorHandler to RemotePtr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update per review feedback Created 6 years, 11 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
« no previous file with comments | « mojo/public/bindings/tests/connector_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/bindings/tests/remote_ptr_unittest.cc
diff --git a/mojo/public/bindings/tests/remote_ptr_unittest.cc b/mojo/public/bindings/tests/remote_ptr_unittest.cc
index c99459ac0b14d66db88a609b7d3e29e1d5487df5..f495f178760b9e40f8f4f01decd280ebeaba0428 100644
--- a/mojo/public/bindings/tests/remote_ptr_unittest.cc
+++ b/mojo/public/bindings/tests/remote_ptr_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "mojo/public/bindings/error_handler.h"
#include "mojo/public/bindings/remote_ptr.h"
#include "mojo/public/environment/environment.h"
#include "mojo/public/utility/run_loop.h"
@@ -10,6 +11,22 @@
namespace mojo {
namespace test {
+namespace {
+
+class ErrorObserver : public ErrorHandler {
+ public:
+ ErrorObserver() : encountered_error_(false) {
+ }
+
+ bool encountered_error() const { return encountered_error_; }
+
+ virtual void OnError() MOJO_OVERRIDE {
+ encountered_error_ = true;
+ }
+
+ private:
+ bool encountered_error_;
+};
class MathCalculatorImpl : public math::Calculator {
public:
@@ -41,8 +58,9 @@ class MathCalculatorImpl : public math::Calculator {
class MathCalculatorUIImpl : public math::CalculatorUI {
public:
- explicit MathCalculatorUIImpl(ScopedMessagePipeHandle pipe)
- : calculator_(pipe.Pass(), this),
+ explicit MathCalculatorUIImpl(ScopedMessagePipeHandle pipe,
+ ErrorHandler* error_handler = NULL)
+ : calculator_(pipe.Pass(), this, error_handler),
output_(0.0) {
}
@@ -102,6 +120,8 @@ class RemotePtrTest : public testing::Test {
RunLoop loop_;
};
+} // namespace
+
TEST_F(RemotePtrTest, EndToEnd) {
// Suppose this is instantiated in a process that has pipe0_.
MathCalculatorImpl calculator(pipe0_.Pass());
@@ -174,5 +194,35 @@ TEST_F(RemotePtrTest, EncounteredError) {
EXPECT_TRUE(calculator_ui.encountered_error());
}
+TEST_F(RemotePtrTest, EncounteredErrorCallback) {
+ MathCalculatorImpl* calculator = new MathCalculatorImpl(pipe0_.Pass());
+
+ ErrorObserver error_observer;
+ MathCalculatorUIImpl calculator_ui(pipe1_.Pass(), &error_observer);
+
+ calculator_ui.Add(2.0);
+ PumpMessages();
+ EXPECT_EQ(2.0, calculator_ui.GetOutput());
+ EXPECT_FALSE(calculator_ui.encountered_error());
+
+ calculator_ui.Multiply(5.0);
+ EXPECT_FALSE(calculator_ui.encountered_error());
+
+ // Close the other side of the pipe.
+ delete calculator;
+
+ // The state change isn't picked up locally yet.
+ EXPECT_FALSE(calculator_ui.encountered_error());
+
+ PumpMessages();
+
+ // OK, now we see the error.
+ EXPECT_TRUE(calculator_ui.encountered_error());
+
+ // We should have also been able to observe the error through the
+ // ErrorHandler interface.
+ EXPECT_TRUE(error_observer.encountered_error());
+}
+
} // namespace test
} // namespace mojo
« no previous file with comments | « mojo/public/bindings/tests/connector_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698